forked from LBRYCommunity/lbry-sdk
Merge pull request #3692 from lbryio/fix-import/export-backwards-compat
fix backwards compatibility in wallet import/export
This commit is contained in:
commit
20ae51b949
3 changed files with 14 additions and 6 deletions
|
@ -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()
|
||||
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):
|
||||
|
|
|
@ -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'])
|
||||
|
|
|
@ -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="")
|
||||
|
||||
|
|
Loading…
Reference in a new issue