2021-06-28 07:48:36 +02:00
|
|
|
# standard imports
|
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
|
|
|
|
# local imports
|
2021-08-21 09:27:40 +02:00
|
|
|
from chainlib.jsonrpc import JSONRPCRequest
|
2021-06-28 07:48:36 +02:00
|
|
|
from chainlib.eth.connection import EthHTTPConnection
|
|
|
|
|
|
|
|
# set up node connection and execute rpc call
|
|
|
|
rpc_provider = os.environ.get('RPC_PROVIDER', 'http://localhost:8545')
|
2021-08-21 09:27:40 +02:00
|
|
|
conn = EthHTTPConnection(rpc_provider)
|
2021-06-28 07:48:36 +02:00
|
|
|
|
|
|
|
# check the connection
|
2021-08-21 09:27:40 +02:00
|
|
|
if not conn.check():
|
2021-06-28 07:48:36 +02:00
|
|
|
sys.stderr.write('node {} not usable\n'.format(rpc_provider))
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
# build and send rpc call
|
2021-08-21 09:27:40 +02:00
|
|
|
g = JSONRPCRequest()
|
|
|
|
o = g.template()
|
2021-06-28 07:48:36 +02:00
|
|
|
o['method'] = 'eth_blockNumber'
|
2021-08-21 09:27:40 +02:00
|
|
|
r = conn.do(o)
|
2021-06-28 07:48:36 +02:00
|
|
|
|
|
|
|
# interpret result for humans
|
|
|
|
try:
|
|
|
|
block_number = int(r, 10)
|
|
|
|
except ValueError:
|
|
|
|
block_number = int(r, 16)
|
|
|
|
|
|
|
|
print('block number {}'.format(block_number))
|