test_databasefile = os.path.join(BCL_DATABASE_DIR, 'bitcoinlib.test.sqlite') test_database = 'sqlite:///' + test_databasefile if os.path.isfile(test_databasefile): os.remove(test_databasefile) # # Create a multi-signature wallet using Bitcoinlib testnet and then create a transaction # # Create 3 wallets with one private keys each, and 2 public keys corresponding with other wallets NETWORK = 'bitcoinlib_test' pk1 = HDKey(network=NETWORK) pk2 = HDKey(network=NETWORK) pk3 = HDKey(network=NETWORK) klist = [pk1, pk2.public_master_multisig(), pk3.public_master_multisig()] wl1 = HDWallet.create('multisig_2of3_cosigner1', sigs_required=2, keys=klist, network=NETWORK, db_uri=test_database) klist = [pk1.public_master_multisig(), pk2, pk3.public_master_multisig()] wl2 = HDWallet.create('multisig_2of3_cosigner2', sigs_required=2, keys=klist, network=NETWORK, db_uri=test_database) klist = [pk1.public_master_multisig(), pk2.public_master_multisig(), pk3] wl3 = HDWallet.create('multisig_2of3_cosigner3', sigs_required=2, keys=klist,
) if len(cosigner['key'].split(" ")) > 1: hdkey = HDKey.from_passphrase(cosigner['key'], key_type=cosigner['key_type'], witness_type=WITNESS_TYPE, network=NETWORK) else: hdkey = HDKey(cosigner['key'], key_type=cosigner['key_type'], witness_type=WITNESS_TYPE, network=NETWORK) if cosigner['name'] != COSIGNER_NAME_THIS_WALLET: if hdkey.key_type == 'single': hdkey = hdkey.public() else: hdkey = hdkey.public_master_multisig() cosigner['hdkey'] = hdkey key_list.append(hdkey) 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(WALLET_NAME, key_list, sigs_required=SIGS_REQUIRED, witness_type=WITNESS_TYPE, network=NETWORK) wallet3o5.new_key() print("\n\nA multisig wallet with 1 key has been created on this system") else: