From 2cefa48def5e6d0b94496bd7132a18a5b0dc7f44 Mon Sep 17 00:00:00 2001 From: The MMGen Project Date: Wed, 7 May 2025 18:24:07 +0000 Subject: [PATCH] TwAddresses: new `is_used` attribute --- mmgen/proto/btc/tw/addresses.py | 2 ++ mmgen/proto/eth/tw/addresses.py | 1 + mmgen/tw/addresses.py | 15 +++++++++------ mmgen/tw/prune.py | 8 ++++---- 4 files changed, 16 insertions(+), 10 deletions(-) diff --git a/mmgen/proto/btc/tw/addresses.py b/mmgen/proto/btc/tw/addresses.py index bd6dcad7..dfaf9a85 100755 --- a/mmgen/proto/btc/tw/addresses.py +++ b/mmgen/proto/btc/tw/addresses.py @@ -63,6 +63,7 @@ class BitcoinTwAddresses(TwAddresses, BitcoinTwRPC): 'addr': e.coinaddr, 'amt': amt0, 'recvd': amt0, + 'is_used': False, 'confs': 0, 'lbl': e.label} qmsg('done') @@ -75,6 +76,7 @@ class BitcoinTwAddresses(TwAddresses, BitcoinTwRPC): assert label.mmid in addrs, f'{label.mmid!r} not found in addrlist!' amt = coin_amt(d['amount']) addrs[label.mmid]['recvd'] = amt + addrs[label.mmid]['is_used'] = bool(amt) addrs[label.mmid]['confs'] = d['confirmations'] qmsg('done') diff --git a/mmgen/proto/eth/tw/addresses.py b/mmgen/proto/eth/tw/addresses.py index 4b9d424b..9e14072d 100755 --- a/mmgen/proto/eth/tw/addresses.py +++ b/mmgen/proto/eth/tw/addresses.py @@ -75,6 +75,7 @@ class EthereumTwAddresses(TwAddresses, EthereumTwView, EthereumTwRPC): 'addr': e.coinaddr, 'amt': bal, 'recvd': bal, # current bal only, CF btc.tw.addresses.get_rpc_data() + 'is_used': bool(bal), # ditto 'confs': 0, 'lbl': e.label} self.total += bal diff --git a/mmgen/tw/addresses.py b/mmgen/tw/addresses.py index d8896210..d3ad0fe4 100755 --- a/mmgen/tw/addresses.py +++ b/mmgen/tw/addresses.py @@ -55,6 +55,7 @@ class TwAddresses(TwView): 'comment', 'amt', 'recvd', + 'is_used', 'date', 'skip'} invalid_attrs = {'proto'} @@ -66,6 +67,7 @@ class TwAddresses(TwView): comment = ListItemAttr(TwComment, reassign_ok=True) amt = ImmutableAttr(CoinAmtChk, include_proto=True) recvd = ImmutableAttr(CoinAmtChk, include_proto=True) + is_used = ImmutableAttr(bool) date = ListItemAttr(int, typeconv=False, reassign_ok=True) skip = ListItemAttr(str, typeconv=False, reassign_ok=True) @@ -114,6 +116,7 @@ class TwAddresses(TwView): comment = data['lbl'].comment, amt = data['amt'], recvd = data['recvd'], + is_used = data['is_used'], date = 0, skip = '') for twmmid, data in rpc_data.items() @@ -125,8 +128,8 @@ class TwAddresses(TwView): else: return (d for d in self.data if (self.all_labels and d.comment) or - (self.showused == 2 and d.recvd) or - (not (d.recvd and not self.showused) and (d.amt or self.showempty)) + (self.showused == 2 and d.is_used) or + (not (d.is_used and not self.showused) and (d.amt or self.showempty)) ) def get_column_widths(self, data, wide, interactive): @@ -184,7 +187,7 @@ class TwAddresses(TwView): return fs.format( n = str(n) + ')', m = d.twmmid.fmt(cw.mmid, color=color), - u = yes if d.recvd else no, + u = yes if d.is_used else no, a = d.addr.fmt(self.addr_view_pref, cw.addr, color=color), c = d.comment.fmt2(cw.comment, color=color, nullrepl='-'), A = d.amt.fmt(cw.iwidth, color=color, prec=self.disp_prec), @@ -195,7 +198,7 @@ class TwAddresses(TwView): return fs.format( n = str(n) + ')', m = d.twmmid.fmt(cw.mmid, color=color), - u = yes if d.recvd else no, + u = yes if d.is_used else no, a = d.addr.fmt(self.addr_view_pref, cw.addr, color=color), c = d.comment.fmt2(cw.comment, color=color, nullrepl='-'), A = d.amt.fmt(cw.iwidth, color=color, prec=self.disp_prec), @@ -280,7 +283,7 @@ class TwAddresses(TwView): def is_used(self, coinaddr): for e in self.data: if e.addr == coinaddr: - return bool(e.recvd) + return e.is_used return None # addr not in tracking wallet def get_change_address(self, al_id, *, bot=None, top=None, exclude=None, desc=None): @@ -325,7 +328,7 @@ class TwAddresses(TwView): for d in data[start:]: if d.al_id == al_id: if ( - not d.recvd + not d.is_used and not d.twmmid in exclude and (self.cfg.autochg_ignore_labels or not d.comment) ): diff --git a/mmgen/tw/prune.py b/mmgen/tw/prune.py index bd95e084..27f9d25f 100755 --- a/mmgen/tw/prune.py +++ b/mmgen/tw/prune.py @@ -51,7 +51,7 @@ class TwAddressesPrune(TwAddresses): pruned.append(n) if d.amt: rmsg(f'Warning: pruned address {d.twmmid.addr} has a balance!') - elif self.warn_used and d.recvd: + elif self.warn_used and d.is_used: ymsg(f'Warning: pruned address {d.twmmid.addr} is used!') else: yield d @@ -133,11 +133,11 @@ class TwAddressesPrune(TwAddresses): if auto[desc]: # we’ve switched to auto mode, so go back and fix up all previous entries for idx in addrnums[:n]: e = parent.disp_data[idx-1] - if skip_all_used and e.recvd: + if skip_all_used and e.is_used: e.tag = False elif desc == 'amt' and e.amt: e.tag = prune - elif desc == 'used' and (e.recvd and not e.amt): + elif desc == 'used' and (e.is_used and not e.amt): e.tag = prune # skipping all used addrs implies skipping all addrs with balances if skip_all_used: @@ -154,7 +154,7 @@ class TwAddressesPrune(TwAddresses): e = parent.disp_data[addrnum-1] if e.amt and not dfl['amt']: e.tag = do_entry('amt', n, addrnum, e) - elif parent.warn_used and (e.recvd and not e.amt) and not dfl['used']: + elif parent.warn_used and (e.is_used and not e.amt) and not dfl['used']: e.tag = do_entry('used', n, addrnum, e) else: e.tag = True