How to use the bitcoinlib.wallets.HDWallet function in bitcoinlib

To help you get started, we’ve selected a few bitcoinlib examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github 1200wd / bitcoinlib / tools / cli-wallet.py View on Github external
if wallet_delete(args.wallet_name, force=True, databasefile=databasefile):
                clw_exit("\nWallet %s has been removed" % args.wallet_name)
            else:
                clw_exit("\nError when deleting wallet")
        else:
            clw_exit("\nSpecified wallet name incorrect")

    wlt = None
    if args.wallet_name and not args.wallet_name.isdigit() and \
            not wallet_exists(args.wallet_name, databasefile=databasefile):
        if input("Wallet %s does not exist, create new wallet [yN]? " % args.wallet_name).lower() == 'y':
            wlt = create_wallet(args.wallet_name, args, databasefile)
            args.wallet_info = True
    else:
        try:
            wlt = HDWallet(args.wallet_name, databasefile=databasefile)
            if args.passphrase is not None or args.passphrase_strength is not None:
                print("WARNING: Using passphrase options for existing wallet ignored")
        except WalletError as e:
            clw_exit("Error: %s" % e.msg)
    if wlt is None:
        clw_exit("Could not open wallet %s" % args.wallet_name)

    if args.receive:
        addr = wlt.get_key().address
        print("Receive address is %s" % addr)
        if QRCODES_AVAILABLE:
            qrcode = pyqrcode.create(addr)
            print(qrcode.terminal())
        else:
            print("Install qr code module to show QR codes: pip install pyqrcode")
        clw_exit()
github 1200wd / bitcoinlib / tools / cli-wallet.py View on Github external
def create_wallet(wallet_name, args, databasefile):
    print("\nCREATE wallet '%s' (%s network)" % (wallet_name, args.network))
    if args.create_multisig:
        if not isinstance(args.create_multisig, list) or len(args.create_multisig) < 3:
            clw_exit("Please enter multisig creation parameter in the following format: "
                     "   [ ... ]")
        try:
            sigs_required = int(args.create_multisig[0])
        except ValueError:
            clw_exit("Number of signatures required (first argument) must be a numeric value. %s" %
                     args.create_multisig[0])
        key_list = args.create_multisig[1:]
        return HDWallet.create_multisig(name=wallet_name, key_list=key_list, sigs_required=sigs_required,
                                        network=args.network, databasefile=databasefile)
    else:
        passphrase = args.passphrase
        if passphrase is None:
            inp_passphrase = Mnemonic('english').generate(args.passphrase_strength)
            print("\nYour mnemonic private key sentence is: %s" % inp_passphrase)
            print("\nPlease write down on paper and backup. With this key you can restore your wallet and all keys")
            passphrase = inp_passphrase.split(' ')
            inp = input("\nType 'yes' if you understood and wrote down your key: ")
            if inp not in ['yes', 'Yes', 'YES']:
                clw_exit("Exiting...")
        elif not passphrase:
            passphrase = input("Enter Passphrase: ")
        if not isinstance(passphrase, list):
            passphrase = passphrase.split(' ')
        elif len(passphrase) == 1:
github 1200wd / bitcoinlib / bitcoinlib / tools / clw.py View on Github external
else:
                clw_exit("\nError when deleting wallet")
        else:
            clw_exit("\nSpecified wallet name incorrect")

    wlt = None
    if args.wallet_name and not args.wallet_name.isdigit() and not wallet_exists(args.wallet_name,
                                                                                 db_uri=db_uri):
        if not args.create_from_key and input(
                    "Wallet %s does not exist, create new wallet [yN]? " % args.wallet_name).lower() != 'y':
            clw_exit('Aborted')
        wlt = create_wallet(args.wallet_name, args, db_uri)
        args.wallet_info = True
    else:
        try:
            wlt = HDWallet(args.wallet_name, db_uri=db_uri)
            if args.passphrase is not None:
                print("WARNING: Using passphrase option for existing wallet ignored")
            if args.create_from_key is not None:
                print("WARNING: Using create_from_key option for existing wallet ignored")
        except WalletError as e:
            clw_exit("Error: %s" % e.msg)

    if wlt is None:
        clw_exit("Could not open wallet %s" % args.wallet_name)

    if args.import_private:
        if wlt.import_key(args.import_private):
            clw_exit("Private key imported")
        else:
            clw_exit("Failed to import key")
github 1200wd / bitcoinlib / bitcoinlib / tools / wallet_multisig_3of5.py View on Github external
cosigners_private.append(cosigner['name'])
        cosigner['hdkey'] = hdkey
        key_list.append(hdkey)

    # YOU SHOULD ENABLE THIS CHECK FOR REAL WALLETS
    # if len(cosigners_private) > 1:
    #    raise ValueError("It is strongly advised to use not more then 1 private key per wallet.")

    if len(key_list) != SIGS_N:
        raise ValueError("Number of cosigners (%d) is different then expected. SIG_N=%d" % (len(key_list), SIGS_N))
    wallet3o5 = HDWallet.create_multisig(WALLET_NAME, key_list, SIGS_REQUIRED, sort_keys=True, network=NETWORK)
    wallet3o5.new_key()

    print("\n\nA multisig wallet with 1 key has been created on this system")
else:
    wallet3o5 = HDWallet(WALLET_NAME)

print("\nUpdating UTXO's...")
wallet3o5.utxos_update()
wallet3o5.info()
utxos = wallet3o5.utxos()
github 1200wd / bitcoinlib / examples / wallets_transactions.py View on Github external
from pprint import pprint
from bitcoinlib.wallets import HDWallet, BCL_DATABASE_DIR


#
# Create Wallets
#

# First recreate database to avoid already exist errors
test_databasefile = BCL_DATABASE_DIR + 'bitcoinlib.test.sqlite'
test_database = 'sqlite:///' + test_databasefile
if os.path.isfile(test_databasefile):
    os.remove(test_databasefile)

print("\n=== Create a wallet and a simple transaction ===")
wlt = HDWallet.create('wlttest1', network='bitcoinlib_test', db_uri=test_database)
wlt.get_key()
wlt.utxos_update()  # Create some test UTXOs
wlt.info()
to_key = wlt.get_key()
print("\n- Create transaction (send to own wallet)")
t = wlt.send_to(to_key.address, 50000000)
t.info()

print("\n- Successfully send, updated wallet info:")
wlt.info()


print("\n=== Create a wallet, generate 6 UTXOs and create a sweep transaction ===")
wlt = HDWallet.create('wlttest2', network='bitcoinlib_test', db_uri=test_database)
wlt.get_key(number_of_keys=3)
wlt.utxos_update()  # Create some test UTXOs
github 1200wd / bitcoinlib / bitcoinlib / wallets.py View on Github external
def __init__(self, hdwallet, *args, **kwargs):
        """
        Initialize HDWalletTransaction object with reference to a HDWallet object

        :param hdwallet: HDWallet object, wallet name or ID
        :type hdWallet: HDwallet, str, int
        :param args: Arguments for HDWallet parent class
        :type args: args
        :param kwargs: Keyword arguments for HDWallet parent class
        :type kwargs: kwargs
        """
        assert isinstance(hdwallet, HDWallet)
        self.hdwallet = hdwallet
        self.pushed = False
        self.error = None
        Transaction.__init__(self, *args, **kwargs)
github Tribler / tribler / Tribler / Core / Modules / wallet / btc_wallet.py View on Github external
def __init__(self, wallet_dir):
        super(BitcoinWallet, self).__init__()

        bitcoinlib_main.initialize_lib(wallet_dir)
        from bitcoinlib.wallets import wallet_exists, HDWallet

        self.network = 'testnet' if self.TESTNET else 'bitcoin'
        self.wallet_dir = wallet_dir
        self.min_confirmations = 0
        self.wallet = None
        self.unlocked = True
        self.db_path = os.path.join(wallet_dir, 'wallets.sqlite')
        self.wallet_name = 'tribler_testnet' if self.TESTNET else 'tribler'

        if wallet_exists(self.wallet_name, databasefile=self.db_path):
            self.wallet = HDWallet(self.wallet_name, databasefile=self.db_path)
            self.created = True