Beispiel #1
41
    def create_wallet(self):
        """
        Create a new bitcoin wallet.
        """
        from bitcoinlib.wallets import wallet_exists, HDWallet, WalletError

        if wallet_exists(self.wallet_name, databasefile=self.db_path):
            return fail(RuntimeError("Bitcoin wallet with name %s already exists." % self.wallet_name))

        self._logger.info("Creating wallet in %s", self.wallet_dir)
        try:
            self.wallet = HDWallet.create(self.wallet_name, network=self.network, databasefile=self.db_path)
            self.wallet.new_key('tribler_payments')
            self.wallet.new_key('tribler_change', change=1)
            self.created = True
        except WalletError as exc:
            self._logger.error("Cannot create BTC wallet!")
            return fail(Failure(exc))
        return succeed(None)
Beispiel #2
40
 def test_wallet_import_public_wallet(self):
     pubkey = 'tpubDDkyPBhSAx8DFYxx5aLjvKH6B6Eq2eDK1YN76x1WeijE8eVUswpibGbv8zJjD6yLDHzVcqWzSp2fWVFhEW9XnBssFqM' \
              'wt9SrsVeBeqfBbR3'
     pubwal = HDWallet.create(
         databasefile=DATABASEFILE_UNITTESTS,
         name='test_wallet_import_public_wallet',
         key=pubkey,
         network='testnet',
         account_id=0)
     newkey = pubwal.new_key()
     self.assertEqual(newkey.address, u'mweZrbny4fmpCmQw9hJH7EVfkuWX8te9jc')
Beispiel #3
40
 def test_wallet_import_account(self):
     accountkey = 'tprv8h4wEmfC2aSckSCYa68t8MhL7F8p9xAy322B5d6ipzY5ZWGGwksJMoajMCqd73cP4EVRygPQubgJPu9duBzPn3QV' \
                  '8Y7KbKUnaMzx9nnsSvh'
     wallet_import = HDWallet.create(
         databasefile=DATABASEFILE_UNITTESTS,
         name='test_wallet_import_account',
         key=accountkey,
         network='testnet',
         account_id=99)
     self.assertEqual(wallet_import.main_key.key_wif, accountkey)
     self.assertEqual(wallet_import.main_key.address, u'mowRx2TNXTgRSUmepjqhx5C1TTigmHLGRh')
     self.assertEqual(wallet_import.main_key.path, "m/44'/1'/99'")
Beispiel #4
40
    def create_wallet(self):
        """
        Create a new bitcoin wallet.
        """
        from bitcoinlib.wallets import HDWallet, WalletError

        self._logger.info("Creating wallet in %s", self.wallet_dir)
        try:
            if self.wallet:
                raise WalletError("Wallet with name '%s' already created" % self.wallet_name)

            self.wallet = HDWallet.create(self.wallet_name, network=self.network, databasefile=self.db_path)
            self.wallet.new_key('tribler_payments')
            self.wallet.new_key('tribler_change', change=1)
            self.created = True
        except WalletError as exc:
            self._logger.error("Cannot create BTC wallet!")
            return fail(Failure(exc))
        return succeed(None)
Beispiel #5
39
 def test_wallet_import_account_new_keys(self):
     accountkey = 'tprv8h4wEmfC2aSckSCYa68t8MhL7F8p9xAy322B5d6ipzY5ZWGGwksJMoajMCqd73cP4EVRygPQubgJPu9duBzPn3QV' \
                  '8Y7KbKUnaMzx9nnsSvh'
     wallet_import = HDWallet.create(
         databasefile=DATABASEFILE_UNITTESTS,
         name='test_wallet_import_account_new_key',
         key=accountkey,
         network='testnet',
         account_id=99)
     newkey = wallet_import.new_key(account_id=99)
     newkey_change = wallet_import.new_key_change(account_id=99, name='change')
     self.assertEqual(wallet_import.main_key.key_wif, accountkey)
     self.assertEqual(newkey.address, u'mfvFzusKPZzGBAhS69AWvziRPjamtRhYpZ')
     self.assertEqual(newkey.path, "m/44'/1'/99'/0/0")
     self.assertEqual(newkey_change.address, u'mkzpsGwaUU7rYzrDZZVXFne7dXEeo6Zpw2')
     self.assertEqual(newkey_change.path, "m/44'/1'/99'/1/0")
Beispiel #6
35
 def test_wallet_litecoin(self):
     accountkey = 'Ltpv71G8qDifUiNet6mn25D7GPAVLZeaFRWzDABxx5xNeigVpFEviHK1ZggPS1kbtegB3U2i8w6ToNfM5sdvEQPW' \
                  'tov4KWyQ5NxWUd3oDWXQb4C'
     wallet_import = HDWallet.create(
         databasefile=DATABASEFILE_UNITTESTS,
         name='test_wallet_litecoin',
         key=accountkey,
         network='litecoin')
     newkey = wallet_import.new_key()
     self.assertEqual(wallet_import.main_key.key_wif, accountkey)
     self.assertEqual(newkey.address, u'LPkJcpV1cmT8qLFmUApySBtxt7UWavoQmh')
     self.assertEqual(newkey.path, "m/44'/2'/0'/0/0")
Beispiel #7
0
def create_wallet(wallet_name, args, databasefile):
    if args.network is None:
        args.network = DEFAULT_NETWORK
    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) < 2:
            clw_exit("Please enter multisig creation parameter in the following format: "
                     "<number-of-signatures> <number-of-signatures-required> "
                     "<key-0> <key-1> [<key-2> ... <key-n>]")
        try:
            sigs_total = int(args.create_multisig[0])
        except ValueError:
            clw_exit("Number of total signatures (first argument) must be a numeric value. %s" %
                     args.create_multisig[0])
        try:
            sigs_required = int(args.create_multisig[1])
        except ValueError:
            clw_exit("Number of signatures required (second argument) must be a numeric value. %s" %
                     args.create_multisig[1])
        key_list = args.create_multisig[2:]
        keys_missing = sigs_total - len(key_list)
        assert(keys_missing >= 0)
        if keys_missing:
            print("Not all keys provided, creating %d additional keys" % keys_missing)
            for _ in range(keys_missing):
                passphrase = get_passphrase(args)
                passphrase = ' '.join(passphrase)
                seed = binascii.hexlify(Mnemonic().to_seed(passphrase))
                key_list.append(HDKey().from_seed(seed, network=args.network))
        return HDWallet.create_multisig(name=wallet_name, keys=key_list, sigs_required=sigs_required,
                                        network=args.network, databasefile=databasefile, sort_keys=True,
                                        witness_type=args.witness_type)
    elif args.create_from_key:
        return HDWallet.create(name=wallet_name, network=args.network, keys=args.create_from_key,
                               databasefile=databasefile, witness_type=args.witness_type)
    else:
        passphrase = args.passphrase
        if passphrase is None:
            passphrase = get_passphrase(args)
        elif not passphrase:
            passphrase = input("Enter Passphrase: ")
        if not isinstance(passphrase, list):
            passphrase = passphrase.split(' ')
        elif len(passphrase) == 1:
            passphrase = passphrase[0].split(' ')
        if len(passphrase) < 12:
            clw_exit("Please specify passphrase with 12 words or more")
        passphrase = ' '.join(passphrase)
        seed = binascii.hexlify(Mnemonic().to_seed(passphrase))
        hdkey = HDKey().from_seed(seed, network=args.network)
        return HDWallet.create(name=wallet_name, network=args.network, keys=hdkey, witness_type=args.witness_type,
                               databasefile=databasefile)
Beispiel #8
0
def create_wallet(wallet_name, args, databasefile):
    if args.network is None:
        args.network = DEFAULT_NETWORK
    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: "
                "<number-of-signatures-required> <key-0> <key-1> [<key-2> ... <key-n>]"
            )
        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,
                                        sort_keys=True)
    elif args.create_from_key:
        return HDWallet.create(name=wallet_name,
                               network=args.network,
                               key=args.create_from_key,
                               databasefile=databasefile)
    else:
        passphrase = args.passphrase
        if passphrase is None:
            passphrase = get_passphrase(args)
        elif not passphrase:
            passphrase = input("Enter Passphrase: ")
        if not isinstance(passphrase, list):
            passphrase = passphrase.split(' ')
        elif len(passphrase) == 1:
            passphrase = passphrase[0].split(' ')
        if len(passphrase) < 12:
            clw_exit("Please specify passphrase with 12 words or more")
        passphrase = ' '.join(passphrase)
        seed = binascii.hexlify(Mnemonic().to_seed(passphrase))
        hdkey = HDKey().from_seed(seed, network=args.network)
        return HDWallet.create(name=wallet_name,
                               network=args.network,
                               key=hdkey.wif(),
                               databasefile=databasefile)
 def test_wallet_import_key_network_error(self):
     w = HDWallet.create(name='Wallet Error',
                         databasefile=DATABASEFILE_UNITTESTS)
     self.assertRaisesRegexp(
         WalletError,
         "Network litecoin not available in this wallet, please create an account "
         "for this network first.", w.import_key,
         'T43gB4F6k1Ly3YWbMuddq13xLb56hevUDP3RthKArr7FPHjQiXpp')
 def test_wallet_import_public_wallet(self):
     pubkey = 'tpubDDkyPBhSAx8DFYxx5aLjvKH6B6Eq2eDK1YN76x1WeijE8eVUswpibGbv8zJjD6yLDHzVcqWzSp2fWVFhEW9XnBssFqMwt' \
              '9SrsVeBeqfBbR3'
     pubwal = HDWallet.create(databasefile=DATABASEFILE_UNITTESTS,
                              name='test_wallet_import_public_wallet',
                              key=pubkey,
                              network='testnet',
                              account_id=0)
     newkey = pubwal.new_key()
     self.assertEqual(newkey.address, u'mweZrbny4fmpCmQw9hJH7EVfkuWX8te9jc')
 def test_wallet_multisig_2_wallets_private_master_plus_account_public(
         self):
     if os.path.isfile(DATABASEFILE_UNITTESTS):
         os.remove(DATABASEFILE_UNITTESTS)
     pk1 = 'tprv8ZgxMBicQKsPdPVdNSEeAhagkU6tUDhUQi8DcCTmJyNLUyU7svTFzXQdkYqNJDEtQ3S2wAspz3K56CMcmMsZ9eXZ2nkNq' \
           'gVxJhMHq3bGJ1X'
     pk1_acc_pub = 'tpubDCZUk9HLxh5gdB9eC8FUxPB1AbZtsSnbvyrAAzsC8x3tiYDgbzyxcngU99rG333jegHG5vJhs11AHcSVkbwrU' \
                   'bYEsPK8vA7E6yFB9qbsTYi'
     w1 = self.wallet = HDWallet.create(name='test_wallet_create_1',
                                        key=pk1,
                                        databasefile=DATABASEFILE_UNITTESTS)
     w2 = self.wallet = HDWallet.create(name='test_wallet_create_2',
                                        key=pk1_acc_pub,
                                        databasefile=DATABASEFILE_UNITTESTS)
     wk1 = w1.new_key()
     wk2 = w2.new_key()
     self.assertTrue(wk1.is_private)
     self.assertFalse(wk2.is_private)
     self.assertEqual(wk1.address, wk2.address)
 def setUp(self):
     if os.path.isfile(DATABASEFILE_UNITTESTS):
         os.remove(DATABASEFILE_UNITTESTS)
     self.private_wif = 'xprv9s21ZrQH143K24Mfq5zL5MhWK9hUhhGbd45hLXo2Pq2oqzMMo63oStZzF9ySUHZw5qJkk5LCALAhXS' \
                        'XoCmCSnStRvgwLBtcbGsg1PeKT2en'
     self.wallet = HDWallet.create(key=self.private_wif,
                                   name='test_wallet_keys',
                                   databasefile=DATABASEFILE_UNITTESTS)
     self.wallet.new_key()
     self.wallet.new_key_change()
 def test_wallet_keys_single_key(self):
     if os.path.isfile(DATABASEFILE_UNITTESTS):
         os.remove(DATABASEFILE_UNITTESTS)
     wk = 'xprv9s21ZrQH143K3tCgu8uhkA2fw9F9opbvoNNzh5wcuEvNHbCU6Kg3c6dam2a6cw4UYeDxAsgBorAqXp2nsoYS84DqYMwkzxZ15' \
          'ujRHzmBMxE'
     w = HDWallet.create('test_wallet_keys_single_key',
                         wk,
                         scheme='single',
                         databasefile=DATABASEFILE_UNITTESTS)
     self.assertEqual(w.new_key(), w.new_key())
 def test_wallet_import_litecoin(self):
     accountkey = 'Ltpv71G8qDifUiNet6mn25D7GPAVLZeaFRWzDABxx5xNeigVpFEviHK1ZggPS1kbtegB3U2i8w6ToNfM5sdvEQPW' \
                  'tov4KWyQ5NxWUd3oDWXQb4C'
     wallet_import = HDWallet.create(databasefile=DATABASEFILE_UNITTESTS,
                                     name='test_wallet_litecoin',
                                     key=accountkey,
                                     network='litecoin')
     newkey = wallet_import.new_key()
     self.assertEqual(wallet_import.main_key.wif, accountkey)
     self.assertEqual(newkey.address, u'LPkJcpV1cmT8qLFmUApySBtxt7UWavoQmh')
     self.assertEqual(newkey.path, "m/44'/2'/0'/0/0")
 def test_wallet_import(self):
     keystr = 'tprv8ZgxMBicQKsPeWn8NtYVK5Hagad84UEPEs85EciCzf8xYWocuJovxsoNoxZAgfSrCp2xa6DdhDrzYVE8UXF75r2dKePy' \
              'A7irEvBoe4aAn52'
     wallet_import = HDWallet.create(databasefile=DATABASEFILE_UNITTESTS,
                                     name='test_wallet_import',
                                     network='testnet',
                                     key=keystr)
     wallet_import.new_account(account_id=99)
     self.assertEqual(wallet_import.main_key.wif, keystr)
     self.assertEqual(wallet_import.main_key.address,
                      u'n3UKaXBRDhTVpkvgRH7eARZFsYE989bHjw')
     self.assertEqual(wallet_import.main_key.path, 'm')
 def test_wallet_bitcoinlib_testnet_sweep(self):
     if os.path.isfile(DATABASEFILE_UNITTESTS):
         os.remove(DATABASEFILE_UNITTESTS)
     w = HDWallet.create(network='bitcoinlib_test',
                         name='test_wallet_bitcoinlib_testnet',
                         databasefile=DATABASEFILE_UNITTESTS)
     w.new_key()
     w.new_key()
     w.new_key()
     w.utxos_update()
     self.assertEqual(w.sweep('21DBmFUMQMP7A6KeENXgZQ4wJdSCeGc2zFo'),
                      'succesfull_test_sendrawtransaction')
 def test_wallet_bitcoinlib_testnet_sendto_no_funds_txfee(self):
     if os.path.isfile(DATABASEFILE_UNITTESTS):
         os.remove(DATABASEFILE_UNITTESTS)
     w = HDWallet.create(network='bitcoinlib_test',
                         name='test_wallet_bitcoinlib_testnet',
                         databasefile=DATABASEFILE_UNITTESTS)
     w.new_key()
     w.utxos_update()
     balance = w.balance()
     self.assertRaisesRegexp(
         WalletError, 'Not enough unspent transaction outputs found',
         w.send_to, '21DBmFUMQMP7A6KeENXgZQ4wJdSCeGc2zFo', balance),
 def test_wallet_import_account(self):
     accountkey = 'tprv8h4wEmfC2aSckSCYa68t8MhL7F8p9xAy322B5d6ipzY5ZWGGwksJMoajMCqd73cP4EVRygPQubgJPu9duBzPn3QV' \
                  '8Y7KbKUnaMzx9nnsSvh'
     wallet_import = HDWallet.create(databasefile=DATABASEFILE_UNITTESTS,
                                     name='test_wallet_import_account',
                                     key=accountkey,
                                     network='testnet',
                                     account_id=99)
     self.assertEqual(wallet_import.main_key.wif, accountkey)
     self.assertEqual(wallet_import.main_key.address,
                      u'mowRx2TNXTgRSUmepjqhx5C1TTigmHLGRh')
     self.assertEqual(wallet_import.main_key.path, "m/44'/1'/99'")
    def test_wallet_bitcoinlib_testnet_send_utxos_updated(self):
        if os.path.isfile(DATABASEFILE_UNITTESTS):
            os.remove(DATABASEFILE_UNITTESTS)
        w = HDWallet.create(network='bitcoinlib_test',
                            name='test_wallet_bitcoinlib_testnet',
                            databasefile=DATABASEFILE_UNITTESTS)

        w.new_key()
        w.utxos_update()
        self.assertEqual(len(w.utxos()), 1)
        w.send_to('21DBmFUMQMP7A6KeENXgZQ4wJdSCeGc2zFo', 50000000)
        self.assertEqual(w.utxos(), [])
Beispiel #20
0
 def test_wallet_import(self):
     keystr = 'tprv8ZgxMBicQKsPeWn8NtYVK5Hagad84UEPEs85EciCzf8xYWocuJovxsoNoxZAgfSrCp2xa6DdhDrzYVE8UXF75r2dKePy' \
              'A7irEvBoe4aAn52'
     wallet_import = HDWallet.create(
         databasefile=DATABASEFILE_UNITTESTS,
         name='test_wallet_import',
         network='testnet',
         key=keystr)
     wallet_import.new_account(account_id=99)
     self.assertEqual(wallet_import.main_key.key_wif, keystr)
     self.assertEqual(wallet_import.main_key.address, u'n3UKaXBRDhTVpkvgRH7eARZFsYE989bHjw')
     self.assertEqual(wallet_import.main_key.path, 'm')
     wallet_import.info(detail=3)
Beispiel #21
0
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: "
                "<number-of-signatures-required> <key-0> <key-1> [<key-2> ... <key-n>]"
            )
        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:
            passphrase = passphrase[0].split(' ')
        if len(passphrase) < 12:
            clw_exit("Please specify passphrase with 12 words or more")
        passphrase = ' '.join(passphrase)
        seed = binascii.hexlify(Mnemonic().to_seed(passphrase))
        hdkey = HDKey().from_seed(seed, network=args.network)
        return HDWallet.create(name=wallet_name,
                               network=args.network,
                               key=hdkey.wif(),
                               databasefile=databasefile)
Beispiel #22
0
 def create_wallet(self):
     """
     Create a new bitcoin wallet.
     """
     self._logger.info("Creating wallet in %s", self.wallet_dir)
     try:
         self.wallet = HDWallet.create(self.wallet_name, network=self.network, databasefile=self.db_path)
         self.wallet.new_key('tribler_payments')
         self.wallet.new_key('tribler_change', change=1)
         self.created = True
     except WalletError as exc:
         self._logger.error("Cannot create BTC wallet!")
         return fail(Failure(exc))
     return succeed(None)
    def create_wallet(self):
        if self.created:
            return fail(RuntimeError(f"{self.network} wallet with name {self.wallet_name} already exists."))

        self._logger.info("Creating wallet in %s", self.wallet_dir)
        try:
            self.wallet = HDWallet.create(self.wallet_name, network=self.network, db_uri=self.db_path)
            self.wallet.new_key('tribler_payments')
            self.wallet.new_key('tribler_change', change=1)
            self.created = True
        except WalletError as exc:
            self._logger.error("Cannot create %s wallet!", self.network)
            return fail(exc)
        return succeed(None)
    def setUp(self):
        if os.path.isfile(DATABASEFILE_UNITTESTS):
            os.remove(DATABASEFILE_UNITTESTS)
        self.pk = 'dHHM83S1ptYryy3ZeV6Q8zQBT9NvqiSjUMJPwf6xg2CdaFLiHbyzsCSeP9FG1wzbsPVY9VtC85VsWoFvU9z1S4GzqwDBh' \
                  'CawMAogXrUh2KgVahL'
        self.wallet = HDWallet.create(key=self.pk,
                                      name='test_wallet_multicurrency',
                                      databasefile=DATABASEFILE_UNITTESTS)

        self.wallet.new_account(network='litecoin')
        self.wallet.new_account(network='bitcoin')
        self.wallet.new_account(network='testnet')
        self.wallet.new_account(network='dash')
        self.wallet.new_key()
        self.wallet.new_key()
        self.wallet.new_key(network='bitcoin')
 def test_wallet_import_account_new_keys(self):
     accountkey = 'tprv8h4wEmfC2aSckSCYa68t8MhL7F8p9xAy322B5d6ipzY5ZWGGwksJMoajMCqd73cP4EVRygPQubgJPu9duBzPn3QV' \
                  '8Y7KbKUnaMzx9nnsSvh'
     wallet_import = HDWallet.create(
         databasefile=DATABASEFILE_UNITTESTS,
         name='test_wallet_import_account_new_key',
         key=accountkey,
         network='testnet',
         account_id=99)
     newkey = wallet_import.new_key(account_id=99)
     newkey_change = wallet_import.new_key_change(account_id=99,
                                                  name='change')
     self.assertEqual(wallet_import.main_key.wif, accountkey)
     self.assertEqual(newkey.address, u'mfvFzusKPZzGBAhS69AWvziRPjamtRhYpZ')
     self.assertEqual(newkey.path, "m/44'/1'/99'/0/0")
     self.assertEqual(newkey_change.address,
                      u'mkzpsGwaUU7rYzrDZZVXFne7dXEeo6Zpw2')
     self.assertEqual(newkey_change.path, "m/44'/1'/99'/1/0")
 def setUp(self):
     if os.path.isfile(DATABASEFILE_UNITTESTS):
         os.remove(DATABASEFILE_UNITTESTS)
     self.pk = 'xprv9s21ZrQH143K2fuscnMTwUadsPqEbYdFQVJ1uWPawUYi7C485NHhCiotGy6Kz3Cz7ReVr65oXNwhREZ8ePrz8p7zy' \
               'Hra82D1EGS7cQQmreK'
     self.wallet = HDWallet.create(key=self.pk,
                                   name='test_wallet_electrum',
                                   databasefile=DATABASEFILE_UNITTESTS)
     workdir = os.path.dirname(__file__)
     with open('%s/%s' % (workdir, 'electrum_keys.json'), 'r') as f:
         self.el_keys = json.load(f)
     for i in range(20):
         self.wallet.key_for_path('m/0/%d' % i,
                                  name='-test- Receiving #%d' % i,
                                  enable_checks=False)
     for i in range(6):
         self.wallet.key_for_path('m/1/%d' % i,
                                  name='-test- Change #%d' % i,
                                  enable_checks=False)
from bitcoinlib.wallets import HDWallet  # importing bitcoinlib
wallet = HDWallet.create('Wallet1')  # creating a new crypto wallet
key1 = wallet.new_key()  # Geenrating a new HD Key
print(key1.address)  # create a new address
Beispiel #28
0
#
# Create Wallets
#

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

print("\n=== Create a simple Mnemonic wallet ===")
passphrase = Mnemonic().generate()
print("Your private key passphrase is:", passphrase)
password = input("Enter password to protect passphrase: ")
wlt = HDWallet.create('mnwlttest1',
                      key=passphrase,
                      password=password,
                      network='bitcoinlib_test',
                      databasefile=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()
Beispiel #29
0
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,
                      network=NETWORK,
                      db_uri=test_database)
Beispiel #30
0
from pprint import pprint
from bitcoinlib.wallets import HDWallet, DEFAULT_DATABASEDIR

#
# Create Wallets
#

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

print("\n=== Create a wallet and a simple transaction ===")
wlt = HDWallet.create('wlttest1',
                      network='bitcoinlib_test',
                      databasefile=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 ==="
)
                          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:
    wallet3o5 = HDWallet(WALLET_NAME)

print("\nUpdating UTXO's...")
wallet3o5.utxos_update()
wallet3o5.info()
utxos = wallet3o5.utxos()
wallet3o5.info()

# Creating transactions just like in a normal wallet, then send raw transaction to other cosigners. They
# can sign the transaction with there on key and pass it on to the next signer or broadcast it to the network.
Beispiel #32
0
from bitcoinlib.wallets import HDWallet, wallet_delete

from bitcoinlib.mnemonic import Mnemonic

passphrase = Mnemonic().generate()

print(passphrase)

wallet = HDWallet.create("mWallet1", keys=passphrase, network='bitcoin')

key1 = wallet.new_key()

print(key1.address)
 def test_delete_wallet(self):
     HDWallet.create(name='wallet_to_remove',
                     databasefile=DATABASEFILE_UNITTESTS)
     self.assertEqual(
         delete_wallet('wallet_to_remove',
                       databasefile=DATABASEFILE_UNITTESTS), 1)
Beispiel #34
0
	def new_wallet(name):
		return HDWallet.create(name)
Beispiel #35
0
 def setUp(self):
     if os.path.isfile(DATABASEFILE_UNITTESTS):
         os.remove(DATABASEFILE_UNITTESTS)
     self.wallet = HDWallet.create(
         name='test_wallet_create',
         databasefile=DATABASEFILE_UNITTESTS)
 def setUp(self):
     if os.path.isfile(DATABASEFILE_UNITTESTS):
         os.remove(DATABASEFILE_UNITTESTS)
     self.wallet = HDWallet.create(name='test_wallet_create',
                                   databasefile=DATABASEFILE_UNITTESTS)