proto.eth.tw.unspent: move do_sort and get_rpc_data to parent cls

This commit is contained in:
The MMGen Project 2025-05-26 09:39:11 +00:00
commit 7d47cedd91
Signed by: mmgen
GPG key ID: 3F8B1861E32B7DA2
3 changed files with 16 additions and 20 deletions

View file

@ -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

View file

@ -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()

View file

@ -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)}')