From 24e9c7b435d9d43e55385910b2bddb8e77245953 Mon Sep 17 00:00:00 2001 From: zeppi Date: Tue, 18 Oct 2022 10:53:51 -0400 Subject: [PATCH] fix backwards compatibility in wallet import/export --- lbry/extras/daemon/daemon.py | 6 +++--- lbry/wallet/wallet.py | 6 +++--- tests/integration/blockchain/test_wallet_commands.py | 8 ++++++++ 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/lbry/extras/daemon/daemon.py b/lbry/extras/daemon/daemon.py index 6604b0d41..8ce3b1e0a 100644 --- a/lbry/extras/daemon/daemon.py +++ b/lbry/extras/daemon/daemon.py @@ -1346,9 +1346,9 @@ class Daemon(metaclass=JSONRPCServerType): """ wallet = self.wallet_manager.get_wallet_or_default(wallet_id) - if password: - return wallet.pack(password).decode() - return wallet.to_json() + if password is None: + return wallet.to_json() + return wallet.pack(password).decode() @requires("wallet") async def jsonrpc_wallet_import(self, data, password=None, wallet_id=None, blocking=False): diff --git a/lbry/wallet/wallet.py b/lbry/wallet/wallet.py index 956b7c18f..1a2588ad3 100644 --- a/lbry/wallet/wallet.py +++ b/lbry/wallet/wallet.py @@ -189,10 +189,10 @@ class Wallet: password: str, data: str) -> (List['Account'], List['Account']): assert not self.is_locked, "Cannot sync apply on a locked wallet." added_accounts, merged_accounts = [], [] - if password: - decrypted_data = self.unpack(password, data) - else: + if password is None: decrypted_data = json.loads(data) + else: + decrypted_data = self.unpack(password, data) self.preferences.merge(decrypted_data.get('preferences', {})) for account_dict in decrypted_data['accounts']: ledger = manager.get_or_create_ledger(account_dict['ledger']) diff --git a/tests/integration/blockchain/test_wallet_commands.py b/tests/integration/blockchain/test_wallet_commands.py index 6ead8e0fe..5623e4379 100644 --- a/tests/integration/blockchain/test_wallet_commands.py +++ b/tests/integration/blockchain/test_wallet_commands.py @@ -501,3 +501,11 @@ class WalletEncryptionAndSynchronization(CommandTestCase): json_data["preferences"]["four"] = {"value": 4, "ts": 0} await daemon.jsonrpc_wallet_import(data=json.dumps(json_data), blocking=True) self.assertEqual(daemon.jsonrpc_preference_get("four"), {"four": 4}) + + # if password is empty string, export is encrypted + data = await daemon2.jsonrpc_wallet_export(password="") + self.assertNotEqual(data[0], "{") + + # if password is empty string, import is decrypted + await daemon.jsonrpc_wallet_import(data, password="") +