commit a582b8bc0ed6a03f02ee16b0452b2648c71f3443
parent f56263db4b4257ed93974be07f5d5dbd212bdde0
Author: lash <dev@holbrook.no>
Date: Wed, 8 Feb 2023 08:18:01 +0000
Add arbitrary type definition for method signature in contract
Diffstat:
3 files changed, 29 insertions(+), 3 deletions(-)
diff --git a/chainlib/eth/contract.py b/chainlib/eth/contract.py
@@ -34,10 +34,12 @@ class ABIContractType(enum.Enum):
UINT8 = 'uint8'
ADDRESS = 'address'
STRING = 'string'
+ BYTES = 'bytes'
BOOLEAN = 'bool'
dynamic_contract_types = [
ABIContractType.STRING,
+ ABIContractType.BYTES,
]
@@ -100,6 +102,13 @@ class ABIMethodEncoder(ABIContract):
self.__log_method()
+ def typ_literal(self, v):
+ if type(v).__name__ != 'str':
+ raise ValueError('literal type must be string')
+ self.method_contents.append(v)
+ self.__log_method()
+
+
def __log_method(self):
logg.debug('method set to {}'.format(self.get_method()))
@@ -298,6 +307,7 @@ class ABIContractLogDecoder(ABIMethodEncoder, ABIContractDecoder):
self.types.append(v.value)
+
def apply(self, topics, data):
"""Set log entry data to parse.
@@ -430,7 +440,12 @@ class ABIContractEncoder(ABIMethodEncoder):
return contents
- def bytes_fixed(self, mx, v, exact=0):
+ def bytes(self, v):
+ l = len(v)
+
+
+
+ def bytes_fixed(self, mx, v, exact=0, enforce_word=False):
"""Add arbirary length byte data to value vector.
:param mx: Max length of input data.
@@ -445,15 +460,23 @@ class ABIContractEncoder(ABIMethodEncoder):
if typ == 'str':
v = strip_0x(v)
l = len(v)
+ if mx == 0:
+ mx = l
if exact > 0 and l != exact * 2:
raise ValueError('value wrong size; expected {}, got {})'.format(mx, l))
+ if enforce_word and mx % 32 > 0:
+ raise ValueError('value size {} does not match word boundary'.format(mx))
if l > mx * 2:
raise ValueError('value too long ({})'.format(l))
v = pad(v, mx)
elif typ == 'bytes':
l = len(v)
+ if mx == 0:
+ mx = l
if exact > 0 and l != exact:
raise ValueError('value wrong size; expected {}, got {})'.format(mx, l))
+ if enforce_word and mx % 32 > 0:
+ raise ValueError('value size {} does not match word boundary'.format(mx))
b = bytearray(mx)
b[mx-l:] = v
v = pad(b.hex(), mx)
diff --git a/chainlib/eth/runnable/decode.py b/chainlib/eth/runnable/decode.py
@@ -51,7 +51,10 @@ def process_config_local(config, arg, args, flags):
data = strip_0x(data)
config.add(data, '_TX_DATA', False)
-
+
+ # workaround to avoid rpc lookup of fee parameters when using arg mode
+ config.add(0, '_FEE_PRICE', True)
+ config.add(0, '_FEE_LIMIT', True)
return config
diff --git a/setup.cfg b/setup.cfg
@@ -1,6 +1,6 @@
[metadata]
name = chainlib-eth
-version = 0.4.10
+version = 0.4.11
description = Ethereum implementation of the chainlib interface
author = Louis Holbrook
author_email = dev@holbrook.no