chainlib

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

commit 29f4fdb7772e3004e50597302df4ca93b37117fe
parent df4d62e3e7dcfb2cb398bd69d56f95c6f3338041
Author: nolash <dev@holbrook.no>
Date:   Wed, 14 Apr 2021 14:45:37 +0200

Add missing import in checksum cli

Diffstat:
Mchainlib/eth/erc20.py | 6+++---
Mchainlib/eth/gas.py | 6++++--
Mchainlib/eth/runnable/checksum.py | 9++++++++-
Mchainlib/eth/runnable/get.py | 2+-
Mchainlib/eth/runnable/transfer.py | 2+-
Mchainlib/eth/tx.py | 36++++++++++++------------------------
Mchainlib/eth/unittest/base.py | 1-
Mrequirements.txt | 4++--
Msetup.cfg | 2+-
Mtests/test_stat.py | 2+-
10 files changed, 33 insertions(+), 37 deletions(-)

diff --git a/chainlib/eth/erc20.py b/chainlib/eth/erc20.py @@ -108,7 +108,7 @@ class ERC20(TxFactory): def transfer_from(self, contract_address, sender_address, holder_address, recipient_address, value, tx_format=TxFormat.JSONRPC): enc = ABIContractEncoder() - enc.method('transfer') + enc.method('transferFrom') enc.typ(ABIContractType.ADDRESS) enc.typ(ABIContractType.ADDRESS) enc.typ(ABIContractType.UINT256) @@ -122,12 +122,12 @@ class ERC20(TxFactory): return tx - def approve(self, contract_address, sender_address, recipient_address, value, tx_format=TxFormat.JSONRPC): + def approve(self, contract_address, sender_address, spender_address, value, tx_format=TxFormat.JSONRPC): enc = ABIContractEncoder() enc.method('approve') enc.typ(ABIContractType.ADDRESS) enc.typ(ABIContractType.UINT256) - enc.address(recipient_address) + enc.address(spender_address) enc.uint256(value) data = add_0x(enc.get()) tx = self.template(sender_address, contract_address, use_nonce=True) diff --git a/chainlib/eth/gas.py b/chainlib/eth/gas.py @@ -94,12 +94,14 @@ class OverrideGasOracle(RPCGasOracle): self.limit = limit self.price = price + price_conn = None + if self.limit == None or self.price == None: - price_conn = None if self.price == None: price_conn = conn logg.debug('override gas oracle with rpc fallback; price {} limit {}'.format(self.price, self.limit)) - super(OverrideGasOracle, self).__init__(price_conn, code_callback) + + super(OverrideGasOracle, self).__init__(price_conn, code_callback) def get_gas(self, code=None): diff --git a/chainlib/eth/runnable/checksum.py b/chainlib/eth/runnable/checksum.py @@ -1,8 +1,15 @@ # standard imports import sys +# external imports +from hexathon import strip_0x + # local imports from chainlib.eth.address import to_checksum_address +def main(): + print(to_checksum_address(strip_0x(sys.argv[1]))) + -print(to_checksum_address(sys.argv[1])) +if __name__ == '__main__': + main() diff --git a/chainlib/eth/runnable/get.py b/chainlib/eth/runnable/get.py @@ -60,7 +60,7 @@ elif args.v: conn = EthHTTPConnection(args.p) -tx_hash = args.tx_hash +tx_hash = add_0x(args.tx_hash) class Status(enum.Enum): diff --git a/chainlib/eth/runnable/transfer.py b/chainlib/eth/runnable/transfer.py @@ -104,7 +104,7 @@ def _max_gas(code=None): return 8000000 gas_oracle = None -if args.price != None: +if args.gas_price != None or args.gas_limit != None: gas_oracle = OverrideGasOracle(price=args.gas_price, limit=args.gas_limit) else: gas_oracle = RPCGasOracle(conn, code_callback=_max_gas) diff --git a/chainlib/eth/tx.py b/chainlib/eth/tx.py @@ -14,6 +14,7 @@ from rlp import decode as rlp_decode from rlp import encode as rlp_encode from crypto_dev_signer.eth.transaction import EIP155Transaction from crypto_dev_signer.encoding import public_key_to_address +from potaahto.symbols import snake_and_camel # local imports @@ -30,6 +31,7 @@ from chainlib.jsonrpc import jsonrpc_template logg = logging.getLogger().getChild(__name__) + class TxFormat(enum.IntEnum): DICT = 0x00 RAW = 0x01 @@ -271,8 +273,6 @@ class TxFactory: class Tx: - re_camel_snake = re.compile(r'([a-z0-9]+)([A-Z])') - # TODO: force tx type schema parser (whether expect hex or int etc) def __init__(self, src, block=None, rcpt=None): logg.debug('src {}'.format(src)) @@ -324,7 +324,7 @@ class Tx: if inpt != '0x': inpt = strip_0x(inpt) else: - inpt = None + inpt = '' self.payload = inpt to = src['to'] @@ -349,29 +349,14 @@ class Tx: @classmethod def src_normalize(self, src): - src_normal = {} - for k in src.keys(): - s = '' - right_pos = 0 - for m in self.re_camel_snake.finditer(k): - g = m.group(0) - s += g[:len(g)-1] - s += '_' + g[len(g)-1].lower() - right_pos = m.span()[1] - - - s += k[right_pos:] - src_normal[k] = src[k] - if s != k: - logg.debug('adding snake {} for camel {}'.format(s, k)) - src_normal[s] = src[k] - - return src_normal - + return snake_and_camel(src) def apply_receipt(self, rcpt): logg.debug('rcpt {}'.format(rcpt)) - status_number = int(rcpt['status'], 16) + try: + status_number = int(rcpt['status'], 16) + except TypeError: + status_number = int(rcpt['status']) if status_number == 1: self.status = Status.SUCCESS elif status_number == 0: @@ -383,7 +368,10 @@ class Tx: if contract_address != None: self.contract = contract_address self.logs = rcpt['logs'] - self.gas_used = int(rcpt['gasUsed'], 16) + try: + self.gas_used = int(rcpt['gasUsed'], 16) + except TypeError: + self.gas_used = int(rcpt['gasUsed']) def __repr__(self): diff --git a/chainlib/eth/unittest/base.py b/chainlib/eth/unittest/base.py @@ -122,7 +122,6 @@ class TestRPCConnection(RPCConnection): def eth_getTransactionReceipt(self, p): rcpt = self.backend.get_transaction_receipt(p[0]) - # TODO: use camelcase to snake case converter if rcpt.get('block_number') == None: rcpt['block_number'] = rcpt['blockNumber'] else: diff --git a/requirements.txt b/requirements.txt @@ -1,5 +1,5 @@ -crypto-dev-signer~=0.4.14a17 +crypto-dev-signer~=0.4.14b2 pysha3==1.0.2 hexathon~=0.0.1a7 websocket-client==0.57.0 -redis==3.5.3 +potaahto~=0.0.1a1 diff --git a/setup.cfg b/setup.cfg @@ -1,6 +1,6 @@ [metadata] name = chainlib -version = 0.0.2a8 +version = 0.0.2a14 description = Generic blockchain access library and tooling author = Louis Holbrook author_email = dev@holbrook.no diff --git a/tests/test_stat.py b/tests/test_stat.py @@ -3,7 +3,7 @@ import unittest import datetime # external imports -from chainlib.stat import Stat +from chainlib.stat import ChainStat from chainlib.eth.block import Block