MCPcopy Create free account
hub / github.com/bitcoin/bitcoin / TxToJSON

Function TxToJSON

src/rpc/rawtransaction.cpp:58–85  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

56static constexpr decltype(CTransaction::version) DEFAULT_RAWTX_VERSION{CTransaction::CURRENT_VERSION};
57
58static void TxToJSON(const CTransaction& tx, const uint256 hashBlock, UniValue& entry,
59 Chainstate& active_chainstate, const CTxUndo* txundo = nullptr,
60 TxVerbosity verbosity = TxVerbosity::SHOW_DETAILS)
61{
62 CHECK_NONFATAL(verbosity >= TxVerbosity::SHOW_DETAILS);
63 // Call into TxToUniv() in bitcoin-common to decode the transaction hex.
64 //
65 // Blockchain contextual information (confirmations and blocktime) is not
66 // available to code in bitcoin-common, so we query them here and push the
67 // data into the returned UniValue.
68 TxToUniv(tx, /*block_hash=*/uint256(), entry, /*include_hex=*/true, txundo, verbosity);
69
70 if (!hashBlock.IsNull()) {
71 LOCK(cs_main);
72
73 entry.pushKV("blockhash", hashBlock.GetHex());
74 const CBlockIndex* pindex = active_chainstate.m_blockman.LookupBlockIndex(hashBlock);
75 if (pindex) {
76 if (active_chainstate.m_chain.Contains(*pindex)) {
77 entry.pushKV("confirmations", 1 + active_chainstate.m_chain.Height() - pindex->nHeight);
78 entry.pushKV("time", pindex->GetBlockTime());
79 entry.pushKV("blocktime", pindex->GetBlockTime());
80 }
81 else
82 entry.pushKV("confirmations", 0);
83 }
84 }
85}
86
87static std::vector<RPCArg> CreateTxDoc()
88{

Callers 1

getrawtransactionFunction · 0.85

Calls 9

TxToUnivFunction · 0.85
pushKVMethod · 0.80
LookupBlockIndexMethod · 0.80
HeightMethod · 0.80
uint256Class · 0.50
IsNullMethod · 0.45
GetHexMethod · 0.45
ContainsMethod · 0.45
GetBlockTimeMethod · 0.45

Tested by

no test coverage detected