def wait_for_sync_etherscan(blockchain_service, url, tolerance, sleep):
local_block = blockchain_service.client.block_number()
etherscan_block = etherscan_query_with_retries(url, sleep)
syncing_str = 'Syncing ... Current: {} / Target: ~{}'
if local_block >= etherscan_block - tolerance:
return
print('Waiting for the ethereum node to synchronize. [Use ^C to exit]')
print(syncing_str.format(local_block, etherscan_block), end='')
for i in count():
sys.stdout.flush()
gevent.sleep(sleep)
local_block = blockchain_service.client.block_number()
# update the oracle block number sparsely to not spam the server
if local_block >= etherscan_block or i % 50 == 0:
etherscan_block = etherscan_query_with_retries(url, sleep)
if local_block >= etherscan_block - tolerance:
return
print(CLEARLINE + CURSOR_STARTLINE, end='')
print(syncing_str.format(local_block, etherscan_block), end='')
评论列表
文章目录