RPC/Wallet: Add "use_txids" to output of getaddressinfo

This commit is contained in:
Luke Dashjr 2019-05-05 04:10:54 +00:00
parent 022887d933
commit a00bc6f395
2 changed files with 23 additions and 0 deletions

View File

@ -542,6 +542,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{
@ -635,6 +639,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;
},
};

View File

@ -653,6 +653,16 @@ class WalletTest(BitcoinTestFramework):
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)