TwCtl.set_comment(): return the comment

This commit is contained in:
The MMGen Project 2025-11-22 09:04:09 +00:00
commit bfddd5b8ae
Signed by: mmgen
GPG key ID: 3F8B1861E32B7DA2
3 changed files with 12 additions and 13 deletions

View file

@ -157,13 +157,14 @@ class tool_cmd(tool_cmd_base):
async def add_label(self, mmgen_or_coin_addr: str, label: str):
"add descriptive label for address in tracking wallet"
from ..obj import TwComment
from ..tw.ctl import TwCtl
return await (await TwCtl(self.cfg, self.proto, mode='w')).set_comment(mmgen_or_coin_addr, label)
ret = await (await TwCtl(self.cfg, self.proto, mode='w')).set_comment(mmgen_or_coin_addr, label)
return True if isinstance(ret, TwComment) else False
async def remove_label(self, mmgen_or_coin_addr: str):
"remove descriptive label for address in tracking wallet"
await self.add_label(mmgen_or_coin_addr, '')
return True
return await self.add_label(mmgen_or_coin_addr, '')
async def remove_address(self, mmgen_or_coin_addr: str):
"remove an address from tracking wallet"

View file

@ -141,16 +141,12 @@ class TwCtl(MMGenObject, metaclass=AsyncInit):
msg(
'Added label {} to {}'.format(comment.hl2(encl='‘’'), desc) if comment else
'Removed label from {}'.format(desc))
return True
return comment
else:
if not silent:
msg('Label could not be {}'.format('added' if comment else 'removed'))
return False
@write_mode
async def remove_comment(self, mmaddr):
await self.set_comment(mmaddr, '')
def check_import_mmid(self, addr, old_mmid, new_mmid):
'returns True if mmid needs update, None otherwise'
if new_mmid != old_mmid:

View file

@ -762,13 +762,15 @@ class TwView(MMGenObject, metaclass=AsyncInit):
async def i_comment_add(self, parent, idx):
async def do_comment_add(comment):
if await parent.twctl.set_comment(
async def do_comment_add(comment_in):
from ..obj import TwComment
comment = await parent.twctl.set_comment(
addrspec = None,
comment = comment,
comment = comment_in,
trusted_pair = (entry.twmmid, entry.addr),
silent = parent.scroll):
silent = parent.scroll)
if isinstance(comment, TwComment):
entry.comment = comment
edited = cur_comment and comment
parent.oneshot_msg = (green if comment else yellow)('Label {a} {b}{c}'.format(