| 60 | } |
| 61 | |
| 62 | void TxToJSON(const CTransaction& tx, const uint256 hashBlock, UniValue& entry) |
| 63 | { |
| 64 | uint256 txid = tx.GetHash(); |
| 65 | entry.push_back(Pair("txid", tx.GetHash().GetHex())); |
| 66 | entry.push_back(Pair("hash", tx.GetWitnessHash().GetHex())); |
| 67 | entry.push_back(Pair("size", (int)::GetSerializeSize(tx, SER_NETWORK, PROTOCOL_VERSION))); |
| 68 | entry.push_back(Pair("vsize", (int)::GetVirtualTransactionSize(tx))); |
| 69 | entry.push_back(Pair("version", tx.nVersion)); |
| 70 | entry.push_back(Pair("locktime", (int64_t)tx.nLockTime)); |
| 71 | UniValue vin(UniValue::VARR); |
| 72 | for (unsigned int i = 0; i < tx.vin.size(); i++) { |
| 73 | const CTxIn& txin = tx.vin[i]; |
| 74 | UniValue in(UniValue::VOBJ); |
| 75 | if (tx.IsCoinBase()) |
| 76 | in.push_back(Pair("coinbase", HexStr(txin.scriptSig.begin(), txin.scriptSig.end()))); |
| 77 | else { |
| 78 | in.push_back(Pair("txid", txin.prevout.hash.GetHex())); |
| 79 | in.push_back(Pair("vout", (int64_t)txin.prevout.n)); |
| 80 | UniValue o(UniValue::VOBJ); |
| 81 | o.push_back(Pair("asm", txin.scriptSig.ToString())); |
| 82 | o.push_back(Pair("hex", HexStr(txin.scriptSig.begin(), txin.scriptSig.end()))); |
| 83 | in.push_back(Pair("scriptSig", o)); |
| 84 | } |
| 85 | // Add address and value info if spentindex enabled |
| 86 | CSpentIndexValue spentInfo; |
| 87 | CSpentIndexKey spentKey(txin.prevout.hash, txin.prevout.n); |
| 88 | if (GetSpentIndex(spentKey, spentInfo)) { |
| 89 | in.push_back(Pair("value", ValueFromAmount(spentInfo.satoshis))); |
| 90 | in.push_back(Pair("valueSat", spentInfo.satoshis)); |
| 91 | if (spentInfo.hashType == 1) { |
| 92 | in.push_back(Pair("address", EncodeDestination(CKeyID(spentInfo.hashBytes)))); |
| 93 | } else if (spentInfo.hashType == 2) { |
| 94 | in.push_back(Pair("address", EncodeDestination(CScriptID(spentInfo.hashBytes)))); |
| 95 | } else if (spentInfo.hashType == 4) { |
| 96 | in.push_back(Pair("address", EncodeDestination(WitnessV0KeyHash(spentInfo.hashBytes)))); |
| 97 | } |
| 98 | } |
| 99 | if (!tx.wit.IsNull()) { |
| 100 | if (!tx.wit.vtxinwit[i].IsNull()) { |
| 101 | UniValue txinwitness(UniValue::VARR); |
| 102 | for (unsigned int j = 0; j < tx.wit.vtxinwit[i].scriptWitness.stack.size(); j++) { |
| 103 | std::vector<unsigned char> item = tx.wit.vtxinwit[i].scriptWitness.stack[j]; |
| 104 | txinwitness.push_back(HexStr(item.begin(), item.end())); |
| 105 | } |
| 106 | in.push_back(Pair("txinwitness", txinwitness)); |
| 107 | } |
| 108 | |
| 109 | } |
| 110 | in.push_back(Pair("sequence", (int64_t)txin.nSequence)); |
| 111 | vin.push_back(in); |
| 112 | } |
| 113 | entry.push_back(Pair("vin", vin)); |
| 114 | UniValue vout(UniValue::VARR); |
| 115 | for (unsigned int i = 0; i < tx.vout.size(); i++) { |
| 116 | const CTxOut& txout = tx.vout[i]; |
| 117 | UniValue out(UniValue::VOBJ); |
| 118 | out.push_back(Pair("value", ValueFromAmount(txout.nValue))); |
| 119 | out.push_back(Pair("n", (int64_t)i)); |
no test coverage detected