mirror of
https://github.com/ElementsProject/elements.git
synced 2026-08-19 13:27:35 +02:00
Merge 33f9750b1b into merged_master (Bitcoin PR #16185)
This commit is contained in:
commit
d73a5a5a8d
5 changed files with 24 additions and 4 deletions
3
doc/release-notes-16185.md
Normal file
3
doc/release-notes-16185.md
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
RPC changes
|
||||
-----------
|
||||
The `gettransaction` RPC now accepts a third (boolean) argument `decode`. If set to `true`, a new `decoded` field will be added to the response containing the decoded transaction.
|
||||
|
|
@ -85,6 +85,7 @@ static const CRPCConvertParam vRPCConvertParams[] =
|
|||
{ "getblockheader", 1, "verbose" },
|
||||
{ "getchaintxstats", 0, "nblocks" },
|
||||
{ "gettransaction", 1, "include_watchonly" },
|
||||
{ "gettransaction", 2, "decode" },
|
||||
{ "getrawtransaction", 1, "verbose" },
|
||||
{ "createrawtransaction", 0, "inputs" },
|
||||
{ "createrawtransaction", 1, "outputs" },
|
||||
|
|
|
|||
|
|
@ -1869,6 +1869,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"},
|
||||
{"assetlabel", RPCArg::Type::STR, RPCArg::Optional::OMITTED_NAMED_ARG, "Hex asset id or asset label for balance."},
|
||||
},
|
||||
RPCResult{
|
||||
|
|
@ -1905,11 +1906,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);
|
||||
|
|
@ -1929,9 +1932,11 @@ static UniValue gettransaction(const JSONRPCRequest& request)
|
|||
filter |= ISMINE_WATCH_ONLY;
|
||||
}
|
||||
|
||||
bool decode_tx = request.params[2].isNull() ? false : request.params[2].get_bool();
|
||||
|
||||
std::string asset = "";
|
||||
if (request.params[2].isStr() && !request.params[2].get_str().empty()) {
|
||||
asset = request.params[2].get_str();
|
||||
if (request.params[3].isStr() && !request.params[3].get_str().empty()) {
|
||||
asset = request.params[3].get_str();
|
||||
}
|
||||
|
||||
UniValue entry(UniValue::VOBJ);
|
||||
|
|
@ -1968,6 +1973,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;
|
||||
}
|
||||
|
||||
|
|
@ -6619,7 +6630,7 @@ static const CRPCCommand commands[] =
|
|||
{ "wallet", "getrawchangeaddress", &getrawchangeaddress, {"address_type"} },
|
||||
{ "wallet", "getreceivedbyaddress", &getreceivedbyaddress, {"address","minconf","assetlabel"} },
|
||||
{ "wallet", "getreceivedbylabel", &getreceivedbylabel, {"label","minconf","assetlabel"} },
|
||||
{ "wallet", "gettransaction", &gettransaction, {"txid","include_watchonly","assetlabel"} },
|
||||
{ "wallet", "gettransaction", &gettransaction, {"txid","include_watchonly","decode","assetlabel"} },
|
||||
{ "wallet", "getunconfirmedbalance", &getunconfirmedbalance, {} },
|
||||
{ "wallet", "getbalances", &getbalances, {} },
|
||||
{ "wallet", "getwalletinfo", &getwalletinfo, {} },
|
||||
|
|
|
|||
|
|
@ -218,7 +218,7 @@ class CTTest (BitcoinTestFramework):
|
|||
assert found_unblinded
|
||||
|
||||
assert_equal(self.nodes[1].gettransaction(raw_tx_id, True)['amount']["bitcoin"], value3)
|
||||
assert_equal(self.nodes[1].gettransaction(raw_tx_id, True, "bitcoin")['amount'], value3)
|
||||
assert_equal(self.nodes[1].gettransaction(raw_tx_id, True, False, "bitcoin")['amount'], value3)
|
||||
list_unspent = self.nodes[1].listunspent(1, 9999999, [], True, {"asset": "bitcoin"})
|
||||
assert_equal(list_unspent[0]['amount']+list_unspent[1]['amount'], value1+value3)
|
||||
received_by_address = self.nodes[1].listreceivedbyaddress(1, False, True)
|
||||
|
|
|
|||
|
|
@ -507,6 +507,11 @@ class WalletTest(BitcoinTestFramework):
|
|||
self.nodes[0].setlabel(change, 'foobar')
|
||||
assert_equal(self.nodes[0].getaddressinfo(change)['ischange'], False)
|
||||
|
||||
# Test "decoded" field value in gettransaction response
|
||||
self.log.info("Testing gettransaction decoding...")
|
||||
tx = self.nodes[0].gettransaction(txid=txid, decode=True)
|
||||
assert_equal(tx["decoded"], self.nodes[0].decoderawtransaction(tx["hex"]))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
WalletTest().main()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue