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

Function WalletTxToJSON

src/wallet/rpc/transactions.cpp:18–62  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

16
17namespace wallet {
18static void WalletTxToJSON(const CWallet& wallet, const CWalletTx& wtx, UniValue& entry)
19{
20 interfaces::Chain& chain = wallet.chain();
21 int confirms = wallet.GetTxDepthInMainChain(wtx);
22 entry.pushKV("confirmations", confirms);
23 if (wtx.IsCoinBase())
24 entry.pushKV("generated", true);
25 if (auto* conf = wtx.state<TxStateConfirmed>())
26 {
27 entry.pushKV("blockhash", conf->confirmed_block_hash.GetHex());
28 entry.pushKV("blockheight", conf->confirmed_block_height);
29 entry.pushKV("blockindex", conf->position_in_block);
30 int64_t block_time;
31 CHECK_NONFATAL(chain.findBlock(conf->confirmed_block_hash, FoundBlock().time(block_time)));
32 entry.pushKV("blocktime", block_time);
33 } else {
34 entry.pushKV("trusted", CachedTxIsTrusted(wallet, wtx));
35 }
36 uint256 hash = wtx.GetHash();
37 entry.pushKV("txid", hash.GetHex());
38 UniValue conflicts(UniValue::VARR);
39 for (const uint256& conflict : wallet.GetTxConflicts(wtx))
40 conflicts.push_back(conflict.GetHex());
41 entry.pushKV("walletconflicts", conflicts);
42 entry.pushKV("time", wtx.GetTxTime());
43 entry.pushKV("timereceived", int64_t{wtx.nTimeReceived});
44
45 // Add opt-in RBF status
46 std::string rbfStatus = "no";
47 if (confirms <= 0) {
48 RBFTransactionState rbfState = chain.isRBFOptIn(*wtx.tx);
49 if (rbfState == RBFTransactionState::UNKNOWN)
50 rbfStatus = "unknown";
51 else if (rbfState == RBFTransactionState::REPLACEABLE_BIP125)
52 rbfStatus = "yes";
53 }
54 entry.pushKV("bip125-replaceable", rbfStatus);
55
56 for (const std::pair<const std::string, std::string>& item : wtx.mapValue) {
57 // Skip blinding data which isn't parseable
58 if (item.first != "blindingdata") {
59 entry.pushKV(item.first, item.second);
60 }
61 }
62}
63
64struct tallyitem
65{

Callers 1

transactions.cppFile · 0.85

Calls 12

FoundBlockClass · 0.85
CachedTxIsTrustedFunction · 0.85
GetTxDepthInMainChainMethod · 0.80
findBlockMethod · 0.80
GetTxConflictsMethod · 0.80
GetTxTimeMethod · 0.80
isRBFOptInMethod · 0.80
pushKVMethod · 0.45
IsCoinBaseMethod · 0.45
GetHexMethod · 0.45
GetHashMethod · 0.45
push_backMethod · 0.45

Tested by

no test coverage detected