chainlib

Generic blockchain access library and tooling
Log | Files | Refs | README | LICENSE

commit 5bac222e9cb81d3ea9f572553ceea47591085d57
parent 3e3a351c2d16aa4fbfef7e45b1cd2f8ca0548e24
Author: nolash <dev@holbrook.no>
Date:   Fri,  4 Jun 2021 20:52:08 +0200

Add noarg tx helpers, bytes32 in decoder

Diffstat:
Mchainlib/eth/contract.py | 4++++
Mchainlib/eth/gas.py | 1+
Mchainlib/eth/tx.py | 24++++++++++++++++++++++++
Msetup.cfg | 2+-
4 files changed, 30 insertions(+), 1 deletion(-)

diff --git 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 @@ -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 @@ -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 @@ -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