| 66 | using node::ReadBlockFromDisk; |
| 67 | |
| 68 | static 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 | |
| 94 | static std::vector<RPCArg> CreateTxDoc() |
| 95 | { |
no test coverage detected