Browse Source

Merge JoinMarket-Org/joinmarket-clientserver#1775: Support Bitcoin Core descriptor wallets (quick and dirty way)

f3630dc10b Support Bitcoin Core descriptor wallets (quick and dirty way) (Kristaps Kaupe)

Pull request description:

  Basically same as #1064, using `address()` descriptors and importing each watchable address separately, like with legacy wallets. There have been a lot of discussions about better proper implementation, but that requires more changes and nobody has written the code. IMHO this is better than nothing, more and more people are complaining about JoinMarket not working with newer Bitcoin Core versions (as it requires manual changes in `bitcoin.conf`).

  Note that I haven't re-tested this right now.

  Resolves #1571.

ACKs for top commit:
  laanwj:
    Tested ACK f3630dc10b. With this, i was able to recover an existing jm wallet into a new bitcoin core descriptor wallet, and get the same balances. Sending and receiving was also successful.

Tree-SHA512: 8bbce9637bdc0fa73956131f739424ee1247a659048807775d21e5f06da6053b7e93bcc4ee9a5c0dab2518ac4e5bd2bdfe0d789540d1d2c8879ab69dffe43c4c
master
merge-script 8 months ago
parent
commit
bfb01a0c31
No known key found for this signature in database
GPG Key ID: 33E472FE870C7E5D
  1. 12
      docs/USAGE.md
  2. 24
      src/jmclient/blockchaininterface.py

12
docs/USAGE.md

@ -121,19 +121,11 @@ Make sure to follow the following step.
With `bitcoind` running, do:
```
bitcoin-cli -named createwallet wallet_name=jm_wallet descriptors=false
bitcoin-cli -named createwallet wallet_name=jm_wallet disable_private_keys=true
```
If this command fails with error `Unknown named parameter descriptors`, it means you run Bitcoin Core version older than v0.21. In that case do the following instead (but it's recommended to upgrade Bitcoin Core to more recent version):
```
bitcoin-cli createwallet "jm_wallet"
```
If this command fails with error `BDB wallet creation is deprecated and will be removed in a future release. In this release it can be re-enabled temporarily with the -deprecatedrpc=create_bdb setting.`, it means you run Bitcoin Core version v26 or newer. In that case you must add `deprecatedrpc=create_bdb` setting to your `bitcoin.conf`, restart Bitcoin Core and try again.
The "jm_wallet" name is just an example. You can set any name. Alternative to this `bitcoin-cli` command: you can set a line with `wallet=..` in your
`bitcoin.conf` before starting Core (see the Bitcoin Core documentation for details). At the moment, only legacy wallets (`descriptors=false`)
work with Joinmarket. This means that Bitcoin Core needs to have been built with legacy wallet (Berkeley DB) support.
`bitcoin.conf` before starting Core (see the Bitcoin Core documentation for details).
After you create the wallet in the Bitcoin Core, you should set it in the `joinmarket.cfg`:

24
src/jmclient/blockchaininterface.py

@ -356,14 +356,11 @@ class BitcoinCoreInterface(BlockchainInterface):
log.info("Loading Bitcoin RPC wallet " + wallet_name + "...")
self._rpc("loadwallet", [wallet_name])
log.info("Done.")
# We only support legacy wallets currently
# We need to know is this legacy or descriptors wallet because there
# will be different RPC calls needed for address import.
wallet_info = self._getwalletinfo()
if "descriptors" in wallet_info and wallet_info["descriptors"]:
raise Exception(
"JoinMarket currently does not support Bitcoin Core "
"descriptor wallets, use legacy wallet (rpc_wallet_file "
"setting in joinmarket.cfg) instead. See docs/USAGE.md "
"for details.")
self.descriptors = ("descriptors" in wallet_info and
wallet_info["descriptors"])
def is_address_imported(self, addr: str) -> bool:
return len(self._rpc('getaddressinfo', [addr])['labels']) > 0
@ -429,7 +426,8 @@ class BitcoinCoreInterface(BlockchainInterface):
if method not in ['importaddress', 'walletpassphrase', 'getaccount',
'gettransaction', 'getrawtransaction', 'gettxout',
'importmulti', 'listtransactions', 'getblockcount',
'scantxoutset', 'getblock', 'getblockhash']:
'scantxoutset', 'getblock', 'getblockhash',
'importdescriptors']:
log.debug('rpc: ' + method + " " + str(args))
try:
res = self.jsonRpc.call(method, args)
@ -457,6 +455,15 @@ class BitcoinCoreInterface(BlockchainInterface):
def import_addresses(self, addr_list: Iterable[str], wallet_name: str,
restart_cb: Callable[[str], None] = None) -> None:
requests = []
if self.descriptors:
for addr in addr_list:
requests.append({
"desc": btc.get_address_descriptor(addr),
"timestamp": "now",
"label": wallet_name
})
result = self._rpc('importdescriptors', [requests])
else:
for addr in addr_list:
requests.append({
"scriptPubKey": {"address": addr},
@ -464,7 +471,6 @@ class BitcoinCoreInterface(BlockchainInterface):
"label": wallet_name,
"watchonly": True
})
result = self._rpc('importmulti', [requests, {"rescan": False}])
num_failed = 0

Loading…
Cancel
Save