change api for data first, password optional, return (str)

This commit is contained in:
zeppi 2022-07-22 15:37:15 -04:00 committed by Lex Berezhny
parent 30aa0724ec
commit fa5f3e7e55
2 changed files with 33 additions and 36 deletions

View file

@ -1384,51 +1384,51 @@ class Daemon(metaclass=JSONRPCServerType):
return wallet
@requires("wallet")
async def jsonrpc_wallet_export(self, password, wallet_id=None):
async def jsonrpc_wallet_export(self, password=None, wallet_id=None):
"""
Export wallet data
Wallet must be unlocked to perform this operation.
Usage:
wallet_export <password> [--wallet_id=<wallet_id>]
wallet_export [--password=<password>] [--wallet_id=<wallet_id>]
Options:
--password=<password> : (str) password to decrypt incoming and encrypt outgoing data
--wallet_id=<wallet_id> : (str) wallet being sync'ed
--wallet_id=<wallet_id> : (str) wallet being exported
Returns:
(map) sync hash and data
(str) data
"""
assert password is not None, "passwordless use is not implemented yet"
wallet = self.wallet_manager.get_wallet_or_default(wallet_id)
encrypted = wallet.pack(password)
return {
'hash': self.jsonrpc_sync_hash(wallet_id),
'data': encrypted.decode()
}
return encrypted.decode()
@requires("wallet")
async def jsonrpc_wallet_import(self, password, data, wallet_id=None, blocking=False):
async def jsonrpc_wallet_import(self, data, password=None, wallet_id=None, blocking=False):
"""
Import wallet data and merge accounts, preferences.
Wallet must be unlocked to perform this operation.
Usage:
wallet_import <password> (<data> | --data=<data>) [--wallet_id=<wallet_id>] [--blocking]
wallet_import (<data> | --data=<data>) [<password> | --password=<password>] [--wallet_id=<wallet_id>] [--blocking]
Options:
--password=<password> : (str) password to decrypt incoming and encrypt outgoing data
--data=<data> : (str) incoming wallet data
--password=<password> : (str) password to decrypt incoming and encrypt outgoing data
--wallet_id=<wallet_id> : (str) wallet being merged into
--blocking : (bool) wait until any new accounts have merged
Returns:
(map) sync hash and data
(str) data
"""
if data.strip().startswith("{"):
print("passwordless use is not implemented yet")
else:
wallet = self.wallet_manager.get_wallet_or_default(wallet_id)
added_accounts = wallet.merge(self.wallet_manager, password, data)
for new_account in added_accounts:
@ -1443,10 +1443,7 @@ class Daemon(metaclass=JSONRPCServerType):
asyncio.create_task(self.ledger.subscribe_account(new_account))
wallet.save()
encrypted = wallet.pack(password)
return {
'hash': self.jsonrpc_sync_hash(wallet_id),
'data': encrypted.decode()
}
return encrypted.decode()
@requires("wallet")
async def jsonrpc_wallet_add(self, wallet_id):

View file

@ -442,8 +442,8 @@ class WalletEncryptionAndSynchronization(CommandTestCase):
self.assertItemCount(await daemon.jsonrpc_account_list(), 1)
data = await daemon2.jsonrpc_wallet_export('password')
await daemon.jsonrpc_wallet_import('password', data=data['data'], blocking=True)
data = await daemon2.jsonrpc_wallet_export(password='password')
await daemon.jsonrpc_wallet_import(data=data, password='password', blocking=True)
self.assertItemCount(await daemon.jsonrpc_account_list(), 2)
self.assertDictEqual(
@ -473,8 +473,8 @@ class WalletEncryptionAndSynchronization(CommandTestCase):
self.assertItemCount(await daemon2.jsonrpc_channel_list(), 1)
self.assertEqual(len(daemon2.wallet_manager.default_account.channel_keys), 1)
data = await daemon2.jsonrpc_wallet_export('password')
await daemon.jsonrpc_wallet_import('password', data=data['data'], blocking=True)
data = await daemon2.jsonrpc_wallet_export(password='password')
await daemon.jsonrpc_wallet_import(data=data, password='password', blocking=True)
# both daemons have the cert after sync'ing
self.assertEqual(