0
0
Fork 0
mirror of https://github.com/bitcoin/bitcoin.git synced 2025-02-03 09:56:38 -05:00

Merge bitcoin/bitcoin#26349: rpc: make address field optional list{transactions, sinceblock} response

eb679a7896 rpc: make `address` field optional (w0xlt)

Pull request description:

  Close https://github.com/bitcoin/bitcoin/issues/26338.

  This PR makes optional the `address` field in the response of `listtransactions` and `listsinceblock` RPC.
  And adds two tests that fail on master, but not on this branch.

ACKs for top commit:
  achow101:
    ACK eb679a7896
  aureleoules:
    ACK eb679a7896

Tree-SHA512: b267439626e2ec3134ae790c849949a4c40ef0cebd20092e8187be3db0a61941b2da10bbbba92ca880b8369f46c1aaa806d057eaa5159325f65cbec7cb33c52f
This commit is contained in:
Andrew Chow 2022-10-27 13:08:40 -04:00
commit 551c8e9526
No known key found for this signature in database
GPG key ID: 17565732E08E5E41
3 changed files with 28 additions and 2 deletions

View file

@ -447,7 +447,7 @@ RPCHelpMan listtransactions()
{RPCResult::Type::OBJ, "", "", Cat(Cat<std::vector<RPCResult>>(
{
{RPCResult::Type::BOOL, "involvesWatchonly", /*optional=*/true, "Only returns true if imported addresses were involved in transaction."},
{RPCResult::Type::STR, "address", "The bitcoin address of the transaction."},
{RPCResult::Type::STR, "address", /*optional=*/true, "The bitcoin address of the transaction (not returned if the output does not have an address, e.g. OP_RETURN null data)."},
{RPCResult::Type::STR, "category", "The transaction category.\n"
"\"send\" Transactions sent.\n"
"\"receive\" Non-coinbase transactions received.\n"
@ -561,7 +561,7 @@ RPCHelpMan listsinceblock()
{RPCResult::Type::OBJ, "", "", Cat(Cat<std::vector<RPCResult>>(
{
{RPCResult::Type::BOOL, "involvesWatchonly", /*optional=*/true, "Only returns true if imported addresses were involved in transaction."},
{RPCResult::Type::STR, "address", "The bitcoin address of the transaction."},
{RPCResult::Type::STR, "address", /*optional=*/true, "The bitcoin address of the transaction (not returned if the output does not have an address, e.g. OP_RETURN null data)."},
{RPCResult::Type::STR, "category", "The transaction category.\n"
"\"send\" Transactions sent.\n"
"\"receive\" Non-coinbase transactions received.\n"

View file

@ -45,6 +45,7 @@ class ListSinceBlockTest(BitcoinTestFramework):
if self.options.descriptors:
self.test_desc()
self.test_send_to_self()
self.test_op_return()
def test_no_blockhash(self):
self.log.info("Test no blockhash")
@ -448,6 +449,19 @@ class ListSinceBlockTest(BitcoinTestFramework):
assert any(c["address"] == addr for c in coins)
assert all(self.nodes[2].getaddressinfo(c["address"])["ischange"] for c in coins)
def test_op_return(self):
"""Test if OP_RETURN outputs will be displayed correctly."""
block_hash = self.nodes[2].getbestblockhash()
raw_tx = self.nodes[2].createrawtransaction([], [{'data': 'aa'}])
funded_tx = self.nodes[2].fundrawtransaction(raw_tx)
signed_tx = self.nodes[2].signrawtransactionwithwallet(funded_tx['hex'])
tx_id = self.nodes[2].sendrawtransaction(signed_tx['hex'])
op_ret_tx = [tx for tx in self.nodes[2].listsinceblock(blockhash=block_hash)["transactions"] if tx['txid'] == tx_id][0]
assert 'address' not in op_ret_tx
if __name__ == '__main__':
ListSinceBlockTest().main()

View file

@ -109,6 +109,7 @@ class ListTransactionsTest(BitcoinTestFramework):
self.run_rbf_opt_in_test()
self.run_externally_generated_address_test()
self.run_invalid_parameters_test()
self.test_op_return()
def run_rbf_opt_in_test(self):
"""Test the opt-in-rbf flag for sent and received transactions."""
@ -284,6 +285,17 @@ class ListTransactionsTest(BitcoinTestFramework):
assert_raises_rpc_error(-8, "Negative count", self.nodes[0].listtransactions, count=-1)
assert_raises_rpc_error(-8, "Negative from", self.nodes[0].listtransactions, skip=-1)
def test_op_return(self):
"""Test if OP_RETURN outputs will be displayed correctly."""
raw_tx = self.nodes[0].createrawtransaction([], [{'data': 'aa'}])
funded_tx = self.nodes[0].fundrawtransaction(raw_tx)
signed_tx = self.nodes[0].signrawtransactionwithwallet(funded_tx['hex'])
tx_id = self.nodes[0].sendrawtransaction(signed_tx['hex'])
op_ret_tx = [tx for tx in self.nodes[0].listtransactions() if tx['txid'] == tx_id][0]
assert 'address' not in op_ret_tx
if __name__ == '__main__':
ListTransactionsTest().main()