Skip to content

Commit a1d55ce

Browse files
committed
Merge bitcoin/bitcoin#23139: rpc: fix "trusted" field in TransactionDescriptionString(), add coverage
66f6efc rpc: improve TransactionDescriptionString() "generated" help (Jon Atack) 296cfa3 test: add listtransactions/listsinceblock "trusted" coverage (Jon Atack) d95913f rpc: fix "trusted" description in TransactionDescriptionString (Jon Atack) Pull request description: The RPC gettransaction, listtransactions, and listsinceblock helps returned by `TransactionDescriptionString()` inform the user that the `trusted` boolean field is only present if the transaction is trusted and safe to spend from. The field is in fact returned by `WalletTxToJSON()` when the transaction has 0 confirmations (or negative confirmations, if conflicted), and it can be true or false. This patch fixes the help, adds test coverage, and touches up the help for the neighboring `generate` field. ACKs for top commit: rajarshimaitra: tACK bitcoin/bitcoin@66f6efc theStack: Tested ACK 66f6efc Tree-SHA512: 4c2127765b82780e07bbdbf519d27163d414d9f15598e01e02210f210e6009be344c84951d7274e747b1386991d4c3b082cd25aebe885fb8cf0b92d57178f68e
2 parents 91c7d66 + 66f6efc commit a1d55ce

File tree

4 files changed

+18
-6
lines changed

4 files changed

+18
-6
lines changed

src/wallet/rpcwallet.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1389,8 +1389,9 @@ static const std::vector<RPCResult> TransactionDescriptionString()
13891389
{
13901390
return{{RPCResult::Type::NUM, "confirmations", "The number of confirmations for the transaction. Negative confirmations means the\n"
13911391
"transaction conflicted that many blocks ago."},
1392-
{RPCResult::Type::BOOL, "generated", /* optional */ true, "Only present if transaction only input is a coinbase one."},
1393-
{RPCResult::Type::BOOL, "trusted", /* optional */ true, "Only present if we consider transaction to be trusted and so safe to spend from."},
1392+
{RPCResult::Type::BOOL, "generated", /* optional */ true, "Only present if the transaction's only input is a coinbase one."},
1393+
{RPCResult::Type::BOOL, "trusted", /* optional */ true, "Whether we consider the transaction to be trusted and safe to spend from.\n"
1394+
"Only present when the transaction has 0 confirmations (or negative confirmations, if conflicted)."},
13941395
{RPCResult::Type::STR_HEX, "blockhash", /* optional */ true, "The block hash containing the transaction."},
13951396
{RPCResult::Type::NUM, "blockheight", /* optional */ true, "The block height containing the transaction."},
13961397
{RPCResult::Type::NUM, "blockindex", /* optional */ true, "The index of the transaction in the block that includes it."},
@@ -1408,7 +1409,7 @@ static const std::vector<RPCResult> TransactionDescriptionString()
14081409
{RPCResult::Type::NUM_TIME, "timereceived", "The time received expressed in " + UNIX_EPOCH_TIME + "."},
14091410
{RPCResult::Type::STR, "comment", /* optional */ true, "If a comment is associated with the transaction, only present if not empty."},
14101411
{RPCResult::Type::STR, "bip125-replaceable", "(\"yes|no|unknown\") Whether this transaction could be replaced due to BIP125 (replace-by-fee);\n"
1411-
"may be unknown for unconfirmed transactions not in the mempool"}};
1412+
"may be unknown for unconfirmed transactions not in the mempool."}};
14121413
}
14131414

14141415
static RPCHelpMan listtransactions()

test/functional/wallet_import_rescan.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ def check(self, txid=None, amount=None, confirmation_height=None):
9999
assert_equal(tx["label"], self.label)
100100
assert_equal(tx["txid"], txid)
101101
assert_equal(tx["confirmations"], 1 + current_height - confirmation_height)
102-
assert_equal("trusted" not in tx, True)
102+
assert "trusted" not in tx
103103

104104
address, = [ad for ad in addresses if txid in ad["txids"]]
105105
assert_equal(address["address"], self.address["address"])

test/functional/wallet_listsinceblock.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,14 @@ def run_test(self):
4444
def test_no_blockhash(self):
4545
self.log.info("Test no blockhash")
4646
txid = self.nodes[2].sendtoaddress(self.nodes[0].getnewaddress(), 1)
47+
self.sync_all()
48+
assert_array_result(self.nodes[0].listtransactions(), {"txid": txid}, {
49+
"category": "receive",
50+
"amount": 1,
51+
"confirmations": 0,
52+
"trusted": False,
53+
})
54+
4755
blockhash, = self.generate(self.nodes[2], 1)
4856
blockheight = self.nodes[2].getblockheader(blockhash)['height']
4957
self.sync_all()
@@ -56,6 +64,9 @@ def test_no_blockhash(self):
5664
"blockheight": blockheight,
5765
"confirmations": 1,
5866
})
67+
assert_equal(len(txs), 1)
68+
assert "trusted" not in txs[0]
69+
5970
assert_equal(
6071
self.nodes[0].listsinceblock(),
6172
{"lastblock": blockhash,

test/functional/wallet_listtransactions.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@ def run_test(self):
3131
self.sync_all()
3232
assert_array_result(self.nodes[0].listtransactions(),
3333
{"txid": txid},
34-
{"category": "send", "amount": Decimal("-0.1"), "confirmations": 0})
34+
{"category": "send", "amount": Decimal("-0.1"), "confirmations": 0, "trusted": True})
3535
assert_array_result(self.nodes[1].listtransactions(),
3636
{"txid": txid},
37-
{"category": "receive", "amount": Decimal("0.1"), "confirmations": 0})
37+
{"category": "receive", "amount": Decimal("0.1"), "confirmations": 0, "trusted": False})
3838
self.log.info("Test confirmations change after mining a block")
3939
blockhash = self.generate(self.nodes[0], 1)[0]
4040
blockheight = self.nodes[0].getblockheader(blockhash)['height']

0 commit comments

Comments
 (0)