TwAddresses.get_change_address(): support full-list matching
This commit is contained in:
parent
527fedd7d5
commit
3d8fbca67e
3 changed files with 30 additions and 34 deletions
|
|
@ -35,6 +35,7 @@ class TwAddresses(TwView):
|
|||
showused = 1 # tristate: 0: no, 1: yes, 2: only
|
||||
all_labels = False
|
||||
autochg_ignore_labels = False # if set, this overrides the global cfg var of the same name
|
||||
autochg_match_full_list = False
|
||||
mod_subpath = 'tw.addresses'
|
||||
|
||||
prompt_fs_in = [
|
||||
|
|
@ -354,29 +355,33 @@ class TwAddresses(TwView):
|
|||
desc = None):
|
||||
|
||||
"""
|
||||
Get lowest-indexed unused address in tracking wallet for requested AddrListID.
|
||||
Get lowest-indexed unused address in tracking wallet matching requested key, if key is
|
||||
given, else entire tracking wallet.
|
||||
|
||||
Return values on failure:
|
||||
None: no addresses in wallet with requested AddrListID
|
||||
False: no unused addresses in wallet with requested AddrListID
|
||||
None: no addresses in wallet matching requested key
|
||||
False: no unused addresses in wallet matching requested key, if key is given, else
|
||||
no unused addresses in entire wallet
|
||||
"""
|
||||
|
||||
assert self.sort_key == 'twmmid'
|
||||
assert self.reverse is False
|
||||
|
||||
from ..algo import get_start
|
||||
target = self.get_target(key)
|
||||
start = get_start(
|
||||
data = self.data,
|
||||
bot = 0 if bot is None else bot,
|
||||
top = len(self.data) - 1 if top is None else top,
|
||||
target = target,
|
||||
bisect_key_func = self.get_bisect_key,
|
||||
match_key_func = self.get_match_key)
|
||||
if start is None:
|
||||
return None
|
||||
if key:
|
||||
from ..algo import get_start
|
||||
target = self.get_target(key)
|
||||
start = get_start(
|
||||
data = self.data,
|
||||
bot = 0 if bot is None else bot,
|
||||
top = len(self.data) - 1 if top is None else top,
|
||||
target = target,
|
||||
bisect_key_func = self.get_bisect_key,
|
||||
match_key_func = self.get_match_key)
|
||||
if start is None:
|
||||
return None
|
||||
|
||||
for d in self.data[start:]:
|
||||
if self.get_match_key(d) == target:
|
||||
for d in (self.data[start:] if key else self.data):
|
||||
if (not key) or self.get_match_key(d) == target:
|
||||
if (
|
||||
not d.is_used
|
||||
and not d.twmmid in exclude
|
||||
|
|
|
|||
|
|
@ -206,19 +206,15 @@ class New(Base):
|
|||
|
||||
return self._cl_output(arg, mmid or None, coin_addr, amt, None, is_vault)
|
||||
|
||||
async def get_autochg_addr(
|
||||
self,
|
||||
proto,
|
||||
arg,
|
||||
*,
|
||||
exclude,
|
||||
desc,
|
||||
match_all_addrtypes = False):
|
||||
async def get_autochg_addr(self, proto, arg, *, exclude, desc):
|
||||
|
||||
from ..tw.addresses import TwAddresses
|
||||
al = await TwAddresses(self.cfg, proto, get_data=True)
|
||||
|
||||
if match_all_addrtypes:
|
||||
if arg is None and al.autochg_match_full_list:
|
||||
res = al.get_change_address(None, exclude=exclude, desc=desc)
|
||||
req_desc = None
|
||||
elif arg is None:
|
||||
res = al.get_change_address_by_addrtype(None, exclude=exclude, desc=desc)
|
||||
req_desc = 'of any allowed address type'
|
||||
elif obj := get_obj(MMGenAddrType, proto=proto, id_str=arg, silent=True):
|
||||
|
|
@ -231,9 +227,9 @@ class New(Base):
|
|||
if res:
|
||||
return res
|
||||
|
||||
die(2, 'Tracking wallet contains no {t}addresses {d}'.format(
|
||||
die(2, 'Tracking wallet contains no {t}addresses{d}'.format(
|
||||
t = '' if res is None else 'unused ',
|
||||
d = req_desc))
|
||||
d = ' ' + req_desc if req_desc else ''))
|
||||
|
||||
async def process_cmdline_args(self, cmd_args, ad_f, ad_w):
|
||||
|
||||
|
|
|
|||
|
|
@ -53,12 +53,7 @@ class NewSwap(New):
|
|||
return ret(proto.coin, proto.network, pa.addr, pa.mmid)
|
||||
|
||||
full_desc = f'{desc} address on the {proto.coin} {proto.network} network'
|
||||
res = await self.get_autochg_addr(
|
||||
proto,
|
||||
arg,
|
||||
exclude = [],
|
||||
desc = full_desc,
|
||||
match_all_addrtypes = not arg)
|
||||
res = await self.get_autochg_addr(proto, arg, exclude=[], desc=full_desc)
|
||||
self.confirm_autoselected_addr(res.twmmid, res.comment, full_desc)
|
||||
return ret(proto.coin, proto.network, res.addr, res.twmmid)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue