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 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 if keystore.is_address_list(text): wallet = ImportedAddressWallet.from_text(storage, text) elif keystore.is_private_key_list(text): wallet = ImportedPrivkeyWallet.from_text(storage, text, password) 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") if password: k.update_password(None, password) storage.put('keystore', k.dump()) storage.put('wallet_type', 'standard') storage.put('use_encryption', bool(password)) storage.write() wallet = Wallet(storage) if not config.get('offline'): network = Network(config) network.start() wallet.start_threads(network) print("Recovering wallet...") wallet.synchronize() wallet.wait_until_synchronized() msg = ("Recovery successful" if wallet.is_found() 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) storage.put('keystore', k.dump()) storage.put('wallet_type', 'standard') wallet = Wallet(storage) wallet.update_password(None, password, True) 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.") wallet.storage.write() print("Wallet saved in '%s'" % wallet.storage.path) sys.exit(0)
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)