From 79bcc049a5767982f1a0484dc1017f89b609fe7d Mon Sep 17 00:00:00 2001 From: The MMGen Project Date: Sat, 12 Nov 2022 13:34:40 +0000 Subject: [PATCH] proto.{btc,eth}.tw: module moves, class renames - proto.btc.tw.common -> proto.btc.tw.rpc - proto.eth.tw.common -> proto.eth.tw.rpc, proto.eth.tw.view - BitcoinTwCommon -> BitcoinTwRPC - EthereumTwCommon -> EthereumTwRPC, EthereumTwView --- mmgen/proto/btc/tw/addresses.py | 4 +-- mmgen/proto/btc/tw/ctl.py | 4 +-- mmgen/proto/btc/tw/{common.py => rpc.py} | 4 +-- mmgen/proto/btc/tw/txhistory.py | 6 ++--- mmgen/proto/eth/tw/addresses.py | 5 ++-- mmgen/proto/eth/tw/ctl.py | 4 +-- mmgen/proto/eth/tw/{common.py => rpc.py} | 23 +++------------- mmgen/proto/eth/tw/unspent.py | 4 +-- mmgen/proto/eth/tw/view.py | 34 ++++++++++++++++++++++++ 9 files changed, 53 insertions(+), 35 deletions(-) rename mmgen/proto/btc/tw/{common.py => rpc.py} (96%) rename mmgen/proto/eth/tw/{common.py => rpc.py} (60%) create mode 100755 mmgen/proto/eth/tw/view.py diff --git a/mmgen/proto/btc/tw/addresses.py b/mmgen/proto/btc/tw/addresses.py index eb36a8a2..85a5b53a 100755 --- a/mmgen/proto/btc/tw/addresses.py +++ b/mmgen/proto/btc/tw/addresses.py @@ -17,9 +17,9 @@ from ....tw.shared import TwLabel from ....util import msg,msg_r from ....addr import CoinAddr from ....obj import NonNegativeInt,get_obj -from .common import BitcoinTwCommon +from .rpc import BitcoinTwRPC -class BitcoinTwAddresses(TwAddresses,BitcoinTwCommon): +class BitcoinTwAddresses(TwAddresses,BitcoinTwRPC): has_age = True prompt = """ diff --git a/mmgen/proto/btc/tw/ctl.py b/mmgen/proto/btc/tw/ctl.py index 4a0d0790..41b0611b 100755 --- a/mmgen/proto/btc/tw/ctl.py +++ b/mmgen/proto/btc/tw/ctl.py @@ -15,9 +15,9 @@ proto.btc.twctl: Bitcoin base protocol tracking wallet control class from ....globalvars import g from ....tw.ctl import TrackingWallet,write_mode from ....util import msg,msg_r,rmsg,vmsg,die,suf,fmt_list -from .common import BitcoinTwCommon +from .rpc import BitcoinTwRPC -class BitcoinTrackingWallet(TrackingWallet,BitcoinTwCommon): +class BitcoinTrackingWallet(TrackingWallet,BitcoinTwRPC): def init_empty(self): self.data = { 'coin': self.proto.coin, 'addresses': {} } diff --git a/mmgen/proto/btc/tw/common.py b/mmgen/proto/btc/tw/rpc.py similarity index 96% rename from mmgen/proto/btc/tw/common.py rename to mmgen/proto/btc/tw/rpc.py index 7fdf3804..c3d7ed33 100755 --- a/mmgen/proto/btc/tw/common.py +++ b/mmgen/proto/btc/tw/rpc.py @@ -9,7 +9,7 @@ # https://gitlab.com/mmgen/mmgen """ -proto.btc.tw.common: Bitcoin base protocol tracking wallet dependency classes +proto.btc.tw.rpc: Bitcoin base protocol tracking wallet RPC classes """ from ....addr import CoinAddr @@ -17,7 +17,7 @@ from ....util import die,msg,rmsg from ....obj import MMGenList from ....tw.shared import get_tw_label -class BitcoinTwCommon: +class BitcoinTwRPC: async def get_addr_label_pairs(self,twmmid=None): """ diff --git a/mmgen/proto/btc/tw/txhistory.py b/mmgen/proto/btc/tw/txhistory.py index d2309402..4e597c9f 100755 --- a/mmgen/proto/btc/tw/txhistory.py +++ b/mmgen/proto/btc/tw/txhistory.py @@ -20,9 +20,9 @@ from ....addr import CoinAddr from ....util import msg,msg_r from ....color import nocolor,red,pink,gray from ....obj import TwComment,CoinTxID,Int -from .common import BitcoinTwCommon +from .rpc import BitcoinTwRPC -class BitcoinTwTransaction(BitcoinTwCommon): +class BitcoinTwTransaction(BitcoinTwRPC): def __init__(self,parent,proto,rpc, idx, # unique numeric identifier of this transaction in listing @@ -221,7 +221,7 @@ class BitcoinTwTransaction(BitcoinTwCommon): self.fee.to_unit(atomic_unit) // self.vsize, atomic_unit )) ) -class BitcoinTwTxHistory(TwTxHistory,BitcoinTwCommon): +class BitcoinTwTxHistory(TwTxHistory,BitcoinTwRPC): has_age = True hdr_lbl = 'transaction history' diff --git a/mmgen/proto/eth/tw/addresses.py b/mmgen/proto/eth/tw/addresses.py index 3f273965..10092f67 100755 --- a/mmgen/proto/eth/tw/addresses.py +++ b/mmgen/proto/eth/tw/addresses.py @@ -15,9 +15,10 @@ proto.eth.tw.addresses: Ethereum base protocol tracking wallet address list clas from ....tw.addresses import TwAddresses from ....tw.ctl import TrackingWallet from ....addr import CoinAddr -from .common import EthereumTwCommon +from .view import EthereumTwView +from .rpc import EthereumTwRPC -class EthereumTwAddresses(EthereumTwCommon,TwAddresses): +class EthereumTwAddresses(EthereumTwView,EthereumTwRPC,TwAddresses): has_age = False prompt = """ diff --git a/mmgen/proto/eth/tw/ctl.py b/mmgen/proto/eth/tw/ctl.py index 5c434ca5..252d3427 100755 --- a/mmgen/proto/eth/tw/ctl.py +++ b/mmgen/proto/eth/tw/ctl.py @@ -25,9 +25,9 @@ from ....tw.ctl import TrackingWallet,write_mode from ....addr import is_coin_addr,is_mmgen_id from ....amt import ETHAmt from ..contract import Token,TokenResolve -from .common import EthereumTwCommon +from .rpc import EthereumTwRPC -class EthereumTrackingWallet(EthereumTwCommon,TrackingWallet): +class EthereumTrackingWallet(EthereumTwRPC,TrackingWallet): caps = ('batch',) data_key = 'accounts' diff --git a/mmgen/proto/eth/tw/common.py b/mmgen/proto/eth/tw/rpc.py similarity index 60% rename from mmgen/proto/eth/tw/common.py rename to mmgen/proto/eth/tw/rpc.py index a2c7f0af..c33b29c8 100755 --- a/mmgen/proto/eth/tw/common.py +++ b/mmgen/proto/eth/tw/rpc.py @@ -9,31 +9,14 @@ # https://gitlab.com/mmgen/mmgen """ -proto.eth.tw.common: Ethereum base protocol tracking wallet dependency classes +proto.eth.tw.rpc: Ethereum base protocol tracking wallet RPC class """ -from ....globalvars import g + from ....tw.ctl import TrackingWallet -from ....tw.view import TwView from ....addr import CoinAddr from ....tw.shared import TwLabel -class EthereumTwCommon(TwView): - - def age_disp(self,o,age_fmt): # TODO - pass - - def get_disp_prec(self,wide): - return self.proto.coin_amt.max_prec if wide else 8 - - def subheader(self,color): - ret = '' - if self.disp_prec == 8: - ret += 'Balances truncated to 8 decimal points\n' - if g.cached_balances: - from ....color import nocolor,yellow - ret += (nocolor,yellow)[color]( - 'WARNING: Using cached balances. These may be out of date!') + '\n' - return ret +class EthereumTwRPC: async def get_addr_label_pairs(self,twmmid=None): wallet = ( diff --git a/mmgen/proto/eth/tw/unspent.py b/mmgen/proto/eth/tw/unspent.py index 50a3de5e..ed0eef47 100755 --- a/mmgen/proto/eth/tw/unspent.py +++ b/mmgen/proto/eth/tw/unspent.py @@ -22,10 +22,10 @@ proto.eth.twuo: Ethereum tracking wallet unspent outputs class from ....tw.shared import TwLabel from ....tw.unspent import TwUnspentOutputs -from .common import EthereumTwCommon +from .view import EthereumTwView # No unspent outputs with Ethereum, but naming must be consistent -class EthereumTwUnspentOutputs(EthereumTwCommon,TwUnspentOutputs): +class EthereumTwUnspentOutputs(EthereumTwView,TwUnspentOutputs): class display_type(TwUnspentOutputs.display_type): diff --git a/mmgen/proto/eth/tw/view.py b/mmgen/proto/eth/tw/view.py new file mode 100755 index 00000000..15e1766b --- /dev/null +++ b/mmgen/proto/eth/tw/view.py @@ -0,0 +1,34 @@ +#!/usr/bin/env python3 +# +# mmgen = Multi-Mode GENerator, a command-line cryptocurrency wallet +# Copyright (C)2013-2022 The MMGen Project +# Licensed under the GNU General Public License, Version 3: +# https://www.gnu.org/licenses +# Public project repositories: +# https://github.com/mmgen/mmgen +# https://gitlab.com/mmgen/mmgen + +""" +proto.eth.tw.view: Ethereum base protocol base class for tracking wallet view classes +""" + +from ....globalvars import g +from ....tw.view import TwView + +class EthereumTwView(TwView): + + def age_disp(self,o,age_fmt): # TODO + pass + + def get_disp_prec(self,wide): + return self.proto.coin_amt.max_prec if wide else 8 + + def subheader(self,color): + ret = '' + if self.disp_prec == 8: + ret += 'Balances truncated to 8 decimal points\n' + if g.cached_balances: + from ....color import nocolor,yellow + ret += (nocolor,yellow)[color]( + 'WARNING: Using cached balances. These may be out of date!') + '\n' + return ret