Skip to content

Commit 7f3bb24

Browse files
committed
gettransaction: add an argument to decode the transaction
This adds a new boolean parameter 'decode' to the gettransaction call, which, if set to true, add a 'decoded' field to the result containing the decoded transaction
1 parent d8fc997 commit 7f3bb24

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

src/rpc/client.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ static const CRPCConvertParam vRPCConvertParams[] =
8585
{ "getblockheader", 1, "verbose" },
8686
{ "getchaintxstats", 0, "nblocks" },
8787
{ "gettransaction", 1, "include_watchonly" },
88+
{ "gettransaction", 2, "decode" },
8889
{ "getrawtransaction", 1, "verbose" },
8990
{ "createrawtransaction", 0, "inputs" },
9091
{ "createrawtransaction", 1, "outputs" },

src/wallet/rpcwallet.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1649,6 +1649,7 @@ static UniValue gettransaction(const JSONRPCRequest& request)
16491649
{
16501650
{"txid", RPCArg::Type::STR, RPCArg::Optional::NO, "The transaction id"},
16511651
{"include_watchonly", RPCArg::Type::BOOL, /* default */ "true for watch-only wallets, otherwise false", "Whether to include watch-only addresses in balance calculation and details[]"},
1652+
{"decode", RPCArg::Type::BOOL, /* default */ "false", "Whether to add a field with the decoded transaction"},
16521653
},
16531654
RPCResult{
16541655
"{\n"
@@ -1684,11 +1685,13 @@ static UniValue gettransaction(const JSONRPCRequest& request)
16841685
" ,...\n"
16851686
" ],\n"
16861687
" \"hex\" : \"data\" (string) Raw data for transaction\n"
1688+
" \"decoded\" : transaction (json object) Optional, the decoded transaction\n"
16871689
"}\n"
16881690
},
16891691
RPCExamples{
16901692
HelpExampleCli("gettransaction", "\"1075db55d416d3ca199f55b6084e2115b9345e16c5cf302fc80e9d5fbf5d48d\"")
16911693
+ HelpExampleCli("gettransaction", "\"1075db55d416d3ca199f55b6084e2115b9345e16c5cf302fc80e9d5fbf5d48d\" true")
1694+
+ HelpExampleCli("gettransaction", "\"1075db55d416d3ca199f55b6084e2115b9345e16c5cf302fc80e9d5fbf5d48d\" false true")
16921695
+ HelpExampleRpc("gettransaction", "\"1075db55d416d3ca199f55b6084e2115b9345e16c5cf302fc80e9d5fbf5d48d\"")
16931696
},
16941697
}.Check(request);
@@ -1708,6 +1711,8 @@ static UniValue gettransaction(const JSONRPCRequest& request)
17081711
filter |= ISMINE_WATCH_ONLY;
17091712
}
17101713

1714+
bool decode_tx = request.params[2].isNull() ? false : request.params[2].get_bool();
1715+
17111716
UniValue entry(UniValue::VOBJ);
17121717
auto it = pwallet->mapWallet.find(hash);
17131718
if (it == pwallet->mapWallet.end()) {
@@ -1733,6 +1738,12 @@ static UniValue gettransaction(const JSONRPCRequest& request)
17331738
std::string strHex = EncodeHexTx(*wtx.tx, pwallet->chain().rpcSerializationFlags());
17341739
entry.pushKV("hex", strHex);
17351740

1741+
if (decode_tx) {
1742+
UniValue decoded(UniValue::VOBJ);
1743+
TxToUniv(*wtx.tx, uint256(), decoded, false);
1744+
entry.pushKV("decoded", decoded);
1745+
}
1746+
17361747
return entry;
17371748
}
17381749

@@ -4175,7 +4186,7 @@ static const CRPCCommand commands[] =
41754186
{ "wallet", "getrawchangeaddress", &getrawchangeaddress, {"address_type"} },
41764187
{ "wallet", "getreceivedbyaddress", &getreceivedbyaddress, {"address","minconf"} },
41774188
{ "wallet", "getreceivedbylabel", &getreceivedbylabel, {"label","minconf"} },
4178-
{ "wallet", "gettransaction", &gettransaction, {"txid","include_watchonly"} },
4189+
{ "wallet", "gettransaction", &gettransaction, {"txid","include_watchonly","decode"} },
41794190
{ "wallet", "getunconfirmedbalance", &getunconfirmedbalance, {} },
41804191
{ "wallet", "getbalances", &getbalances, {} },
41814192
{ "wallet", "getwalletinfo", &getwalletinfo, {} },

0 commit comments

Comments
 (0)