示例#1
0
    def create(self,
               name,
               password,
               seed=None,
               passphrase="",
               bip39_derivation=None,
               master=None,
               addresses=None,
               privkeys=None):
        """Create or restore a new wallet"""
        path = self._wallet_path(name)
        if exists(path):
            raise FileExistsError(path)
        storage = WalletStorage(path)

        if addresses is not None:
            wallet = ImportedAddressWallet.from_text(storage, addresses)
        elif privkeys is not None:
            wallet = ImportedPrivkeyWallet.from_text(storage, privkeys)
        else:
            if bip39_derivation is not None:
                ks = keystore.from_bip39_seed(seed, passphrase,
                                              bip39_derivation)
            elif master is not None:
                ks = keystore.from_master_key(master)
            else:
                if seed is None:
                    seed = self.make_seed()
                    print("Your wallet generation seed is:\n\"%s\"" % seed)
                ks = keystore.from_seed(seed, passphrase, False)

            storage.put('keystore', ks.dump())
            wallet = Standard_Wallet(storage)

        wallet.update_password(None, password, True)
示例#2
0
    def create(self, name, password, seed=None, passphrase="", bip39_derivation=None,
               master=None, addresses=None, privkeys=None, multisig=False):
        """Create or restore a new wallet"""
        path = self._wallet_path(name)
        if exists(path):
            raise FileExistsError(path)
        storage = WalletStorage(path)

        if addresses is not None:
            wallet = ImportedAddressWallet.from_text(storage, addresses)
        elif privkeys is not None:
            wallet = ImportedPrivkeyWallet.from_text(storage, privkeys)
        else:
            if bip39_derivation is not None:
                ks = keystore.from_seed(seed, passphrase, seed_type='bip39',
                                        derivation=bip39_derivation)
            elif master is not None:
                ks = keystore.from_master_key(master)
            else:
                if seed is None:
                    seed = self.make_seed()
                    print("Your wallet generation seed is:\n\"%s\"" % seed)
                ks = keystore.from_seed(seed, passphrase)

            if not multisig:
                storage.put('keystore', ks.dump())
                wallet = Standard_Wallet(storage)
            else:
                # For multisig wallets, we do not immediately create a wallet storage file.
                # Instead, we just get the keystore; create_multisig() handles wallet storage
                # later, once all cosigners are added.
                return ks.dump()

        wallet.update_password(None, password, encrypt=True)
示例#3
0
 def testImportedAddrWallet(self, addrStr):
     network = Network(None)
     network.start()
     path = os.path.join(self.topDir, 'wallets', 'test.wallet')
     storage = WalletStorage(path)
     wal = ImportedAddressWallet.from_text(storage, addrStr)
     print(wal)
     wal.start_threads(network)
     wal.synchronize()
     wal.wait_until_synchronized()
     bal = wal.get_balance()
     print(bal)
示例#4
0
    def create_multisig_addr(self,
                             idx,
                             partner_x_pubkey,
                             generated_by_me=True):
        wallet = self.getContractWallet(idx)
        c = commands.Commands(None, wallet, None)
        contract = self.contracts[idx]

        if 'address' in contract:
            print_msg(
                "Cash Rip**********************************Overwriting old contract. It will be saved in contracts-bkp.txt"
            )
            backupContract(contract)

        (partner_pubkey,
         partner_address) = keystore.xpubkey_to_address(partner_x_pubkey)
        if generated_by_me:
            multiaddress = c.createmultisig(
                2, [contract["my_pubkey"], partner_pubkey])
        else:
            multiaddress = c.createmultisig(
                2, [partner_pubkey, contract["my_pubkey"]])
        multiaddress["address"] = Address.from_string(
            multiaddress["address"]).to_ui_string()
        partner_address = partner_address.to_ui_string()

        contract.update(multiaddress)
        contract["partner_addr"] = partner_address
        contract["partner_x_pubkey"] = partner_x_pubkey
        contract["partner_pubkey"] = partner_pubkey
        contract["gen_by_me"] = generated_by_me

        addrWalletFile = contract["walletFile"][:-7] + "-address.wallet"
        #print("addrWalletFile: {}".format(addrWalletFile))
        storage = WalletStorage(addrWalletFile)
        if storage.file_exists():
            os.remove(addrWalletFile)
            storage = WalletStorage(addrWalletFile)
        #wal = ImportedAddressWallet.from_text(storage, contract["address"].to_ui_string())
        wal = ImportedAddressWallet.from_text(storage, contract["address"])
        wal.synchronize()
        wal.storage.write()
        print_msg("Wallet saved in '%s'" % wal.storage.path)
        contract["addrWalletFile"] = addrWalletFile
        #print_msg("contracts now: %s" % contracts)
        self.updateContracts()
        self.multiWallets[idx] = wal
        return contract
示例#5
0
    def create(self, name, password, seed=None, addresses=None, privkeys=None):
        """Create or restore a new wallet"""
        path = self._wallet_path(name)
        if exists(path):
            raise FileExistsError(path)
        storage = WalletStorage(path)

        if addresses:
            wallet = ImportedAddressWallet.from_text(storage, addresses)
        elif privkeys:
            wallet = ImportedPrivkeyWallet.from_text(storage, privkeys)
        else:
            if seed is None:
                seed = self.make_seed()
                print("Your wallet generation seed is:\n\"%s\"" % seed)
            storage.put('keystore', keystore.from_seed(seed, "", False).dump())
            wallet = Standard_Wallet(storage)

        wallet.update_password(None, password, True)