@@ -17,26 +17,28 @@ def syncing(id, params):
1717 if err is not None :
1818 raise rpcerrorhandler .BadRequestError (err .message )
1919
20- blockchainInfo = RPCConnector .request (RPC_ENDPOINT , id ,
21- GET_SYNC_INFO , None )
20+ blockchainInfo = RPCConnector .request (RPC_ENDPOINT , id , GET_INFO , None )
2221
2322 if blockchainInfo is None :
2423 logger .printWarning ("Could not get blockchain info from node" )
25- raise rpcerrorhandler .BadRequestError (
26- "Could not get blockchain info from node" )
27-
28- # if blockchainInfo[BLOCKS] != blockchainInfo[HEADERS]:
29- # response = {
30- # SYNCING: True,
31- # SYNC_PERCENTAGE:
32- # f'{str(blockchainInfo[VERIFICATION_PROGRESS]*100)}%',
33- # CURRENT_BLOCK_INDEX: blockchainInfo[BLOCKS],
34- # LATEST_BLOCK_INDEX: blockchainInfo[HEADERS],
35- # }
36- # else:
37- # response = {SYNCING: False}
38-
39- response = {SYNCING : blockchainInfo }
24+ raise rpcerrorhandler .BadRequestError ("Could not get blockchain info from node" )
25+
26+ if not blockchainInfo [SYNCHRONIZED ]:
27+ syncInfo = RPCConnector .request (RPC_ENDPOINT , id , GET_SYNC_INFO , None )
28+
29+ if syncInfo is None :
30+ logger .printWarning ("Could not get syncing info from node" )
31+ raise rpcerrorhandler .BadRequestError ("Could not get syncing info from node" )
32+
33+ response = {
34+ SYNCING : True ,
35+ SYNC_PERCENTAGE :
36+ f'{ str (syncInfo [HEIGHT ] / syncInfo [TARGET_HEIGHT ] * 100 )} %' ,
37+ CURRENT_BLOCK_INDEX : str (syncInfo [HEIGHT ]),
38+ LATEST_BLOCK_INDEX : str (syncInfo [TARGET_HEIGHT ]),
39+ }
40+ else :
41+ response = {SYNCING : False }
4042
4143 err = rpcutils .validateJSONRPCSchema (response , responseSchema )
4244 if err is not None :
0 commit comments