whitespace, minor cleanups
This commit is contained in:
parent
9a859bac70
commit
037bbda14a
14 changed files with 45 additions and 40 deletions
|
|
@ -25,6 +25,7 @@ from collections import namedtuple
|
|||
from .objmethods import HiliteStr,InitErrors,MMGenObject
|
||||
from .obj import ImmutableAttr,MMGenIdx,get_obj
|
||||
from .seed import SeedID
|
||||
from . import color as color_mod
|
||||
|
||||
ati = namedtuple('addrtype_info',
|
||||
['name','pubkey_type','compressed','gen_method','addr_fmt','wif_label','extra_attrs','desc'])
|
||||
|
|
@ -144,19 +145,19 @@ class MMGenID(HiliteStr,InitErrors,MMGenObject):
|
|||
def is_mmgen_id(proto,s):
|
||||
return get_obj( MMGenID, proto=proto, id_str=s, silent=True, return_bool=True )
|
||||
|
||||
class CoinAddr(HiliteStr,InitErrors,MMGenObject):
|
||||
class CoinAddr(HiliteStr, InitErrors, MMGenObject):
|
||||
color = 'cyan'
|
||||
hex_width = 40
|
||||
width = 1
|
||||
trunc_ok = False
|
||||
|
||||
def __new__(cls,proto,addr):
|
||||
if isinstance(addr,cls):
|
||||
return addr
|
||||
try:
|
||||
assert addr.isascii() and addr.isalnum(), 'not an ASCII alphanumeric string'
|
||||
me = str.__new__(cls,addr)
|
||||
ap = proto.decode_addr(addr)
|
||||
assert ap, f'coin address {addr!r} could not be parsed'
|
||||
me = str.__new__(cls, addr)
|
||||
me.addr_fmt = ap.fmt
|
||||
me.bytes = ap.bytes
|
||||
me.ver_bytes = ap.ver_bytes
|
||||
|
|
@ -171,15 +172,14 @@ class CoinAddr(HiliteStr,InitErrors,MMGenObject):
|
|||
self._parsed = self.proto.parse_addr(self.ver_bytes,self.bytes,self.addr_fmt)
|
||||
return self._parsed
|
||||
|
||||
# reimplement some HiliteStr methods:
|
||||
@classmethod
|
||||
def fmtc(cls,s,width,color=False):
|
||||
return super().fmtc( s=s[:width-2]+'..' if len(s) > width else s, width=width, color=color )
|
||||
|
||||
def fmt(self,width,color=False):
|
||||
return (
|
||||
super().fmtc( s=self[:width-2]+'..', width=width, color=color ) if len(self) > width else
|
||||
super().fmt( width=width, color=color )
|
||||
)
|
||||
def fmt(self, width, color=False):
|
||||
s = self
|
||||
return super().fmtc(f'{s[:width-2]}..' if len(s) > width else s, width=width, color=color)
|
||||
|
||||
def is_coin_addr(proto,s):
|
||||
return get_obj( CoinAddr, proto=proto, addr=s, silent=True, return_bool=True )
|
||||
|
|
|
|||
|
|
@ -93,11 +93,11 @@ class UserOpts:
|
|||
def __init__(
|
||||
self,
|
||||
cfg,
|
||||
opts_data = None,
|
||||
init_opts = None, # dict containing opts to pre-initialize
|
||||
opt_filter = None, # whitelist of opt letters; all others are skipped
|
||||
parse_only = False,
|
||||
parsed_opts = None ):
|
||||
opts_data,
|
||||
init_opts, # dict containing opts to pre-initialize
|
||||
opt_filter, # whitelist of opt letters; all others are skipped
|
||||
parse_only,
|
||||
parsed_opts):
|
||||
|
||||
self.opts_data = od = opts_data or opts_data_dfl
|
||||
self.opt_filter = opt_filter
|
||||
|
|
|
|||
|
|
@ -75,7 +75,7 @@ class mainnet(CoinProtocol.Secp256k1): # chainparams.cpp
|
|||
pubkey_type = self.wif_ver_bytes_to_pubkey_type[key_data[:vlen]],
|
||||
compressed = len(key) == self.privkey_len + 1 )
|
||||
|
||||
def decode_addr(self,addr):
|
||||
def decode_addr(self, addr):
|
||||
|
||||
if 'B' in self.mmtypes and addr[:len(self.bech32_hrp)] == self.bech32_hrp:
|
||||
from ...contrib import bech32
|
||||
|
|
@ -86,12 +86,12 @@ class mainnet(CoinProtocol.Secp256k1): # chainparams.cpp
|
|||
msg(f'{ret[0]}: Invalid witness version number')
|
||||
return False
|
||||
|
||||
return decoded_addr( bytes(ret[1]), None, 'bech32' ) if ret[1] else False
|
||||
return decoded_addr(bytes(ret[1]), None, 'bech32') if ret[1] else False
|
||||
|
||||
return self.decode_addr_bytes(b58chk_decode(addr))
|
||||
|
||||
def pubhash2addr(self,pubhash,p2sh):
|
||||
assert len(pubhash) == 20, f'{len(pubhash)}: invalid length for pubkey hash'
|
||||
assert len(pubhash) == self.addr_len, f'{len(pubhash)}: invalid length for pubkey hash'
|
||||
return b58chk_encode(
|
||||
self.addr_fmt_to_ver_bytes[('p2pkh','p2sh')[p2sh]] + pubhash
|
||||
)
|
||||
|
|
|
|||
|
|
@ -48,8 +48,7 @@ class TxInfo(TxInfo):
|
|||
out += f', Base {tsize-wsize}, Witness {wsize}'
|
||||
return out + '\n'
|
||||
|
||||
def format_body(self,blockcount,nonmm_str,max_mmwid,enl,terse,sort):
|
||||
tx = self.tx
|
||||
def format_body(self, blockcount, nonmm_str, max_mmwid, enl, terse, sort):
|
||||
|
||||
if sort not in self.sort_orders:
|
||||
die(1,'{!r}: invalid transaction view sort order. Valid options: {}'.format(
|
||||
|
|
@ -61,12 +60,14 @@ class TxInfo(TxInfo):
|
|||
is_input = desc == 'inputs'
|
||||
yield desc.capitalize() + ':\n' + enl
|
||||
confs_per_day = 60*60*24 // tx.proto.avg_bdi
|
||||
|
||||
io_sorted = {
|
||||
'addr': lambda: sorted(
|
||||
io, # prepend '+' (sorts before '0') to ensure non-MMGen addrs are displayed first
|
||||
key = lambda o: (o.mmid.sort_key if o.mmid else f'+{o.addr}') + f'{o.amt:040.20f}' ),
|
||||
'raw': lambda: io
|
||||
}[sort]
|
||||
|
||||
if terse:
|
||||
iwidth = max(len(str(int(e.amt))) for e in io)
|
||||
else:
|
||||
|
|
@ -107,6 +108,7 @@ class TxInfo(TxInfo):
|
|||
yield ('', 'change:', green('True'))
|
||||
yield '\n'.join('{:>{w}} {:<8} {}'.format(*d,w=col1_w) for d in gen()) + '\n\n'
|
||||
|
||||
tx = self.tx
|
||||
addr_w = max(len(e.addr) for f in (tx.inputs,tx.outputs) for e in f)
|
||||
|
||||
return (
|
||||
|
|
|
|||
|
|
@ -54,9 +54,9 @@ class mainnet(CoinProtocol.DummyWIF,CoinProtocol.Secp256k1):
|
|||
def dcoin(self):
|
||||
return self.tokensym or self.coin
|
||||
|
||||
def decode_addr(self,addr):
|
||||
def decode_addr(self, addr):
|
||||
if is_hex_str_lc(addr) and len(addr) == self.addr_len * 2:
|
||||
return decoded_addr( bytes.fromhex(addr), None, 'ethereum' )
|
||||
return decoded_addr(bytes.fromhex(addr), None, 'ethereum')
|
||||
if self.cfg.debug:
|
||||
Msg(f'Invalid address: {addr}')
|
||||
return False
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ class TxInfo(TxInfo):
|
|||
""")
|
||||
fmt_keys = ('from','to','amt','nonce')
|
||||
|
||||
def format_body(self,blockcount,nonmm_str,max_mmwid,enl,terse,sort):
|
||||
def format_body(self, blockcount, nonmm_str, max_mmwid, enl, terse, sort):
|
||||
tx = self.tx
|
||||
m = {}
|
||||
for k in ('inputs','outputs'):
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ class mainnet(mainnet):
|
|||
def get_addr_len(self,addr_fmt):
|
||||
return (20,64)[addr_fmt in ('zcash_z','viewkey')]
|
||||
|
||||
def decode_addr_bytes(self,addr_bytes):
|
||||
def decode_addr_bytes(self, addr_bytes):
|
||||
"""
|
||||
vlen must be set dynamically since Zcash has variable-length version bytes
|
||||
"""
|
||||
|
|
@ -53,7 +53,7 @@ class mainnet(mainnet):
|
|||
vlen = len(ver_bytes)
|
||||
if addr_bytes[:vlen] == ver_bytes:
|
||||
if len(addr_bytes[vlen:]) == self.get_addr_len(addr_fmt):
|
||||
return decoded_addr( addr_bytes[vlen:], ver_bytes, addr_fmt )
|
||||
return decoded_addr(addr_bytes[vlen:], ver_bytes, addr_fmt)
|
||||
|
||||
return False
|
||||
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ from .cfg import gc
|
|||
from .objmethods import MMGenObject
|
||||
|
||||
decoded_wif = namedtuple('decoded_wif',['sec','pubkey_type','compressed'])
|
||||
decoded_addr = namedtuple('decoded_addr',['bytes','ver_bytes','fmt'])
|
||||
decoded_addr = namedtuple('decoded_addr', ['bytes', 'ver_bytes', 'fmt'])
|
||||
parsed_addr = namedtuple('parsed_addr',['ver_bytes','data'])
|
||||
|
||||
_finfo = namedtuple('fork_info',['height','hash','name','replayable'])
|
||||
|
|
@ -149,12 +149,12 @@ class CoinProtocol(MMGenObject):
|
|||
def get_addr_len(self,addr_fmt):
|
||||
return self.addr_len
|
||||
|
||||
def decode_addr_bytes(self,addr_bytes):
|
||||
def decode_addr_bytes(self, addr_bytes):
|
||||
vlen = self.addr_ver_bytes_len
|
||||
return decoded_addr(
|
||||
addr_bytes[vlen:],
|
||||
addr_bytes[:vlen],
|
||||
self.addr_ver_bytes[addr_bytes[:vlen]] )
|
||||
self.addr_ver_bytes[addr_bytes[:vlen]])
|
||||
|
||||
def coin_addr(self,addr):
|
||||
from .addr import CoinAddr
|
||||
|
|
|
|||
|
|
@ -31,7 +31,6 @@ class TwMMGenID(HiliteStr,InitErrors,MMGenObject):
|
|||
coin,addr = id_str.split(':',1)
|
||||
assert coin == proto.base_coin.lower(),(
|
||||
f'not a string beginning with the prefix {proto.base_coin.lower()!r}:' )
|
||||
assert addr.isascii() and addr.isalnum(), 'not an ASCII alphanumeric string'
|
||||
ret,sort_key,idtype,disp = (id_str,'z_'+id_str,'non-mmgen','non-MMGen')
|
||||
addr = proto.coin_addr(addr)
|
||||
except Exception as e2:
|
||||
|
|
|
|||
|
|
@ -418,7 +418,7 @@ class TwView(MMGenObject,metaclass=AsyncInit):
|
|||
|
||||
yield from getattr(self,dt.subhdr_fmt_method)(cw,color)
|
||||
|
||||
yield ''
|
||||
yield ' ' * self.term_width
|
||||
|
||||
if data and dt.colhdr_fmt_method:
|
||||
col_hdr = getattr(self,dt.colhdr_fmt_method)(cw,hdr_fs,color)
|
||||
|
|
@ -580,7 +580,7 @@ class TwView(MMGenObject,metaclass=AsyncInit):
|
|||
msg('')
|
||||
if self.scroll:
|
||||
self.term.set('echo')
|
||||
return self.disp_data
|
||||
return
|
||||
else:
|
||||
if not scroll:
|
||||
msg_r('\ninvalid keypress ')
|
||||
|
|
|
|||
|
|
@ -126,7 +126,7 @@ class Base(MMGenObject):
|
|||
@property
|
||||
def info(self):
|
||||
from .info import init_info
|
||||
return init_info(self)
|
||||
return init_info(self.cfg, self)
|
||||
|
||||
def check_correct_chain(self):
|
||||
if hasattr(self,'rpc'):
|
||||
|
|
|
|||
|
|
@ -21,10 +21,11 @@ from ..util2 import format_elapsed_hr
|
|||
|
||||
class TxInfo:
|
||||
|
||||
def __init__(self,tx):
|
||||
def __init__(self, cfg, tx):
|
||||
self.cfg = cfg
|
||||
self.tx = tx
|
||||
|
||||
def format(self,terse=False,sort='addr'):
|
||||
def format(self, terse=False, sort='addr'):
|
||||
|
||||
tx = self.tx
|
||||
|
||||
|
|
@ -61,9 +62,6 @@ class TxInfo:
|
|||
_ = decode_timestamp(val)
|
||||
yield f'{label:8} {make_timestr(_)} ({format_elapsed_hr(_)})\n'
|
||||
|
||||
if not terse:
|
||||
yield '\n'
|
||||
|
||||
if tx.chain != 'mainnet': # if mainnet has a coin-specific name, display it
|
||||
yield green(f'Chain: {tx.chain.upper()}') + '\n'
|
||||
|
||||
|
|
@ -76,7 +74,13 @@ class TxInfo:
|
|||
if tx.comment:
|
||||
yield f'Comment: {tx.comment.hl()}\n{enl}'
|
||||
|
||||
yield self.format_body(blockcount,nonmm_str,max_mmwid,enl,terse=terse,sort=sort)
|
||||
yield self.format_body(
|
||||
blockcount,
|
||||
nonmm_str,
|
||||
max_mmwid,
|
||||
enl,
|
||||
terse = terse,
|
||||
sort = sort)
|
||||
|
||||
iwidth = len(str(int(tx.sum_inputs())))
|
||||
|
||||
|
|
@ -123,7 +127,7 @@ class TxInfo:
|
|||
get_char('Press any key to continue: ')
|
||||
msg('')
|
||||
|
||||
def init_info(tx):
|
||||
def init_info(cfg, tx):
|
||||
return getattr(
|
||||
importlib.import_module(f'mmgen.proto.{tx.proto.base_proto_coin.lower()}.tx.info'),
|
||||
('Token' if tx.proto.tokensym else '') + 'TxInfo' )(tx)
|
||||
('Token' if tx.proto.tokensym else '') + 'TxInfo' )(cfg, tx)
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ author = The MMGen Project
|
|||
author_email = mmgen@tuta.io
|
||||
url = https://github.com/mmgen/mmgen-wallet
|
||||
license = GNU GPL v3
|
||||
platforms = Linux, Armbian, Raspbian, MS Windows
|
||||
platforms = Linux, Armbian, Raspbian, MS Windows, MacOS
|
||||
keywords = file: mmgen/data/keywords
|
||||
project_urls =
|
||||
Website = https://mmgen-wallet.cc
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ if not os.getenv('MMGEN_DEVTOOLS'):
|
|||
|
||||
from mmgen.cfg import Config,gc
|
||||
from mmgen.color import gray, brown, orange, yellow, red
|
||||
from mmgen.util import msg,gmsg,ymsg,Msg
|
||||
from mmgen.util import msg, msg_r, gmsg, ymsg, Msg
|
||||
|
||||
from test.include.common import set_globals,end_msg
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue