chainlib-eth

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

commit d20297a6c7ca5b9ad0b3925bc25c40683bec462f
parent 5b97b9e5f1968c10e81f11cbb7df70c01620c3a3
Author: lash <dev@holbrook.no>
Date:   Mon,  8 May 2023 06:23:40 +0100

Allow short form in bytes and address cli encode

Diffstat:
MCHANGELOG | 4++++
Mchainlib/eth/cli/encode.py | 13++++++++++---
Mchainlib/eth/contract.py | 6+++---
Msetup.cfg | 2+-
4 files changed, 18 insertions(+), 7 deletions(-)

diff --git a/CHANGELOG b/CHANGELOG @@ -1,3 +1,7 @@ +- 0.4.20 + * Enable short 0 value in eth-encode for address and bytes +- 0.4.19 + * Proper hex comparison in contract topic decoder - 0.4.18 * Set a dirty bit on abi encoder when type added before contents generation * Support for tuple abi encoding (decoding not implemented) diff --git a/chainlib/eth/cli/encode.py b/chainlib/eth/cli/encode.py @@ -7,6 +7,8 @@ from chainlib.eth.contract import ( ABIContractType, ABIContractEncoder, ) +from chainlib.eth.constant import ZERO_ADDRESS +from chainlib.eth.constant import ZERO_CONTENT logg = logging.getLogger(__name__) @@ -81,7 +83,7 @@ class CLIEncoder(ABIContractEncoder): return (s, a) - def translate_type(self, typ): + def translate(self, typ, val): r = None for tr in self.__translations: r = getattr(self, tr)(typ) @@ -90,13 +92,18 @@ class CLIEncoder(ABIContractEncoder): if r == None: raise ValueError('no translation for type {}'.format(typ)) logg.debug('type {} translated to {}'.format(typ, r[0])) - return r[1] + if int(val) == 0: + if r[0][0] == 'B': + val = ZERO_CONTENT + elif r[0][0] == 'A': + val = ZERO_ADDRESS + return (r[1], val,) def add_from(self, arg): logg.debug('arg {}'.format(arg)) (typ, val) = arg.split(':', maxsplit=1) - real_typ = self.translate_type(typ) + (real_typ, val) = self.translate(typ, val) if self.signature != None: self.typ(real_typ) fn = getattr(self, real_typ.value) diff --git a/chainlib/eth/contract.py b/chainlib/eth/contract.py @@ -8,6 +8,7 @@ from hexathon import ( strip_0x, add_0x, pad, + same as same_hex, ) # local imports @@ -350,7 +351,7 @@ class ABIContractLogDecoder(ABIMethodEncoder, ABIContractDecoder): :raises ValueError: Topic of input does not match topic set in parser """ t = self.get_signature() - if topics[0] != t: + if not same_hex(topics[0], t): raise ValueError('topic mismatch') for i in range(len(topics) - 1): self.contents.append(topics[i+1]) @@ -430,7 +431,7 @@ class ABIContractEncoder(ABIMethodEncoder): :param v: Ethereum address, in hex :type v: str """ - self.bytes_fixed(32, v, 20) + self.bytes_fixed(32, v, exact=20) self.add_type(ABIContractType.ADDRESS) self.__log_latest(v) @@ -534,7 +535,6 @@ class ABIContractEncoder(ABIMethodEncoder): self.contents.append(v.ljust(64, '0')) - def get_contents(self): """Encode value array. diff --git a/setup.cfg b/setup.cfg @@ -1,6 +1,6 @@ [metadata] name = chainlib-eth -version = 0.4.18 +version = 0.4.20 description = Ethereum implementation of the chainlib interface author = Louis Holbrook author_email = dev@holbrook.no