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_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)
Example #3
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)