Bitcoin Forum

Bitcoin => Bitcoin Technical Support => Topic started by: NotATether on May 10, 2023, 05:43:32 AM



Title: Checking for balances of address [range] using Bitcoin Core using descriptors
Post by: NotATether on May 10, 2023, 05:43:32 AM
I'm designing a wallet that is going to use a Bitcoin Core node to fetch balances of addresses. And yes I am storing master public keys using standard BIP44 derivation. So in other words: m/44'/0'/0'/0/[0-1000 or whatever] and m/44'/0'/0'/1/[0-1000 or whatever], for legacy addresses for example. Other types of addresses are constructed similarly.

But I cannot figure out how to fetch the balance of these xpubs as a descriptor. I would prefer the UTXOs be separated from each other and tagged with the address they belong to.

Of course, if I was working with single addresses, I could just use importaddress, but legacy wallets are deprecated and will be removed soon.

And for example, this fails with "Error -5 missing checksum": bitcoin-cli -rpcwallet=some_wallet importdescriptors '[{"desc": "addr(<address>)", "timestamp": "now"}]'

I'm running Bitcoin Core 24.0.


Title: Re: Checking for balances of address [range] using Bitcoin Core using descriptors
Post by: nc50lc on May 10, 2023, 07:19:04 AM
And for example, this fails with "Error -5 missing checksum": bitcoin-cli -rpcwallet=some_wallet importdescriptors '[{"desc": "addr(<address>)", "timestamp": "now"}]'
Checksum goes after the descriptor.

But first, to get the checksum: use getdescriptorinfo command.
Example (Regtest):
Code:
getdescriptorinfo "addr(bcrt1qjd5q9e4du3rj4f0gux9794tmf330rtaplqkel9)"
Result: -snip- "checksum": "xtu8a9fg", -snip-

Then, include it to your importdescriptors command.
Example:
Code:
importdescriptors "[{\"desc\": \"addr(bcrt1qjd5q9e4du3rj4f0gux9794tmf330rtaplqkel9)#xtu8a9fg\",\"timestamp\": \"now\"}]"


Title: Re: Checking for balances of address [range] using Bitcoin Core using descriptors
Post by: NotATether on May 10, 2023, 08:50:38 AM
I tried that, and it seemed to be rescanning the wallet (I used a real address with UTXOs after block height 690000) and then I got this:

Code:
error: timeout on transient error: Could not connect to the server 127.0.0.1:8332 (error code 0 - "timeout reached")

Make sure the bitcoind server is running and that you are connecting to the correct RPC port.

followed by this (when trying again)

Code:
error code: -4
error message:
Wallet is currently rescanning. Abort existing rescan or wait.

Which RPC do I use to check the status of the rescan?


Title: Re: Checking for balances of address [range] using Bitcoin Core using descriptors
Post by: achow101 on May 11, 2023, 02:30:42 AM
Which RPC do I use to check the status of the rescan?

getwalletinfo


Title: Re: Checking for balances of address [range] using Bitcoin Core using descriptors
Post by: NotATether on May 11, 2023, 11:09:19 AM
Which RPC do I use to check the status of the rescan?

getwalletinfo

Thanks.

I can see the UTXOs for the address, but now I would like to scan for an xpub with a derivation path and specific range. How may I do that?


Title: Re: Checking for balances of address [range] using Bitcoin Core using descriptors
Post by: nc50lc on May 11, 2023, 12:13:51 PM
-snip- but now I would like to scan for an xpub with a derivation path and specific range. How may I do that?
importdescriptors command's arguments are listed in here: https://developer.bitcoin.org/reference/rpc/importdescriptors.html (https://developer.bitcoin.org/reference/rpc/importdescriptors.html)
descriptors are documented here: https://github.com/bitcoin/bitcoin/blob/master/doc/descriptors.md (https://github.com/bitcoin/bitcoin/blob/master/doc/descriptors.md)

Here's an example extended public key with derivation path to 'external_index/address_index' ( /0/* ) and with 'range' argument.
(commonly used path for deriving receiving addresses from an xpub):
Code:
importdescriptors "[{\"desc\": \"wpkh(tpubDC8SbfxbQot4BA2kg476RyWA5EM5yawYj9ZUMbAtDeBEBgPNVTyAYRKDCLJQcbUP1yBus4Z9BUMSZANmaNGruFYnfPXwXBDLrPyU8vM7QWy/0/*)#wg24ts7y\",\"timestamp\": \"now\",\"range\": [0,100]}]"