diff --git a/src/rpc/client.cpp b/src/rpc/client.cpp --- a/src/rpc/client.cpp +++ b/src/rpc/client.cpp @@ -79,6 +79,7 @@ {"getblockheader", 1, "verbose"}, {"getchaintxstats", 0, "nblocks"}, {"gettransaction", 1, "include_watchonly"}, + {"gettransaction", 2, "decode"}, {"getrawtransaction", 1, "verbose"}, {"createrawtransaction", 0, "inputs"}, {"createrawtransaction", 1, "outputs"}, diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -1929,6 +1929,8 @@ /* default */ "true for watch-only wallets, otherwise false", "Whether to include watch-only addresses in balance calculation " "and details[]"}, + {"decode", RPCArg::Type::BOOL, /* default */ "false", + "Whether to add a field with the decoded transaction"}, }, RPCResult{ "{\n" @@ -1990,6 +1992,8 @@ " ,...\n" " ],\n" " \"hex\" : \"data\" (string) Raw data for transaction\n" + " \"decoded\" : transaction (json object) Optional, the " + "decoded transaction\n" "}\n"}, RPCExamples{HelpExampleCli("gettransaction", "\"1075db55d416d3ca199f55b6084e2115b9345e16c" @@ -1997,6 +2001,9 @@ HelpExampleCli("gettransaction", "\"1075db55d416d3ca199f55b6084e2115b9345e16c" "5cf302fc80e9d5fbf5d48d\" true") + + HelpExampleCli("gettransaction", + "\"1075db55d416d3ca199f55b6084e2115b9345e16c" + "5cf302fc80e9d5fbf5d48d\" false true") + HelpExampleRpc("gettransaction", "\"1075db55d416d3ca199f55b6084e2115b9345e16c" "5cf302fc80e9d5fbf5d48d\"")}, @@ -2017,6 +2024,9 @@ filter |= ISMINE_WATCH_ONLY; } + bool decode_tx = + request.params[2].isNull() ? false : request.params[2].get_bool(); + UniValue entry(UniValue::VOBJ); auto it = pwallet->mapWallet.find(txid); if (it == pwallet->mapWallet.end()) { @@ -2047,6 +2057,12 @@ EncodeHexTx(*wtx.tx, pwallet->chain().rpcSerializationFlags()); entry.pushKV("hex", strHex); + if (decode_tx) { + UniValue decoded(UniValue::VOBJ); + TxToUniv(*wtx.tx, uint256(), decoded, false); + entry.pushKV("decoded", decoded); + } + return entry; } @@ -4735,7 +4751,7 @@ { "wallet", "getrawchangeaddress", getrawchangeaddress, {"address_type"} }, { "wallet", "getreceivedbyaddress", getreceivedbyaddress, {"address","minconf"} }, { "wallet", "getreceivedbylabel", getreceivedbylabel, {"label","minconf"} }, - { "wallet", "gettransaction", gettransaction, {"txid","include_watchonly"} }, + { "wallet", "gettransaction", gettransaction, {"txid","include_watchonly","decode"} }, { "wallet", "getunconfirmedbalance", getunconfirmedbalance, {} }, { "wallet", "getbalances", getbalances, {} }, { "wallet", "getwalletinfo", getwalletinfo, {} },