This commit is contained in:
jessop 2019-11-26 11:01:11 -05:00 committed by Lex Berezhny
parent 6e3a25d255
commit c2dae43965

View file

@ -107,42 +107,36 @@ class WalletComponent(Component):
return self.wallet_manager return self.wallet_manager
async def get_status(self): async def get_status(self):
if self.wallet_manager: if self.wallet_manager is None:
sessions = self.wallet_manager.ledger.network.session_pool.sessions return
session_pool = self.wallet_manager.ledger.network.session_pool
sessions = session_pool.sessions
result = {
'servers': [
{
'host': session.server[0],
'port': session.server[1],
'latency': session.connection_latency,
'availability': session.available,
} for session in sessions
],
'known_servers': len(sessions),
'available_servers': len(list(session_pool.available_sessions))
}
if self.wallet_manager.ledger.network.remote_height: if self.wallet_manager.ledger.network.remote_height:
local_height = self.wallet_manager.ledger.local_height_including_downloaded_height local_height = self.wallet_manager.ledger.local_height_including_downloaded_height
remote_height = self.wallet_manager.ledger.network.remote_height remote_height = self.wallet_manager.ledger.network.remote_height
best_hash = self.wallet_manager.get_best_blockhash() best_hash = self.wallet_manager.get_best_blockhash()
progress = min(max(math.ceil(float(local_height) / float(remote_height) * 100), 0), 100) progress = min(max(math.ceil(float(local_height) / float(remote_height) * 100), 0), 100)
return { result.update({
'servers': [
{
'host': session.server[0],
'port': session.server[1],
'latency': round(session.connection_latency, 2) if session.connection_latency else None,
'availability': session.available,
} for session in sessions
],
'headers_synchronization_progress': progress, 'headers_synchronization_progress': progress,
'blocks': max(local_height, 0), 'blocks': max(local_height, 0),
'blocks_behind': max(remote_height - local_height, 0), 'blocks_behind': max(remote_height - local_height, 0),
'best_blockhash': best_hash, 'best_blockhash': best_hash,
'known_servers': len(sessions), })
'available_servers': sum(s.available is True for s in sessions)
} return result
else:
return {
'servers': [
{
'host': session.server[0],
'port': session.server[1],
'latency': round(session.connection_latency, 2) if session.connection_latency else None,
'availability': session.available,
} for session in sessions
],
'known_servers': len(sessions),
'available_servers': sum(s.available is True for s in sessions)
}
async def start(self): async def start(self):
log.info("Starting torba wallet") log.info("Starting torba wallet")