From 4b41093ce999f52614491ab8f253ac9a359e724d Mon Sep 17 00:00:00 2001 From: The MMGen Project Date: Mon, 23 May 2022 16:28:54 +0000 Subject: [PATCH] minor fixes --- mmgen/tool/rpc.py | 3 +++ mmgen/tw/common.py | 27 +++++++++++++++------------ mmgen/tw/unspent.py | 6 ++---- 3 files changed, 20 insertions(+), 16 deletions(-) diff --git a/mmgen/tool/rpc.py b/mmgen/tool/rpc.py index bd997905..6098c9ca 100755 --- a/mmgen/tool/rpc.py +++ b/mmgen/tool/rpc.py @@ -98,10 +98,13 @@ class tool_cmd(tool_cmd_base): async def twops(self, obj,pager,reverse,wide,sort,age_fmt,show_mmid,wide_show_confs,interactive): + obj.reverse = reverse obj.age_fmt = age_fmt obj.show_mmid = show_mmid + await obj.get_data(sort_key=sort,reverse_sort=reverse) + if interactive: await obj.view_and_sort() return True diff --git a/mmgen/tw/common.py b/mmgen/tw/common.py index b9017afa..bd945b9c 100755 --- a/mmgen/tw/common.py +++ b/mmgen/tw/common.py @@ -78,7 +78,8 @@ class TwCommon: async def set_dates(rpc,us): if us and us[0].date is None: # 'blocktime' differs from 'time', is same as getblockheader['time'] - dates = [o['blocktime'] for o in await rpc.gathered_call('gettransaction',[(o.txid,) for o in us])] + dates = [ o.get('blocktime',0) + for o in await rpc.gathered_call('gettransaction',[(o.txid,) for o in us]) ] for idx,o in enumerate(us): o.date = dates[idx] @@ -113,20 +114,21 @@ class TwCommon: ret.append('Grouped') return ret + sort_funcs = { + 'addr': lambda i: i.addr, + 'age': lambda i: 0 - i.confs, + 'amt': lambda i: i.amt, + 'txid': lambda i: f'{i.txid} {i.vout:04}', + 'twmmid': lambda i: i.twmmid.sort_key + } + def do_sort(self,key=None,reverse=False): - sort_funcs = { - 'addr': lambda i: i.addr, - 'age': lambda i: 0 - i.confs, - 'amt': lambda i: i.amt, - 'txid': lambda i: f'{i.txid} {i.vout:04}', - 'twmmid': lambda i: i.twmmid.sort_key - } key = key or self.sort_key - if key not in sort_funcs: - die(1,f'{key!r}: invalid sort key. Valid options: {" ".join(sort_funcs.keys())}') + if key not in self.sort_funcs: + die(1,f'{key!r}: invalid sort key. Valid options: {" ".join(self.sort_funcs)}') self.sort_key = key assert type(reverse) == bool - self.data.sort(key=sort_funcs[key],reverse=reverse or self.reverse) + self.data.sort(key=self.sort_funcs[key],reverse=reverse or self.reverse) async def format_for_display(self): data = self.data @@ -236,9 +238,10 @@ class TwCommon: await getattr(self,action)(self.parent) async def a_print(self,parent): - outfile = '{}-{}[{}].out'.format( + outfile = '{}-{}{}[{}].out'.format( parent.dump_fn_pfx, parent.proto.dcoin, + ('' if parent.proto.network == 'mainnet' else '-'+parent.proto.network.upper()), ','.join(parent.sort_info(include_group=False)).lower() ) msg('') from ..fileutil import write_data_to_file diff --git a/mmgen/tw/unspent.py b/mmgen/tw/unspent.py index 8b11facd..73d32d35 100755 --- a/mmgen/tw/unspent.py +++ b/mmgen/tw/unspent.py @@ -20,7 +20,7 @@ twuo: Tracking wallet unspent outputs class for the MMGen suite """ -import time +import asyncio from collections import namedtuple from ..globalvars import g @@ -58,7 +58,7 @@ class TwUnspentOutputs(MMGenObject,TwCommon,metaclass=AsyncInit): txid = ListItemAttr(CoinTxID) vout = ListItemAttr(int,typeconv=False) amt = ImmutableAttr(None) - amt2 = ListItemAttr(None) + amt2 = ListItemAttr(None) # the ETH balance for token account label = ListItemAttr(TwComment,reassign_ok=True) twmmid = ImmutableAttr(TwMMGenID,include_proto=True) addr = ImmutableAttr(CoinAddr,include_proto=True) @@ -256,7 +256,6 @@ class TwUnspentOutputs(MMGenObject,TwCommon,metaclass=AsyncInit): await uo.get_data() uo.oneshot_msg = yellow(f'{capfirst(uo.item_desc)} #{idx} removed\n\n') else: - import asyncio await asyncio.sleep(3) uo.oneshot_msg = red('Address could not be removed\n\n') @@ -271,7 +270,6 @@ class TwUnspentOutputs(MMGenObject,TwCommon,metaclass=AsyncInit): uo.item_desc, idx )) else: - import asyncio await asyncio.sleep(3) uo.oneshot_msg = red('Label could not be added\n\n')