MCPcopy Create free account
hub / github.com/ElementsProject/elements / TxToJSON

Function TxToJSON

src/rpc/rawtransaction.cpp:68–92  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

66using node::ReadBlockFromDisk;
67
68static void TxToJSON(const CTransaction& tx, const uint256 hashBlock, UniValue& entry, CChainState& active_chainstate)
69{
70 // Call into TxToUniv() in bitcoin-common to decode the transaction hex.
71 //
72 // Blockchain contextual information (confirmations and blocktime) is not
73 // available to code in bitcoin-common, so we query them here and push the
74 // data into the returned UniValue.
75 TxToUniv(tx, uint256(), entry, true, RPCSerializationFlags());
76
77 if (!hashBlock.IsNull()) {
78 LOCK(cs_main);
79
80 entry.pushKV("blockhash", hashBlock.GetHex());
81 CBlockIndex* pindex = active_chainstate.m_blockman.LookupBlockIndex(hashBlock);
82 if (pindex) {
83 if (active_chainstate.m_chain.Contains(pindex)) {
84 entry.pushKV("confirmations", 1 + active_chainstate.m_chain.Height() - pindex->nHeight);
85 entry.pushKV("time", pindex->GetBlockTime());
86 entry.pushKV("blocktime", pindex->GetBlockTime());
87 }
88 else
89 entry.pushKV("confirmations", 0);
90 }
91 }
92}
93
94static std::vector<RPCArg> CreateTxDoc()
95{

Callers 1

getrawtransactionFunction · 0.85

Calls 10

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

Tested by

no test coverage detected