From e0dc8e0192c319c9c1d6d98922333d098184ef84 Mon Sep 17 00:00:00 2001 From: nolash Date: Thu, 11 Feb 2021 12:43:54 +0100 Subject: [PATCH] Move hash wrappers to agnostic package --- chainlib/eth/erc20.py | 2 +- chainlib/eth/gas.py | 2 +- chainlib/eth/tx.py | 28 +++++++++++++++++++++++++--- chainlib/{eth => }/hash.py | 0 setup.cfg | 2 +- 5 files changed, 28 insertions(+), 6 deletions(-) rename chainlib/{eth => }/hash.py (100%) diff --git a/chainlib/eth/erc20.py b/chainlib/eth/erc20.py index 781fb78..f15c82e 100644 --- a/chainlib/eth/erc20.py +++ b/chainlib/eth/erc20.py @@ -5,7 +5,7 @@ from eth_abi import encode_single from crypto_dev_signer.eth.transaction import EIP155Transaction # local imports -from .hash import ( +from chainlib.hash import ( keccak256_hex_to_hex, keccak256_string_to_hex, ) diff --git a/chainlib/eth/gas.py b/chainlib/eth/gas.py index e7c4a1a..d8fa202 100644 --- a/chainlib/eth/gas.py +++ b/chainlib/eth/gas.py @@ -8,7 +8,7 @@ from crypto_dev_signer.eth.transaction import EIP155Transaction # local imports from chainlib.eth.rpc import jsonrpc_template from chainlib.eth.tx import TxFactory -from chainlib.eth.hash import keccak256_hex_to_hex +from chainlib.hash import keccak256_hex_to_hex def price(): diff --git a/chainlib/eth/tx.py b/chainlib/eth/tx.py index 29c0ea3..8a7ade1 100644 --- a/chainlib/eth/tx.py +++ b/chainlib/eth/tx.py @@ -15,6 +15,7 @@ from .address import to_checksum from .constant import ( MINIMUM_FEE_UNITS, MINIMUM_FEE_PRICE, + ZERO_ADDRESS, ) logg = logging.getLogger(__name__) @@ -142,10 +143,31 @@ class Tx: def __init__(self, src, block): self.index = int(strip_0x(src['transactionIndex']), 16) - self.nonce = src['nonce'] - self.hash = src['hash'] + self.value = int(strip_0x(src['value']), 16) + self.nonce = int(strip_0x(src['nonce']), 16) + self.hash = strip_0x(src['hash']) + self.outputs = [strip_0x(src['from'])] + + inpt = src['input'] + if inpt != '0x': + inpt = strip_0x(inpt) + else: + inpt = None + self.payload = inpt + + to = src['to'] + if to == None: + to = ZERO_ADDRESS + self.inputs = [strip_0x(to)] + self.block = block + self.wire = src['raw'] + self.src = src + + + def __repr__(self): + return 'block {} tx {} {}'.format(self.block.number, self.index, self.hash) def __str__(self): - return 'block {} tx {} {}'.format(self.block.number, self.index, self.hash) + return 'from {} to {} value {} input {}'.format(self.outputs[0], self.inputs[0], self.value, self.payload) diff --git a/chainlib/eth/hash.py b/chainlib/hash.py similarity index 100% rename from chainlib/eth/hash.py rename to chainlib/hash.py diff --git a/setup.cfg b/setup.cfg index 5beafbf..a861ce2 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,6 +1,6 @@ [metadata] name = chainlib -version = 0.0.1a5 +version = 0.0.1a6 description = Generic blockchain access library and tooling author = Louis Holbrook author_email = dev@holbrook.no