chainlib-eth

Ethereum implementation of the chainlib interface
Log | Files | Refs | README | LICENSE

commit e9f31ed7f154ae074636e0e2362dc8798fbdf729
parent 7f2c32975d18f43f417c7ebd0cfa1000c2de1623
Author: lash <dev@holbrook.no>
Date:   Sat, 12 Feb 2022 12:30:13 +0000

Make block by number compatible with geth

Diffstat:
MCHANGELOG | 3+++
Mchainlib/eth/block.py | 5+++--
Mchainlib/eth/runnable/info.py | 5++++-
Mchainlib/eth/tx.py | 16+++++++++++-----
Mrequirements.txt | 2+-
Msetup.cfg | 3+--
6 files changed, 23 insertions(+), 11 deletions(-)

diff --git a/CHANGELOG b/CHANGELOG @@ -1,5 +1,8 @@ +- 0.0.23: + * Make get block args and responses compatible with picky golang marhaling in geth - 0.0.22: * Enable unpack of pre EIP-155 transactions + * Allow missing status property of receipts in non-strict modes - 0.0.21: * Remove warnings from cytoolz/rlp in funga-eth - 0.0.15: diff --git a/chainlib/eth/block.py b/chainlib/eth/block.py @@ -4,7 +4,7 @@ from chainlib.block import Block as BaseBlock from hexathon import ( add_0x, strip_0x, - even, + compact, ) # local imports @@ -34,7 +34,8 @@ def block_by_hash(hsh, include_tx=True, id_generator=None): def block_by_number(n, include_tx=True, id_generator=None): """Implements chainlib.interface.ChainInterface method """ - nhx = add_0x(even(hex(n)[2:])) + hx = strip_0x(hex(n)) + nhx = add_0x(compact(hx), compact_value=True) j = JSONRPCRequest(id_generator) o = j.template() o['method'] = 'eth_getBlockByNumber' diff --git a/chainlib/eth/runnable/info.py b/chainlib/eth/runnable/info.py @@ -105,7 +105,10 @@ def main(): o = block_latest(id_generator=rpc.id_generator) r = conn.do(o) - n = int(r, 16) + try: + n = int(r, 16) + except ValueError: + n = int(r) first_block_number = n if human: n = format(n, ',') diff --git a/chainlib/eth/tx.py b/chainlib/eth/tx.py @@ -519,7 +519,7 @@ class Tx(BaseTx): #:todo: divide up constructor method """ - def __init__(self, src, block=None, rcpt=None): + def __init__(self, src, block=None, rcpt=None, strict=False): self.__rcpt_block_hash = None src = self.src_normalize(src) @@ -575,7 +575,7 @@ class Tx(BaseTx): self.logs = None if rcpt != None: - self.apply_receipt(rcpt) + self.apply_receipt(rcpt, strict=strict) self.v = src.get('v') self.r = src.get('r') @@ -618,7 +618,7 @@ class Tx(BaseTx): return self.src() - def apply_receipt(self, rcpt): + def apply_receipt(self, rcpt, strict=False): """Apply receipt data to transaction object. Effect is the same as passing a receipt at construction. @@ -642,6 +642,12 @@ class Tx(BaseTx): status_number = int(rcpt['status'], 16) except TypeError: status_number = int(rcpt['status']) + except KeyError as e: + if strict: + raise(e) + logg.warning('setting "sucess" status on missing status property for {}'.format(self.hash)) + status_number = 1 + if rcpt['block_number'] == None: self.status = Status.PENDING else: @@ -696,12 +702,12 @@ class Tx(BaseTx): @staticmethod - def from_src(src, block=None, rcpt=None): + def from_src(src, block=None, rcpt=None, strict=False): """Creates a new Tx object. Alias of constructor. """ - return Tx(src, block=block, rcpt=rcpt) + return Tx(src, block=block, rcpt=rcpt, strict=strict) def __str__(self): diff --git a/requirements.txt b/requirements.txt @@ -1,6 +1,6 @@ funga-eth~=0.5.3 pysha3==1.0.2 -hexathon~=0.1.1 +hexathon~=0.1.2 websocket-client==0.57.0 potaahto~=0.1.0 chainlib~=0.0.17 diff --git a/setup.cfg b/setup.cfg @@ -1,6 +1,6 @@ [metadata] name = chainlib-eth -version = 0.0.22 +version = 0.0.23 description = Ethereum implementation of the chainlib interface author = Louis Holbrook author_email = dev@holbrook.no @@ -48,4 +48,3 @@ console_scripts = eth-info = chainlib.eth.runnable.info:main eth-nonce = chainlib.eth.runnable.count:main eth-wait = chainlib.eth.runnable.wait:main - eth = chainlib.eth.runnable.info:main