From bfddd5b8ae59b710aa40aa6c6431d6a367310d84 Mon Sep 17 00:00:00 2001 From: The MMGen Project Date: Sat, 22 Nov 2025 09:04:09 +0000 Subject: [PATCH] TwCtl.set_comment(): return the comment --- mmgen/tool/rpc.py | 7 ++++--- mmgen/tw/ctl.py | 6 +----- mmgen/tw/view.py | 12 +++++++----- 3 files changed, 12 insertions(+), 13 deletions(-) diff --git a/mmgen/tool/rpc.py b/mmgen/tool/rpc.py index 0ae1ab65..a2fdf80e 100755 --- a/mmgen/tool/rpc.py +++ b/mmgen/tool/rpc.py @@ -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" diff --git a/mmgen/tw/ctl.py b/mmgen/tw/ctl.py index 89c8ad07..15df1d18 100755 --- a/mmgen/tw/ctl.py +++ b/mmgen/tw/ctl.py @@ -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: diff --git a/mmgen/tw/view.py b/mmgen/tw/view.py index a38cbc7a..35f3d8f2 100755 --- a/mmgen/tw/view.py +++ b/mmgen/tw/view.py @@ -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(