From 46fe2d8fe42a146861a6a7c2f3dbbae018f0fe2f Mon Sep 17 00:00:00 2001 From: Cryp Toon Date: Thu, 16 May 2024 22:50:55 +0200 Subject: [PATCH] Add instructions for a readonly bitcoinlib wallet from bitcoin core --- bitcoinlib/services/services.py | 2 ++ examples/wallet_bitcoind_connected_wallets.py | 2 +- .../wallet_bitcoind_connected_wallets2.py | 19 ++++++++++--------- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/bitcoinlib/services/services.py b/bitcoinlib/services/services.py index 7c476f97..522bab08 100644 --- a/bitcoinlib/services/services.py +++ b/bitcoinlib/services/services.py @@ -78,6 +78,8 @@ def __init__(self, network=DEFAULT_NETWORK, min_providers=1, max_providers=1, pr :type exclude_providers: list of str :param strict: Strict checks of valid signatures, scripts and transactions. Normally use strict=True for wallets, transaction validations etcetera. For blockchain parsing strict=False should be used, but be sure to check warnings in the log file. Default is True. :type strict: bool + :param wallet_name: Name of wallet if connecting to bitcoin node + :type wallet_name: str """ diff --git a/examples/wallet_bitcoind_connected_wallets.py b/examples/wallet_bitcoind_connected_wallets.py index f17b479b..7acb2116 100644 --- a/examples/wallet_bitcoind_connected_wallets.py +++ b/examples/wallet_bitcoind_connected_wallets.py @@ -5,7 +5,7 @@ # EXAMPLES - Using Bitcoin Core wallets with Bitcoinlib # # Method 1 - Create wallet in Bitcoin Core and use the same wallet in Bitcoinlib using the bitcoin node to -# receive and send bitcoin transactions. +# receive and send bitcoin transactions. Only works for legacy wallets. # # © 2024 April - 1200 Web Development # diff --git a/examples/wallet_bitcoind_connected_wallets2.py b/examples/wallet_bitcoind_connected_wallets2.py index f37c60ee..8151df18 100644 --- a/examples/wallet_bitcoind_connected_wallets2.py +++ b/examples/wallet_bitcoind_connected_wallets2.py @@ -4,9 +4,9 @@ # # EXAMPLES - Using Bitcoin Core wallets with Bitcoinlib # -# Method 2 - ... +# Method 2 - Create wallet in Bitcoin Core, export public keys to bitcoinlib and easily manage wallet from bitcoinlib. # -# © 2024 April - 1200 Web Development +# © 2024 May - 1200 Web Development # from bitcoinlib.wallets import * @@ -16,14 +16,15 @@ # Settings and Initialization # -pkwif = 'cTAyLb37Sr4XQPzWCiwihJxdFpkLKeJBFeSnd5hwNiW8aqrbsZCd' +# Create wallet in Bitcoin Core and export descriptors +# $ bitcoin-cli createwallet wallet_bitcoincore2 +# $ bitcoin-cli -rpcwallet=wallet_bitcoincore2 listdescriptors -w = wallet_create_or_open("wallet_bitcoincore2", keys=pkwif, network='testnet', witness_type='segwit', - key_path=KEY_PATH_BITCOINCORE) +# Now copy the descriptor of the public master key, which looks like: wpkh([.../84h/1h/0h] +pkwif = 'tpubDDuQM8y9z4VQW5FS13BXGMxUwkUKEXc8KG5xzzbe6UsssrJDKJEygqbgMATnn6ZDwLXQ5PQipH989qWRTzFhPPZMiHxYYrG14X34vc24pD6' + +# You can create the wallet and manage it from bitcoinlib +w = wallet_create_or_open("wallet_bitcoincore2", keys=pkwif, witness_type='segwit') w.providers=['bitcoind'] -w.get_key() w.scan(scan_gap_limit=1) w.info() - -# TODO -# FIXME