mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-19 15:14:23 +01:00
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:
@@ -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):
|
||||
"""
|
||||
|
||||
@@ -1189,21 +1189,37 @@ 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.
|
||||
bitcoind.rpc.importmulti([{
|
||||
"desc": descriptor,
|
||||
# No need to rescan, we'll transact afterward
|
||||
"timestamp": "now",
|
||||
# The default
|
||||
"range": [0, 99]
|
||||
}])
|
||||
try:
|
||||
bitcoind.rpc.importmulti([{
|
||||
"desc": descriptor,
|
||||
# No need to rescan, we'll transact afterward
|
||||
"timestamp": "now",
|
||||
# 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
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user