| 227 | } |
| 228 | |
| 229 | void TxToUniv(const CTransaction& tx, const uint256& hashBlock, UniValue& entry, bool include_hex, int serialize_flags, const CTxUndo* txundo, TxVerbosity verbosity) |
| 230 | { |
| 231 | entry.pushKV("txid", tx.GetHash().GetHex()); |
| 232 | entry.pushKV("hash", tx.GetWitnessHash().GetHex()); |
| 233 | if (g_con_elementsmode) { |
| 234 | entry.pushKV("wtxid", tx.GetWitnessHash().GetHex()); |
| 235 | entry.pushKV("withash", tx.GetWitnessOnlyHash().GetHex()); |
| 236 | } |
| 237 | // Transaction version is actually unsigned in consensus checks, just signed in memory, |
| 238 | // so cast to unsigned before giving it to the user. |
| 239 | entry.pushKV("version", static_cast<int64_t>(static_cast<uint32_t>(tx.nVersion))); |
| 240 | entry.pushKV("size", (int)::GetSerializeSize(tx, PROTOCOL_VERSION)); |
| 241 | entry.pushKV("vsize", (GetTransactionWeight(tx) + WITNESS_SCALE_FACTOR - 1) / WITNESS_SCALE_FACTOR); |
| 242 | entry.pushKV("weight", GetTransactionWeight(tx)); |
| 243 | // ELEMENTS: add discountvsize |
| 244 | if (Params().GetAcceptDiscountCT()) { |
| 245 | entry.pushKV("discountvsize", GetDiscountVirtualTransactionSize(tx)); |
| 246 | entry.pushKV("discountweight", GetDiscountTransactionWeight(tx)); |
| 247 | } |
| 248 | entry.pushKV("locktime", (int64_t)tx.nLockTime); |
| 249 | |
| 250 | UniValue vin{UniValue::VARR}; |
| 251 | |
| 252 | const bool have_undo = txundo != nullptr; |
| 253 | |
| 254 | for (unsigned int i = 0; i < tx.vin.size(); i++) { |
| 255 | const CTxIn& txin = tx.vin[i]; |
| 256 | UniValue in(UniValue::VOBJ); |
| 257 | if (tx.IsCoinBase()) { |
| 258 | in.pushKV("coinbase", HexStr(txin.scriptSig)); |
| 259 | } else { |
| 260 | in.pushKV("txid", txin.prevout.hash.GetHex()); |
| 261 | in.pushKV("vout", (int64_t)txin.prevout.n); |
| 262 | UniValue o(UniValue::VOBJ); |
| 263 | o.pushKV("asm", ScriptToAsmStr(txin.scriptSig, true)); |
| 264 | o.pushKV("hex", HexStr(txin.scriptSig)); |
| 265 | in.pushKV("scriptSig", o); |
| 266 | in.pushKV("is_pegin", txin.m_is_pegin); |
| 267 | } |
| 268 | if (have_undo) { |
| 269 | const Coin& prev_coin = txundo->vprevout[i]; |
| 270 | const CTxOut& prev_txout = prev_coin.out; |
| 271 | |
| 272 | |
| 273 | if (verbosity == TxVerbosity::SHOW_DETAILS_AND_PREVOUT) { |
| 274 | UniValue o_script_pub_key(UniValue::VOBJ); |
| 275 | ScriptPubKeyToUniv(prev_txout.scriptPubKey, o_script_pub_key, /*include_hex=*/ true); |
| 276 | |
| 277 | UniValue p(UniValue::VOBJ); |
| 278 | p.pushKV("generated", bool(prev_coin.fCoinBase)); |
| 279 | p.pushKV("height", uint64_t(prev_coin.nHeight)); |
| 280 | if (prev_txout.nValue.IsExplicit()) { |
| 281 | p.pushKV("value", ValueFromAmount(prev_txout.nValue.GetAmount())); |
| 282 | } else { |
| 283 | p.pushKV("value", "<confidential>"); |
| 284 | } |
| 285 | p.pushKV("scriptPubKey", o_script_pub_key); |
| 286 | in.pushKV("prevout", p); |