Skip to content

Commit 1028882

Browse files
author
MarcoFalke
committed
Merge #17437: rpc: Expose block height of wallet transactions
a5e7795 rpc: Expose block height of wallet transactions (João Barbosa) Pull request description: Closes #17296. ACKs for top commit: practicalswift: ACK a5e7795 -- diff looks correct now (good catch @theStack!) theStack: ACK a5e7795 ryanofsky: Code review ACK a5e7795. Changes since last review getblockhash python test fixes, and removing the last hardcoded height Tree-SHA512: 57dcd0e4e7083f34016bf9cf8ef578fbfde49e882b6cd8623dd1c64716e096e62f6177a4c2ed94f5de304e751fe23fb9d11cf107a86fbf0a3c5f539cd2844916
2 parents 6d4b97c + a5e7795 commit 1028882

File tree

4 files changed

+15
-4
lines changed

4 files changed

+15
-4
lines changed

doc/release-notes-17437.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Low-level RPC Changes
2+
===
3+
4+
- The RPC gettransaction, listtransactions and listsinceblock responses now also
5+
includes the height of the block that contains the wallet transaction, if any.

src/wallet/rpcwallet.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ static void WalletTxToJSON(interfaces::Chain& chain, interfaces::Chain::Lock& lo
142142
if (confirms > 0)
143143
{
144144
entry.pushKV("blockhash", wtx.m_confirm.hashBlock.GetHex());
145+
entry.pushKV("blockheight", wtx.m_confirm.block_height);
145146
entry.pushKV("blockindex", wtx.m_confirm.nIndex);
146147
int64_t block_time;
147148
bool found_block = chain.findBlock(wtx.m_confirm.hashBlock, nullptr /* block */, &block_time);
@@ -1367,6 +1368,7 @@ static const std::string TransactionDescriptionString()
13671368
" \"generated\": xxx, (bool) Only present if transaction only input is a coinbase one.\n"
13681369
" \"trusted\": xxx, (bool) Only present if we consider transaction to be trusted and so safe to spend from.\n"
13691370
" \"blockhash\": \"hashvalue\", (string) The block hash containing the transaction.\n"
1371+
" \"blockheight\": n, (numeric) The block height containing the transaction.\n"
13701372
" \"blockindex\": n, (numeric) The index of the transaction in the block that includes it.\n"
13711373
" \"blocktime\": xxx, (numeric) The block time in seconds since epoch (1 Jan 1970 GMT).\n"
13721374
" \"txid\": \"transactionid\", (string) The transaction id.\n"

test/functional/wallet_listsinceblock.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,15 @@ def run_test(self):
4040
def test_no_blockhash(self):
4141
txid = self.nodes[2].sendtoaddress(self.nodes[0].getnewaddress(), 1)
4242
blockhash, = self.nodes[2].generate(1)
43+
blockheight = self.nodes[2].getblockheader(blockhash)['height']
4344
self.sync_all()
4445

4546
txs = self.nodes[0].listtransactions()
4647
assert_array_result(txs, {"txid": txid}, {
4748
"category": "receive",
4849
"amount": 1,
4950
"blockhash": blockhash,
51+
"blockheight": blockheight,
5052
"confirmations": 1,
5153
})
5254
assert_equal(
@@ -276,7 +278,8 @@ def test_double_send(self):
276278
self.sync_all()
277279

278280
# gettransaction should work for txid1
279-
self.nodes[0].gettransaction(txid1)
281+
tx1 = self.nodes[0].gettransaction(txid1)
282+
assert_equal(tx1['blockheight'], self.nodes[0].getblockheader(tx1['blockhash'])['height'])
280283

281284
# listsinceblock(lastblockhash) should now include txid1 in transactions
282285
# as well as in removed

test/functional/wallet_listtransactions.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,15 @@ def run_test(self):
4040
{"txid": txid},
4141
{"category": "receive", "amount": Decimal("0.1"), "confirmations": 0})
4242
# mine a block, confirmations should change:
43-
self.nodes[0].generate(1)
43+
blockhash = self.nodes[0].generate(1)[0]
44+
blockheight = self.nodes[0].getblockheader(blockhash)['height']
4445
self.sync_all()
4546
assert_array_result(self.nodes[0].listtransactions(),
4647
{"txid": txid},
47-
{"category": "send", "amount": Decimal("-0.1"), "confirmations": 1})
48+
{"category": "send", "amount": Decimal("-0.1"), "confirmations": 1, "blockhash": blockhash, "blockheight": blockheight})
4849
assert_array_result(self.nodes[1].listtransactions(),
4950
{"txid": txid},
50-
{"category": "receive", "amount": Decimal("0.1"), "confirmations": 1})
51+
{"category": "receive", "amount": Decimal("0.1"), "confirmations": 1, "blockhash": blockhash, "blockheight": blockheight})
5152

5253
# send-to-self:
5354
txid = self.nodes[0].sendtoaddress(self.nodes[0].getnewaddress(), 0.2)

0 commit comments

Comments
 (0)