Browse Source

Windows bugfixes, base32 routines in 'mmgen-tool'

philemon 10 years ago
parent
commit
1ce8a6c2fd
6 changed files with 44 additions and 24 deletions
  1. 15 12
      mmgen/main.py
  2. 2 1
      mmgen/main_addrimport.py
  3. 16 3
      mmgen/rpc/connection.py
  4. 1 1
      mmgen/tool.py
  5. 4 3
      mmgen/tx.py
  6. 6 4
      mmgen/util.py

+ 15 - 12
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)

+ 2 - 1
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)

+ 16 - 3
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 <hex string> [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):

+ 1 - 1
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,{})

+ 4 - 3
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):

+ 6 - 4
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: