From 307ccfa87df765a00d74974a4171168225dbe25d Mon Sep 17 00:00:00 2001 From: The MMGen Project Date: Thu, 27 Jan 2022 11:08:06 +0000 Subject: [PATCH] remove altcoins.eth.obj module - ETHAmt -> mmgen.amt - ETHNonce -> mmgen.obj --- mmgen/altcoins/eth/contract.py | 2 +- mmgen/altcoins/eth/obj.py | 43 ---------------------------------- mmgen/altcoins/eth/twctl.py | 2 +- mmgen/altcoins/eth/twuo.py | 8 +++---- mmgen/altcoins/eth/tx.py | 21 ++++++++--------- mmgen/amt.py | 15 ++++++++++++ mmgen/obj.py | 3 +++ mmgen/protocol.py | 3 +-- test/objtest.py | 1 - test/test_py_d/ts_ethdev.py | 2 +- test/unit_tests_d/ut_obj.py | 3 +-- 11 files changed, 37 insertions(+), 66 deletions(-) delete mode 100755 mmgen/altcoins/eth/obj.py diff --git a/mmgen/altcoins/eth/contract.py b/mmgen/altcoins/eth/contract.py index e73430ea..b957f742 100755 --- a/mmgen/altcoins/eth/contract.py +++ b/mmgen/altcoins/eth/contract.py @@ -28,7 +28,7 @@ from mmgen.globalvars import g from mmgen.base_obj import AsyncInit from mmgen.obj import MMGenObject,CoinTxID from mmgen.addr import CoinAddr,TokenAddr -from .obj import ETHAmt +from mmgen.amt import ETHAmt def parse_abi(s): return [s[:8]] + [s[8+x*64:8+(x+1)*64] for x in range(len(s[8:])//64)] diff --git a/mmgen/altcoins/eth/obj.py b/mmgen/altcoins/eth/obj.py deleted file mode 100755 index 72b371bc..00000000 --- a/mmgen/altcoins/eth/obj.py +++ /dev/null @@ -1,43 +0,0 @@ -#!/usr/bin/env python3 -# -# mmgen = Multi-Mode GENerator, command-line Bitcoin cold storage solution -# Copyright (C)2013-2022 The MMGen Project -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - -""" -altcoins.eth.obj: Ethereum data type classes for the MMGen suite -""" - -from decimal import Decimal -from mmgen.obj import Int -from mmgen.amt import CoinAmt - -# Kwei (babbage) 3, Mwei (lovelace) 6, Gwei (shannon) 9, µETH (szabo) 12, mETH (finney) 15, ETH 18 -class ETHAmt(CoinAmt): - max_prec = 18 - wei = Decimal('0.000000000000000001') - Kwei = Decimal('0.000000000000001') - Mwei = Decimal('0.000000000001') - Gwei = Decimal('0.000000001') - szabo = Decimal('0.000001') - finney = Decimal('0.001') - units = ('wei','Kwei','Mwei','Gwei','szabo','finney') - amt_fs = '4.18' - - def toWei(self): - return int(Decimal(self) // self.wei) - -class ETHNonce(Int): - min_val = 0 diff --git a/mmgen/altcoins/eth/twctl.py b/mmgen/altcoins/eth/twctl.py index 4b4800a5..606b6631 100755 --- a/mmgen/altcoins/eth/twctl.py +++ b/mmgen/altcoins/eth/twctl.py @@ -23,8 +23,8 @@ altcoins.eth.twctl: Ethereum tracking wallet control class for the MMGen suite from mmgen.util import msg,ymsg,write_mode from mmgen.twctl import TrackingWallet from mmgen.addr import is_coin_addr,is_mmgen_id +from mmgen.amt import ETHAmt from .contract import Token,TokenResolve -from .obj import ETHAmt class EthereumTrackingWallet(TrackingWallet): diff --git a/mmgen/altcoins/eth/twuo.py b/mmgen/altcoins/eth/twuo.py index f8c7535d..7c453aec 100755 --- a/mmgen/altcoins/eth/twuo.py +++ b/mmgen/altcoins/eth/twuo.py @@ -20,8 +20,8 @@ altcoins.eth.twuo: Ethereum tracking wallet unspent outputs class for the MMGen suite """ -from mmgen.tw import TwLabel -from mmgen.twuo import TwUnspentOutputs +from ...tw import TwLabel +from ...twuo import TwUnspentOutputs # No unspent outputs with Ethereum, but naming must be consistent class EthereumTwUnspentOutputs(TwUnspentOutputs): @@ -46,9 +46,9 @@ Actions: [q]uit view, [p]rint to file, pager [v]iew, [w]ide view, 'l':'a_lbl_add','D':'a_addr_delete','R':'a_balance_refresh' } async def __init__(self,proto,*args,**kwargs): - from mmgen.globalvars import g + from ...globalvars import g if g.cached_balances: - from mmgen.color import yellow + from ...color import yellow self.hdr_fmt += '\n' + yellow('WARNING: Using cached balances. These may be out of date!') await TwUnspentOutputs.__init__(self,proto,*args,**kwargs) diff --git a/mmgen/altcoins/eth/tx.py b/mmgen/altcoins/eth/tx.py index ff80c680..3e610178 100755 --- a/mmgen/altcoins/eth/tx.py +++ b/mmgen/altcoins/eth/tx.py @@ -25,19 +25,18 @@ from collections import namedtuple from decimal import Decimal -from mmgen.globalvars import g -from mmgen.color import red,yellow,blue,pink -from mmgen.opts import opt -from mmgen.util import msg,msg_r,ymsg,dmsg,fmt,line_input,is_int,is_hex_str,make_chksum_6,die,suf,capfirst,pp_fmt -from mmgen.exception import TransactionChainMismatch -from mmgen.obj import Int,Str,HexStr,CoinTxID,MMGenTxID -from mmgen.addr import MMGenID,CoinAddr,TokenAddr,is_mmgen_id,is_coin_addr - -from mmgen.tx import MMGenTX -from mmgen.twctl import TrackingWallet +from ...globalvars import g +from ...color import red,yellow,blue,pink +from ...opts import opt +from ...util import msg,msg_r,ymsg,dmsg,fmt,line_input,is_int,is_hex_str,make_chksum_6,die,suf,capfirst,pp_fmt +from ...exception import TransactionChainMismatch +from ...obj import Int,Str,HexStr,CoinTxID,MMGenTxID,ETHNonce +from ...addr import MMGenID,CoinAddr,TokenAddr,is_mmgen_id,is_coin_addr +from ...amt import ETHAmt +from ...tx import MMGenTX +from ...twctl import TrackingWallet from .contract import Token -from .obj import ETHAmt,ETHNonce class EthereumMMGenTX: diff --git a/mmgen/amt.py b/mmgen/amt.py index 882c9607..0bdee443 100755 --- a/mmgen/amt.py +++ b/mmgen/amt.py @@ -174,3 +174,18 @@ class XMRAmt(CoinAmt): atomic = Decimal('0.000000000001') units = ('atomic',) amt_fs = '4.12' + +# Kwei (babbage) 3, Mwei (lovelace) 6, Gwei (shannon) 9, µETH (szabo) 12, mETH (finney) 15, ETH 18 +class ETHAmt(CoinAmt): + max_prec = 18 + wei = Decimal('0.000000000000000001') + Kwei = Decimal('0.000000000000001') + Mwei = Decimal('0.000000000001') + Gwei = Decimal('0.000000001') + szabo = Decimal('0.000001') + finney = Decimal('0.001') + units = ('wei','Kwei','Mwei','Gwei','szabo','finney') + amt_fs = '4.18' + + def toWei(self): + return int(Decimal(self) // self.wei) diff --git a/mmgen/obj.py b/mmgen/obj.py index cf6280d6..52e01c72 100755 --- a/mmgen/obj.py +++ b/mmgen/obj.py @@ -294,6 +294,9 @@ class Int(int,Hilite,InitErrors): class MMGenIdx(Int): min_val = 1 +class ETHNonce(Int): + min_val = 0 + class Str(str,Hilite): pass diff --git a/mmgen/protocol.py b/mmgen/protocol.py index e588c6be..a3cc5b3f 100755 --- a/mmgen/protocol.py +++ b/mmgen/protocol.py @@ -26,9 +26,8 @@ from collections import namedtuple from .util import msg,ymsg,Msg,ydie from .devtools import * from .globalvars import g -from .amt import BTCAmt,LTCAmt,BCHAmt,XMRAmt -from .altcoins.eth.obj import ETHAmt import mmgen.bech32 as bech32 +from .amt import BTCAmt,LTCAmt,BCHAmt,XMRAmt,ETHAmt parsed_wif = namedtuple('parsed_wif',['sec','pubkey_type','compressed']) parsed_addr = namedtuple('parsed_addr',['bytes','fmt']) diff --git a/test/objtest.py b/test/objtest.py index 582671c7..27309568 100755 --- a/test/objtest.py +++ b/test/objtest.py @@ -31,7 +31,6 @@ os.environ['MMGEN_TEST_SUITE'] = '1' # Import these _after_ local path's been added to sys.path from mmgen.common import * from mmgen.obj import * -from mmgen.altcoins.eth.obj import * from mmgen.seedsplit import * from mmgen.addr import * from mmgen.addrlist import * diff --git a/test/test_py_d/ts_ethdev.py b/test/test_py_d/ts_ethdev.py index f5b2e652..472c9089 100755 --- a/test/test_py_d/ts_ethdev.py +++ b/test/test_py_d/ts_ethdev.py @@ -29,7 +29,7 @@ from mmgen.globalvars import g from mmgen.opts import opt from mmgen.util import die from mmgen.exception import * -from mmgen.altcoins.eth.obj import ETHAmt +from mmgen.amt import ETHAmt from mmgen.protocol import CoinProtocol from ..include.common import * from .common import * diff --git a/test/unit_tests_d/ut_obj.py b/test/unit_tests_d/ut_obj.py index dea4eb02..aba76a56 100755 --- a/test/unit_tests_d/ut_obj.py +++ b/test/unit_tests_d/ut_obj.py @@ -9,8 +9,7 @@ class unit_tests: def coinamt(self,name,ut): - from mmgen.amt import BTCAmt,LTCAmt,XMRAmt - from mmgen.altcoins.eth.obj import ETHAmt + from mmgen.amt import BTCAmt,LTCAmt,XMRAmt,ETHAmt for cls,aa,bb in ( ( BTCAmt, '1.2345', '11234567.897' ),