简体   繁体   中英

Bitcoinlib won't return all addresses from my master public key

Made a wallet with Bitcoinlib set the key parameter to my Master Public Key. However, when trying to print a list of all my addresses using their depth=-1 flag which should show all the addresses associated with my key, however it only returns a list of 3 addresses.

Code

# Creation of the wallet was done before like so:
# Wallet.create("Ledger", keys=xpub)
# However after creating a wallet Bitcoinlib stores it locally so you don't make one everytime.
from bitcoinlib.wallets import Wallet
import base64, secrets


def base64_encode(string: str):
    b64 = base64.b64encode(string.encode('ascii'))
    return b64.decode('ascii')


def base64_decode(string: str):
    b64 = base64.b64decode(string.encode('ascii'))
    return b64.decode('ascii')


xpub = base64_decode(secrets.xpub)
wallet = Wallet("Ledger")
print(wallet.addresslist(depth=-1))

Output: ['bc1qg2rl6fjutq4knttna2cqlssjp3vlmr9g0wxvk5', 'bc1qw84m5u94tt8xujesl78yq5tnswm58r309nrmus', 'bc1qlu5yuz0vsm7r867mslgkf2v89976y8qtfflvps']

edit: I know that the master public key has a lot more addresses associated as on Electrum it already shows 30+ addresses tied to this master public key

When you create a wallet bitcoinlib only generates the master key and derivation key addresses.

To create new addresses for payment and change you can use:

wallet.new_key()

Or to get 10 new unused addresses (whether created or not):

wallet.get_keys(number_of_keys=10)

Note: The command wallet.addresslist(depth=-1) shows all generated addresses, also the masterkeys, the payment/change keys and everything in between. Normally wallet.addresslist() should be sufficient: this returns only the keys/addresses which are use for change and payment.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM