Windows bugfixes, base32 routines in 'mmgen-tool'

This commit is contained in:
philemon 2014-08-26 00:27:02 +04:00
commit 1ce8a6c2fd
6 changed files with 44 additions and 24 deletions

View file

@ -33,15 +33,18 @@ def launch_walletchk(): import mmgen.main_walletchk
def launch_walletgen(): import mmgen.main_walletgen def launch_walletgen(): import mmgen.main_walletgen
def main(progname): def main(progname):
import sys, termios try: import termios
fd = sys.stdin.fileno() except: eval("launch_"+progname+"()") # Windows
old = termios.tcgetattr(fd) else:
try: eval("launch_"+progname+"()") import sys
except KeyboardInterrupt: fd = sys.stdin.fileno()
sys.stderr.write("\nUser interrupt\n") old = termios.tcgetattr(fd)
termios.tcsetattr(fd, termios.TCSADRAIN, old) try: eval("launch_"+progname+"()")
sys.exit(1) except KeyboardInterrupt:
except EOFError: sys.stderr.write("\nUser interrupt\n")
sys.stderr.write("\nEnd of file\n") termios.tcsetattr(fd, termios.TCSADRAIN, old)
termios.tcsetattr(fd, termios.TCSADRAIN, old) sys.exit(1)
sys.exit(1) except EOFError:
sys.stderr.write("\nEnd of file\n")
termios.tcsetattr(fd, termios.TCSADRAIN, old)
sys.exit(1)

View file

@ -57,7 +57,8 @@ if len(cmd_args) == 1:
pf(infile,addr_data) pf(infile,addr_data)
seed_id = addr_data.keys()[0] seed_id = addr_data.keys()[0]
e = addr_data[seed_id] 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: else:
msg_r("You must specify an mmgen address list (or a list of ") msg_r("You must specify an mmgen address list (or a list of ")
msg("non-%s addresses with\nthe '--addrlist' option)" % g.proj_name) msg("non-%s addresses with\nthe '--addrlist' option)" % g.proj_name)

View file

@ -66,9 +66,14 @@ class BitcoinConnection(object):
return self.proxy.importaddress(address,label,rescan) return self.proxy.importaddress(address,label,rescan)
except JSONRPCException as e: except JSONRPCException as e:
if e.error['message'] == "Method not found": if e.error['message'] == "Method not found":
from mmgen.util import msg_r from mmgen.util import msg
msg_r(""" msg("""
ERROR: 'importaddress' method not found. Is your bitcoind enabled for watch-only addresses?""") *******************************************************************************
*******************************************************************************
ERROR: 'importaddress' not found. Does your bitcoind support watch-only addrs?
*******************************************************************************
*******************************************************************************
""")
raise _wrap_exception(e.error) raise _wrap_exception(e.error)
# sendrawtransaction <hex string> [allowhighfees=false] # sendrawtransaction <hex string> [allowhighfees=false]
@ -471,6 +476,14 @@ ERROR: 'importaddress' method not found. Is your bitcoind enabled for watch-onl
else: else:
return self.proxy.listaccounts(minconf,includeWatchonly).keys() return self.proxy.listaccounts(minconf,includeWatchonly).keys()
except JSONRPCException as e: 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) raise _wrap_exception(e.error)
def listreceivedbyaccount(self, minconf=1, includeempty=False): def listreceivedbyaccount(self, minconf=1, includeempty=False):

View file

@ -423,7 +423,7 @@ def viewtx(infile,pager=False):
tx_data = get_lines_from_file(infile,"transaction data") tx_data = get_lines_from_file(infile,"transaction data")
metadata,tx_hex,inputs_data,b2m_map,comment = parse_tx_file(tx_data,infile) 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 addrfile_chksum(infile): parse_addrfile(infile,{})
def keyaddrfile_chksum(infile): parse_keyaddr_file(infile,{}) def keyaddrfile_chksum(infile): parse_keyaddr_file(infile,{})

View file

@ -133,7 +133,7 @@ Only ASCII printable characters are permitted.
sys.exit(3) 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) 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) if pager: do_pager(o)
else: else:
print "\n"+o print "\n"+o
get_char("Press any key to continue: ") if pause:
msg("") get_char("Press any key to continue: ")
msg("")
def parse_tx_file(tx_data,infile): def parse_tx_file(tx_data,infile):

View file

@ -165,7 +165,7 @@ def open_file_or_exit(filename,mode):
try: try:
f = open(filename, mode) f = open(filename, mode)
except: 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)) msg("Unable to open file '%s' for %s" % (filename,what))
sys.exit(2) sys.exit(2)
return f return f
@ -329,7 +329,7 @@ def write_to_file(outfile,data,opts,what="data",confirm_overwrite=False,verbose=
else: else:
msg("Overwriting file '%s'" % outfile) msg("Overwriting file '%s'" % outfile)
f = open_file_or_exit(outfile,'w') f = open_file_or_exit(outfile,'wb')
try: try:
f.write(data) f.write(data)
except: 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): def get_data_from_file(infile,what="data",dash=False):
if dash and infile == "-": return sys.stdin.read() if dash and infile == "-": return sys.stdin.read()
qmsg("Getting %s from file '%s'" % (what,infile)) 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() data = f.read()
f.close() f.close()
return data 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): 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(): if use_readline and sys.stdout.isatty():
import readline
def st_hook(): readline.insert_text(insert_txt) def st_hook(): readline.insert_text(insert_txt)
readline.set_startup_hook(st_hook) readline.set_startup_hook(st_hook)
else: else: