Skip to content

Commit

Permalink
RPC/Wallet: Add "use_txids" to output of getaddressinfo
Browse files Browse the repository at this point in the history
Github-Pull: bitcoin#22693
Rebased-From: a00bc6f
  • Loading branch information
luke-jr committed Feb 21, 2024
1 parent 559a93d commit 06aafaa
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/wallet/rpc/addresses.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,10 @@ RPCHelpMan getaddressinfo()
{
{RPCResult::Type::STR, "label name", "Label name (defaults to \"\")."},
}},
{RPCResult::Type::ARR, "use_txids", "",
{
{RPCResult::Type::STR_HEX, "txid", "The ids of transactions involving this wallet which received with the address"},
}},
}
},
RPCExamples{
Expand Down Expand Up @@ -631,6 +635,15 @@ RPCHelpMan getaddressinfo()
}
ret.pushKV("labels", std::move(labels));

// NOTE: Intentionally not special-casing a single txid: while addresses
// should never be reused, it's not unexpected to have RBF result in
// multiple txids for a single use.
UniValue use_txids(UniValue::VARR);
pwallet->FindScriptPubKeyUsed(std::set<CScript>{scriptPubKey}, [&use_txids](const CWalletTx&wtx) {
use_txids.push_back(wtx.GetHash().GetHex());
});
ret.pushKV("use_txids", std::move(use_txids));

return ret;
},
};
Expand Down
10 changes: 10 additions & 0 deletions test/functional/wallet_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -655,6 +655,16 @@ def run_test(self):
assert not address_info["iswatchonly"]
assert not address_info["isscript"]
assert not address_info["ischange"]
assert_equal(address_info['use_txids'], [])

# Test getaddressinfo 'use_txids' field
addr = "mneYUmWYsuk7kySiURxCi3AGxrAqZxLgPZ"
txid_1 = self.nodes[0].sendtoaddress(addr, 1)
address_info = self.nodes[0].getaddressinfo(addr)
assert_equal(address_info['use_txids'], [txid_1])
txid_2 = self.nodes[0].sendtoaddress(addr, 1)
address_info = self.nodes[0].getaddressinfo(addr)
assert_equal(sorted(address_info['use_txids']), sorted([txid_1, txid_2]))

# Test getaddressinfo 'ischange' field on change address.
self.generate(self.nodes[0], 1, sync_fun=self.no_op)
Expand Down

0 comments on commit 06aafaa

Please sign in to comment.