tw/unspent.py: variable and method renames
This commit is contained in:
parent
3176c568d7
commit
1c0c1e4552
12 changed files with 57 additions and 57 deletions
|
|
@ -7,7 +7,7 @@ In addition to improved reliability, maintainability and extensibility, this
|
|||
major code overhaul has led to significant performance improvements and
|
||||
reductions in memory usage.
|
||||
|
||||
#### Important new features:
|
||||
#### Important new feature:
|
||||
|
||||
- message signing: 86e3b273, e5cf3b6ec, 25efac31b, 770b209af, a81ff33f0
|
||||
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ Actions: [q]uit view, [p]rint to file, pager [v]iew, [w]ide view, add [l]abel:
|
|||
display_hdr_fs_fs = ' {{n:{cw}}} {{t:{tw}}} {{a}} {{A}} {{c:<}}'
|
||||
print_fs_fs = ' {{n:4}} {{t:{tw}}} {{a}} {{m}} {{A:{aw}}} {cf}{{b:<8}} {{D:<19}} {{l}}'
|
||||
|
||||
async def get_unspent_rpc(self):
|
||||
async def get_rpc_data(self):
|
||||
# bitcoin-cli help listunspent:
|
||||
# Arguments:
|
||||
# 1. minconf (numeric, optional, default=1) The minimum confirmations to filter
|
||||
|
|
|
|||
|
|
@ -63,7 +63,7 @@ Actions: [q]uit view, [p]rint to file, pager [v]iew, [w]ide view,
|
|||
if key == 'txid': return
|
||||
super().do_sort(key=key,reverse=reverse)
|
||||
|
||||
async def get_unspent_rpc(self):
|
||||
async def get_rpc_data(self):
|
||||
wl = self.wallet.sorted_list
|
||||
if self.addrs:
|
||||
wl = [d for d in wl if d['addr'] in self.addrs]
|
||||
|
|
@ -92,7 +92,7 @@ class EthereumTokenTwUnspentOutputs(EthereumTwUnspentOutputs):
|
|||
def get_display_precision(self):
|
||||
return 10 # truncate precision for narrow display
|
||||
|
||||
async def get_unspent_data(self,*args,**kwargs):
|
||||
await super().get_unspent_data(*args,**kwargs)
|
||||
for e in self.unspent:
|
||||
async def get_data(self,*args,**kwargs):
|
||||
await super().get_data(*args,**kwargs)
|
||||
for e in self.data:
|
||||
e.amt2 = await self.wallet.get_eth_balance(e.addr)
|
||||
|
|
|
|||
|
|
@ -109,7 +109,7 @@ class tool_cmd(tool_cmd_base):
|
|||
|
||||
from ..tw.unspent import TwUnspentOutputs
|
||||
twuo = await TwUnspentOutputs(self.proto,minconf=minconf)
|
||||
await twuo.get_unspent_data(reverse_sort=reverse)
|
||||
await twuo.get_data(reverse_sort=reverse)
|
||||
twuo.age_fmt = age_fmt
|
||||
twuo.show_mmid = show_mmid
|
||||
if wide:
|
||||
|
|
|
|||
|
|
@ -40,8 +40,8 @@ from ..util import (
|
|||
)
|
||||
from ..base_obj import AsyncInit
|
||||
from ..objmethods import MMGenObject
|
||||
from ..obj import ImmutableAttr,ListItemAttr,MMGenListItem,TwComment,get_obj,HexStr,CoinTxID
|
||||
from ..addr import CoinAddr,MMGenID,AddrIdx
|
||||
from ..obj import ImmutableAttr,ListItemAttr,MMGenListItem,TwComment,get_obj,HexStr,CoinTxID,MMGenIdx
|
||||
from ..addr import CoinAddr,MMGenID
|
||||
from ..rpc import rpc_init
|
||||
from .common import TwCommon,TwMMGenID,get_tw_label
|
||||
|
||||
|
|
@ -82,7 +82,7 @@ class TwUnspentOutputs(MMGenObject,TwCommon,metaclass=AsyncInit):
|
|||
|
||||
async def __init__(self,proto,minconf=1,addrs=[]):
|
||||
self.proto = proto
|
||||
self.unspent = self.MMGenTwOutputList()
|
||||
self.data = self.MMGenTwOutputList()
|
||||
self.fmt_display = ''
|
||||
self.fmt_print = ''
|
||||
self.cols = None
|
||||
|
|
@ -113,11 +113,11 @@ class TwUnspentOutputs(MMGenObject,TwCommon,metaclass=AsyncInit):
|
|||
|
||||
@property
|
||||
def total(self):
|
||||
return sum(i.amt for i in self.unspent)
|
||||
return sum(i.amt for i in self.data)
|
||||
|
||||
async def get_unspent_data(self,sort_key=None,reverse_sort=False):
|
||||
async def get_data(self,sort_key=None,reverse_sort=False):
|
||||
|
||||
us_raw = await self.get_unspent_rpc()
|
||||
us_raw = await self.get_rpc_data()
|
||||
|
||||
if not us_raw:
|
||||
die(0,fmt(f"""
|
||||
|
|
@ -144,9 +144,9 @@ class TwUnspentOutputs(MMGenObject,TwCommon,metaclass=AsyncInit):
|
|||
self.proto,
|
||||
**{ k:v for k,v in o.items() if k in self.MMGenTwUnspentOutput.valid_attrs } )
|
||||
|
||||
self.unspent = self.MMGenTwOutputList(gen_unspent())
|
||||
self.data = self.MMGenTwOutputList(gen_unspent())
|
||||
|
||||
if not self.unspent:
|
||||
if not self.data:
|
||||
die(1, f'No tracked {self.item_desc}s in tracking wallet!')
|
||||
|
||||
self.do_sort(key=sort_key,reverse=reverse_sort)
|
||||
|
|
@ -164,7 +164,7 @@ class TwUnspentOutputs(MMGenObject,TwCommon,metaclass=AsyncInit):
|
|||
die(1,f'{key!r}: invalid sort key. Valid options: {" ".join(sort_funcs.keys())}')
|
||||
self.sort_key = key
|
||||
assert type(reverse) == bool
|
||||
self.unspent.sort(key=sort_funcs[key],reverse=reverse or self.reverse)
|
||||
self.data.sort(key=sort_funcs[key],reverse=reverse or self.reverse)
|
||||
|
||||
def sort_info(self,include_group=True):
|
||||
ret = ([],['Reverse'])[self.reverse]
|
||||
|
|
@ -184,15 +184,15 @@ class TwUnspentOutputs(MMGenObject,TwCommon,metaclass=AsyncInit):
|
|||
+ f'Please resize your screen to at least {g.min_screen_width} characters and hit ENTER ' )
|
||||
|
||||
def get_display_constants(self):
|
||||
unsp = self.unspent
|
||||
for i in unsp:
|
||||
data = self.data
|
||||
for i in data:
|
||||
i.skip = ''
|
||||
|
||||
# allow for 7-digit confirmation nums
|
||||
col1_w = max(3,len(str(len(unsp)))+1) # num + ')'
|
||||
mmid_w = max(len(('',i.twmmid)[i.twmmid.type=='mmgen']) for i in unsp) or 12 # DEADBEEF:S:1
|
||||
max_acct_w = max(i.label.screen_width for i in unsp) + mmid_w + 1
|
||||
max_btcaddr_w = max(len(i.addr) for i in unsp)
|
||||
col1_w = max(3,len(str(len(data)))+1) # num + ')'
|
||||
mmid_w = max(len(('',i.twmmid)[i.twmmid.type=='mmgen']) for i in data) or 12 # DEADBEEF:S:1
|
||||
max_acct_w = max(i.label.screen_width for i in data) + mmid_w + 1
|
||||
max_btcaddr_w = max(len(i.addr) for i in data)
|
||||
min_addr_w = self.cols - self.col_adj
|
||||
addr_w = min(max_btcaddr_w + (0,1+max_acct_w)[self.show_mmid],min_addr_w)
|
||||
acct_w = min(max_acct_w, max(24,addr_w-10))
|
||||
|
|
@ -205,9 +205,9 @@ class TwUnspentOutputs(MMGenObject,TwCommon,metaclass=AsyncInit):
|
|||
return dc(col1_w,mmid_w,addr_w,btaddr_w,label_w,tx_w,txdots)
|
||||
|
||||
async def format_for_display(self):
|
||||
unsp = self.unspent
|
||||
data = self.data
|
||||
if self.has_age and self.age_fmt in self.age_fmts_date_dependent:
|
||||
await self.set_dates(self.rpc,unsp)
|
||||
await self.set_dates(self.rpc,data)
|
||||
self.set_term_columns()
|
||||
|
||||
c = getattr(self,'display_constants',None)
|
||||
|
|
@ -215,7 +215,7 @@ class TwUnspentOutputs(MMGenObject,TwCommon,metaclass=AsyncInit):
|
|||
c = self.display_constants = self.get_display_constants()
|
||||
|
||||
if self.group and (self.sort_key in ('addr','txid','twmmid')):
|
||||
for a,b in [(unsp[i],unsp[i+1]) for i in range(len(unsp)-1)]:
|
||||
for a,b in [(data[i],data[i+1]) for i in range(len(data)-1)]:
|
||||
for k in ('addr','txid','twmmid'):
|
||||
if self.sort_key == k and getattr(a,k) == getattr(b,k):
|
||||
b.skip = (k,'addr')[k=='twmmid']
|
||||
|
|
@ -241,7 +241,7 @@ class TwUnspentOutputs(MMGenObject,TwCommon,metaclass=AsyncInit):
|
|||
}[self.age_fmt],
|
||||
).rstrip()
|
||||
|
||||
for n,i in enumerate(unsp):
|
||||
for n,i in enumerate(data):
|
||||
addr_dots = '|' + '.'*(c.addr_w-1)
|
||||
mmid_disp = MMGenID.fmtc(
|
||||
(
|
||||
|
|
@ -283,9 +283,9 @@ class TwUnspentOutputs(MMGenObject,TwCommon,metaclass=AsyncInit):
|
|||
|
||||
async def format_for_printing(self,color=False,show_confs=True):
|
||||
if self.has_age:
|
||||
await self.set_dates(self.rpc,self.unspent)
|
||||
addr_w = max(len(i.addr) for i in self.unspent)
|
||||
mmid_w = max(len(('',i.twmmid)[i.twmmid.type=='mmgen']) for i in self.unspent) or 12 # DEADBEEF:S:1
|
||||
await self.set_dates(self.rpc,self.data)
|
||||
addr_w = max(len(i.addr) for i in self.data)
|
||||
mmid_w = max(len(('',i.twmmid)[i.twmmid.type=='mmgen']) for i in self.data) or 12 # DEADBEEF:S:1
|
||||
fs = self.print_fs_fs.format(
|
||||
tw = self.txid_w + 3,
|
||||
cf = '{c:<8} ' if show_confs else '',
|
||||
|
|
@ -304,8 +304,8 @@ class TwUnspentOutputs(MMGenObject,TwCommon,metaclass=AsyncInit):
|
|||
D = 'Date',
|
||||
l = 'Label' )
|
||||
|
||||
max_lbl_len = max([len(i.label) for i in self.unspent if i.label] or [2])
|
||||
for n,i in enumerate(self.unspent):
|
||||
max_lbl_len = max([len(i.label) for i in self.data if i.label] or [2])
|
||||
for n,i in enumerate(self.data):
|
||||
yield fs.format(
|
||||
n = str(n+1) + ')',
|
||||
t = '{},{}'.format(
|
||||
|
|
@ -349,8 +349,8 @@ class TwUnspentOutputs(MMGenObject,TwCommon,metaclass=AsyncInit):
|
|||
msg('\nTotal unspent: {} {} ({} output{})'.format(
|
||||
self.total.hl(),
|
||||
self.proto.dcoin,
|
||||
len(self.unspent),
|
||||
suf(self.unspent) ))
|
||||
len(self.data),
|
||||
suf(self.data) ))
|
||||
|
||||
def get_idx_from_user(self,action):
|
||||
msg('')
|
||||
|
|
@ -358,12 +358,12 @@ class TwUnspentOutputs(MMGenObject,TwCommon,metaclass=AsyncInit):
|
|||
ret = line_input(f'Enter {self.item_desc} number (or RETURN to return to main menu): ')
|
||||
if ret == '':
|
||||
return (None,None) if action == 'a_lbl_add' else None
|
||||
n = get_obj(AddrIdx,n=ret,silent=True)
|
||||
if not n or n < 1 or n > len(self.unspent):
|
||||
msg(f'Choice must be a single number between 1 and {len(self.unspent)}')
|
||||
n = get_obj(MMGenIdx,n=ret,silent=True)
|
||||
if not n or n < 1 or n > len(self.data):
|
||||
msg(f'Choice must be a single number between 1 and {len(self.data)}')
|
||||
else:
|
||||
if action == 'a_lbl_add':
|
||||
cur_lbl = self.unspent[n-1].label
|
||||
cur_lbl = self.data[n-1].label
|
||||
msg('Current label: {}'.format(cur_lbl.hl() if cur_lbl else '(none)'))
|
||||
while True:
|
||||
s = line_input(
|
||||
|
|
@ -422,25 +422,25 @@ class TwUnspentOutputs(MMGenObject,TwCommon,metaclass=AsyncInit):
|
|||
elif action == 'd_redraw':
|
||||
pass
|
||||
elif action == 'd_reverse':
|
||||
self.unspent.reverse()
|
||||
self.data.reverse()
|
||||
self.reverse = not self.reverse
|
||||
elif action == 'a_quit':
|
||||
msg('')
|
||||
return self.unspent
|
||||
return self.data
|
||||
elif action == 'a_balance_refresh':
|
||||
idx = self.get_idx_from_user(action)
|
||||
if idx:
|
||||
e = self.unspent[idx-1]
|
||||
e = self.data[idx-1]
|
||||
bal = await self.wallet.get_balance(e.addr,force_rpc=True)
|
||||
await self.get_unspent_data()
|
||||
await self.get_data()
|
||||
oneshot_msg = yellow(f'{self.proto.dcoin} balance for account #{idx} refreshed\n\n')
|
||||
self.display_constants = self.get_display_constants()
|
||||
elif action == 'a_lbl_add':
|
||||
idx,lbl = self.get_idx_from_user(action)
|
||||
if idx:
|
||||
e = self.unspent[idx-1]
|
||||
e = self.data[idx-1]
|
||||
if await self.wallet.add_label(e.twmmid,lbl,addr=e.addr):
|
||||
await self.get_unspent_data()
|
||||
await self.get_data()
|
||||
oneshot_msg = yellow('Label {} {} #{}\n\n'.format(
|
||||
('added to' if lbl else 'removed from'),
|
||||
self.item_desc,
|
||||
|
|
@ -451,9 +451,9 @@ class TwUnspentOutputs(MMGenObject,TwCommon,metaclass=AsyncInit):
|
|||
elif action == 'a_addr_delete':
|
||||
idx = self.get_idx_from_user(action)
|
||||
if idx:
|
||||
e = self.unspent[idx-1]
|
||||
e = self.data[idx-1]
|
||||
if await self.wallet.remove_address(e.addr):
|
||||
await self.get_unspent_data()
|
||||
await self.get_data()
|
||||
oneshot_msg = yellow(f'{capfirst(self.item_desc)} #{idx} removed\n\n')
|
||||
else:
|
||||
oneshot_msg = red('Address could not be removed\n\n')
|
||||
|
|
|
|||
|
|
@ -290,10 +290,10 @@ class New(Base):
|
|||
|
||||
while True:
|
||||
us_f = self.select_unspent_cmdline if opt.inputs else self.select_unspent
|
||||
sel_nums = us_f(self.twuo.unspent)
|
||||
sel_nums = us_f(self.twuo.data)
|
||||
|
||||
msg(f'Selected output{suf(sel_nums)}: {{}}'.format(' '.join(str(n) for n in sel_nums)))
|
||||
sel_unspent = self.twuo.MMGenTwOutputList([self.twuo.unspent[i-1] for i in sel_nums])
|
||||
sel_unspent = self.twuo.MMGenTwOutputList([self.twuo.data[i-1] for i in sel_nums])
|
||||
|
||||
inputs_sum = sum(s.amt for s in sel_unspent)
|
||||
if not await self.precheck_sufficient_funds(inputs_sum,sel_unspent,outputs_sum):
|
||||
|
|
@ -326,7 +326,7 @@ class New(Base):
|
|||
twuo_addrs = await self.get_cmdline_input_addrs()
|
||||
|
||||
self.twuo = await TwUnspentOutputs(self.proto,minconf=opt.minconf,addrs=twuo_addrs)
|
||||
await self.twuo.get_unspent_data()
|
||||
await self.twuo.get_data()
|
||||
|
||||
if not do_info:
|
||||
await self.get_outputs_from_cmdline(cmd_args)
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
import os
|
||||
from .unspent_orig import *
|
||||
|
||||
if os.getenv('MMGEN_BOGUS_WALLET_DATA'):
|
||||
if os.getenv('MMGEN_BOGUS_UNSPENT_DATA'):
|
||||
|
||||
async def fake_get_unspent_rpc(foo):
|
||||
async def fake_get_rpc_data(foo):
|
||||
from decimal import Decimal
|
||||
import json
|
||||
from ....fileutil import get_data_from_file
|
||||
return json.loads(get_data_from_file(os.getenv('MMGEN_BOGUS_WALLET_DATA')),parse_float=Decimal)
|
||||
return json.loads(get_data_from_file(os.getenv('MMGEN_BOGUS_UNSPENT_DATA')),parse_float=Decimal)
|
||||
|
||||
BitcoinTwUnspentOutputs.get_unspent_rpc = fake_get_unspent_rpc
|
||||
BitcoinTwUnspentOutputs.get_rpc_data = fake_get_rpc_data
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
from .rpc_orig import *
|
||||
|
||||
if os.getenv('MMGEN_BOGUS_WALLET_DATA'):
|
||||
if os.getenv('MMGEN_BOGUS_UNSPENT_DATA'):
|
||||
|
||||
rpc_init_orig = rpc_init
|
||||
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ if os.getenv('MMGEN_TEST_SUITE_DETERMINISTIC'):
|
|||
'date_time': lambda rpc,secs: '{}-{:02}-{:02} {:02}:{:02}'.format(*time.gmtime(next(_time_iter))[:5]),
|
||||
}
|
||||
|
||||
if os.getenv('MMGEN_BOGUS_WALLET_DATA'):
|
||||
if os.getenv('MMGEN_BOGUS_UNSPENT_DATA'):
|
||||
|
||||
async def fake_set_dates(foo,rpc,us):
|
||||
for o in us:
|
||||
|
|
|
|||
|
|
@ -791,7 +791,7 @@ class TestSuiteRunner(object):
|
|||
start_test_daemons(network_id,remove_datadir=True)
|
||||
self.daemons_started = True
|
||||
|
||||
os.environ['MMGEN_BOGUS_WALLET_DATA'] = '' # zero this here, so test groups don't have to
|
||||
os.environ['MMGEN_BOGUS_UNSPENT_DATA'] = '' # zero this here, so test groups don't have to
|
||||
|
||||
self.ts = self.gm.gm_init_group(self,gname,self.spawn_wrapper)
|
||||
self.ts_clsname = type(self.ts).__name__
|
||||
|
|
|
|||
|
|
@ -200,7 +200,7 @@ class TestSuiteMain(TestSuiteBase,TestSuiteShared):
|
|||
self.txbump_fee = {'btc':'123s','bch':'567s','ltc':'12345s'}[self.proto.coin.lower()]
|
||||
|
||||
self.unspent_data_file = joinpath('test','trash','unspent.json')
|
||||
os.environ['MMGEN_BOGUS_WALLET_DATA'] = self.unspent_data_file
|
||||
os.environ['MMGEN_BOGUS_UNSPENT_DATA'] = self.unspent_data_file
|
||||
|
||||
def _get_addrfile_checksum(self,display=False):
|
||||
addrfile = self.get_file_with_ext('addrs')
|
||||
|
|
|
|||
|
|
@ -80,7 +80,7 @@ class TestSuiteTool(TestSuiteMain,TestSuiteBase):
|
|||
return t
|
||||
|
||||
def tool_twview_bad_comment(self): # test correct operation of get_tw_label()
|
||||
os.environ['MMGEN_BOGUS_WALLET_DATA'] = joinpath(ref_dir,'bad-comment-unspent.json')
|
||||
os.environ['MMGEN_BOGUS_UNSPENT_DATA'] = joinpath(ref_dir,'bad-comment-unspent.json')
|
||||
t = self.spawn('mmgen-tool',['twview'])
|
||||
t.expect('cannot be converted to TwComment')
|
||||
t.req_exit_val = 2
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue