Skip to content

Commit 551c8e9

Browse files
committed
Merge bitcoin/bitcoin#26349: rpc: make address field optional list{transactions, sinceblock} response
eb679a7 rpc: make `address` field optional (w0xlt) Pull request description: Close bitcoin/bitcoin#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 eb679a7 aureleoules: ACK eb679a7 Tree-SHA512: b267439626e2ec3134ae790c849949a4c40ef0cebd20092e8187be3db0a61941b2da10bbbba92ca880b8369f46c1aaa806d057eaa5159325f65cbec7cb33c52f
2 parents bd47889 + eb679a7 commit 551c8e9

File tree

3 files changed

+28
-2
lines changed

3 files changed

+28
-2
lines changed

src/wallet/rpc/transactions.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,7 @@ RPCHelpMan listtransactions()
447447
{RPCResult::Type::OBJ, "", "", Cat(Cat<std::vector<RPCResult>>(
448448
{
449449
{RPCResult::Type::BOOL, "involvesWatchonly", /*optional=*/true, "Only returns true if imported addresses were involved in transaction."},
450-
{RPCResult::Type::STR, "address", "The bitcoin address of the transaction."},
450+
{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)."},
451451
{RPCResult::Type::STR, "category", "The transaction category.\n"
452452
"\"send\" Transactions sent.\n"
453453
"\"receive\" Non-coinbase transactions received.\n"
@@ -561,7 +561,7 @@ RPCHelpMan listsinceblock()
561561
{RPCResult::Type::OBJ, "", "", Cat(Cat<std::vector<RPCResult>>(
562562
{
563563
{RPCResult::Type::BOOL, "involvesWatchonly", /*optional=*/true, "Only returns true if imported addresses were involved in transaction."},
564-
{RPCResult::Type::STR, "address", "The bitcoin address of the transaction."},
564+
{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)."},
565565
{RPCResult::Type::STR, "category", "The transaction category.\n"
566566
"\"send\" Transactions sent.\n"
567567
"\"receive\" Non-coinbase transactions received.\n"

test/functional/wallet_listsinceblock.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ def run_test(self):
4545
if self.options.descriptors:
4646
self.test_desc()
4747
self.test_send_to_self()
48+
self.test_op_return()
4849

4950
def test_no_blockhash(self):
5051
self.log.info("Test no blockhash")
@@ -448,6 +449,19 @@ def test_send_to_self(self):
448449
assert any(c["address"] == addr for c in coins)
449450
assert all(self.nodes[2].getaddressinfo(c["address"])["ischange"] for c in coins)
450451

452+
def test_op_return(self):
453+
"""Test if OP_RETURN outputs will be displayed correctly."""
454+
block_hash = self.nodes[2].getbestblockhash()
455+
456+
raw_tx = self.nodes[2].createrawtransaction([], [{'data': 'aa'}])
457+
funded_tx = self.nodes[2].fundrawtransaction(raw_tx)
458+
signed_tx = self.nodes[2].signrawtransactionwithwallet(funded_tx['hex'])
459+
tx_id = self.nodes[2].sendrawtransaction(signed_tx['hex'])
460+
461+
op_ret_tx = [tx for tx in self.nodes[2].listsinceblock(blockhash=block_hash)["transactions"] if tx['txid'] == tx_id][0]
462+
463+
assert 'address' not in op_ret_tx
464+
451465

452466
if __name__ == '__main__':
453467
ListSinceBlockTest().main()

test/functional/wallet_listtransactions.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ def run_test(self):
109109
self.run_rbf_opt_in_test()
110110
self.run_externally_generated_address_test()
111111
self.run_invalid_parameters_test()
112+
self.test_op_return()
112113

113114
def run_rbf_opt_in_test(self):
114115
"""Test the opt-in-rbf flag for sent and received transactions."""
@@ -284,6 +285,17 @@ def run_invalid_parameters_test(self):
284285
assert_raises_rpc_error(-8, "Negative count", self.nodes[0].listtransactions, count=-1)
285286
assert_raises_rpc_error(-8, "Negative from", self.nodes[0].listtransactions, skip=-1)
286287

288+
def test_op_return(self):
289+
"""Test if OP_RETURN outputs will be displayed correctly."""
290+
raw_tx = self.nodes[0].createrawtransaction([], [{'data': 'aa'}])
291+
funded_tx = self.nodes[0].fundrawtransaction(raw_tx)
292+
signed_tx = self.nodes[0].signrawtransactionwithwallet(funded_tx['hex'])
293+
tx_id = self.nodes[0].sendrawtransaction(signed_tx['hex'])
294+
295+
op_ret_tx = [tx for tx in self.nodes[0].listtransactions() if tx['txid'] == tx_id][0]
296+
297+
assert 'address' not in op_ret_tx
298+
287299

288300
if __name__ == '__main__':
289301
ListTransactionsTest().main()

0 commit comments

Comments
 (0)