From 7d47cedd91b14399680d5e650cd7f143e3c02875 Mon Sep 17 00:00:00 2001 From: The MMGen Project Date: Mon, 26 May 2025 09:39:11 +0000 Subject: [PATCH] proto.eth.tw.unspent: move `do_sort` and `get_rpc_data` to parent cls --- mmgen/proto/eth/tw/unspent.py | 19 ------------------- mmgen/tw/unspent.py | 15 ++++++++++++++- mmgen/tw/view.py | 2 ++ 3 files changed, 16 insertions(+), 20 deletions(-) diff --git a/mmgen/proto/eth/tw/unspent.py b/mmgen/proto/eth/tw/unspent.py index 88a1d64f..fa4d97da 100755 --- a/mmgen/proto/eth/tw/unspent.py +++ b/mmgen/proto/eth/tw/unspent.py @@ -20,7 +20,6 @@ proto.eth.tw.unspent: Ethereum tracking wallet unspent outputs class """ -from ....tw.shared import TwLabel from ....tw.unspent import TwUnspentOutputs from .view import EthereumTwView @@ -31,24 +30,6 @@ class EthereumTwUnspentOutputs(EthereumTwView, TwUnspentOutputs): item_desc = 'account' item_desc_pl = 'accounts' - def do_sort(self, key=None, *, reverse=False): - if key == 'txid': - return - super().do_sort(key=key, reverse=reverse) - - async def get_rpc_data(self): - wl = self.twctl.sorted_list - minconf = int(self.minconf) - block = self.twctl.rpc.get_block_from_minconf(minconf) - if self.addrs: - wl = [d for d in wl if d['addr'] in self.addrs] - return [{ - 'account': TwLabel(self.proto, d['mmid']+' '+d['comment']), - 'address': d['addr'], - 'amt': await self.twctl.get_balance(d['addr'], block=block), - 'confirmations': minconf, - } for d in wl] - class EthereumTokenTwUnspentOutputs(EthereumTwUnspentOutputs): has_amt2 = True diff --git a/mmgen/tw/unspent.py b/mmgen/tw/unspent.py index d1baf760..7dd19960 100755 --- a/mmgen/tw/unspent.py +++ b/mmgen/tw/unspent.py @@ -30,7 +30,7 @@ from ..obj import ( NonNegativeInt) from ..addr import CoinAddr from ..amt import CoinAmtChk -from .shared import TwMMGenID, get_tw_label +from .shared import TwMMGenID, TwLabel, get_tw_label from .view import TwView class TwUnspentOutputs(TwView): @@ -126,6 +126,19 @@ class TwUnspentOutputs(TwView): self.proto, **{k:v for k, v in o.items() if k in self.MMGenTwUnspentOutput.valid_attrs}) + async def get_rpc_data(self): + wl = self.twctl.sorted_list + minconf = int(self.minconf) + block = self.twctl.rpc.get_block_from_minconf(minconf) + if self.addrs: + wl = [d for d in wl if d['addr'] in self.addrs] + return [{ + 'account': TwLabel(self.proto, d['mmid']+' '+d['comment']), + 'address': d['addr'], + 'amt': await self.twctl.get_balance(d['addr'], block=block), + 'confirmations': minconf, + } for d in wl] + def filter_data(self): data = self.data.copy() diff --git a/mmgen/tw/view.py b/mmgen/tw/view.py index 69dccf97..b2bebb7c 100755 --- a/mmgen/tw/view.py +++ b/mmgen/tw/view.py @@ -266,6 +266,8 @@ class TwView(MMGenObject, metaclass=AsyncInit): return ret def do_sort(self, key=None, *, reverse=False): + if key == 'txid' and not self.txid_w: + return key = key or self.sort_key if key not in self.sort_funcs: die(1, f'{key!r}: invalid sort key. Valid options: {" ".join(self.sort_funcs)}')