Browse Source

TwCtl.set_comment(): return the comment

The MMGen Project 1 week ago
parent
commit
bfddd5b8ae
3 changed files with 12 additions and 13 deletions
  1. 4 3
      mmgen/tool/rpc.py
  2. 1 5
      mmgen/tw/ctl.py
  3. 7 5
      mmgen/tw/view.py

+ 4 - 3
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"

+ 1 - 5
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:

+ 7 - 5
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(