class rename: TrackingWallet -> TwCtl

This commit is contained in:
The MMGen Project 2022-11-14 09:54:02 +00:00
commit 21b8084b37
Signed by: mmgen
GPG key ID: 3F8B1861E32B7DA2
17 changed files with 46 additions and 46 deletions

View file

@ -133,11 +133,11 @@ def check_opts(tw):
return batch,rescan
async def main():
from .tw.ctl import TrackingWallet
from .tw.ctl import TwCtl
if opt.token_addr:
proto.tokensym = 'foo' # hack to trigger 'Token' in proto.base_proto_subclass()
tw = await TrackingWallet(
tw = await TwCtl(
proto = proto,
token_addr = opt.token_addr,
mode = 'i' )

View file

@ -130,11 +130,11 @@ async def main():
kl = get_keylist(orig_tx.proto,opt)
sign_and_send = bool(seed_files or kl or kal)
from .tw.ctl import TrackingWallet
from .tw.ctl import TwCtl
tx = await BumpTX(
data = orig_tx.__dict__,
send = sign_and_send,
tw = await TrackingWallet(orig_tx.proto) if orig_tx.proto.tokensym else None )
tw = await TwCtl(orig_tx.proto) if orig_tx.proto.tokensym else None )
from .rpc import rpc_init
tx.rpc = await rpc_init(tx.proto)

View file

@ -82,7 +82,7 @@ async def main():
proto = init_proto_from_opts(need_amt=True)
from .tx import NewTX
from .tw.ctl import TrackingWallet
from .tw.ctl import TwCtl
tx1 = await NewTX(proto=proto)
from .rpc import rpc_init

View file

@ -122,7 +122,7 @@ from .tx.sign import *
seed_files = get_seed_files(opt,cmd_args)
async def main():
from .tw.ctl import TrackingWallet
from .tw.ctl import TwCtl
from .protocol import init_proto_from_opts
proto = init_proto_from_opts(need_amt=True)

View file

@ -13,10 +13,10 @@ proto.btc.tw.ctl: Bitcoin base protocol tracking wallet control class
"""
from ....globalvars import g
from ....tw.ctl import TrackingWallet,write_mode
from ....tw.ctl import TwCtl,write_mode
from ....util import msg,msg_r,rmsg,vmsg,die,suf,fmt_list
class BitcoinTrackingWallet(TrackingWallet):
class BitcoinTwCtl(TwCtl):
def init_empty(self):
self.data = { 'coin': self.proto.coin, 'addresses': {} }

View file

@ -33,10 +33,10 @@ class EthereumTwAddrData(TwAddrData):
}
async def get_tw_data(self,wallet=None):
from ...tw.ctl import TrackingWallet
from ...tw.ctl import TwCtl
from ...util import vmsg
vmsg('Getting address data from tracking wallet')
tw = (wallet or await TrackingWallet(self.proto)).mmid_ordered_dict
tw = (wallet or await TwCtl(self.proto)).mmid_ordered_dict
# emulate the output of RPC 'listaccounts' and 'getaddressesbyaccount'
return [(mmid+' '+d['comment'],[d['addr']]) for mmid,d in list(tw.items())]

View file

@ -13,7 +13,7 @@ proto.eth.tw.addresses: Ethereum base protocol tracking wallet address list clas
"""
from ....tw.addresses import TwAddresses
from ....tw.ctl import TrackingWallet
from ....tw.ctl import TwCtl
from ....addr import CoinAddr
from .view import EthereumTwView
from .rpc import EthereumTwRPC

View file

@ -20,7 +20,7 @@
proto.eth.twbal: Ethereum tracking wallet getbalance class
"""
from ....tw.ctl import TrackingWallet
from ....tw.ctl import TwCtl
from ....tw.bal import TwGetBalance
class EthereumTwGetBalance(TwGetBalance):
@ -31,7 +31,7 @@ class EthereumTwGetBalance(TwGetBalance):
}
async def __init__(self,proto,*args,**kwargs):
self.wallet = await TrackingWallet(proto,mode='w')
self.wallet = await TwCtl(proto,mode='w')
await super().__init__(proto,*args,**kwargs)
async def create_data(self):

View file

@ -21,12 +21,12 @@ proto.eth.twctl: Ethereum tracking wallet control class
"""
from ....util import msg,ymsg,die
from ....tw.ctl import TrackingWallet,write_mode
from ....tw.ctl import TwCtl,write_mode
from ....addr import is_coin_addr,is_mmgen_id
from ....amt import ETHAmt
from ..contract import Token,TokenResolve
class EthereumTrackingWallet(TrackingWallet):
class EthereumTwCtl(TwCtl):
caps = ('batch',)
data_key = 'accounts'
@ -166,7 +166,7 @@ class EthereumTrackingWallet(TrackingWallet):
def mmid_ordered_dict(self):
return dict((x['mmid'],{'addr':x['addr'],'comment':x['comment']}) for x in self.sorted_list)
class EthereumTokenTrackingWallet(EthereumTrackingWallet):
class EthereumTokenTwCtl(EthereumTwCtl):
desc = 'Ethereum token tracking wallet'
decimals = None
@ -183,7 +183,7 @@ class EthereumTokenTrackingWallet(EthereumTrackingWallet):
if not is_coin_addr(proto,token_addr):
die( 'InvalidTokenAddress', f'{token_addr!r}: invalid token address' )
else:
assert token_addr == None,'EthereumTokenTrackingWallet_chk1'
assert token_addr == None,'EthereumTokenTwCtl_chk1'
token_addr = await self.sym2addr(proto.tokensym) # returns None on failure
if not is_coin_addr(proto,token_addr):
die( 'UnrecognizedTokenSymbol', f'Specified token {proto.tokensym!r} could not be resolved!' )

View file

@ -12,7 +12,7 @@
proto.eth.tw.rpc: Ethereum base protocol tracking wallet RPC class
"""
from ....tw.ctl import TrackingWallet
from ....tw.ctl import TwCtl
from ....addr import CoinAddr
from ....tw.shared import TwLabel
from ....tw.rpc import TwRPC

View file

@ -20,7 +20,7 @@ from ....opts import opt
from ....obj import Int,ETHNonce,MMGenTxID,Str,HexStr
from ....amt import ETHAmt
from ....util import msg,is_int,is_hex_str,make_chksum_6
from ....tw.ctl import TrackingWallet
from ....tw.ctl import TwCtl
from ....addr import is_mmgen_id,is_coin_addr
from ..contract import Token
@ -144,7 +144,7 @@ class New(Base,TxBase.New):
async def get_cmdline_input_addrs(self):
ret = []
if opt.inputs:
data_root = (await TrackingWallet(self.proto)).data_root # must create new instance here
data_root = (await TwCtl(self.proto)).data_root # must create new instance here
errmsg = 'Address {!r} not in tracking wallet'
for addr in opt.inputs.split(','):
if is_mmgen_id(self.proto,addr):

View file

@ -140,8 +140,8 @@ class tool_cmd(tool_cmd_base):
async def add_label(self,mmgen_or_coin_addr:str,label:str):
"add descriptive label for address in tracking wallet"
from ..tw.ctl import TrackingWallet
return await (await TrackingWallet(self.proto,mode='w')).set_comment(mmgen_or_coin_addr,label)
from ..tw.ctl import TwCtl
return await (await TwCtl(self.proto,mode='w')).set_comment(mmgen_or_coin_addr,label)
async def remove_label(self,mmgen_or_coin_addr:str):
"remove descriptive label for address in tracking wallet"
@ -150,9 +150,9 @@ class tool_cmd(tool_cmd_base):
async def remove_address(self,mmgen_or_coin_addr:str):
"remove an address from tracking wallet"
from ..tw.ctl import TrackingWallet
from ..tw.ctl import TwCtl
# returns None on failure:
ret = await (await TrackingWallet(self.proto,mode='w')).remove_address(mmgen_or_coin_addr)
ret = await (await TwCtl(self.proto,mode='w')).remove_address(mmgen_or_coin_addr)
if ret:
from ..util import msg
msg(f'Address {ret!r} deleted from tracking wallet')
@ -160,8 +160,8 @@ class tool_cmd(tool_cmd_base):
async def resolve_address(self,mmgen_or_coin_addr:str):
"resolve an MMGen address in the tracking wallet to a coin address or vice-versa"
from ..tw.ctl import TrackingWallet
ret = await (await TrackingWallet(self.proto,mode='w')).resolve_address( mmgen_or_coin_addr )
from ..tw.ctl import TwCtl
ret = await (await TwCtl(self.proto,mode='w')).resolve_address( mmgen_or_coin_addr )
if ret:
from ..util import Msg
from ..addr import is_coin_addr
@ -171,8 +171,8 @@ class tool_cmd(tool_cmd_base):
async def rescan_address(self,mmgen_or_coin_addr:str):
"rescan an address in the tracking wallet to update its balance"
from ..tw.ctl import TrackingWallet
return await (await TrackingWallet(self.proto,mode='w')).rescan_address( mmgen_or_coin_addr )
from ..tw.ctl import TwCtl
return await (await TwCtl(self.proto,mode='w')).rescan_address( mmgen_or_coin_addr )
async def rescan_blockchain(self,
start_block: int = None,
@ -186,8 +186,8 @@ class tool_cmd(tool_cmd_base):
using Ctrl-C. An interrupted rescan may be resumed using the start_block
parameter.
"""
from ..tw.ctl import TrackingWallet
ret = await (await TrackingWallet(self.proto,mode='w')).rescan_blockchain(start_block,stop_block)
from ..tw.ctl import TwCtl
ret = await (await TwCtl(self.proto,mode='w')).rescan_blockchain(start_block,stop_block)
return True
async def twexport(self,include_amts=True,pretty=False):

View file

@ -34,7 +34,7 @@ from .shared import TwMMGenID,TwLabel
addr_info = namedtuple('addr_info',['twmmid','coinaddr'])
# decorator for TrackingWallet
# decorator for TwCtl
def write_mode(orig_func):
def f(self,*args,**kwargs):
if self.mode != 'w':
@ -45,7 +45,7 @@ def write_mode(orig_func):
return orig_func(self,*args,**kwargs)
return f
class TrackingWallet(MMGenObject,metaclass=AsyncInit):
class TwCtl(MMGenObject,metaclass=AsyncInit):
caps = ('rescan','batch')
data_key = 'addresses'
@ -122,9 +122,9 @@ class TrackingWallet(MMGenObject,metaclass=AsyncInit):
def __del__(self):
"""
TrackingWallet instances opened in write or import mode must be explicitly destroyed
with 'del twctl', 'del twuo.wallet' and the like to ensure the instance is deleted and
wallet is written before global vars are destroyed by the interpreter at shutdown.
TwCtl instances opened in write or import mode must be explicitly destroyed with 'del
twuo.twctl' and the like to ensure the instance is deleted and wallet is written before
global vars are destroyed by the interpreter at shutdown.
Not that this code can only be debugged by examining the program output, as exceptions
are ignored within __del__():

View file

@ -19,7 +19,7 @@ from ..util import msg,ymsg,fmt,die,make_timestamp,make_chksum_8,compare_or_die
from ..base_obj import AsyncInit
from ..objmethods import MMGenObject
from ..rpc import json_encoder
from .ctl import TrackingWallet
from .ctl import TwCtl
class TwJSON:
@ -66,7 +66,7 @@ class TwJSON:
super().__init__(proto)
self.tw = await TrackingWallet( proto, mode='i', rpc_ignore_wallet=True )
self.tw = await TwCtl( proto, mode='i', rpc_ignore_wallet=True )
def check_network(data):
coin,network = data['network'].split('_')
@ -132,7 +132,7 @@ class TwJSON:
if not include_amts:
self.keys.remove('amount')
self.tw = await TrackingWallet( proto )
self.tw = await TwCtl( proto )
self.entries = await self.get_entries()

View file

@ -119,8 +119,8 @@ class TwView(MMGenObject,metaclass=AsyncInit):
self.proto = proto
self.rpc = await rpc_init(proto)
if self.has_wallet:
from .ctl import TrackingWallet
self.wallet = await TrackingWallet(proto,mode='w')
from .ctl import TwCtl
self.wallet = await TwCtl(proto,mode='w')
self.amt_keys = {'amt':'iwidth','amt2':'iwidth2'} if self.has_amt2 else {'amt':'iwidth'}
@property

View file

@ -71,8 +71,8 @@ async def _get_obj_async( _clsname, _modname, *args, **kwargs ):
# No tracking wallet required for the Unsigned and Signed(data=unsigned.__dict__) classes used
# during signing.
if proto and proto.tokensym and clsname in ('New','OnlineSigned'):
from ..tw.ctl import TrackingWallet
kwargs['tw'] = await TrackingWallet(proto)
from ..tw.ctl import TwCtl
kwargs['tw'] = await TwCtl(proto)
return _base_proto_subclass( clsname, modname, proto )(*args,**kwargs)

View file

@ -1322,8 +1322,8 @@ class TestSuiteEthdev(TestSuiteBase,TestSuiteShared):
async def twmove(self):
self.spawn('',msg_only=True)
from mmgen.tw.ctl import TrackingWallet
tw = await TrackingWallet(self.proto)
from mmgen.tw.ctl import TwCtl
tw = await TwCtl(self.proto)
imsg(f'Moving tracking wallet')
bakfile = tw.tw_fn + '.bak.json'
if os.path.exists(bakfile):
@ -1354,8 +1354,8 @@ class TestSuiteEthdev(TestSuiteBase,TestSuiteShared):
async def twcompare(self):
self.spawn('',msg_only=True)
from mmgen.tw.ctl import TrackingWallet
tw = await TrackingWallet(self.proto)
from mmgen.tw.ctl import TwCtl
tw = await TwCtl(self.proto)
fn = tw.tw_fn
imsg(f'Comparing imported tracking wallet with original')
data = [json.dumps(json.loads(read_from_file(f)),sort_keys=True) for f in (fn,fn+'.bak.json')]