tx.process_cmd_arg(), tx.add_comment(): cleanups

This commit is contained in:
The MMGen Project 2022-11-16 17:56:04 +00:00
commit 4b07f8fac8
Signed by: mmgen
GPG key ID: 3F8B1861E32B7DA2
2 changed files with 29 additions and 24 deletions

View file

@ -155,23 +155,24 @@ class Base(MMGenObject):
def add_blockcount(self):
self.blockcount = self.rpc.blockcount
# returns true if comment added or changed
# returns True if comment added or changed, False otherwise
def add_comment(self,infile=None):
if infile:
from ..fileutil import get_data_from_file
self.comment = MMGenTxComment(get_data_from_file(infile,'transaction comment'))
else: # get comment from user, or edit existing comment
m = ('Add a comment to transaction?','Edit transaction comment?')[bool(self.comment)]
else:
from ..ui import keypress_confirm,line_input
if keypress_confirm(m,default_yes=False):
while True:
s = MMGenTxComment(line_input('Comment: ',insert_txt=self.comment))
if not s:
ymsg('Warning: comment is empty')
save = self.comment
self.comment = s
return (True,False)[save == self.comment]
return False
if keypress_confirm(
prompt = 'Edit transaction comment?' if self.comment else 'Add a comment to transaction?',
default_yes = False ):
res = MMGenTxComment(line_input('Comment: ',insert_txt=self.comment))
if not res:
ymsg('Warning: comment is empty')
changed = res != self.comment
self.comment = res
return changed
else:
return False
def get_non_mmaddrs(self,desc):
return remove_dups(

View file

@ -169,21 +169,25 @@ class New(Base):
def process_cmd_arg(self,arg,ad_f,ad_w):
def add_output_chk(addr,amt,err_desc):
if not amt and self.get_chg_output_idx() != None:
die(2,'ERROR: More than one change address listed on command line')
if is_mmgen_id(self.proto,addr) or is_coin_addr(self.proto,addr):
coin_addr = ( mmaddr2coinaddr(addr,ad_w,ad_f,self.proto) if is_mmgen_id(self.proto,addr)
else CoinAddr(self.proto,addr) )
self.add_output(coin_addr,self.proto.coin_amt(amt or '0'),is_chg=not amt)
else:
die(2,f'{addr}: invalid {err_desc} {{!r}}'.format(f'{addr},{amt}' if amt else addr))
if ',' in arg:
addr,amt = arg.split(',',1)
add_output_chk(addr,amt,'coin argument in command-line argument')
err_desc = 'coin argument in command-line argument'
else:
add_output_chk(arg,None,'command-line argument')
addr,amt = (arg,None)
err_desc = 'command-line argument'
if is_mmgen_id(self.proto,addr):
coin_addr = mmaddr2coinaddr(addr,ad_w,ad_f,self.proto)
elif is_coin_addr(self.proto,addr):
coin_addr = CoinAddr(self.proto,addr)
else:
die(2,f'{addr}: invalid {err_desc} {{!r}}'.format(f'{addr},{amt}' if amt else addr))
if not amt and self.get_chg_output_idx() is not None:
die(2,'ERROR: More than one change address {} on command line'.format(
'requested' if self.chg_autoselected else 'listed'))
self.add_output(coin_addr,self.proto.coin_amt(amt or '0'),is_chg=not amt)
def process_cmd_args(self,cmd_args,ad_f,ad_w):