Browse Source

mmgen-txcreate interface improvements
utils.py -> util.py rename

philemon 11 years ago
parent
commit
1c9b0f8816

+ 1 - 1
mmgen-addrgen

@@ -27,7 +27,7 @@ import sys
 from mmgen.Opts   import *
 from mmgen.Opts   import *
 import mmgen.config as g
 import mmgen.config as g
 from mmgen.license import *
 from mmgen.license import *
-from mmgen.utils  import *
+from mmgen.util  import *
 from mmgen.addr   import *
 from mmgen.addr   import *
 
 
 invoked_as = sys.argv[0].split("-")[-1]
 invoked_as = sys.argv[0].split("-")[-1]

+ 1 - 1
mmgen-addrimport

@@ -23,7 +23,7 @@ mmgen-addrimport: Import addresses into a bitcoind watching wallet.
 import sys
 import sys
 from mmgen.Opts   import *
 from mmgen.Opts   import *
 from mmgen.license import *
 from mmgen.license import *
-from mmgen.utils import check_infile,confirm_or_exit,msg,msg_r,secs_to_hms,get_lines_from_file
+from mmgen.util import check_infile,confirm_or_exit,msg,msg_r,secs_to_hms,get_lines_from_file
 from mmgen.tx import connect_to_bitcoind,parse_addrs_file
 from mmgen.tx import connect_to_bitcoind,parse_addrs_file
 from mmgen.bitcoin import verify_addr
 from mmgen.bitcoin import verify_addr
 
 

+ 1 - 1
mmgen-passchg

@@ -22,7 +22,7 @@ mmgen-passchg: Change a mmgen deterministic wallet's passphrase, label or
 
 
 import sys
 import sys
 from mmgen.Opts import *
 from mmgen.Opts import *
-from mmgen.utils import *
+from mmgen.util import *
 import mmgen.config as g
 import mmgen.config as g
 
 
 help_data = {
 help_data = {

+ 5 - 5
mmgen-pywallet

@@ -44,7 +44,7 @@ mmgen-pywallet: Dump contents of a bitcoind wallet to file
 # Ported from C code written by Laurent Haan (http://www.progressive-coding.com)
 # Ported from C code written by Laurent Haan (http://www.progressive-coding.com)
 
 
 from mmgen.Opts import *
 from mmgen.Opts import *
-from mmgen.utils import msg
+from mmgen.util import msg
 from bsddb.db import *
 from bsddb.db import *
 import sys, time
 import sys, time
 import json
 import json
@@ -92,7 +92,7 @@ long_opts  = "help","outdir=","echo_passphrase","json","keys","addrs",\
 
 
 opts,cmd_args = process_opts(sys.argv,help_data,short_opts,long_opts)
 opts,cmd_args = process_opts(sys.argv,help_data,short_opts,long_opts)
 
 
-from mmgen.utils import check_infile
+from mmgen.util import check_infile
 
 
 check_opts(opts,long_opts)
 check_opts(opts,long_opts)
 
 
@@ -1575,7 +1575,7 @@ def read_wallet(json_db, db_env, db_file, print_wallet, print_wallet_transaction
 
 
 			if password == None and \
 			if password == None and \
 				('json' in opts or 'keysforaddrs' in opts or 'keys' in opts):
 				('json' in opts or 'keysforaddrs' in opts or 'keys' in opts):
-				from mmgen.utils import get_bitcoind_passphrase
+				from mmgen.util import get_bitcoind_passphrase
 				password = get_bitcoind_passphrase("Enter password: ",opts)
 				password = get_bitcoind_passphrase("Enter password: ",opts)
 
 
 			if password != None:
 			if password != None:
@@ -1682,7 +1682,7 @@ elif 'addrs' in opts:
 	ext,what = "addrs","addresses"
 	ext,what = "addrs","addresses"
 
 
 elif 'keysforaddrs' in opts:
 elif 'keysforaddrs' in opts:
-	from mmgen.utils import get_lines_from_file
+	from mmgen.util import get_lines_from_file
 	usr_addrs = get_lines_from_file(opts['keysforaddrs'],"addresses")
 	usr_addrs = get_lines_from_file(opts['keysforaddrs'],"addresses")
 	for addr in usr_addrs:
 	for addr in usr_addrs:
 		try:
 		try:
@@ -1696,7 +1696,7 @@ len_arg = "%s" % len(wallet_addrs) \
    if len(data) == len(wallet_addrs) or ext == "json" \
    if len(data) == len(wallet_addrs) or ext == "json" \
    else "%s:%s" % (len(data),len(wallet_addrs))
    else "%s:%s" % (len(data),len(wallet_addrs))
 
 
-from mmgen.utils import make_chksum_8,write_walletdat_dump_to_file,write_to_stdout
+from mmgen.util import make_chksum_8,write_walletdat_dump_to_file,write_to_stdout
 wallet_id = make_chksum_8(str(sorted(wallet_addrs)))
 wallet_id = make_chksum_8(str(sorted(wallet_addrs)))
 
 
 data = "\n".join(data) + "\n"
 data = "\n".join(data) + "\n"

+ 1 - 1
mmgen-txcreate

@@ -26,7 +26,7 @@ from mmgen.Opts import *
 from mmgen.license import *
 from mmgen.license import *
 import mmgen.config as g
 import mmgen.config as g
 from mmgen.tx import *
 from mmgen.tx import *
-from mmgen.utils import msg, msg_r, user_confirm
+from mmgen.util import msg, msg_r, user_confirm
 from decimal import Decimal
 from decimal import Decimal
 
 
 prog_name = sys.argv[0].split("/")[-1]
 prog_name = sys.argv[0].split("/")[-1]

+ 1 - 1
mmgen-txsend

@@ -25,7 +25,7 @@ from mmgen.Opts import *
 from mmgen.license import *
 from mmgen.license import *
 import mmgen.config as g
 import mmgen.config as g
 from mmgen.tx import *
 from mmgen.tx import *
-from mmgen.utils import msg,check_infile,get_lines_from_file,confirm_or_exit
+from mmgen.util import msg,check_infile,get_lines_from_file,confirm_or_exit
 
 
 prog_name = sys.argv[0].split("/")[-1]
 prog_name = sys.argv[0].split("/")[-1]
 
 

+ 1 - 1
mmgen-txsign

@@ -25,7 +25,7 @@ from mmgen.Opts import *
 from mmgen.license import *
 from mmgen.license import *
 import mmgen.config as g
 import mmgen.config as g
 from mmgen.tx import *
 from mmgen.tx import *
-from mmgen.utils import msg
+from mmgen.util import msg
 
 
 help_data = {
 help_data = {
 	'prog_name': sys.argv[0].split("/")[-1],
 	'prog_name': sys.argv[0].split("/")[-1],

+ 1 - 1
mmgen-walletchk

@@ -23,7 +23,7 @@ mmgen-walletchk: Check integrity of a mmgen deterministic wallet, display
 import sys
 import sys
 from mmgen.Opts import *
 from mmgen.Opts import *
 
 
-from mmgen.utils import *
+from mmgen.util import *
 
 
 help_data = {
 help_data = {
 	'prog_name': sys.argv[0].split("/")[-1],
 	'prog_name': sys.argv[0].split("/")[-1],

+ 1 - 1
mmgen-walletgen

@@ -26,7 +26,7 @@ from mmgen.Opts import *
 from mmgen.license import *
 from mmgen.license import *
 import mmgen.config as g
 import mmgen.config as g
 from mmgen.walletgen import *
 from mmgen.walletgen import *
-from mmgen.utils import *
+from mmgen.util import *
 prog_name = sys.argv[0].split("/")[-1]
 prog_name = sys.argv[0].split("/")[-1]
 
 
 help_data = {
 help_data = {

+ 1 - 1
mmgen/Opts.py

@@ -18,7 +18,7 @@
 
 
 import sys, getopt
 import sys, getopt
 import mmgen.config as g
 import mmgen.config as g
-from mmgen.utils import msg
+from mmgen.util import msg
 
 
 def usage(hd):
 def usage(hd):
 	print "USAGE: %s %s" % (hd['prog_name'], hd['usage'])
 	print "USAGE: %s %s" % (hd['prog_name'], hd['usage'])

+ 1 - 1
mmgen/__init__.py

@@ -29,7 +29,7 @@ __all__ = [
 	'mn_tirosh.py',
 	'mn_tirosh.py',
 	'Opts.py',
 	'Opts.py',
 	'tx.py',
 	'tx.py',
-	'utils.py',
+	'util.py',
 	'walletgen.py'
 	'walletgen.py'
 ]
 ]
 
 

+ 1 - 1
mmgen/addr.py

@@ -210,7 +210,7 @@ def write_addr_data_to_file(seed, data, addr_list, opts):
 	else:                              ext = "akeys"
 	else:                              ext = "akeys"
 
 
 	if 'b16' in opts: ext = ext.replace("keys","xkeys")
 	if 'b16' in opts: ext = ext.replace("keys","xkeys")
-	from mmgen.utils import write_to_file, make_chksum_8, msg
+	from mmgen.util import write_to_file, make_chksum_8, msg
 	outfile = "{}[{}].{}".format(
 	outfile = "{}[{}].{}".format(
 			make_chksum_8(seed),
 			make_chksum_8(seed),
 			fmt_addr_list(addr_list),
 			fmt_addr_list(addr_list),

+ 2 - 2
mmgen/license.py

@@ -20,7 +20,7 @@ license.py:  Show the license
 """
 """
 
 
 import sys
 import sys
-from mmgen.utils import msg, msg_r, get_char
+from mmgen.util import msg, msg_r, get_char
 
 
 gpl = {
 gpl = {
 	'warning': """
 	'warning': """
@@ -591,7 +591,7 @@ def do_license_msg(immed=False):
 	while True:
 	while True:
 		reply = get_char(prompt, immed_chars="wc" if immed else "")
 		reply = get_char(prompt, immed_chars="wc" if immed else "")
 		if reply == 'w':
 		if reply == 'w':
-			from mmgen.utils import do_pager
+			from mmgen.util import do_pager
 			do_pager(gpl['conditions'])
 			do_pager(gpl['conditions'])
 		elif reply == 'c':
 		elif reply == 'c':
 			msg(""); break
 			msg(""); break

+ 1 - 1
mmgen/mnemonic.py

@@ -31,7 +31,7 @@ def mn_len(hexnum): return len(hexnum) * 3 / 8
 
 
 import sys
 import sys
 
 
-from mmgen.utils import msg,make_chksum_8
+from mmgen.util import msg,make_chksum_8
 import mmgen.config as g
 import mmgen.config as g
 
 
 # These universal base-conversion routines work for any base
 # These universal base-conversion routines work for any base

+ 1 - 1
mmgen/rpc/connection.py

@@ -66,7 +66,7 @@ class BitcoinConnection(object):
 			return self.proxy.importaddress(address,label)
 			return self.proxy.importaddress(address,label)
 		except JSONRPCException as e:
 		except JSONRPCException as e:
 			if e.error['message'] == "Method not found":
 			if e.error['message'] == "Method not found":
-				from mmgen.utils import msg_r
+				from mmgen.util import msg_r
 				msg_r("""
 				msg_r("""
 ERROR: 'importaddress' method not found.  Is your bitcoind enabled for watch-only addresses?""")
 ERROR: 'importaddress' method not found.  Is your bitcoind enabled for watch-only addresses?""")
 			raise _wrap_exception(e.error)
 			raise _wrap_exception(e.error)

+ 1 - 1
mmgen/rpc/proxy.py

@@ -104,7 +104,7 @@ class AuthServiceProxy(object):
 					'Authorization' : self.__authhdr,
 					'Authorization' : self.__authhdr,
 					'Content-type' : 'application/json' })
 					'Content-type' : 'application/json' })
 		except:
 		except:
-			from mmgen.utils import msg
+			from mmgen.util import msg
 			import sys
 			import sys
 			msg("\nUnable to connect to bitcoind.")
 			msg("\nUnable to connect to bitcoind.")
 			sys.exit(2)
 			sys.exit(2)

+ 0 - 0
tests/__init__.py → mmgen/tests/__init__.py


+ 3 - 3
tests/addr.py → mmgen/tests/addr.py

@@ -2,17 +2,17 @@
 #
 #
 # mmgen = Multi-Mode GENerator, command-line Bitcoin cold storage solution
 # mmgen = Multi-Mode GENerator, command-line Bitcoin cold storage solution
 # Copyright (C) 2013 by philemon <mmgen-py@yandex.com>
 # Copyright (C) 2013 by philemon <mmgen-py@yandex.com>
-# 
+#
 # This program is free software: you can redistribute it and/or modify
 # This program is free software: you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
 # it under the terms of the GNU General Public License as published by
 # the Free Software Foundation, either version 3 of the License, or
 # the Free Software Foundation, either version 3 of the License, or
 # (at your option) any later version.
 # (at your option) any later version.
-# 
+#
 # This program is distributed in the hope that it will be useful,
 # This program is distributed in the hope that it will be useful,
 # but WITHOUT ANY WARRANTY; without even the implied warranty of
 # but WITHOUT ANY WARRANTY; without even the implied warranty of
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 # GNU General Public License for more details.
 # GNU General Public License for more details.
-# 
+#
 # You should have received a copy of the GNU General Public License
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 """
 """

+ 4 - 4
tests/bitcoin.py → mmgen/tests/bitcoin.py

@@ -2,17 +2,17 @@
 #
 #
 # mmgen = Multi-Mode GENerator, command-line Bitcoin cold storage solution
 # mmgen = Multi-Mode GENerator, command-line Bitcoin cold storage solution
 # Copyright (C) 2013 by philemon <mmgen-py@yandex.com>
 # Copyright (C) 2013 by philemon <mmgen-py@yandex.com>
-# 
+#
 # This program is free software: you can redistribute it and/or modify
 # This program is free software: you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
 # it under the terms of the GNU General Public License as published by
 # the Free Software Foundation, either version 3 of the License, or
 # the Free Software Foundation, either version 3 of the License, or
 # (at your option) any later version.
 # (at your option) any later version.
-# 
+#
 # This program is distributed in the hope that it will be useful,
 # This program is distributed in the hope that it will be useful,
 # but WITHOUT ANY WARRANTY; without even the implied warranty of
 # but WITHOUT ANY WARRANTY; without even the implied warranty of
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 # GNU General Public License for more details.
 # GNU General Public License for more details.
-# 
+#
 # You should have received a copy of the GNU General Public License
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 """
 """
@@ -20,7 +20,7 @@ bitcoin.py:  Test suite for mmgen.bitcoin module
 """
 """
 
 
 from mmgen.bitcoin import *
 from mmgen.bitcoin import *
-from mmgen.utils import msg
+from mmgen.util import msg
 from test import *
 from test import *
 
 
 import sys
 import sys

+ 3 - 3
tests/mn_electrum.py → mmgen/tests/mn_electrum.py

@@ -2,17 +2,17 @@
 #
 #
 # mmgen = Multi-Mode GENerator, command-line Bitcoin cold storage solution
 # mmgen = Multi-Mode GENerator, command-line Bitcoin cold storage solution
 # Copyright (C) 2013 by philemon <mmgen-py@yandex.com>
 # Copyright (C) 2013 by philemon <mmgen-py@yandex.com>
-# 
+#
 # This program is free software: you can redistribute it and/or modify
 # This program is free software: you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
 # it under the terms of the GNU General Public License as published by
 # the Free Software Foundation, either version 3 of the License, or
 # the Free Software Foundation, either version 3 of the License, or
 # (at your option) any later version.
 # (at your option) any later version.
-# 
+#
 # This program is distributed in the hope that it will be useful,
 # This program is distributed in the hope that it will be useful,
 # but WITHOUT ANY WARRANTY; without even the implied warranty of
 # but WITHOUT ANY WARRANTY; without even the implied warranty of
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 # GNU General Public License for more details.
 # GNU General Public License for more details.
-# 
+#
 # You should have received a copy of the GNU General Public License
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 """
 """

+ 3 - 3
tests/mn_tirosh.py → mmgen/tests/mn_tirosh.py

@@ -2,17 +2,17 @@
 #
 #
 # mmgen = Multi-Mode GENerator, command-line Bitcoin cold storage solution
 # mmgen = Multi-Mode GENerator, command-line Bitcoin cold storage solution
 # Copyright (C) 2013 by philemon <mmgen-py@yandex.com>
 # Copyright (C) 2013 by philemon <mmgen-py@yandex.com>
-# 
+#
 # This program is free software: you can redistribute it and/or modify
 # This program is free software: you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
 # it under the terms of the GNU General Public License as published by
 # the Free Software Foundation, either version 3 of the License, or
 # the Free Software Foundation, either version 3 of the License, or
 # (at your option) any later version.
 # (at your option) any later version.
-# 
+#
 # This program is distributed in the hope that it will be useful,
 # This program is distributed in the hope that it will be useful,
 # but WITHOUT ANY WARRANTY; without even the implied warranty of
 # but WITHOUT ANY WARRANTY; without even the implied warranty of
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 # GNU General Public License for more details.
 # GNU General Public License for more details.
-# 
+#
 # You should have received a copy of the GNU General Public License
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 """
 """

+ 7 - 3
tests/mnemonic.py → mmgen/tests/mnemonic.py

@@ -2,17 +2,17 @@
 #
 #
 # mmgen = Multi-Mode GENerator, command-line Bitcoin cold storage solution
 # mmgen = Multi-Mode GENerator, command-line Bitcoin cold storage solution
 # Copyright (C) 2013 by philemon <mmgen-py@yandex.com>
 # Copyright (C) 2013 by philemon <mmgen-py@yandex.com>
-# 
+#
 # This program is free software: you can redistribute it and/or modify
 # This program is free software: you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
 # it under the terms of the GNU General Public License as published by
 # the Free Software Foundation, either version 3 of the License, or
 # the Free Software Foundation, either version 3 of the License, or
 # (at your option) any later version.
 # (at your option) any later version.
-# 
+#
 # This program is distributed in the hope that it will be useful,
 # This program is distributed in the hope that it will be useful,
 # but WITHOUT ANY WARRANTY; without even the implied warranty of
 # but WITHOUT ANY WARRANTY; without even the implied warranty of
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 # GNU General Public License for more details.
 # GNU General Public License for more details.
-# 
+#
 # You should have received a copy of the GNU General Public License
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 """
 """
@@ -66,7 +66,9 @@ def random192(): do_random_tests(24)
 def random256(): do_random_tests(32)
 def random256(): do_random_tests(32)
 def random512(): do_random_tests(64)
 def random512(): do_random_tests(64)
 def electrum():  check_wordlist(el,"electrum")
 def electrum():  check_wordlist(el,"electrum")
+def electrum_print():  print "%s" % el.strip()
 def tirosh():    check_wordlist(tl,"tirosh")
 def tirosh():    check_wordlist(tl,"tirosh")
+def tirosh_print():  print "%s" % tl.strip()
 
 
 def base10tohex(num,quiet=False):
 def base10tohex(num,quiet=False):
 	enc,dec = baseNtohex_test(num,10,"0123456789",quiet)
 	enc,dec = baseNtohex_test(num,10,"0123456789",quiet)
@@ -99,6 +101,8 @@ tests = {
 	"random512":      [],
 	"random512":      [],
 	"electrum":       [],
 	"electrum":       [],
 	"tirosh":         [],
 	"tirosh":         [],
+	"electrum_print": [],
+	"tirosh_print":   [],
 	"base10tohex":    ['base10num [int]','quiet [bool=False]'],
 	"base10tohex":    ['base10num [int]','quiet [bool=False]'],
 	"hextobase10":    ['hexnum [str]',   'quiet [bool=False]'],
 	"hextobase10":    ['hexnum [str]',   'quiet [bool=False]'],
 	"base8tohex":     ['base8num [int]', 'quiet [bool=False]'],
 	"base8tohex":     ['base8num [int]', 'quiet [bool=False]'],

+ 5 - 5
tests/test.py → mmgen/tests/test.py

@@ -2,17 +2,17 @@
 #
 #
 # mmgen = Multi-Mode GENerator, command-line Bitcoin cold storage solution
 # mmgen = Multi-Mode GENerator, command-line Bitcoin cold storage solution
 # Copyright (C) 2013 by philemon <mmgen-py@yandex.com>
 # Copyright (C) 2013 by philemon <mmgen-py@yandex.com>
-# 
+#
 # This program is free software: you can redistribute it and/or modify
 # This program is free software: you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
 # it under the terms of the GNU General Public License as published by
 # the Free Software Foundation, either version 3 of the License, or
 # the Free Software Foundation, either version 3 of the License, or
 # (at your option) any later version.
 # (at your option) any later version.
-# 
+#
 # This program is distributed in the hope that it will be useful,
 # This program is distributed in the hope that it will be useful,
 # but WITHOUT ANY WARRANTY; without even the implied warranty of
 # but WITHOUT ANY WARRANTY; without even the implied warranty of
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 # GNU General Public License for more details.
 # GNU General Public License for more details.
-# 
+#
 # You should have received a copy of the GNU General Public License
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 """
 """
@@ -20,7 +20,7 @@ test.py:  Shared routines for mmgen test suite
 """
 """
 
 
 import sys
 import sys
-from mmgen.utils import msg
+from mmgen.util import msg
 
 
 def nomsg(s): pass
 def nomsg(s): pass
 
 
@@ -55,7 +55,7 @@ def process_test_args(argv, tests):
 		print "'%s': no such test" % argv[1]
 		print "'%s': no such test" % argv[1]
 		sys.exit(2)
 		sys.exit(2)
 	else:
 	else:
-		cargs = tests[argv[1]] 
+		cargs = tests[argv[1]]
 		uargs = argv[2:]
 		uargs = argv[2:]
 		if len(uargs) > len(cargs):
 		if len(uargs) > len(cargs):
 			print "Too many arguments\nUsage: %s(%s)" % \
 			print "Too many arguments\nUsage: %s(%s)" % \

+ 5 - 5
tests/utils.py → mmgen/tests/utils.py

@@ -2,24 +2,24 @@
 #
 #
 # mmgen = Multi-Mode GENerator, command-line Bitcoin cold storage solution
 # mmgen = Multi-Mode GENerator, command-line Bitcoin cold storage solution
 # Copyright (C) 2013 by philemon <mmgen-py@yandex.com>
 # Copyright (C) 2013 by philemon <mmgen-py@yandex.com>
-# 
+#
 # This program is free software: you can redistribute it and/or modify
 # This program is free software: you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
 # it under the terms of the GNU General Public License as published by
 # the Free Software Foundation, either version 3 of the License, or
 # the Free Software Foundation, either version 3 of the License, or
 # (at your option) any later version.
 # (at your option) any later version.
-# 
+#
 # This program is distributed in the hope that it will be useful,
 # This program is distributed in the hope that it will be useful,
 # but WITHOUT ANY WARRANTY; without even the implied warranty of
 # but WITHOUT ANY WARRANTY; without even the implied warranty of
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 # GNU General Public License for more details.
 # GNU General Public License for more details.
-# 
+#
 # You should have received a copy of the GNU General Public License
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 """
 """
-utils.py:  Test suite for mmgen.utils module
+util.py:  Test suite for mmgen.util module
 """
 """
 
 
-from mmgen.utils import *
+from mmgen.util import *
 
 
 tests = "none",
 tests = "none",
 
 

+ 3 - 3
tests/walletgen.py → mmgen/tests/walletgen.py

@@ -2,17 +2,17 @@
 #
 #
 # mmgen = Multi-Mode GENerator, command-line Bitcoin cold storage solution
 # mmgen = Multi-Mode GENerator, command-line Bitcoin cold storage solution
 # Copyright (C) 2013 by philemon <mmgen-py@yandex.com>
 # Copyright (C) 2013 by philemon <mmgen-py@yandex.com>
-# 
+#
 # This program is free software: you can redistribute it and/or modify
 # This program is free software: you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
 # it under the terms of the GNU General Public License as published by
 # the Free Software Foundation, either version 3 of the License, or
 # the Free Software Foundation, either version 3 of the License, or
 # (at your option) any later version.
 # (at your option) any later version.
-# 
+#
 # This program is distributed in the hope that it will be useful,
 # This program is distributed in the hope that it will be useful,
 # but WITHOUT ANY WARRANTY; without even the implied warranty of
 # but WITHOUT ANY WARRANTY; without even the implied warranty of
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 # GNU General Public License for more details.
 # GNU General Public License for more details.
-# 
+#
 # You should have received a copy of the GNU General Public License
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 """
 """

+ 96 - 78
mmgen/tx.py

@@ -20,7 +20,7 @@ tx.py:  Bitcoin transaction routines
 """
 """
 
 
 from binascii import unhexlify
 from binascii import unhexlify
-from mmgen.utils import *
+from mmgen.util import *
 import sys, os
 import sys, os
 from decimal import Decimal
 from decimal import Decimal
 import mmgen.config as g
 import mmgen.config as g
@@ -169,6 +169,32 @@ def print_sent_tx_to_file(tx,metadata,opts):
 	msg("Transaction ID saved to file '%s'" % outfile)
 	msg("Transaction ID saved to file '%s'" % outfile)
 
 
 
 
+def format_unspent_outputs_for_printing(out,sort_info,total):
+
+	pfs  = " %-4s %-67s %-34s %-12s %-13s %-10s %s"
+	pout = [pfs % ("Num","TX id,Vout","Address","MMgen ID",
+		"Amount (BTC)","Age (days)", "Comment")]
+
+	for n,i in enumerate(out):
+		if verify_mmgen_label(i.account):
+			s = i.account.split(None,1)
+			mmid,cmt = s[0],(s[1] if len(s) == 2 else "")
+		else:
+			mmid,cmt = "",i.account
+
+		addr = "=" if i.skip == "addr" and "grouped" in sort_info else i.address
+		tx = " " * 63 + "=" \
+			  if i.skip == "txid" and "grouped" in sort_info else str(i.txid)
+
+		s = pfs % (str(n+1)+")", tx+","+str(i.vout),addr,mmid,i.amt,i.days,cmt)
+		pout.append(s.rstrip())
+
+	return \
+"Unspent outputs ({} UTC)\nSort order: {}\n\n{}\n\nTotal BTC: {}\n".format(
+		make_timestr(), " ".join(sort_info), "\n".join(pout), total
+	)
+
+
 def sort_and_view(unspent):
 def sort_and_view(unspent):
 
 
 	def s_amt(a,b):  return cmp(a.amount,b.amount)
 	def s_amt(a,b):  return cmp(a.amount,b.amount)
@@ -182,27 +208,28 @@ def sort_and_view(unspent):
 	sort,group,show_mmaddr,reverse = "",False,False,False
 	sort,group,show_mmaddr,reverse = "",False,False,False
 	total = trim_exponent(sum([i.amount for i in unspent]))
 	total = trim_exponent(sum([i.amount for i in unspent]))
 
 
+	hdr_fmt   = "UNSPENT OUTPUTS (sort order: %s)  Total BTC: %s"
+	table_hdr = fs % ("Num","TX id  Vout","","Address","Amount (BTC)", "Age(days)")
+
+	options_msg = """
+Sort options: [t]xid, [a]mount, a[d]dress, [A]ge, [r]everse, [M]mgen addr
+Format options: [g]roup, show [m]mgen addr
+""".strip()
+	prompt = \
+"('q' = quit sorting, 'p' = print to file, 'v' = pager view, 'w' = wide view): "
+
 	from copy import deepcopy
 	from copy import deepcopy
+	print_to_file_msg = ""
 	msg("")
 	msg("")
+
 	while True:
 	while True:
 		out = deepcopy(unspent)
 		out = deepcopy(unspent)
 		for i in out: i.skip = ""
 		for i in out: i.skip = ""
-		for n in range(len(out)):
-			if group and n < len(out)-1:
+		if group and (sort == "address" or sort == "txid"):
+			for n in range(len(out)-1):
 				a,b = out[n],out[n+1]
 				a,b = out[n],out[n+1]
-				if sort == "address" and a.address == b.address:
-					out[n+1].skip = "d"
-				elif sort == "txid" and a.txid == b.txid:
-					out[n+1].skip = "t"
-
-		output = ["UNSPENT OUTPUTS (sort order: %s%s%s)  Total BTC: %s" % (
-				"reverse " if reverse else "",
-				sort if sort else "None",
-	" (grouped)" if group and (sort == "address" or sort == "txid") else "",
-				total
-			)]
-		output.append(fs % ("Num","TX id  Vout","","Address","Amount (BTC)",
-					"Age(days)"))
+				if sort == "address" and a.address == b.address: b.skip = "addr"
+				elif sort == "txid" and a.txid == b.txid:        b.skip = "txid"
 
 
 		for i in out:
 		for i in out:
 			amt = str(trim_exponent(i.amount))
 			amt = str(trim_exponent(i.amount))
@@ -210,81 +237,72 @@ def sort_and_view(unspent):
 			i.amt = " "*lfill + amt
 			i.amt = " "*lfill + amt
 			i.days = int(i.confirmations * g.mins_per_block / (60*24))
 			i.days = int(i.confirmations * g.mins_per_block / (60*24))
 
 
-		for n,i in enumerate(out):
-			if i.skip == "d":
-				addr = "|" + "." * 33
+			if i.skip == "addr":
+				i.addr = "|" + "." * 33
 			else:
 			else:
 				if show_mmaddr:
 				if show_mmaddr:
 					if verify_mmgen_label(i.account):
 					if verify_mmgen_label(i.account):
-						addr = "%s.. %s" % (i.address[:4],i.account)
+						i.addr = "%s.. %s" % (i.address[:4],i.account)
 					else:
 					else:
-						addr = i.address
+						i.addr = i.address
 				else:
 				else:
-					addr = i.address
-			txid = "       |..." if i.skip == "t" else i.txid[:8]+"..."
+					i.addr = i.address
+
+			i.tx = "       |..." if i.skip == "txid" else i.txid[:8]+"..."
 
 
-			output.append(fs % (str(n+1)+")",txid,i.vout,addr,i.amt,i.days))
+		sort_info = ["reverse"] if reverse else []
+		sort_info.append(sort if sort else "unsorted")
+		if group and (sort == "address" or sort == "txid"):
+			sort_info.append("grouped")
+
+		output = [hdr_fmt % (" ".join(sort_info), total), table_hdr]
+
+		for n,i in enumerate(out):
+			output.append(fs % (str(n+1)+")",i.tx,i.vout,i.addr,i.amt,i.days))
+
+		msg("\n".join(output) +"\n\n" + print_to_file_msg + options_msg)
+		print_to_file_msg = ""
+
+		immed_chars = "qpPtadArMgm"
+		skip_prompt = False
 
 
-		skip_body = False
 		while True:
 		while True:
-			if skip_body:
-				skip_body = False
-				immed_chars = "qpP"
-			else:
-				msg("\n".join(output))
-				msg("""
-Sort options: [t]xid, [a]mount, a[d]dress, [A]ge, [r]everse, [M]mgen addr
-View options: [g]roup, show [m]mgen addr""")
-				immed_chars = "qpPtadArMgm"
-
-			reply = get_char(
-"(Type 'q' to quit sorting, 'p' to print to file, 'v' to view in pager): ",
-				immed_chars=immed_chars)
-
-			if   reply == 'a': unspent.sort(s_amt);  sort = "amount"; break
-			elif reply == 't': unspent.sort(s_txid); sort = "txid"; break
-			elif reply == 'd': unspent.sort(s_addr); sort = "address"; break
-			elif reply == 'A': unspent.sort(s_age);  sort = "age"; break
-			elif reply == 'M': unspent.sort(s_mmgen); show_mmaddr,sort=True,"mmgen"; break
+			reply = get_char(prompt, immed_chars=immed_chars)
+
+			if   reply == 'a': unspent.sort(s_amt);  sort = "amount"
+			elif reply == 't': unspent.sort(s_txid); sort = "txid"
+			elif reply == 'd': unspent.sort(s_addr); sort = "address"
+			elif reply == 'A': unspent.sort(s_age);  sort = "age"
+			elif reply == 'M':
+				unspent.sort(s_mmgen)
+				sort = "mmgen"
+				show_mmaddr = True
 			elif reply == 'r':
 			elif reply == 'r':
-				reverse = False if reverse else True
 				unspent.reverse()
 				unspent.reverse()
-				break
-			elif reply == 'g': group = False if group else True; break
-			elif reply == 'm': show_mmaddr = False if show_mmaddr else True; break
+				reverse = False if reverse else True
+			elif reply == 'g': group = False if group else True
+			elif reply == 'm': show_mmaddr = False if show_mmaddr else True
+			elif reply == 'q': pass
 			elif reply == 'p':
 			elif reply == 'p':
-				pfs  = " %-4s %-67s %-34s %-12s %-13s %-10s %s"
-				pout = [pfs % ("Num","TX id,Vout","Address","MMgen ID",
-					"Amount (BTC)","Age (days)", "Comment")]
+				data = format_unspent_outputs_for_printing(out,sort_info,total)
+				outfile = "listunspent[%s].out" % ",".join(sort_info)
+				write_to_file(outfile, data)
+				print_to_file_msg = "Data written to '%s'\n\n" % outfile
+			elif reply == 'v':
+				do_pager("\n".join(output))
+				continue
+			elif reply == 'w':
+				data = format_unspent_outputs_for_printing(out,sort_info,total)
+				do_pager(data)
+				continue
+			else:
+				msg("\nInvalid input")
+				continue
 
 
-				for n,i in enumerate(out):
-					if verify_mmgen_label(i.account):
-						s = i.account.split(None,1)
-						mmid,cmt = s[0],(s[1] if len(s) == 2 else "")
-					else:
-						mmid,cmt = "",i.account
-					os = pfs % (str(n+1)+")", str(i.txid)+","+str(i.vout),
-							i.address,mmid,i.amt,i.days,cmt)
-					pout.append(os.rstrip())
-
-				sort_info = (
-					("reverse," if reverse else "") +
-					(sort if sort else "unsorted")
-				)
-				outdata = \
-"Unspent outputs ({} UTC)\nSort order: {}\n\n{}\n\nTotal BTC: {}\n".format(
-					make_timestr(), sort_info, "\n".join(pout), total
-				)
-				outfile = "listunspent[%s].out" % sort_info
-				write_to_file(outfile, outdata)
-				skip_body = True
-				msg("\nData written to '%s'" % outfile)
-			elif reply == 'v': do_pager("\n".join(output))
-			elif reply == 'q': break
-			else: msg("Invalid input")
+			break
 
 
 		msg("\n")
 		msg("\n")
-		if reply in 'q': break
+		if reply == 'q': break
 
 
 	return tuple(unspent)
 	return tuple(unspent)
 
 
@@ -401,7 +419,7 @@ def select_outputs(unspent,prompt):
 
 
 		if not reply: continue
 		if not reply: continue
 
 
-		from mmgen.utils import parse_address_list
+		from mmgen.util import parse_address_list
 		selected = parse_address_list(reply,sep=None)
 		selected = parse_address_list(reply,sep=None)
 
 
 		if not selected: continue
 		if not selected: continue

+ 2 - 2
mmgen/utils.py → mmgen/util.py

@@ -16,7 +16,7 @@
 # You should have received a copy of the GNU General Public License
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 """
 """
-utils.py:  Shared routines for the mmgen suite
+util.py:  Shared routines for the mmgen suite
 """
 """
 
 
 import sys
 import sys
@@ -964,4 +964,4 @@ def do_pager(text):
 	else: print text+end
 	else: print text+end
 
 
 if __name__ == "__main__":
 if __name__ == "__main__":
-	print "utils.py"
+	print "util.py"

+ 1 - 1
mmgen/walletgen.py

@@ -20,7 +20,7 @@ walletgen.py:  Routines used for seed generation and wallet creation
 """
 """
 
 
 import sys
 import sys
-from mmgen.utils import msg, msg_r, get_char, prompt_and_get_char
+from mmgen.util import msg, msg_r, get_char, prompt_and_get_char
 from binascii import hexlify
 from binascii import hexlify
 
 
 def get_random_data_from_user(opts):
 def get_random_data_from_user(opts):

+ 9 - 9
setup.py

@@ -31,15 +31,15 @@ setup(
 			'mmgen.rpc.proxy',
 			'mmgen.rpc.proxy',
 			'mmgen.rpc.util',
 			'mmgen.rpc.util',
 
 
-			'tests.__init__',
-			'tests.addr',
-			'tests.bitcoin',
-			'tests.mn_electrum',
-			'tests.mnemonic',
-			'tests.mn_tirosh',
-			'tests.test',
-			'tests.utils',
-			'tests.walletgen'
+			'mmgen.tests.__init__',
+			'mmgen.tests.addr',
+			'mmgen.tests.bitcoin',
+			'mmgen.tests.mn_electrum',
+			'mmgen.tests.mnemonic',
+			'mmgen.tests.mn_tirosh',
+			'mmgen.tests.test',
+			'mmgen.tests.utils',
+			'mmgen.tests.walletgen'
 		],
 		],
 		scripts=[
 		scripts=[
 			'mmgen-addrgen',
 			'mmgen-addrgen',