change api for data first, password optional, return (str)
This commit is contained in:
parent
30aa0724ec
commit
fa5f3e7e55
2 changed files with 33 additions and 36 deletions
|
@ -1384,69 +1384,66 @@ class Daemon(metaclass=JSONRPCServerType):
|
||||||
return wallet
|
return wallet
|
||||||
|
|
||||||
@requires("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
|
Export wallet data
|
||||||
|
|
||||||
Wallet must be unlocked to perform this operation.
|
Wallet must be unlocked to perform this operation.
|
||||||
|
|
||||||
Usage:
|
Usage:
|
||||||
wallet_export <password> [--wallet_id=<wallet_id>]
|
wallet_export [--password=<password>] [--wallet_id=<wallet_id>]
|
||||||
|
|
||||||
Options:
|
Options:
|
||||||
--password=<password> : (str) password to decrypt incoming and encrypt outgoing data
|
--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:
|
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)
|
wallet = self.wallet_manager.get_wallet_or_default(wallet_id)
|
||||||
encrypted = wallet.pack(password)
|
encrypted = wallet.pack(password)
|
||||||
return {
|
return encrypted.decode()
|
||||||
'hash': self.jsonrpc_sync_hash(wallet_id),
|
|
||||||
'data': encrypted.decode()
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@requires("wallet")
|
@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.
|
Import wallet data and merge accounts, preferences.
|
||||||
|
|
||||||
Wallet must be unlocked to perform this operation.
|
Wallet must be unlocked to perform this operation.
|
||||||
|
|
||||||
Usage:
|
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:
|
Options:
|
||||||
--password=<password> : (str) password to decrypt incoming and encrypt outgoing data
|
|
||||||
--data=<data> : (str) incoming wallet 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
|
--wallet_id=<wallet_id> : (str) wallet being merged into
|
||||||
--blocking : (bool) wait until any new accounts have merged
|
--blocking : (bool) wait until any new accounts have merged
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
(map) sync hash and data
|
(str) data
|
||||||
|
|
||||||
"""
|
"""
|
||||||
wallet = self.wallet_manager.get_wallet_or_default(wallet_id)
|
|
||||||
added_accounts = wallet.merge(self.wallet_manager, password, data)
|
if data.strip().startswith("{"):
|
||||||
for new_account in added_accounts:
|
print("passwordless use is not implemented yet")
|
||||||
await new_account.maybe_migrate_certificates()
|
else:
|
||||||
if added_accounts and self.ledger.network.is_connected:
|
wallet = self.wallet_manager.get_wallet_or_default(wallet_id)
|
||||||
if blocking:
|
added_accounts = wallet.merge(self.wallet_manager, password, data)
|
||||||
await asyncio.wait([
|
for new_account in added_accounts:
|
||||||
a.ledger.subscribe_account(a) for a in added_accounts
|
await new_account.maybe_migrate_certificates()
|
||||||
])
|
if added_accounts and self.ledger.network.is_connected:
|
||||||
else:
|
if blocking:
|
||||||
for new_account in added_accounts:
|
await asyncio.wait([
|
||||||
asyncio.create_task(self.ledger.subscribe_account(new_account))
|
a.ledger.subscribe_account(a) for a in added_accounts
|
||||||
wallet.save()
|
])
|
||||||
encrypted = wallet.pack(password)
|
else:
|
||||||
return {
|
for new_account in added_accounts:
|
||||||
'hash': self.jsonrpc_sync_hash(wallet_id),
|
asyncio.create_task(self.ledger.subscribe_account(new_account))
|
||||||
'data': encrypted.decode()
|
wallet.save()
|
||||||
}
|
encrypted = wallet.pack(password)
|
||||||
|
return encrypted.decode()
|
||||||
|
|
||||||
@requires("wallet")
|
@requires("wallet")
|
||||||
async def jsonrpc_wallet_add(self, wallet_id):
|
async def jsonrpc_wallet_add(self, wallet_id):
|
||||||
|
|
|
@ -442,8 +442,8 @@ class WalletEncryptionAndSynchronization(CommandTestCase):
|
||||||
|
|
||||||
self.assertItemCount(await daemon.jsonrpc_account_list(), 1)
|
self.assertItemCount(await daemon.jsonrpc_account_list(), 1)
|
||||||
|
|
||||||
data = await daemon2.jsonrpc_wallet_export('password')
|
data = await daemon2.jsonrpc_wallet_export(password='password')
|
||||||
await daemon.jsonrpc_wallet_import('password', data=data['data'], blocking=True)
|
await daemon.jsonrpc_wallet_import(data=data, password='password', blocking=True)
|
||||||
|
|
||||||
self.assertItemCount(await daemon.jsonrpc_account_list(), 2)
|
self.assertItemCount(await daemon.jsonrpc_account_list(), 2)
|
||||||
self.assertDictEqual(
|
self.assertDictEqual(
|
||||||
|
@ -473,8 +473,8 @@ class WalletEncryptionAndSynchronization(CommandTestCase):
|
||||||
self.assertItemCount(await daemon2.jsonrpc_channel_list(), 1)
|
self.assertItemCount(await daemon2.jsonrpc_channel_list(), 1)
|
||||||
self.assertEqual(len(daemon2.wallet_manager.default_account.channel_keys), 1)
|
self.assertEqual(len(daemon2.wallet_manager.default_account.channel_keys), 1)
|
||||||
|
|
||||||
data = await daemon2.jsonrpc_wallet_export('password')
|
data = await daemon2.jsonrpc_wallet_export(password='password')
|
||||||
await daemon.jsonrpc_wallet_import('password', data=data['data'], blocking=True)
|
await daemon.jsonrpc_wallet_import(data=data, password='password', blocking=True)
|
||||||
|
|
||||||
# both daemons have the cert after sync'ing
|
# both daemons have the cert after sync'ing
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
|
|
Loading…
Reference in a new issue