mirror of
https://github.com/dashpay/dash.git
synced 2024-12-25 03:52:49 +01:00
Merge #16185: gettransaction: add an argument to decode the transaction
9965940e35c445ccded55510348af228ff22f0e9 doc: Add release note for the new gettransaction argument (darosior) b8b3f0435a2837d3897e9e232ef6ca839ce74eb8 tests: Add a new functional test for gettransaction (darosior) 7f3bb247a811582d1aa4805d8e601c19808dc7ba gettransaction: add an argument to decode the transaction (darosior) Pull request description: This PR adds a new parameter to the `gettransaction` call : `decode`. If set to `true`, it will add a new `decoded` field to the response. This mimics the behavior of `getrawtransaction`'s `verbose` argument to avoid using 2 calls if we want to decode a wallet transaction (`gettransaction` then `decoderawtransaction`). Fix #16181 . ACKs for top commit: meshcollider: re-utACK 9965940e35c445ccded55510348af228ff22f0e9 Tree-SHA512: bcb6b4bd252b3488d6afc77659c499c2ad99fd58661eb24b6a2e17014c74f22e47fde70e00fedb4f4754915786622ad02483b2cf2c4dea0ab0eb4ac8276dbeee
This commit is contained in:
parent
0c05d0b59d
commit
4c72e6966d
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.
|
@ -105,6 +105,7 @@ static const CRPCConvertParam vRPCConvertParams[] =
|
|||||||
{ "getchaintxstats", 0, "nblocks" },
|
{ "getchaintxstats", 0, "nblocks" },
|
||||||
{ "getmerkleblocks", 2, "count" },
|
{ "getmerkleblocks", 2, "count" },
|
||||||
{ "gettransaction", 1, "include_watchonly" },
|
{ "gettransaction", 1, "include_watchonly" },
|
||||||
|
{ "gettransaction", 2, "decode" },
|
||||||
{ "getrawtransaction", 1, "verbose" },
|
{ "getrawtransaction", 1, "verbose" },
|
||||||
{ "createrawtransaction", 0, "inputs" },
|
{ "createrawtransaction", 0, "inputs" },
|
||||||
{ "createrawtransaction", 1, "outputs" },
|
{ "createrawtransaction", 1, "outputs" },
|
||||||
|
@ -1655,6 +1655,7 @@ static UniValue gettransaction(const JSONRPCRequest& request)
|
|||||||
{
|
{
|
||||||
{"txid", RPCArg::Type::STR, RPCArg::Optional::NO, "The transaction id"},
|
{"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[]"},
|
{"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{
|
RPCResult{
|
||||||
RPCResult::Type::OBJ, "", "", Cat(Cat<std::vector<RPCResult>>(
|
RPCResult::Type::OBJ, "", "", Cat(Cat<std::vector<RPCResult>>(
|
||||||
@ -1688,6 +1689,10 @@ static UniValue gettransaction(const JSONRPCRequest& request)
|
|||||||
}},
|
}},
|
||||||
}},
|
}},
|
||||||
{RPCResult::Type::STR_HEX, "hex", "Raw data for transaction"},
|
{RPCResult::Type::STR_HEX, "hex", "Raw data for transaction"},
|
||||||
|
{RPCResult::Type::OBJ, "decoded", /*optional=*/true, "The decoded transaction",
|
||||||
|
{
|
||||||
|
{RPCResult::Type::ELISION, "", "Equivalent to the RPC decoderawtransaction method, or the RPC getrawtransaction method when `verbose` is passed."},
|
||||||
|
}},
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
RPCExamples{
|
RPCExamples{
|
||||||
@ -1715,6 +1720,8 @@ static UniValue gettransaction(const JSONRPCRequest& request)
|
|||||||
filter |= ISMINE_WATCH_ONLY;
|
filter |= ISMINE_WATCH_ONLY;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool decode_tx = request.params[2].isNull() ? false : request.params[2].get_bool();
|
||||||
|
|
||||||
UniValue entry(UniValue::VOBJ);
|
UniValue entry(UniValue::VOBJ);
|
||||||
auto it = pwallet->mapWallet.find(hash);
|
auto it = pwallet->mapWallet.find(hash);
|
||||||
if (it == pwallet->mapWallet.end()) {
|
if (it == pwallet->mapWallet.end()) {
|
||||||
@ -1740,6 +1747,12 @@ static UniValue gettransaction(const JSONRPCRequest& request)
|
|||||||
std::string strHex = EncodeHexTx(*wtx.tx);
|
std::string strHex = EncodeHexTx(*wtx.tx);
|
||||||
entry.pushKV("hex", strHex);
|
entry.pushKV("hex", strHex);
|
||||||
|
|
||||||
|
if (decode_tx) {
|
||||||
|
UniValue decoded(UniValue::VOBJ);
|
||||||
|
TxToUniv(*wtx.tx, uint256(), decoded, false);
|
||||||
|
entry.pushKV("decoded", decoded);
|
||||||
|
}
|
||||||
|
|
||||||
return entry;
|
return entry;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -4093,7 +4106,7 @@ static const CRPCCommand commands[] =
|
|||||||
{ "wallet", "getrawchangeaddress", &getrawchangeaddress, {} },
|
{ "wallet", "getrawchangeaddress", &getrawchangeaddress, {} },
|
||||||
{ "wallet", "getreceivedbyaddress", &getreceivedbyaddress, {"address","minconf","addlocked"} },
|
{ "wallet", "getreceivedbyaddress", &getreceivedbyaddress, {"address","minconf","addlocked"} },
|
||||||
{ "wallet", "getreceivedbylabel", &getreceivedbylabel, {"label","minconf","addlocked"} },
|
{ "wallet", "getreceivedbylabel", &getreceivedbylabel, {"label","minconf","addlocked"} },
|
||||||
{ "wallet", "gettransaction", &gettransaction, {"txid","include_watchonly"} },
|
{ "wallet", "gettransaction", &gettransaction, {"txid","include_watchonly","decode"} },
|
||||||
{ "wallet", "getunconfirmedbalance", &getunconfirmedbalance, {} },
|
{ "wallet", "getunconfirmedbalance", &getunconfirmedbalance, {} },
|
||||||
{ "wallet", "getbalances", &getbalances, {} },
|
{ "wallet", "getbalances", &getbalances, {} },
|
||||||
{ "wallet", "getwalletinfo", &getwalletinfo, {} },
|
{ "wallet", "getwalletinfo", &getwalletinfo, {} },
|
||||||
|
@ -496,6 +496,11 @@ class WalletTest(BitcoinTestFramework):
|
|||||||
self.nodes[0].setlabel(change, 'foobar')
|
self.nodes[0].setlabel(change, 'foobar')
|
||||||
assert_equal(self.nodes[0].getaddressinfo(change)['ischange'], False)
|
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__':
|
if __name__ == '__main__':
|
||||||
WalletTest().main()
|
WalletTest().main()
|
||||||
|
Loading…
Reference in New Issue
Block a user