mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-07-01 11:11:15 +02:00
rpc: output wallet descriptors for received entries in listsinceblock
The descriptor wallets allow an application to track coins of multiple descriptors in a single wallet. However, such an application would not previously be able to (easily) tell what received coin "belongs" to what descriptor. This commit tackles this issues by adding a "wallet_desc" entry to the entries for received coins in 'listsinceblock'.
This commit is contained in:
@ -6,6 +6,7 @@
|
||||
|
||||
from test_framework.address import key_to_p2wpkh
|
||||
from test_framework.blocktools import COINBASE_MATURITY
|
||||
from test_framework.descriptors import descsum_create
|
||||
from test_framework.key import ECKey
|
||||
from test_framework.test_framework import BitcoinTestFramework
|
||||
from test_framework.messages import MAX_BIP125_RBF_SEQUENCE
|
||||
@ -39,6 +40,7 @@ class ListSinceBlockTest(BitcoinTestFramework):
|
||||
self.test_double_send()
|
||||
self.double_spends_filtered()
|
||||
self.test_targetconfirmations()
|
||||
self.test_desc()
|
||||
|
||||
def test_no_blockhash(self):
|
||||
self.log.info("Test no blockhash")
|
||||
@ -383,5 +385,44 @@ class ListSinceBlockTest(BitcoinTestFramework):
|
||||
assert_equal(original_found, False)
|
||||
assert_equal(double_found, False)
|
||||
|
||||
def test_desc(self):
|
||||
"""Make sure we can track coins by descriptor."""
|
||||
self.log.info("Test descriptor lookup by scriptPubKey.")
|
||||
|
||||
# Create a watchonly wallet tracking two multisig descriptors.
|
||||
multi_a = descsum_create("wsh(multi(1,tpubD6NzVbkrYhZ4YBNjUo96Jxd1u4XKWgnoc7LsA1jz3Yc2NiDbhtfBhaBtemB73n9V5vtJHwU6FVXwggTbeoJWQ1rzdz8ysDuQkpnaHyvnvzR/*,tpubD6NzVbkrYhZ4YHdDGMAYGaWxMSC1B6tPRTHuU5t3BcfcS3nrF523iFm5waFd1pP3ZvJt4Jr8XmCmsTBNx5suhcSgtzpGjGMASR3tau1hJz4/*))")
|
||||
multi_b = descsum_create("wsh(multi(1,tpubD6NzVbkrYhZ4YHdDGMAYGaWxMSC1B6tPRTHuU5t3BcfcS3nrF523iFm5waFd1pP3ZvJt4Jr8XmCmsTBNx5suhcSgtzpGjGMASR3tau1hJz4/*,tpubD6NzVbkrYhZ4Y2RLiuEzNQkntjmsLpPYDm3LTRBYynUQtDtpzeUKAcb9sYthSFL3YR74cdFgF5mW8yKxv2W2CWuZDFR2dUpE5PF9kbrVXNZ/*))")
|
||||
self.nodes[0].createwallet(wallet_name="wo", descriptors=True, disable_private_keys=True)
|
||||
wo_wallet = self.nodes[0].get_wallet_rpc("wo")
|
||||
wo_wallet.importdescriptors([
|
||||
{
|
||||
"desc": multi_a,
|
||||
"active": False,
|
||||
"timestamp": "now",
|
||||
},
|
||||
{
|
||||
"desc": multi_b,
|
||||
"active": False,
|
||||
"timestamp": "now",
|
||||
},
|
||||
])
|
||||
|
||||
# Send a coin to each descriptor.
|
||||
assert_equal(len(wo_wallet.listsinceblock()["transactions"]), 0)
|
||||
addr_a = self.nodes[0].deriveaddresses(multi_a, 0)[0]
|
||||
addr_b = self.nodes[0].deriveaddresses(multi_b, 0)[0]
|
||||
self.nodes[2].sendtoaddress(addr_a, 1)
|
||||
self.nodes[2].sendtoaddress(addr_b, 2)
|
||||
self.generate(self.nodes[2], 1)
|
||||
|
||||
# We can identify on which descriptor each coin was received.
|
||||
coins = wo_wallet.listsinceblock()["transactions"]
|
||||
assert_equal(len(coins), 2)
|
||||
coin_a = next(c for c in coins if c["amount"] == 1)
|
||||
assert_equal(coin_a["parent_descs"][0], multi_a)
|
||||
coin_b = next(c for c in coins if c["amount"] == 2)
|
||||
assert_equal(coin_b["parent_descs"][0], multi_b)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
ListSinceBlockTest().main()
|
||||
|
Reference in New Issue
Block a user