Handle null-value block hashes on receipts

This commit is contained in:
nolash 2021-10-25 11:24:55 +02:00
parent 31e75f60de
commit 6ee3ea4638
Signed by: lash
GPG Key ID: 21D2E7BB88C2A746
4 changed files with 82 additions and 28 deletions

View File

@ -60,6 +60,20 @@ def transaction_count(block_hash, id_generator=None):
return j.finalize(o) return j.finalize(o)
def syncing(id_generator=None):
"""Request the syncing state of the node
:param id_generator: JSONRPC id generator
:type id_generator: JSONRPCIdGenerator
:rtype: dict
:returns: rpc query object
"""
j = JSONRPCRequest(id_generator)
o = j.template()
o['method'] = 'eth_syncing'
return j.finalize(o)
class Block(BaseBlock): class Block(BaseBlock):
"""Encapsulates an Ethereum block """Encapsulates an Ethereum block

View File

@ -36,6 +36,7 @@ from chainlib.jsonrpc import (
from chainlib.eth.tx import ( from chainlib.eth.tx import (
unpack, unpack,
) )
from potaahto.symbols import snake_and_camel
logg = logging.getLogger(__name__) logg = logging.getLogger(__name__)
@ -88,6 +89,11 @@ class EthHTTPConnection(JSONRPCHTTPConnection):
e = jsonrpc_result(r, error_parser) e = jsonrpc_result(r, error_parser)
if e != None: if e != None:
e = snake_and_camel(e)
# In openethereum we encounter receipts that have NONE block hashes and numbers. WTF...
if e['block_hash'] == None:
logg.warning('poll receipt attempt {} returned receipt but with a null block hash value!'.format(i))
else:
logg.debug('({}) poll receipt completed {}'.format(str(self), r)) logg.debug('({}) poll receipt completed {}'.format(str(self), r))
logg.debug('e {}'.format(strip_0x(e['status']))) logg.debug('e {}'.format(strip_0x(e['status'])))
if strip_0x(e['status']) == '00': if strip_0x(e['status']) == '00':

View File

@ -24,6 +24,7 @@ from chainlib.eth.chain import network_id
from chainlib.eth.block import ( from chainlib.eth.block import (
block_latest, block_latest,
block_by_number, block_by_number,
syncing,
Block, Block,
) )
from chainlib.eth.tx import count from chainlib.eth.tx import count
@ -43,25 +44,35 @@ logg = logging.getLogger()
script_dir = os.path.dirname(os.path.realpath(__file__)) script_dir = os.path.dirname(os.path.realpath(__file__))
config_dir = os.path.join(script_dir, '..', 'data', 'config') config_dir = os.path.join(script_dir, '..', 'data', 'config')
results_translation = {
'network_id': 'Network Id',
'block': 'Block',
'syncing': 'Syncing',
'gas_limit': 'Gas Limit',
'gas_price': 'Gas Price',
'block_time': 'Block time',
}
arg_flags = chainlib.eth.cli.argflag_std_read arg_flags = chainlib.eth.cli.argflag_std_read
argparser = chainlib.eth.cli.ArgumentParser(arg_flags) argparser = chainlib.eth.cli.ArgumentParser(arg_flags)
argparser.add_positional('address', type=str, help='Address to retrieve info for', required=False)
argparser.add_argument('--long', action='store_true', help='Calculate averages through sampling of blocks and txs') argparser.add_argument('--long', action='store_true', help='Calculate averages through sampling of blocks and txs')
argparser.add_argument('--local', action='store_true', help='Include local info')
argparser.add_positional('entry', required=False, help='Output single item')
args = argparser.parse_args() args = argparser.parse_args()
config = chainlib.eth.cli.Config.from_args(args, arg_flags, extra_args={'long': None}, default_config_dir=config_dir) extra_args = {
'local': None,
'long': None,
'entry': None,
}
config = chainlib.eth.cli.Config.from_args(args, arg_flags, extra_args=extra_args, default_config_dir=config_dir)
holder_address = None if config.get('_ENTRY') != None:
try: if config.get('_ENTRY') not in results_translation.keys():
holder_address = add_0x(args.address) raise ValueError('Unknown entry {}'.format(config.get('_ENTRY')))
except ValueError:
pass
wallet = chainlib.eth.cli.Wallet()
wallet.from_config(config)
if wallet.get_signer_address() == None and holder_address != None:
wallet.from_address(holder_address)
rpc = chainlib.eth.cli.Rpc(wallet=wallet) rpc = chainlib.eth.cli.Rpc()
conn = rpc.connect_by_config(config) conn = rpc.connect_by_config(config)
token_symbol = 'eth' token_symbol = 'eth'
@ -72,12 +83,25 @@ human = not config.true('_RAW')
longmode = config.true('_LONG') longmode = config.true('_LONG')
def set_result(results, k, v, w=sys.stdout):
kt = results_translation[k]
if str(config.get('_ENTRY')) == k:
w.write('{}'.format(v))
return True
logg.info('{}: {}\n'.format(kt, v))
results[k] = v
return False
def main(): def main():
results = {}
o = network_id(id_generator=rpc.id_generator) o = network_id(id_generator=rpc.id_generator)
r = conn.do(o) r = conn.do(o)
#if human: #if human:
# n = format(n, ',') # n = format(n, ',')
sys.stdout.write('Network id: {}\n'.format(r)) if set_result(results, 'network_id', r):
return
o = block_latest(id_generator=rpc.id_generator) o = block_latest(id_generator=rpc.id_generator)
r = conn.do(o) r = conn.do(o)
@ -85,7 +109,8 @@ def main():
first_block_number = n first_block_number = n
if human: if human:
n = format(n, ',') n = format(n, ',')
sys.stdout.write('Block: {}\n'.format(n)) if set_result(results, 'block', n):
return
o = block_by_number(first_block_number, False, id_generator=rpc.id_generator) o = block_by_number(first_block_number, False, id_generator=rpc.id_generator)
r = conn.do(o) r = conn.do(o)
@ -111,22 +136,31 @@ def main():
if human: if human:
n = format(n, ',') n = format(n, ',')
sys.stdout.write('Gaslimit: {}\n'.format(n)) if set_result(results, 'gas_limit', n):
sys.stdout.write('Blocktime: {}\n'.format(aggr_time / BLOCK_SAMPLES)) return
if set_result(results, 'block_time', aggr_time / BLOCK_SAMPLES):
return
o = price(id_generator=rpc.id_generator) o = price(id_generator=rpc.id_generator)
r = conn.do(o) r = conn.do(o)
n = int(r, 16) n = int(r, 16)
if human: if human:
n = format(n, ',') n = format(n, ',')
sys.stdout.write('Gasprice: {}\n'.format(n)) if set_result(results, 'gas_price', n):
return
if holder_address != None: if config.get('_LOCAL'):
o = count(holder_address) o = syncing()
r = conn.do(o) r = conn.do(o)
n = int(r, 16) if set_result(results, 'syncing', r):
sys.stdout.write('Address: {}\n'.format(holder_address)) return
sys.stdout.write('Nonce: {}\n'.format(n))
if config.get('_ENTRY') != None:
raise RuntimeError('entry {} ({}) not processed, please review the flag settings'.format(config.get('_ENTRY'), results_translation[config.get('_ENTRY')]))
for k in results.keys():
kt = results_translation[k]
sys.stdout.write('{}: {}\n'.format(kt, results[k]))
if __name__ == '__main__': if __name__ == '__main__':

View File

@ -1,6 +1,6 @@
[metadata] [metadata]
name = chainlib-eth name = chainlib-eth
version = 0.0.10a13 version = 0.0.10a15
description = Ethereum implementation of the chainlib interface description = Ethereum implementation of the chainlib interface
author = Louis Holbrook author = Louis Holbrook
author_email = dev@holbrook.no author_email = dev@holbrook.no