diff --git a/mmgen/main.py b/mmgen/main.py index 27e67399..4545e4c0 100755 --- a/mmgen/main.py +++ b/mmgen/main.py @@ -33,15 +33,18 @@ def launch_walletchk(): import mmgen.main_walletchk def launch_walletgen(): import mmgen.main_walletgen def main(progname): - import sys, termios - fd = sys.stdin.fileno() - old = termios.tcgetattr(fd) - try: eval("launch_"+progname+"()") - except KeyboardInterrupt: - sys.stderr.write("\nUser interrupt\n") - termios.tcsetattr(fd, termios.TCSADRAIN, old) - sys.exit(1) - except EOFError: - sys.stderr.write("\nEnd of file\n") - termios.tcsetattr(fd, termios.TCSADRAIN, old) - sys.exit(1) + try: import termios + except: eval("launch_"+progname+"()") # Windows + else: + import sys + fd = sys.stdin.fileno() + old = termios.tcgetattr(fd) + try: eval("launch_"+progname+"()") + except KeyboardInterrupt: + sys.stderr.write("\nUser interrupt\n") + termios.tcsetattr(fd, termios.TCSADRAIN, old) + sys.exit(1) + except EOFError: + sys.stderr.write("\nEnd of file\n") + termios.tcsetattr(fd, termios.TCSADRAIN, old) + sys.exit(1) diff --git a/mmgen/main_addrimport.py b/mmgen/main_addrimport.py index 2fe91bfd..955c926e 100755 --- a/mmgen/main_addrimport.py +++ b/mmgen/main_addrimport.py @@ -57,7 +57,8 @@ if len(cmd_args) == 1: pf(infile,addr_data) seed_id = addr_data.keys()[0] e = addr_data[seed_id] - addr_list = [(k,e[k][0],e[k][1]) for k in e.keys()] + def s_addrdata(a): return ("{:>0%s}"%g.mmgen_idx_max_digits).format(a) + addr_list = [(k,e[k][0],e[k][1]) for k in sorted(e.keys(),key=s_addrdata)] else: msg_r("You must specify an mmgen address list (or a list of ") msg("non-%s addresses with\nthe '--addrlist' option)" % g.proj_name) diff --git a/mmgen/rpc/connection.py b/mmgen/rpc/connection.py index 7c859853..27cc7e3e 100755 --- a/mmgen/rpc/connection.py +++ b/mmgen/rpc/connection.py @@ -66,9 +66,14 @@ class BitcoinConnection(object): return self.proxy.importaddress(address,label,rescan) except JSONRPCException as e: if e.error['message'] == "Method not found": - from mmgen.util import msg_r - msg_r(""" -ERROR: 'importaddress' method not found. Is your bitcoind enabled for watch-only addresses?""") + from mmgen.util import msg + msg(""" +******************************************************************************* +******************************************************************************* +ERROR: 'importaddress' not found. Does your bitcoind support watch-only addrs? +******************************************************************************* +******************************************************************************* +""") raise _wrap_exception(e.error) # sendrawtransaction [allowhighfees=false] @@ -471,6 +476,14 @@ ERROR: 'importaddress' method not found. Is your bitcoind enabled for watch-onl else: return self.proxy.listaccounts(minconf,includeWatchonly).keys() except JSONRPCException as e: + from mmgen.util import msg + msg(""" +******************************************************************************* +******************************************************************************* +ERROR: 'listaccounts' failed. Does your bitcoind support watch-only addresses? +******************************************************************************* +******************************************************************************* +""") raise _wrap_exception(e.error) def listreceivedbyaccount(self, minconf=1, includeempty=False): diff --git a/mmgen/tool.py b/mmgen/tool.py index 99a340b8..879d97a5 100755 --- a/mmgen/tool.py +++ b/mmgen/tool.py @@ -423,7 +423,7 @@ def viewtx(infile,pager=False): tx_data = get_lines_from_file(infile,"transaction data") metadata,tx_hex,inputs_data,b2m_map,comment = parse_tx_file(tx_data,infile) - view_tx_data(c,inputs_data,tx_hex,b2m_map,comment,metadata,pager) + view_tx_data(c,inputs_data,tx_hex,b2m_map,comment,metadata,pager,pause=False) def addrfile_chksum(infile): parse_addrfile(infile,{}) def keyaddrfile_chksum(infile): parse_keyaddr_file(infile,{}) diff --git a/mmgen/tx.py b/mmgen/tx.py index d98531b0..48f0c5f0 100755 --- a/mmgen/tx.py +++ b/mmgen/tx.py @@ -133,7 +133,7 @@ Only ASCII printable characters are permitted. sys.exit(3) -def view_tx_data(c,inputs_data,tx_hex,b2m_map,comment,metadata,pager=False): +def view_tx_data(c,inputs_data,tx_hex,b2m_map,comment,metadata,pager=False,pause=True): td = c.decoderawtransaction(tx_hex) @@ -187,8 +187,9 @@ def view_tx_data(c,inputs_data,tx_hex,b2m_map,comment,metadata,pager=False): if pager: do_pager(o) else: print "\n"+o - get_char("Press any key to continue: ") - msg("") + if pause: + get_char("Press any key to continue: ") + msg("") def parse_tx_file(tx_data,infile): diff --git a/mmgen/util.py b/mmgen/util.py index 11be5e28..c69d04ce 100755 --- a/mmgen/util.py +++ b/mmgen/util.py @@ -165,7 +165,7 @@ def open_file_or_exit(filename,mode): try: f = open(filename, mode) except: - what = "reading" if mode == 'r' else "writing" + what = "reading" if 'r' in mode else "writing" msg("Unable to open file '%s' for %s" % (filename,what)) sys.exit(2) return f @@ -329,7 +329,7 @@ def write_to_file(outfile,data,opts,what="data",confirm_overwrite=False,verbose= else: msg("Overwriting file '%s'" % outfile) - f = open_file_or_exit(outfile,'w') + f = open_file_or_exit(outfile,'wb') try: f.write(data) except: @@ -546,7 +546,7 @@ def get_lines_from_file(infile,what="",trim_comments=False): def get_data_from_file(infile,what="data",dash=False): if dash and infile == "-": return sys.stdin.read() qmsg("Getting %s from file '%s'" % (what,infile)) - f = open_file_or_exit(infile,'r') + f = open_file_or_exit(infile,'rb') data = f.read() f.close() return data @@ -641,8 +641,10 @@ def get_hash_preset_from_user(hp='3',what="data"): def my_raw_input(prompt,echo=True,insert_txt="",use_readline=True): + try: import readline + except: use_readline = False # Windows + if use_readline and sys.stdout.isatty(): - import readline def st_hook(): readline.insert_text(insert_txt) readline.set_startup_hook(st_hook) else: