Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions lbry/extras/daemon/daemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -1346,9 +1346,9 @@ async def jsonrpc_wallet_export(self, password=None, wallet_id=None):

"""
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):
Expand Down
6 changes: 3 additions & 3 deletions lbry/wallet/wallet.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,10 +189,10 @@ def merge(self, manager: 'WalletManager',
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'])
Expand Down
8 changes: 8 additions & 0 deletions tests/integration/blockchain/test_wallet_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -501,3 +501,11 @@ async def test_wallet_import_and_export(self):
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="")