minor fixes and cleanups

This commit is contained in:
The MMGen Project 2022-02-06 13:28:44 +00:00
commit 71d7986391
Signed by: mmgen
GPG key ID: 3F8B1861E32B7DA2
13 changed files with 48 additions and 40 deletions

View file

@ -20,24 +20,22 @@
addrdata.py: MMGen AddrData and related classes
"""
from .util import vmsg,base_proto_subclass
from .util import vmsg,base_proto_subclass,fmt,die
from .base_obj import AsyncInit
from .obj import MMGenObject,MMGenDict,get_obj
from .addr import MMGenID,AddrListID
from .addrlist import AddrListEntry,AddrListData,AddrList
class AddrData(MMGenObject):
msgs = {
'too_many_acct_addresses': """
ERROR: More than one address found for account: '{}'.
Your 'wallet.dat' file appears to have been altered by a non-{} program.
Please restore your tracking wallet from a backup or create a new one and
re-import your addresses.
""".strip()
}
def __new__(cls,proto,*args,**kwargs):
return MMGenObject.__new__(base_proto_subclass(cls,proto,'tw'))
msgs = {
'multiple_acct_addrs': """
ERROR: More than one address found for account: {acct!r}.
Your 'wallet.dat' file appears to have been altered by a non-{proj} program.
Please restore your tracking wallet from a backup or create a new one and
re-import your addresses.
"""
}
def __init__(self,proto,*args,**kwargs):
self.al_ids = {}
@ -97,7 +95,8 @@ class TwAddrData(AddrData,metaclass=AsyncInit):
if l and l.mmid.type == 'mmgen':
obj = l.mmid.obj
if len(addr_array) != 1:
die(2,self.msgs['too_many_acct_addresses'].format(acct,g.prog_name))
message = self.msgs['multiple_acct_addrs'].strip().format( acct=acct, proj=g.proj_name )
die(3, fmt( message, indent=' ' ))
al_id = AddrListID(SeedID(sid=obj.sid),self.proto.addr_type(obj.mmtype))
if al_id not in out:
out[al_id] = []
@ -105,6 +104,7 @@ class TwAddrData(AddrData,metaclass=AsyncInit):
i += 1
vmsg(f'{i} {g.prog_name} addresses found, {len(twd)} accounts total')
for al_id in out:
self.add(AddrList(self.proto,al_id=al_id,adata=AddrListData(sorted(out[al_id],key=lambda a: a.idx))))

View file

@ -17,10 +17,10 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
altcoins.base_proto.ethereum.tw: Ethereum tracking wallet dependency classes
base_proto.ethereum.tw: Ethereum tracking wallet dependency classes
"""
from ...addrdata import AddrData,TwAddrData
from ...addrdata import TwAddrData
class EthereumTwAddrData(TwAddrData):
@ -32,7 +32,5 @@ class EthereumTwAddrData(TwAddrData):
# emulate the output of RPC 'listaccounts' and 'getaddressesbyaccount'
return [(mmid+' '+d['comment'],[d['addr']]) for mmid,d in list(tw.items())]
class EthereumTokenTwAddrData(EthereumTwAddrData): pass
class EthereumAddrData(AddrData): pass
class EthereumTokenAddrData(EthereumAddrData): pass
class EthereumTokenTwAddrData(EthereumTwAddrData):
pass

View file

@ -17,7 +17,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
altcoins.base_proto.ethereum.twaddrs: Ethereum tracking wallet listaddresses class
base_proto.ethereum.twaddrs: Ethereum tracking wallet address list class
"""
from ...twaddrs import TwAddrList

View file

@ -17,7 +17,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
altcoins.base_proto.ethereum.twbal: Ethereum tracking wallet getbalance class
base_proto.ethereum.twbal: Ethereum tracking wallet getbalance class
"""
from ...twctl import TrackingWallet
@ -29,7 +29,7 @@ class EthereumTwGetBalance(TwGetBalance):
async def __init__(self,proto,*args,**kwargs):
self.wallet = await TrackingWallet(proto,mode='w')
await TwGetBalance.__init__(self,proto,*args,**kwargs)
await super().__init__(proto,*args,**kwargs)
async def create_data(self):
data = self.wallet.mmid_ordered_dict

View file

@ -17,7 +17,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
altcoins.base_proto.ethereum.twctl: Ethereum tracking wallet control class
base_proto.ethereum.twctl: Ethereum tracking wallet control class
"""
from ...util import msg,ymsg,write_mode,die

View file

@ -17,7 +17,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
altcoins.base_proto.ethereum.twuo: Ethereum tracking wallet unspent outputs class
base_proto.ethereum.twuo: Ethereum tracking wallet unspent outputs class
"""
from ...tw import TwLabel
@ -26,6 +26,10 @@ from ...twuo import TwUnspentOutputs
# No unspent outputs with Ethereum, but naming must be consistent
class EthereumTwUnspentOutputs(TwUnspentOutputs):
class MMGenTwUnspentOutput(TwUnspentOutputs.MMGenTwUnspentOutput):
valid_attrs = {'txid','vout','amt','amt2','label','twmmid','addr','confs','skip'}
invalid_attrs = {'proto'}
disp_type = 'eth'
can_group = False
col_adj = 29
@ -50,7 +54,7 @@ Actions: [q]uit view, [p]rint to file, pager [v]iew, [w]ide view,
if g.cached_balances:
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)
await super().__init__(proto,*args,**kwargs)
def do_sort(self,key=None,reverse=False):
if key == 'txid': return
@ -67,12 +71,8 @@ Actions: [q]uit view, [p]rint to file, pager [v]iew, [w]ide view,
'confirmations': 0, # TODO
} for d in wl]
class MMGenTwUnspentOutput(TwUnspentOutputs.MMGenTwUnspentOutput):
valid_attrs = {'txid','vout','amt','amt2','label','twmmid','addr','confs','skip'}
invalid_attrs = {'proto'}
def age_disp(self,o,age_fmt): # TODO
return None
pass
class EthereumTokenTwUnspentOutputs(EthereumTwUnspentOutputs):

View file

@ -28,10 +28,12 @@ class MMGenError(Exception):
super().__init__(strerror)
def __repr__(self):
return f'{type(self).__name__}({self.mmcode}): {self}'
return f'{type(self).__name__}({self.mmcode}):\n{self}'
class MMGenSystemExit(MMGenError):
pass
def __repr__(self):
return f'{type(self).__name__}({self.mmcode}): {self}'
# 1: no hl, message only
class UserNonConfirmation(Exception): mmcode = 1

View file

@ -60,9 +60,9 @@ def launch(mod):
0: _o(nocolor, 1, '{message}'),
1: _o(nocolor, 1, '{message}'),
2: _o(yellow, 2, '{message}'),
3: _o(yellow, 3, '\nMMGen Error ({name}): {message}'),
4: _o(red, 4, '\nMMGen Fatal Error ({name}): {message}'),
'x': _o(yellow, 5, '\nMMGen Unhandled Exception ({name}): {message}'),
3: _o(yellow, 3, '\nMMGen Error ({name}):\n{message}'),
4: _o(red, 4, '\nMMGen Fatal Error ({name}):\n{message}'),
'x': _o(yellow, 5, '\nMMGen Unhandled Exception ({name}):\n{message}'),
}[getattr(e,'mmcode','x')]
(sys.stdout if getattr(e,'stdout',None) else sys.stderr).write(

View file

@ -272,7 +272,8 @@ if __name__ == '__main__':
code = create_src( proto, solidity_code_template, token_data, cmd_args[0] )
if opt.preprocess:
Die(0,code)
Msg(code)
sys.exit(0)
out = compile_code(code)

View file

@ -44,6 +44,10 @@ def exec_wrapper_write_traceback(e):
if exc.startswith('SystemExit:'):
lines.pop()
if os.getenv('MMGEN_TEST_SUITE_DETERMINISTIC'):
pat = re.compile(", line [0-9]+,")
lines = [pat.sub(", line (scrubbed),",line) for line in lines]
c = exec_wrapper_get_colors()
message = ( repr(e) if type(e).__name__ in ('MMGenError','MMGenSystemExit') else exc )
sys.stdout.write('{}{}'.format(

View file

@ -16,5 +16,12 @@ if os.getenv('MMGEN_TEST_SUITE_DETERMINISTIC'):
}
if os.getenv('MMGEN_BOGUS_WALLET_DATA'):
async def fake_set_dates(foo,rpc,us):
for o in us:
o.date = 1831006505 - int(9.7 * 60 * (o.confs - 1))
TwCommon.set_dates = fake_set_dates
# 1831006505 (09 Jan 2028) = projected time of block 1000000
TwCommon.date_formatter['days'] = lambda rpc,secs: (1831006505 - secs) // 86400

View file

@ -3,15 +3,10 @@ from .twuo_orig import *
if os.getenv('MMGEN_BOGUS_WALLET_DATA'):
async def fake_set_dates(foo,rpc,us):
for o in us:
o.date = 1831006505 - int(9.7 * 60 * (o.confs - 1))
async def fake_get_unspent_rpc(foo):
from decimal import Decimal
import json
from mmgen.fileutil import get_data_from_file
return json.loads(get_data_from_file(os.getenv('MMGEN_BOGUS_WALLET_DATA')),parse_float=Decimal)
TwUnspentOutputs.set_dates = fake_set_dates
TwUnspentOutputs.get_unspent_rpc = fake_get_unspent_rpc

View file

@ -608,7 +608,8 @@ class CmdGroupMgr(object):
cls.__doc__.strip() if cls.__doc__ else cls.__name__
))
Die(0,'\n'+' '.join(e[0] for e in ginfo))
Msg( '\n' + ' '.join(e[0] for e in ginfo) )
sys.exit(0)
def find_cmd_in_groups(self,cmd,group=None):
"""