bitcoind: importmulti fails (bitcoin master), use importdescriptors

But this requires a watch-only wallet, and python-bitcoinlib doesn't support
multiple wallets, so we need to unload the original one, but then we need
to generate a block, so that can't generate a new address, so we need
an address arg to generate_block.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell
2022-02-18 10:14:11 +10:30
parent c4ec1d576e
commit d0c7e18995
2 changed files with 30 additions and 12 deletions

View File

@@ -422,7 +422,7 @@ class BitcoinD(TailableProc):
# int > 0 := wait for at least N transactions
# 'tx_id' := wait for one transaction id given as a string
# ['tx_id1', 'tx_id2'] := wait until all of the specified transaction IDs
def generate_block(self, numblocks=1, wait_for_mempool=0):
def generate_block(self, numblocks=1, wait_for_mempool=0, to_addr=None):
if wait_for_mempool:
if isinstance(wait_for_mempool, str):
wait_for_mempool = [wait_for_mempool]
@@ -439,7 +439,9 @@ class BitcoinD(TailableProc):
))
# As of 0.16, generate() is removed; use generatetoaddress.
return self.rpc.generatetoaddress(numblocks, self.rpc.getnewaddress())
if to_addr is None:
to_addr = self.rpc.getnewaddress()
return self.rpc.generatetoaddress(numblocks, to_addr)
def simple_reorg(self, height, shift=0):
"""

View File

@@ -1189,9 +1189,11 @@ def test_hsmtool_dump_descriptors(node_factory, bitcoind):
out = subprocess.check_output(cmd_line).decode("utf8").split("\n")
descriptor = [l for l in out if l.startswith("wpkh(tpub")][0]
# If we switch wallet, we can't generate address: do so now.
mine_to_addr = bitcoind.rpc.getnewaddress()
# Import the descriptor to bitcoind
# FIXME: if we update the testsuite to use the upcoming 0.21 we could use
# importdescriptors instead.
try:
bitcoind.rpc.importmulti([{
"desc": descriptor,
# No need to rescan, we'll transact afterward
@@ -1199,11 +1201,25 @@ def test_hsmtool_dump_descriptors(node_factory, bitcoind):
# The default
"range": [0, 99]
}])
except JSONRPCError:
# Oh look, a new API!
# Need watch-only wallet, since descriptor has no privkeys.
bitcoind.rpc.createwallet("lightningd-ro", True)
# FIXME: No way to access non-default wallet in python-bitcoinlib
bitcoind.rpc.unloadwallet("lightningd-tests", True)
bitcoind.rpc.importdescriptors([{
"desc": descriptor,
# No need to rescan, we'll transact afterward
"timestamp": "now",
# The default
"range": [0, 99]
}])
# Funds sent to lightningd can be retrieved by bitcoind
addr = l1.rpc.newaddr()["bech32"]
txid = l1.rpc.withdraw(addr, 10**3)["txid"]
bitcoind.generate_block(1, txid)
bitcoind.generate_block(1, txid, mine_to_addr)
assert len(bitcoind.rpc.listunspent(1, 1, [addr])) == 1