def test_old(self, tmp_storage) -> None: seed_words = ('powerful random nobody notice nothing important ' + 'anyway look away hidden message over') child_keystore = from_seed(seed_words, '', False) assert isinstance(child_keystore, Old_KeyStore) parent_wallet = ParentWallet.as_legacy_wallet_container(tmp_storage) keystore_usage = parent_wallet.add_keystore(child_keystore.dump()) child_wallet = Standard_Wallet.create_within_parent( parent_wallet, keystore_usage=[keystore_usage]) parent_keystores = parent_wallet.get_keystores() assert len(parent_keystores) == 1 child_keystores = child_wallet.get_keystores() assert len(child_keystores) == 1 assert parent_keystores[0] is child_keystores[0] keystore_data = parent_keystores[0].dump() assert len(keystore_data) == 3 assert keystore_data['type'] == 'old' assert 'mpk' in keystore_data assert 'seed' in keystore_data child_wallet_data = child_wallet.dump() assert len(child_wallet_data) == 3 assert child_wallet_data['id'] == 0 assert child_wallet_data['wallet_type'] == 'standard' keystore_usage = child_wallet_data['keystore_usage'] assert len(keystore_usage) == 1 assert len(keystore_usage[0]) == 1 assert keystore_usage[0]['index'] == 0
def test_imported_pubkey(self, tmp_storage) -> None: text = """ 15hETetDmcXm1mM4sEf7U2KXC9hDHFMSzz 1GPHVTY8UD9my6jyP4tb2TYJwUbDetyNC6 """ parent_wallet = ParentWallet.as_legacy_wallet_container(tmp_storage) child_wallet = ImportedAddressWallet.from_text(parent_wallet, text) check_legacy_parent_of_imported_address_wallet(parent_wallet)
def test_standard_electrum(self, tmp_storage) -> None: seed_words = 'cycle rocket west magnet parrot shuffle foot correct salt library feed song' child_keystore = from_seed(seed_words, '', False) parent_wallet = ParentWallet.as_legacy_wallet_container(tmp_storage) keystore_usage = parent_wallet.add_keystore(child_keystore.dump()) child_wallet = Standard_Wallet.create_within_parent( parent_wallet, keystore_usage=[keystore_usage]) check_legacy_parent_of_standard_wallet(parent_wallet)
def test_imported_privkey(self, tmp_storage) -> None: text = """ KzMFjMC2MPadjvX5Cd7b8AKKjjpBSoRKUTpoAtN6B3J9ezWYyXS6 """ parent_wallet = ParentWallet.as_legacy_wallet_container(tmp_storage) child_wallet = ImportedPrivkeyWallet.from_text(parent_wallet, text) keypairs = { '02c6467b7e621144105ed3e4835b0b4ab7e35266a2ae1c4f8baa19e9ca93452997': 'KzMFjMC2MPadjvX5Cd7b8AKKjjpBSoRKUTpoAtN6B3J9ezWYyXS6' } check_legacy_parent_of_imported_privkey_wallet(parent_wallet, keypairs=keypairs)
def test_multisig(self, tmp_storage) -> None: parent_wallet = ParentWallet.as_legacy_wallet_container(tmp_storage) seed_words = ( 'blast uniform dragon fiscal ensure vast young utility dinosaur abandon ' + 'rookie sure') ks1 = from_seed(seed_words, '', True) ks2 = from_xpub( 'xpub661MyMwAqRbcGfCPEkkyo5WmcrhTq8mi3xuBS7VEZ3LYvsgY1cCFDben' + 'T33bdD12axvrmXhuX3xkAbKci3yZY9ZEk8vhLic7KNhLjqdh5ec') keystores = [ks1, ks2] keystore_usages = [] for i, k in enumerate(keystores): keystore_usage = parent_wallet.add_keystore(k.dump()) keystore_usage['name'] = f'x{i+1}/' keystore_usages.append(keystore_usage) child_wallet = Multisig_Wallet.create_within_parent( parent_wallet, keystore_usage=keystore_usages, wallet_type="2of2") check_legacy_parent_of_multisig_wallet(parent_wallet)
def run_non_RPC(config): cmdname = config.get('cmd') storage = WalletStorage(config.get_wallet_path()) if storage.file_exists(): sys.exit("Error: Remove the existing wallet first!") def password_dialog(): return prompt_password( "Password (hit return if you do not wish to encrypt your wallet):") if cmdname == 'restore': text = config.get('text').strip() passphrase = config.get('passphrase', '') password = password_dialog() if keystore.is_private(text) else None parent_wallet = ParentWallet.as_legacy_wallet_container(storage) if keystore.is_address_list(text): legacy_wallet = ImportedAddressWallet.from_text( parent_wallet, text) elif keystore.is_private_key_list(text): legacy_wallet = ImportedPrivkeyWallet.from_text( parent_wallet, text) else: if keystore.is_seed(text): k = keystore.from_seed(text, passphrase, False) elif keystore.is_master_key(text): k = keystore.from_master_key(text) else: sys.exit("Error: Seed or key not recognized") keystore_usage = parent_wallet.add_keystore(k.dump()) Standard_Wallet.create_within_parent( parent_wallet, keystore_usage=[keystore_usage]) if password: parent_wallet.update_password(None, password) if not config.get('offline'): network = Network() network.add_wallet(parent_wallet) print("Recovering wallet...") parent_wallet.synchronize() msg = ("Recovery successful" if parent_wallet.has_usage() else "Found no history for this wallet") else: msg = ("This wallet was restored offline. " "It may contain more addresses than displayed.") print(msg) elif cmdname == 'create': password = password_dialog() passphrase = config.get('passphrase', '') seed_type = 'standard' seed = Mnemonic('en').make_seed(seed_type) k = keystore.from_seed(seed, passphrase, False) parent_wallet = ParentWallet.as_legacy_wallet_container(storage) keystore_usage = parent_wallet.add_keystore(k.dump()) Standard_Wallet.create_within_parent(parent_wallet, keystore_usage=[keystore_usage]) parent_wallet.update_password(None, password) parent_wallet.synchronize() print("Your wallet generation seed is:\n\"%s\"" % seed) print("Please keep it in a safe place; if you lose it, " "you will not be able to restore your wallet.") parent_wallet.save_storage() print("Wallet saved in '%s'" % parent_wallet.get_storage_path()) sys.exit(0)