Add noarg tx helpers, bytes32 in decoder

This commit is contained in:
nolash 2021-06-04 20:52:08 +02:00
parent 3e3a351c2d
commit 5bac222e9c
Signed by: lash
GPG Key ID: 21D2E7BB88C2A746
4 changed files with 30 additions and 1 deletions

View File

@ -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))

View File

@ -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:

View File

@ -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:

View File

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