|
| 1 | +from .constants import * |
| 2 | +from .connector import RPC_ENDPOINT |
| 3 | +from rpcutils import rpcutils, errorhandler as rpcerrorhandler |
| 4 | +from rpcutils.rpcconnector import RPCConnector |
| 5 | +from . import utils |
| 6 | +from logger import logger |
| 7 | + |
| 8 | + |
| 9 | +@rpcutils.rpcMethod |
| 10 | +def syncing(id, params): |
| 11 | + |
| 12 | + logger.printInfo(f"Executing RPC method syncing with id {id} and params {params}") |
| 13 | + |
| 14 | + requestSchema, responseSchema = utils.getMethodSchemas(SYNCING) |
| 15 | + |
| 16 | + err = rpcutils.validateJSONRPCSchema(params, requestSchema) |
| 17 | + if err is not None: |
| 18 | + raise rpcerrorhandler.BadRequestError(err.message) |
| 19 | + |
| 20 | + blockchainInfo = RPCConnector.request(RPC_ENDPOINT, id, |
| 21 | + GET_SYNC_INFO, None) |
| 22 | + |
| 23 | + if blockchainInfo is None: |
| 24 | + 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} |
| 40 | + |
| 41 | + err = rpcutils.validateJSONRPCSchema(response, responseSchema) |
| 42 | + if err is not None: |
| 43 | + raise rpcerrorhandler.BadRequestError(err.message) |
| 44 | + |
| 45 | + return response |
0 commit comments