From 50edca71060e94df82718a1631198b2c8a3a2608 Mon Sep 17 00:00:00 2001 From: nolash Date: Mon, 22 Feb 2021 23:39:33 +0100 Subject: [PATCH] Add decimal bug in balance script, add receipts to tx + status enum --- chainlib/eth/runnable/balance.py | 2 +- chainlib/eth/tx.py | 20 +++++++++++++++++--- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/chainlib/eth/runnable/balance.py b/chainlib/eth/runnable/balance.py index 4ac318a..0b6746e 100644 --- a/chainlib/eth/runnable/balance.py +++ b/chainlib/eth/runnable/balance.py @@ -88,7 +88,7 @@ def main(): balance_str = str(balance) balance_len = len(balance_str) - if balance_len < 19: + if balance_len < decimals + 1: print('0.{}'.format(balance_str.zfill(decimals))) else: offset = balance_len-decimals diff --git a/chainlib/eth/tx.py b/chainlib/eth/tx.py index 6641113..9079811 100644 --- a/chainlib/eth/tx.py +++ b/chainlib/eth/tx.py @@ -16,6 +16,7 @@ from crypto_dev_signer.eth.transaction import EIP155Transaction # local imports from chainlib.hash import keccak256_hex_to_hex +from chainlib.status import Status from .address import to_checksum from .constant import ( MINIMUM_FEE_UNITS, @@ -97,7 +98,7 @@ def unpack(tx_raw_bytes, chain_id=1): def receipt(hsh): o = jsonrpc_template() o['method'] = 'eth_getTransactionReceipt' - o['params'].append(hsh) + o['params'].append(add_0x(hsh)) return o @@ -173,9 +174,8 @@ class TxFactory: class Tx: - def __init__(self, src, block=None): + def __init__(self, src, block=None, rcpt=None): self.index = -1 - self.status = -1 if block != None: self.index = int(strip_0x(src['transactionIndex']), 16) self.value = int(strip_0x(src['value']), 16) @@ -202,6 +202,20 @@ class Tx: self.wire = src['raw'] self.src = src + self.status = Status.PENDING + self.logs = None + + if rcpt != None: + self.apply_receipt(rcpt) + + + def apply_receipt(self, rcpt): + if rcpt['status'] == 1: + self.status = Status.SUCCESS + elif rcpt['status'] == 0: + self.status = Status.PENDING + self.logs = rcpt['logs'] + def __repr__(self): return 'block {} tx {} {}'.format(self.block.number, self.index, self.hash)