Close #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.
291 | @@ -284,6 +292,22 @@ def run_invalid_parameters_test(self): 292 | assert_raises_rpc_error(-8, "Negative count", self.nodes[0].listtransactions, count=-1) 293 | assert_raises_rpc_error(-8, "Negative from", self.nodes[0].listtransactions, skip=-1) 294 | 295 | + def test_op_return(self): 296 | + 297 | + data = random_bytes(8)
Does it need to be random?
291 | @@ -284,6 +292,22 @@ def run_invalid_parameters_test(self): 292 | assert_raises_rpc_error(-8, "Negative count", self.nodes[0].listtransactions, count=-1) 293 | assert_raises_rpc_error(-8, "Negative from", self.nodes[0].listtransactions, skip=-1) 294 | 295 | + def test_op_return(self): 296 | + 297 | + data = random_bytes(8) 298 | + 299 | + tx = CTransaction() 300 | + tx.vout = [CTxOut(nValue=2, scriptPubKey=CScript([OP_RETURN, data]))]
would be shorter to just call createrawtransaction '[]' '[{"data":"aa"}]'?
Done in Done in https://github.com/bitcoin/bitcoin/pull/26349/commits/670395cfa65988ab09afd59854d0d64c0c1438ba. Thanks.
Thanks, Concept ACK
<!--e57a25ab6845829454e8d69fc972939a-->
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.
<!--174a7506f384e20aa4161008e828411d-->
Reviewers, this pull request conflicts with the following ones:
label to listsinceblock by brunoerg)If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.
Concept ACK.
560 | @@ -561,7 +561,7 @@ RPCHelpMan listsinceblock() 561 | {RPCResult::Type::OBJ, "", "", Cat(Cat<std::vector<RPCResult>>( 562 | { 563 | {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."}, 565 | + {RPCResult::Type::STR, "address", /*optional=*/true, "The bitcoin address of the transaction."},
It might be helpful to describe in these two changed helps why (in what case) the address wouldn't be returned.
Done in 078199c245cc475bb594930177fd505d84fede4b.
Thanks for updating! The spelling linter doesn't like "ommited"
src/wallet/rpc/transactions.cpp:450: ommited ==> omitted
src/wallet/rpc/transactions.cpp:564: ommited ==> omitted
Maybe something like:
"The bitcoin address of the transaction (not returned if the transaction contains OP_RETURN null data)."
Done in https://github.com/bitcoin/bitcoin/pull/26349/commits/b725cbea13b0f4774abbdf939b3ffe224fc63696. Thanks for the suggestion.
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)
In your diff in both test files (see #26257):
assert 'address' not in op_ret_tx
This avoids the python linter raising locally and needing to update #26257
test/functional/wallet_listsinceblock.py:463:15: E275 missing whitespace after keyword
test/functional/wallet_listtransactions.py:297:15: E275 missing whitespace after keyword
Done in 078199c245cc475bb594930177fd505d84fede4b.
284 | @@ -284,6 +285,17 @@ def run_invalid_parameters_test(self): 285 | assert_raises_rpc_error(-8, "Negative count", self.nodes[0].listtransactions, count=-1) 286 | assert_raises_rpc_error(-8, "Negative from", self.nodes[0].listtransactions, skip=-1) 287 | 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'}])
In your diff in both test files, if you retouch
raw_tx = self.nodes[0].createrawtransaction([], [{'data': 'aa'}])
Done in 078199c245cc475bb594930177fd505d84fede4b. Thanks.
Also in https://github.com/bitcoin/bitcoin/pull/26349/files#diff-33258976a327dfd9623df9379f0fd15e15c32a1488d658912e3973d2e0bf7a74R456 if you retouch (thanks!)
Approach ACK
ACK modulo two comments
446 | @@ -447,7 +447,7 @@ RPCHelpMan listtransactions() 447 | {RPCResult::Type::OBJ, "", "", Cat(Cat<std::vector<RPCResult>>( 448 | { 449 | {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."}, 451 | + {RPCResult::Type::STR, "address", /*optional=*/true, "The bitcoin address of the transaction (not returned if the transaction contains OP_RETURN null data)."},
I don't think this is true. A scriptpubkey can be nonstandard, but that doesn't imply it has an OP_RETURN
Also (unrelated): A transaction does not have an address. At most it is the address of the output
Is the following message better ?
not returned if the output address cannot be decoded (such as OP_RETURN null data).
I think "does not have an address" is more correct. "cannot be decoded" implies that there is a correct way to encode addresses in a transaction, but that's not correct as addresses are not encoded into transactions, they are turned into scripts.
ACK eb679a7896ce00e322972a011b023661766923b9
I was able to verify that this PR fixes the original issue by reproducing the crash on master+mainnet (with --enable-debug) using the following steps:
$ ./src/bitcoind -blockfilterindex
$ ./src/bitcoin-cli -named createwallet wallet_name=26349 disable_private_keys=true
$ ./src/bitcoin-cli -rpcwallet=26349 importdescriptors '[{"desc": "raw(6a20a015693871d8bde65f57ec82f52f6b192e9a11fa26a37e63e17dc3092c6c7fab)#jgvt3p6e", "timestamp": 1516693300}]'
$ ./src/bitcoin-cli -rpcwallet=26349 listtransactions '*' 500
error code: -1
error message:
Internal bug detected: "std::any_of(m_results.m_results.begin(), m_results.m_results.end(), [&ret](const RPCResult& res) { return res.MatchesType(ret); })"
rpc/util.cpp:587 (HandleRequest)
Please report this issue here: https://github.com/bitcoin/bitcoin/issues
Then on this PR:
$ ./src/bitcoin-cli loadwallet 26349
$ ./src/bitcoin-cli -rpcwallet=26349 listtransactions '*' 500
[
{
"parent_descs": [
"raw(6a20a015693871d8bde65f57ec82f52f6b192e9a11fa26a37e63e17dc3092c6c7fab)#jgvt3p6e"
],
"category": "receive",
"amount": 0.00000000,
"vout": 1,
"confirmations": 254851,
"blockhash": "00000000000000000025a92c80f5c259ca5d9d36d407906dbefbd8075c3ae77b",
"blockheight": 505672,
"blockindex": 857,
"blocktime": 1516693344,
"txid": "b6439e1c9eb3915b3cc89871d2c2479f3f1847f0c7bab252c3ebc503b8f6d344",
"wtxid": "393cfba86cb0d3274850aa461dab433b5d62c1dce68dc10d43de969b8dec2359",
"walletconflicts": [
],
"time": 1516693344,
"timereceived": 1666874521,
"bip125-replaceable": "no"
}
]
ACK eb679a7896ce00e322972a011b023661766923b9
For some reason github is not detecting that this was merged.
Post-merge ACK