Skip to content

Commit 20ae51b

Browse files
authored
Merge pull request #3692 from lbryio/fix-import/export-backwards-compat
fix backwards compatibility in wallet import/export
2 parents b452e76 + 24e9c7b commit 20ae51b

File tree

3 files changed

+14
-6
lines changed

3 files changed

+14
-6
lines changed

lbry/extras/daemon/daemon.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -1346,9 +1346,9 @@ async def jsonrpc_wallet_export(self, password=None, wallet_id=None):
13461346
13471347
"""
13481348
wallet = self.wallet_manager.get_wallet_or_default(wallet_id)
1349-
if password:
1350-
return wallet.pack(password).decode()
1351-
return wallet.to_json()
1349+
if password is None:
1350+
return wallet.to_json()
1351+
return wallet.pack(password).decode()
13521352

13531353
@requires("wallet")
13541354
async def jsonrpc_wallet_import(self, data, password=None, wallet_id=None, blocking=False):

lbry/wallet/wallet.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -189,10 +189,10 @@ def merge(self, manager: 'WalletManager',
189189
password: str, data: str) -> (List['Account'], List['Account']):
190190
assert not self.is_locked, "Cannot sync apply on a locked wallet."
191191
added_accounts, merged_accounts = [], []
192-
if password:
193-
decrypted_data = self.unpack(password, data)
194-
else:
192+
if password is None:
195193
decrypted_data = json.loads(data)
194+
else:
195+
decrypted_data = self.unpack(password, data)
196196
self.preferences.merge(decrypted_data.get('preferences', {}))
197197
for account_dict in decrypted_data['accounts']:
198198
ledger = manager.get_or_create_ledger(account_dict['ledger'])

tests/integration/blockchain/test_wallet_commands.py

+8
Original file line numberDiff line numberDiff line change
@@ -501,3 +501,11 @@ async def test_wallet_import_and_export(self):
501501
json_data["preferences"]["four"] = {"value": 4, "ts": 0}
502502
await daemon.jsonrpc_wallet_import(data=json.dumps(json_data), blocking=True)
503503
self.assertEqual(daemon.jsonrpc_preference_get("four"), {"four": 4})
504+
505+
# if password is empty string, export is encrypted
506+
data = await daemon2.jsonrpc_wallet_export(password="")
507+
self.assertNotEqual(data[0], "{")
508+
509+
# if password is empty string, import is decrypted
510+
await daemon.jsonrpc_wallet_import(data, password="")
511+

0 commit comments

Comments
 (0)