Skip to content

Commit 0f34f54

Browse files
committed
rpc: fix regression in gettransaction
PR 16866 renamed the 'decode' argument in gettransaction to 'verbose' to make it more consistent with other RPC calls like getrawtransaction. However, it seems it inadvertently overloaded the 'details' fields when 'verbose' is passed. The result is that the original 'details' fields are no longer returned, which seems to be a breaking API change. This PR takes the simplest path to restoring the 'details' fields by renaming them from 'details' back to 'decoded', while leaving the 'verbose' argument for API consistency. It also addresses [this comment](bitcoin/bitcoin#16185 (comment)) to mention that the 'decoded' field is identical to decoderawtransaction. Update the RPC help, functional test, and release note.
1 parent 4bfef0d commit 0f34f54

File tree

3 files changed

+15
-9
lines changed

3 files changed

+15
-9
lines changed

doc/release-notes-16185.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
RPC changes
22
-----------
3-
The `gettransaction` RPC now accepts a third (boolean) argument `verbose`. If set to `true`, a new `details` field will be added to the response containing additional transaction details.
3+
The `gettransaction` RPC now accepts a third (boolean) argument `verbose`. If
4+
set to `true`, a new `decoded` field will be added to the response containing
5+
the decoded transaction. This field is equivalent to RPC `decoderawtransaction`,
6+
or RPC `getrawtransaction` when `verbose` is passed.

src/wallet/rpcwallet.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1648,8 +1648,10 @@ static UniValue gettransaction(const JSONRPCRequest& request)
16481648
"\nGet detailed information about in-wallet transaction <txid>\n",
16491649
{
16501650
{"txid", RPCArg::Type::STR, RPCArg::Optional::NO, "The transaction id"},
1651-
{"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-
{"verbose", RPCArg::Type::BOOL, /* default */ "false", "Whether to add a field with additional transaction details"},
1651+
{"include_watchonly", RPCArg::Type::BOOL, /* default */ "true for watch-only wallets, otherwise false",
1652+
"Whether to include watch-only addresses in balance calculation and details[]"},
1653+
{"verbose", RPCArg::Type::BOOL, /* default */ "false",
1654+
"Whether to include a `decoded` field containing the decoded transaction (equivalent to RPC decoderawtransaction)"},
16531655
},
16541656
RPCResult{
16551657
"{\n"
@@ -1685,7 +1687,8 @@ static UniValue gettransaction(const JSONRPCRequest& request)
16851687
" ,...\n"
16861688
" ],\n"
16871689
" \"hex\" : \"data\" (string) Raw data for transaction\n"
1688-
" \"details\" : transaction (json object) Optional, additional transaction details. This object contains the same transaction details as the `getrawtransaction` RPC method\n"
1690+
" \"decoded\" : transaction (json object) Optional, the decoded transaction (only present when `verbose` is passed), equivalent to the\n"
1691+
" RPC decoderawtransaction method, or the RPC getrawtransaction method when `verbose` is passed.\n"
16891692
"}\n"
16901693
},
16911694
RPCExamples{
@@ -1739,9 +1742,9 @@ static UniValue gettransaction(const JSONRPCRequest& request)
17391742
entry.pushKV("hex", strHex);
17401743

17411744
if (verbose) {
1742-
UniValue details(UniValue::VOBJ);
1743-
TxToUniv(*wtx.tx, uint256(), details, false);
1744-
entry.pushKV("details", details);
1745+
UniValue decoded(UniValue::VOBJ);
1746+
TxToUniv(*wtx.tx, uint256(), decoded, false);
1747+
entry.pushKV("decoded", decoded);
17451748
}
17461749

17471750
return entry;

test/functional/wallet_basic.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -499,10 +499,10 @@ def run_test(self):
499499
self.nodes[0].setlabel(change, 'foobar')
500500
assert_equal(self.nodes[0].getaddressinfo(change)['ischange'], False)
501501

502-
# Test "verbose" field value in gettransaction response
502+
# Test "decoded" field value in gettransaction `verbose` response.
503503
self.log.info("Testing verbose gettransaction...")
504504
tx = self.nodes[0].gettransaction(txid=txid, verbose=True)
505-
assert_equal(tx["details"], self.nodes[0].decoderawtransaction(tx["hex"]))
505+
assert_equal(tx["decoded"], self.nodes[0].decoderawtransaction(tx["hex"]))
506506

507507

508508
if __name__ == '__main__':

0 commit comments

Comments
 (0)