def check_legacy_parent_of_standard_wallet( parent_wallet: ParentWallet, seed_words: Optional[str] = None, is_bip39: bool = False, password: Optional[str] = None) -> None: assert len(parent_wallet.get_child_wallets()) == 1 child_wallet: Standard_Wallet = parent_wallet.get_child_wallets()[0] 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_encrypted = parent_wallet.has_password() if keystore_encrypted: assert password is not None assert not child_keystores[0].has_seed( ) or child_keystores[0].get_seed(password) assert type(child_keystores[0].get_passphrase(password)) is str assert child_keystores[0].get_master_private_key(password) keystore_data = parent_keystores[0].dump() entry_count = 4 if is_bip39: entry_count = 3 assert len(keystore_data) == entry_count assert keystore_data['type'] == 'bip32' assert 'xpub' in keystore_data assert 'xprv' in keystore_data assert "encrypted" not in parent_wallet.name() or keystore_encrypted if is_bip39: assert "seed" not in keystore_data else: if seed_words is None: assert "seed" in keystore_data else: assert keystore_data['seed'] == seed_words child_wallet_data = child_wallet.dump() # A newly created wallet. expected_count = 3 if "stored_height" in child_wallet_data: # A wallet that has synced after it was created. assert "labels" in child_wallet_data expected_count = 5 assert len(child_wallet_data) == expected_count 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 run_offline_command(config, config_options): cmdname = config.get('cmd') cmd = known_commands[cmdname] password = config_options.get('password') if cmd.requires_wallet: wallet_path = config.get_wallet_path() if not WalletStorage.files_are_matched_by_path(wallet_path): print("Error: wallet does not exist at given path") sys.exit(1) storage = WalletStorage(wallet_path) if storage.is_encrypted(): storage.decrypt(password) parent_wallet = ParentWallet(storage) else: parent_wallet = None # check password if cmd.requires_password and parent_wallet.has_password(): try: parent_wallet.check_password(password) except InvalidPassword: print("Error: This password does not decode this wallet.") sys.exit(1) if cmd.requires_network: print("Warning: running command offline") # arguments passed to function args = [config.get(x) for x in cmd.params] # decode json arguments if cmdname not in ('setconfig', ): args = [json_decode(arg) for arg in args] # options kwargs = {} for x in cmd.options: kwargs[x] = (config_options.get(x) if x in ['password', 'new_password'] else config.get(x)) cmd_runner = Commands(config, parent_wallet, None) func = getattr(cmd_runner, cmd.name) result = func(*args, **kwargs) # save wallet if parent_wallet: parent_wallet.save_storage() return result
def __init__(self, parent: QWidget, parent_wallet: ParentWallet) -> None: WindowModalDialog.__init__(self, parent) is_encrypted = parent_wallet.is_encrypted() if not parent_wallet.has_password(): msg = _('Your wallet is not protected.') msg += ' ' + _('Use this dialog to add a password to your wallet.') else: if not is_encrypted: msg = _( 'Your bitcoins are password protected. However, your wallet file ' 'is not encrypted.') else: msg = _('Your wallet is password protected and encrypted.') msg += ' ' + _('Use this dialog to change your password.') OK_button = OkButton(self) self.playout = PasswordLayout(parent_wallet, msg, PW_CHANGE, OK_button) self.setWindowTitle(self.playout.title()) vbox = QVBoxLayout(self) vbox.setSizeConstraint(QVBoxLayout.SetFixedSize) vbox.addLayout(self.playout.layout()) vbox.addStretch(1) vbox.addLayout(Buttons(CancelButton(self), OK_button))