mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-11 22:50:59 +01:00
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
This commit is contained in:
@@ -1649,6 +1649,7 @@ static UniValue gettransaction(const JSONRPCRequest& request)
|
||||
{
|
||||
{"txid", RPCArg::Type::STR, RPCArg::Optional::NO, "The transaction id"},
|
||||
{"include_watchonly", RPCArg::Type::BOOL, /* 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"
|
||||
@@ -1684,11 +1685,13 @@ static UniValue gettransaction(const JSONRPCRequest& request)
|
||||
" ,...\n"
|
||||
" ],\n"
|
||||
" \"hex\" : \"data\" (string) Raw data for transaction\n"
|
||||
" \"decoded\" : transaction (json object) Optional, the decoded transaction\n"
|
||||
"}\n"
|
||||
},
|
||||
RPCExamples{
|
||||
HelpExampleCli("gettransaction", "\"1075db55d416d3ca199f55b6084e2115b9345e16c5cf302fc80e9d5fbf5d48d\"")
|
||||
+ HelpExampleCli("gettransaction", "\"1075db55d416d3ca199f55b6084e2115b9345e16c5cf302fc80e9d5fbf5d48d\" true")
|
||||
+ HelpExampleCli("gettransaction", "\"1075db55d416d3ca199f55b6084e2115b9345e16c5cf302fc80e9d5fbf5d48d\" false true")
|
||||
+ HelpExampleRpc("gettransaction", "\"1075db55d416d3ca199f55b6084e2115b9345e16c5cf302fc80e9d5fbf5d48d\"")
|
||||
},
|
||||
}.Check(request);
|
||||
@@ -1708,6 +1711,8 @@ static UniValue gettransaction(const JSONRPCRequest& request)
|
||||
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(hash);
|
||||
if (it == pwallet->mapWallet.end()) {
|
||||
@@ -1733,6 +1738,12 @@ static UniValue gettransaction(const JSONRPCRequest& request)
|
||||
std::string strHex = 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;
|
||||
}
|
||||
|
||||
@@ -4175,7 +4186,7 @@ static const CRPCCommand commands[] =
|
||||
{ "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, {} },
|
||||
|
||||
Reference in New Issue
Block a user