proto.eth.tw: support minconf
This commit is contained in:
parent
b8d1a12b99
commit
9ee01aa5e1
7 changed files with 25 additions and 12 deletions
|
|
@ -92,6 +92,14 @@ class EthereumRPCClient(RPCClient, metaclass=AsyncInit):
|
|||
def make_host_path(self, wallet):
|
||||
return ''
|
||||
|
||||
def get_block_from_minconf(self, minconf):
|
||||
assert minconf - 1 <= self.blockcount, (
|
||||
f'{minconf}: illegal value for ‘minconf’ (exceeds block count)')
|
||||
return (
|
||||
'pending' if minconf == 0 else
|
||||
'latest' if minconf == 1 else
|
||||
hex(self.blockcount - (minconf - 1)))
|
||||
|
||||
rpcmethods = (
|
||||
'eth_blockNumber',
|
||||
'eth_call',
|
||||
|
|
|
|||
|
|
@ -36,6 +36,7 @@ class EthereumTwGetBalance(TwGetBalance):
|
|||
|
||||
async def create_data(self):
|
||||
in_data = self.twctl.mmid_ordered_dict
|
||||
block = self.twctl.rpc.get_block_from_minconf(self.minconf)
|
||||
for d in in_data:
|
||||
if d.type == 'mmgen':
|
||||
label = d.obj.sid
|
||||
|
|
@ -44,7 +45,7 @@ class EthereumTwGetBalance(TwGetBalance):
|
|||
else:
|
||||
label = 'Non-MMGen'
|
||||
|
||||
amt = await self.twctl.get_balance(in_data[d]['addr'])
|
||||
amt = await self.twctl.get_balance(in_data[d]['addr'], block=block)
|
||||
|
||||
self.data['TOTAL']['ge_minconf'] += amt
|
||||
self.data[label]['ge_minconf'] += amt
|
||||
|
|
|
|||
|
|
@ -102,13 +102,15 @@ class EthereumTwUnspentOutputs(EthereumTwView, TwUnspentOutputs):
|
|||
|
||||
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']),
|
||||
'confirmations': 0, # TODO
|
||||
'amt': await self.twctl.get_balance(d['addr'], block=block),
|
||||
'confirmations': minconf,
|
||||
} for d in wl]
|
||||
|
||||
class EthereumTokenTwUnspentOutputs(EthereumTwUnspentOutputs):
|
||||
|
|
|
|||
|
|
@ -131,19 +131,20 @@ class TwAddresses(TwView):
|
|||
async def get_rpc_data(self):
|
||||
|
||||
self.total = self.proto.coin_amt('0')
|
||||
self.minconf = None
|
||||
addrs = {}
|
||||
|
||||
used_addrs = self.twctl.used_addrs
|
||||
minconf = int(self.minconf)
|
||||
block = self.twctl.rpc.get_block_from_minconf(minconf)
|
||||
|
||||
for e in await self.twctl.get_label_addr_pairs():
|
||||
bal = await self.twctl.get_balance(e.coinaddr)
|
||||
bal = await self.twctl.get_balance(e.coinaddr, block=block)
|
||||
addrs[e.label.mmid] = {
|
||||
'addr': e.coinaddr,
|
||||
'amt': bal,
|
||||
'recvd': bal, # current bal only, CF btc.tw.addresses.get_rpc_data()
|
||||
'is_used': bool(bal) or e.coinaddr in used_addrs,
|
||||
'confs': 0,
|
||||
'confs': minconf,
|
||||
'lbl': e.label}
|
||||
self.total += bal
|
||||
|
||||
|
|
|
|||
|
|
@ -72,7 +72,7 @@ class TwUnspentOutputs(TwView):
|
|||
|
||||
async def __init__(self, cfg, proto, *, minconf=1, addrs=[]):
|
||||
await super().__init__(cfg, proto)
|
||||
self.minconf = minconf
|
||||
self.minconf = NonNegativeInt(minconf)
|
||||
self.addrs = addrs
|
||||
from ..cfg import gc
|
||||
self.min_cols = gc.min_screen_width
|
||||
|
|
|
|||
|
|
@ -86,6 +86,7 @@ class TwView(MMGenObject, metaclass=AsyncInit):
|
|||
reverse = False
|
||||
group = False
|
||||
use_cached = False
|
||||
minconf = 1
|
||||
txid_w = 64
|
||||
sort_key = 'age'
|
||||
display_hdr = ()
|
||||
|
|
|
|||
|
|
@ -616,7 +616,7 @@ class CmdTestEthdev(CmdTestEthdevMethods, CmdTestBase, CmdTestShared):
|
|||
('token_bal6', 'the token balance'),
|
||||
|
||||
('listaddresses1', 'listaddresses'),
|
||||
('listaddresses2', 'listaddresses minconf=999999999 (ignored)'),
|
||||
('listaddresses2', 'listaddresses minconf=3'),
|
||||
('listaddresses3', 'listaddresses sort=age (ignored)'),
|
||||
('listaddresses4', 'listaddresses showempty=1 sort=age (ignored)'),
|
||||
|
||||
|
|
@ -663,8 +663,8 @@ class CmdTestEthdev(CmdTestEthdevMethods, CmdTestBase, CmdTestShared):
|
|||
('twview1', 'twview'),
|
||||
('twview2', 'twview wide=1'),
|
||||
('twview3', 'twview wide=1 sort=age (ignored)'),
|
||||
('twview4', 'twview wide=1 minconf=999999999 (ignored)'),
|
||||
('twview5', 'twview wide=1 minconf=0 (ignored)'),
|
||||
('twview4', 'twview wide=1 minconf=15'),
|
||||
('twview5', 'twview wide=1 minconf=0'),
|
||||
('token_twview1', 'twview --token=mm1'),
|
||||
('token_twview2', 'twview --token=mm1 wide=1'),
|
||||
('token_twview3', 'twview --token=mm1 wide=1 sort=age (ignored)'),
|
||||
|
|
@ -1527,7 +1527,7 @@ class CmdTestEthdev(CmdTestEthdevMethods, CmdTestBase, CmdTestShared):
|
|||
def listaddresses1(self):
|
||||
return self.listaddresses()
|
||||
def listaddresses2(self):
|
||||
return self.listaddresses(tool_args=['minconf=999999999'])
|
||||
return self.listaddresses(tool_args=['minconf=3'])
|
||||
def listaddresses3(self):
|
||||
return self.listaddresses(tool_args=['sort=amt', 'reverse=1'])
|
||||
def listaddresses4(self):
|
||||
|
|
@ -1619,7 +1619,7 @@ class CmdTestEthdev(CmdTestEthdevMethods, CmdTestBase, CmdTestShared):
|
|||
def twview3(self):
|
||||
return self.twview(tool_args=['wide=1', 'sort=age'])
|
||||
def twview4(self):
|
||||
return self.twview(tool_args=['wide=1', 'minconf=999999999'])
|
||||
return self.twview(tool_args=['wide=1', 'minconf=15'], expect_str=r'E:1\D.*\D100\D')
|
||||
def twview5(self):
|
||||
return self.twview(tool_args=['wide=1', 'minconf=0'])
|
||||
def twview6(self):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue