Merge pull request #2900 from lbryio/wallet_status_does_not_fail
`wallet_status` no longer fails if wallet component has not started
This commit is contained in:
commit
1a4b0cb12a
4 changed files with 30 additions and 10 deletions
|
@ -158,11 +158,14 @@ class ComponentManager:
|
||||||
for component in self.components
|
for component in self.components
|
||||||
}
|
}
|
||||||
|
|
||||||
def get_component(self, component_name):
|
def get_actual_component(self, component_name):
|
||||||
for component in self.components:
|
for component in self.components:
|
||||||
if component.component_name == component_name:
|
if component.component_name == component_name:
|
||||||
return component.component
|
return component
|
||||||
raise NameError(component_name)
|
raise NameError(component_name)
|
||||||
|
|
||||||
|
def get_component(self, component_name):
|
||||||
|
return self.get_actual_component(component_name).component
|
||||||
|
|
||||||
def has_component(self, component_name):
|
def has_component(self, component_name):
|
||||||
return any(component for component in self.components if component_name == component.component_name)
|
return any(component for component in self.components if component_name == component.component_name)
|
||||||
|
|
|
@ -1341,6 +1341,8 @@ class Daemon(metaclass=JSONRPCServerType):
|
||||||
Returns:
|
Returns:
|
||||||
Dictionary of wallet status information.
|
Dictionary of wallet status information.
|
||||||
"""
|
"""
|
||||||
|
if self.wallet_manager is None:
|
||||||
|
return {'is_encrypted': None, 'is_syncing': None, 'is_locked': None}
|
||||||
wallet = self.wallet_manager.get_wallet_or_default(wallet_id)
|
wallet = self.wallet_manager.get_wallet_or_default(wallet_id)
|
||||||
return {
|
return {
|
||||||
'is_encrypted': wallet.is_encrypted,
|
'is_encrypted': wallet.is_encrypted,
|
||||||
|
|
|
@ -7,6 +7,7 @@ class TaskGroup:
|
||||||
self._loop = loop or get_event_loop()
|
self._loop = loop or get_event_loop()
|
||||||
self._tasks = set()
|
self._tasks = set()
|
||||||
self.done = Event()
|
self.done = Event()
|
||||||
|
self.started = Event()
|
||||||
|
|
||||||
def __len__(self):
|
def __len__(self):
|
||||||
return len(self._tasks)
|
return len(self._tasks)
|
||||||
|
@ -14,6 +15,7 @@ class TaskGroup:
|
||||||
def add(self, coro):
|
def add(self, coro):
|
||||||
task = self._loop.create_task(coro)
|
task = self._loop.create_task(coro)
|
||||||
self._tasks.add(task)
|
self._tasks.add(task)
|
||||||
|
self.started.set()
|
||||||
self.done.clear()
|
self.done.clear()
|
||||||
task.add_done_callback(self._remove)
|
task.add_done_callback(self._remove)
|
||||||
return task
|
return task
|
||||||
|
@ -22,8 +24,10 @@ class TaskGroup:
|
||||||
self._tasks.remove(task)
|
self._tasks.remove(task)
|
||||||
if len(self._tasks) < 1:
|
if len(self._tasks) < 1:
|
||||||
self.done.set()
|
self.done.set()
|
||||||
|
self.started.clear()
|
||||||
|
|
||||||
def cancel(self):
|
def cancel(self):
|
||||||
for task in self._tasks:
|
for task in self._tasks:
|
||||||
task.cancel()
|
task.cancel()
|
||||||
self.done.set()
|
self.done.set()
|
||||||
|
self.started.clear()
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
import asyncio
|
import asyncio
|
||||||
import json
|
import json
|
||||||
import os
|
|
||||||
|
|
||||||
from lbry.wallet import ENCRYPT_ON_DISK
|
from lbry.wallet import ENCRYPT_ON_DISK
|
||||||
from lbry.error import InvalidPasswordError
|
from lbry.error import InvalidPasswordError
|
||||||
|
@ -22,14 +21,26 @@ class WalletCommands(CommandTestCase):
|
||||||
|
|
||||||
async def test_wallet_syncing_status(self):
|
async def test_wallet_syncing_status(self):
|
||||||
address = await self.daemon.jsonrpc_address_unused()
|
address = await self.daemon.jsonrpc_address_unused()
|
||||||
sendtxid = await self.blockchain.send_to_address(address, 1)
|
self.assertFalse(self.daemon.jsonrpc_wallet_status()['is_syncing'])
|
||||||
|
await self.blockchain.send_to_address(address, 1)
|
||||||
|
await self.ledger._update_tasks.started.wait()
|
||||||
|
self.assertTrue(self.daemon.jsonrpc_wallet_status()['is_syncing'])
|
||||||
|
await self.ledger._update_tasks.done.wait()
|
||||||
|
self.assertFalse(self.daemon.jsonrpc_wallet_status()['is_syncing'])
|
||||||
|
|
||||||
async def eventually_will_sync():
|
wallet = self.daemon.component_manager.get_actual_component('wallet')
|
||||||
while not self.daemon.jsonrpc_wallet_status()['is_syncing']:
|
wallet_manager = wallet.wallet_manager
|
||||||
await asyncio.sleep(0)
|
# when component manager hasn't started yet
|
||||||
check_sync = asyncio.create_task(eventually_will_sync())
|
wallet.wallet_manager = None
|
||||||
await self.confirm_tx(sendtxid, self.ledger)
|
self.assertEqual(
|
||||||
await asyncio.wait_for(check_sync, timeout=10)
|
{'is_encrypted': None, 'is_syncing': None, 'is_locked': None},
|
||||||
|
self.daemon.jsonrpc_wallet_status()
|
||||||
|
)
|
||||||
|
wallet.wallet_manager = wallet_manager
|
||||||
|
self.assertEqual(
|
||||||
|
{'is_encrypted': False, 'is_syncing': False, 'is_locked': False},
|
||||||
|
self.daemon.jsonrpc_wallet_status()
|
||||||
|
)
|
||||||
|
|
||||||
async def test_wallet_reconnect(self):
|
async def test_wallet_reconnect(self):
|
||||||
await self.conductor.spv_node.stop(True)
|
await self.conductor.spv_node.stop(True)
|
||||||
|
|
Loading…
Reference in a new issue