From e237cf0e397d3ba532483ad4c8daddf8b4b0305f Mon Sep 17 00:00:00 2001 From: The MMGen Project Date: Sat, 12 Nov 2022 13:34:41 +0000 Subject: [PATCH] tw.view.TwView: add __init__() method --- mmgen/tw/addresses.py | 13 ++++--------- mmgen/tw/txhistory.py | 9 +++------ mmgen/tw/unspent.py | 18 ++++++------------ mmgen/tw/view.py | 11 ++++++++++- 4 files changed, 23 insertions(+), 28 deletions(-) diff --git a/mmgen/tw/addresses.py b/mmgen/tw/addresses.py index 1fb44279..502a8bfe 100755 --- a/mmgen/tw/addresses.py +++ b/mmgen/tw/addresses.py @@ -13,16 +13,14 @@ tw.addresses: Tracking wallet listaddresses class for the MMGen suite """ from ..util import suf -from ..base_obj import AsyncInit from ..objmethods import MMGenObject from ..obj import MMGenListItem,ImmutableAttr,ListItemAttr,TwComment,NonNegativeInt -from ..rpc import rpc_init from ..addr import CoinAddr,MMGenID from ..color import red,green from .view import TwView from .shared import TwMMGenID -class TwAddresses(TwView,metaclass=AsyncInit): +class TwAddresses(TwView): hdr_lbl = 'tracking wallet addresses' desc = 'address list' @@ -76,14 +74,11 @@ class TwAddresses(TwView,metaclass=AsyncInit): def __new__(cls,proto,*args,**kwargs): return MMGenObject.__new__(proto.base_proto_subclass(cls,'tw','addresses')) - async def __init__(self,proto,minconf=1,mmgen_addrs='',wallet=None,get_data=False): + async def __init__(self,proto,minconf=1,mmgen_addrs='',get_data=False): + + await super().__init__(proto) - self.proto = proto self.minconf = NonNegativeInt(minconf) - self.rpc = await rpc_init(proto) - - from .ctl import TrackingWallet - self.wallet = wallet or await TrackingWallet(proto,mode='w') if mmgen_addrs: a = mmgen_addrs.rsplit(':',1) diff --git a/mmgen/tw/txhistory.py b/mmgen/tw/txhistory.py index 3a4d01ac..d53acb57 100755 --- a/mmgen/tw/txhistory.py +++ b/mmgen/tw/txhistory.py @@ -13,13 +13,11 @@ tw.txhistory: Tracking wallet transaction history class for the MMGen suite """ from ..util import fmt -from ..base_obj import AsyncInit from ..objmethods import MMGenObject -from ..rpc import rpc_init from ..obj import NonNegativeInt from .view import TwView -class TwTxHistory(TwView,metaclass=AsyncInit): +class TwTxHistory(TwView): class display_type(TwView.display_type): @@ -42,9 +40,8 @@ class TwTxHistory(TwView,metaclass=AsyncInit): filters = ('show_unconfirmed',) async def __init__(self,proto,sinceblock=0): - self.proto = proto - self.rpc = await rpc_init(proto) - self.sinceblock = NonNegativeIntInt( sinceblock if sinceblock >= 0 else self.rpc.blockcount + sinceblock ) + await super().__init__(proto) + self.sinceblock = NonNegativeInt( sinceblock if sinceblock >= 0 else self.rpc.blockcount + sinceblock ) @property def no_rpcdata_errmsg(self): diff --git a/mmgen/tw/unspent.py b/mmgen/tw/unspent.py index 977ac314..ecbb533b 100755 --- a/mmgen/tw/unspent.py +++ b/mmgen/tw/unspent.py @@ -22,7 +22,6 @@ tw.unspent: Tracking wallet unspent outputs class for the MMGen suite from ..globalvars import g from ..util import msg,suf,fmt -from ..base_obj import AsyncInit from ..objmethods import MMGenObject from ..obj import ( ImmutableAttr, @@ -33,11 +32,10 @@ from ..obj import ( CoinTxID, NonNegativeInt ) from ..addr import CoinAddr,MMGenID -from ..rpc import rpc_init -from .view import TwView from .shared import TwMMGenID,get_tw_label +from .view import TwView -class TwUnspentOutputs(TwView,metaclass=AsyncInit): +class TwUnspentOutputs(TwView): class display_type(TwView.display_type): @@ -82,14 +80,10 @@ class TwUnspentOutputs(TwView,metaclass=AsyncInit): return self.proto.coin_amt(value) async def __init__(self,proto,minconf=1,addrs=[]): - self.proto = proto - self.minconf = minconf - self.addrs = addrs - self.rpc = await rpc_init(proto) - self.min_cols = g.min_screen_width - - from .ctl import TrackingWallet - self.wallet = await TrackingWallet(proto,mode='w') + await super().__init__(proto) + self.minconf = minconf + self.addrs = addrs + self.min_cols = g.min_screen_width @property def total(self): diff --git a/mmgen/tw/view.py b/mmgen/tw/view.py index 936f35c5..5666b61f 100755 --- a/mmgen/tw/view.py +++ b/mmgen/tw/view.py @@ -28,9 +28,11 @@ from ..objmethods import Hilite,InitErrors,MMGenObject from ..obj import get_obj,MMGenIdx,MMGenList from ..color import nocolor,yellow,green,red,blue from ..util import msg,msg_r,fmt,die,capfirst,make_timestr +from ..rpc import rpc_init +from ..base_obj import AsyncInit # base class for TwUnspentOutputs,TwAddresses,TwTxHistory: -class TwView(MMGenObject): +class TwView(MMGenObject,metaclass=AsyncInit): class display_type: @@ -109,6 +111,13 @@ class TwView(MMGenObject): Please resize your screen to at least {} characters and hit any key: """ + async def __init__(self,proto): + self.proto = proto + self.rpc = await rpc_init(proto) + if self.has_wallet: + from .ctl import TrackingWallet + self.wallet = await TrackingWallet(proto,mode='w') + @property def age_w(self): return self.age_col_params[self.age_fmt][0]