From 5bac222e9cb81d3ea9f572553ceea47591085d57 Mon Sep 17 00:00:00 2001 From: nolash Date: Fri, 4 Jun 2021 20:52:08 +0200 Subject: [PATCH] Add noarg tx helpers, bytes32 in decoder --- chainlib/eth/contract.py | 4 ++++ chainlib/eth/gas.py | 1 + chainlib/eth/tx.py | 24 ++++++++++++++++++++++++ setup.cfg | 2 +- 4 files changed, 30 insertions(+), 1 deletion(-) diff --git a/chainlib/eth/contract.py b/chainlib/eth/contract.py index 3a9fa05..85f4db4 100644 --- a/chainlib/eth/contract.py +++ b/chainlib/eth/contract.py @@ -57,6 +57,10 @@ class ABIContractDecoder: return int(v, 16) + def bytes32(self, v): + return v + + def bool(self, v): return bool(self.uint256(v)) diff --git a/chainlib/eth/gas.py b/chainlib/eth/gas.py index 22fa4c1..108b1be 100644 --- a/chainlib/eth/gas.py +++ b/chainlib/eth/gas.py @@ -47,6 +47,7 @@ class Gas(TxFactory): tx_raw_hex = add_0x(tx_raw.hex()) tx_hash_hex = add_0x(keccak256_hex_to_hex(tx_raw_hex)) + o = None if tx_format == TxFormat.JSONRPC: o = raw(tx_raw_hex) elif tx_format == TxFormat.RLP_SIGNED: diff --git a/chainlib/eth/tx.py b/chainlib/eth/tx.py index 3d35069..f347028 100644 --- a/chainlib/eth/tx.py +++ b/chainlib/eth/tx.py @@ -26,6 +26,7 @@ from .constant import ( MINIMUM_FEE_PRICE, ZERO_ADDRESS, ) +from .contract import ABIContractEncoder from chainlib.jsonrpc import jsonrpc_template logg = logging.getLogger().getChild(__name__) @@ -271,6 +272,29 @@ class TxFactory: logg.debug('using hardcoded gas limit of 8000000 until we have reliable vm executor') return tx + + def transact_noarg(self, method, contract_address, sender_address, tx_format=TxFormat.JSONRPC): + enc = ABIContractEncoder() + enc.method(method) + data = enc.get() + tx = self.template(sender_address, contract_address, use_nonce=True) + tx = self.set_code(tx, data) + tx = self.finalize(tx, tx_format) + return tx + + + def call_noarg(self, method, contract_address, sender_address=ZERO_ADDRESS): + o = jsonrpc_template() + o['method'] = 'eth_call' + enc = ABIContractEncoder() + enc.method(method) + data = add_0x(enc.get()) + tx = self.template(sender_address, contract_address) + tx = self.set_code(tx, data) + o['params'].append(self.normalize(tx)) + o['params'].append('latest') + return o + class Tx: diff --git a/setup.cfg b/setup.cfg index cc7c989..5e8f3bf 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,6 +1,6 @@ [metadata] name = chainlib -version = 0.0.3rc2 +version = 0.0.3rc3 description = Generic blockchain access library and tooling author = Louis Holbrook author_email = dev@holbrook.no