adds wallet server counts on startup

This commit is contained in:
jessop 2019-11-24 16:52:58 -05:00 committed by Lex Berezhny
parent 0fee1897eb
commit 4e13cf1d85

View file

@ -107,25 +107,34 @@ 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 and self.wallet_manager.ledger.network.remote_height: if self.wallet_manager:
local_height = self.wallet_manager.ledger.local_height_including_downloaded_height sessions = self.wallet_manager.ledger.network.session_pool.sessions
remote_height = self.wallet_manager.ledger.network.remote_height if self.wallet_manager.ledger.network.remote_height:
best_hash = self.wallet_manager.get_best_blockhash() local_height = self.wallet_manager.ledger.local_height_including_downloaded_height
progress = min(max(math.ceil(float(local_height) / float(remote_height) * 100), 0), 100) remote_height = self.wallet_manager.ledger.network.remote_height
return { best_hash = self.wallet_manager.get_best_blockhash()
'connected_servers': [ progress = min(max(math.ceil(float(local_height) / float(remote_height) * 100), 0), 100)
{ return {
'host': session.server[0], 'connected_servers': [
'port': session.server[1], {
'latency': round(session.connection_latency, 2), 'host': session.server[0],
} for session in self.wallet_manager.ledger.network.session_pool.sessions 'port': session.server[1],
if session and session.available 'latency': round(session.connection_latency, 2),
], } for session in sessions
'headers_synchronization_progress': progress, if session and session.available
'blocks': max(local_height, 0), ],
'blocks_behind': max(remote_height - local_height, 0), 'headers_synchronization_progress': progress,
'best_blockhash': best_hash, 'blocks': max(local_height, 0),
} 'blocks_behind': max(remote_height - local_height, 0),
'best_blockhash': best_hash,
'known_servers': len(sessions),
'available_servers': sum(s.available is True for s in sessions)
}
else:
return {
'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")