From 3036267c53b492c0dbbcd355098852814efe2aac Mon Sep 17 00:00:00 2001 From: MMGen Date: Thu, 28 Feb 2019 10:42:05 +0000 Subject: [PATCH] eth/{contract,tx}.py: delay loading of Transaction module --- mmgen/altcoins/eth/contract.py | 2 +- mmgen/altcoins/eth/tx.py | 11 ++++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/mmgen/altcoins/eth/contract.py b/mmgen/altcoins/eth/contract.py index b2657a44..6fd20a6b 100755 --- a/mmgen/altcoins/eth/contract.py +++ b/mmgen/altcoins/eth/contract.py @@ -22,7 +22,6 @@ altcoins.eth.contract: Ethereum contract and token classes for the MMGen suite from sha3 import keccak_256 from decimal import Decimal -from ethereum.transactions import Transaction import rlp from mmgen.globalvars import g @@ -104,6 +103,7 @@ class Token(MMGenObject): # ERC20 'data': unhexlify(data) } def txsign(self,tx_in,key,from_addr,chain_id=None): + from ethereum.transactions import Transaction if chain_id is None: chain_id_method = ('parity_chainId','eth_chainId')['eth_chainId' in g.rpch.caps] chain_id = int(g.rpch.request(chain_id_method),16) diff --git a/mmgen/altcoins/eth/tx.py b/mmgen/altcoins/eth/tx.py index ac6f1a6a..7aa864cd 100755 --- a/mmgen/altcoins/eth/tx.py +++ b/mmgen/altcoins/eth/tx.py @@ -25,7 +25,6 @@ from mmgen.common import * from mmgen.obj import * from mmgen.tx import MMGenTX,MMGenBumpTX,MMGenSplitTX,DeserializedTX,mmaddr2coinaddr -from mmgen.altcoins.eth.contract import Token class EthereumMMGenTX(MMGenTX): desc = 'Ethereum transaction' @@ -406,8 +405,11 @@ class EthereumTokenMMGenTX(EthereumMMGenTX): def final_inputs_ok_msg(self,change_amt): m = "Transaction leaves ≈{} {} and {} {} in the sender's account" - send_acct_tbal = '0' if self.outputs[0].is_chg else \ - Token(g.token).balance(self.inputs[0].addr) - self.outputs[0].amt + if self.outputs[0].is_chg: + send_acct_tbal = '0' + else: + from mmgen.altcoins.eth.contract import Token + send_acct_tbal = Token(g.token).balance(self.inputs[0].addr) - self.outputs[0].amt return m.format(ETHAmt(change_amt).hl(),g.coin,ETHAmt(send_acct_tbal).hl(),g.dcoin) def get_change_amt(self): # here we know the fee @@ -427,6 +429,7 @@ class EthereumTokenMMGenTX(EthereumMMGenTX): def make_txobj(self): super(EthereumTokenMMGenTX,self).make_txobj() + from mmgen.altcoins.eth.contract import Token t = Token(g.token) o = t.txcreate( self.inputs[0].addr, self.outputs[0].addr, @@ -439,6 +442,7 @@ class EthereumTokenMMGenTX(EthereumMMGenTX): def check_txfile_hex_data(self): d = super(EthereumTokenMMGenTX,self).check_txfile_hex_data() o = self.txobj + from mmgen.altcoins.eth.contract import Token if self.check_sigs(): # online, from rlp rpc_init() o['token_addr'] = TokenAddr(o['to']) @@ -456,6 +460,7 @@ class EthereumTokenMMGenTX(EthereumMMGenTX): r=super(EthereumTokenMMGenTX,self).format_view_body(*args,**kwargs)) def do_sign(self,d,wif,tx_num_str): + from mmgen.altcoins.eth.contract import Token d = self.txobj t = Token(d['token_addr'],decimals=d['decimals']) tx_in = t.txcreate(d['from'],d['to'],d['amt'],self.start_gas,d['gasPrice'],nonce=d['nonce'])