From 1c9b0f88167161e950e21a34fd3b8805f218c000 Mon Sep 17 00:00:00 2001 From: philemon Date: Thu, 3 Apr 2014 14:02:00 +0400 Subject: [PATCH] mmgen-txcreate interface improvements utils.py -> util.py rename --- mmgen-addrgen | 2 +- mmgen-addrimport | 2 +- mmgen-passchg | 2 +- mmgen-pywallet | 10 +- mmgen-txcreate | 2 +- mmgen-txsend | 2 +- mmgen-txsign | 2 +- mmgen-walletchk | 2 +- mmgen-walletgen | 2 +- mmgen/Opts.py | 2 +- mmgen/__init__.py | 2 +- mmgen/addr.py | 2 +- mmgen/license.py | 4 +- mmgen/mnemonic.py | 2 +- mmgen/rpc/connection.py | 2 +- mmgen/rpc/proxy.py | 2 +- {tests => mmgen/tests}/__init__.py | 0 {tests => mmgen/tests}/addr.py | 6 +- {tests => mmgen/tests}/bitcoin.py | 8 +- {tests => mmgen/tests}/mn_electrum.py | 6 +- {tests => mmgen/tests}/mn_tirosh.py | 6 +- {tests => mmgen/tests}/mnemonic.py | 10 +- {tests => mmgen/tests}/test.py | 10 +- {tests => mmgen/tests}/utils.py | 10 +- {tests => mmgen/tests}/walletgen.py | 6 +- mmgen/tx.py | 172 ++++++++++++++------------ mmgen/{utils.py => util.py} | 4 +- mmgen/walletgen.py | 2 +- setup.py | 18 +-- 29 files changed, 161 insertions(+), 139 deletions(-) rename {tests => mmgen/tests}/__init__.py (100%) rename {tests => mmgen/tests}/addr.py (99%) rename {tests => mmgen/tests}/bitcoin.py (99%) rename {tests => mmgen/tests}/mn_electrum.py (99%) rename {tests => mmgen/tests}/mn_tirosh.py (99%) rename {tests => mmgen/tests}/mnemonic.py (96%) rename {tests => mmgen/tests}/test.py (97%) rename {tests => mmgen/tests}/utils.py (91%) rename {tests => mmgen/tests}/walletgen.py (99%) rename mmgen/{utils.py => util.py} (99%) diff --git a/mmgen-addrgen b/mmgen-addrgen index 33c55fb8..d27295f0 100755 --- a/mmgen-addrgen +++ b/mmgen-addrgen @@ -27,7 +27,7 @@ import sys from mmgen.Opts import * import mmgen.config as g from mmgen.license import * -from mmgen.utils import * +from mmgen.util import * from mmgen.addr import * invoked_as = sys.argv[0].split("-")[-1] diff --git a/mmgen-addrimport b/mmgen-addrimport index 68f17012..690cd051 100755 --- a/mmgen-addrimport +++ b/mmgen-addrimport @@ -23,7 +23,7 @@ mmgen-addrimport: Import addresses into a bitcoind watching wallet. import sys from mmgen.Opts 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.bitcoin import verify_addr diff --git a/mmgen-passchg b/mmgen-passchg index 7d9ae728..ad50803c 100755 --- a/mmgen-passchg +++ b/mmgen-passchg @@ -22,7 +22,7 @@ mmgen-passchg: Change a mmgen deterministic wallet's passphrase, label or import sys from mmgen.Opts import * -from mmgen.utils import * +from mmgen.util import * import mmgen.config as g help_data = { diff --git a/mmgen-pywallet b/mmgen-pywallet index fdd6fe99..4684d892 100755 --- a/mmgen-pywallet +++ b/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) from mmgen.Opts import * -from mmgen.utils import msg +from mmgen.util import msg from bsddb.db import * import sys, time 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) -from mmgen.utils import check_infile +from mmgen.util import check_infile 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 \ ('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) if password != None: @@ -1682,7 +1682,7 @@ elif 'addrs' in opts: ext,what = "addrs","addresses" 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") for addr in usr_addrs: try: @@ -1696,7 +1696,7 @@ len_arg = "%s" % len(wallet_addrs) \ if len(data) == len(wallet_addrs) or ext == "json" \ 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))) data = "\n".join(data) + "\n" diff --git a/mmgen-txcreate b/mmgen-txcreate index 0166642b..5a7b53ed 100755 --- a/mmgen-txcreate +++ b/mmgen-txcreate @@ -26,7 +26,7 @@ from mmgen.Opts import * from mmgen.license import * import mmgen.config as g 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 prog_name = sys.argv[0].split("/")[-1] diff --git a/mmgen-txsend b/mmgen-txsend index 93592980..ed168a2d 100755 --- a/mmgen-txsend +++ b/mmgen-txsend @@ -25,7 +25,7 @@ from mmgen.Opts import * from mmgen.license import * import mmgen.config as g 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] diff --git a/mmgen-txsign b/mmgen-txsign index abe3fb21..40857d5e 100755 --- a/mmgen-txsign +++ b/mmgen-txsign @@ -25,7 +25,7 @@ from mmgen.Opts import * from mmgen.license import * import mmgen.config as g from mmgen.tx import * -from mmgen.utils import msg +from mmgen.util import msg help_data = { 'prog_name': sys.argv[0].split("/")[-1], diff --git a/mmgen-walletchk b/mmgen-walletchk index 01688adb..4b36770f 100755 --- a/mmgen-walletchk +++ b/mmgen-walletchk @@ -23,7 +23,7 @@ mmgen-walletchk: Check integrity of a mmgen deterministic wallet, display import sys from mmgen.Opts import * -from mmgen.utils import * +from mmgen.util import * help_data = { 'prog_name': sys.argv[0].split("/")[-1], diff --git a/mmgen-walletgen b/mmgen-walletgen index 99a65672..b1e29a13 100755 --- a/mmgen-walletgen +++ b/mmgen-walletgen @@ -26,7 +26,7 @@ from mmgen.Opts import * from mmgen.license import * import mmgen.config as g from mmgen.walletgen import * -from mmgen.utils import * +from mmgen.util import * prog_name = sys.argv[0].split("/")[-1] help_data = { diff --git a/mmgen/Opts.py b/mmgen/Opts.py index 17f5b0a5..7a877f2f 100755 --- a/mmgen/Opts.py +++ b/mmgen/Opts.py @@ -18,7 +18,7 @@ import sys, getopt import mmgen.config as g -from mmgen.utils import msg +from mmgen.util import msg def usage(hd): print "USAGE: %s %s" % (hd['prog_name'], hd['usage']) diff --git a/mmgen/__init__.py b/mmgen/__init__.py index 1fb11312..c3b62a79 100755 --- a/mmgen/__init__.py +++ b/mmgen/__init__.py @@ -29,7 +29,7 @@ __all__ = [ 'mn_tirosh.py', 'Opts.py', 'tx.py', - 'utils.py', + 'util.py', 'walletgen.py' ] diff --git a/mmgen/addr.py b/mmgen/addr.py index a5df8cb7..a6b43475 100755 --- a/mmgen/addr.py +++ b/mmgen/addr.py @@ -210,7 +210,7 @@ def write_addr_data_to_file(seed, data, addr_list, opts): else: ext = "akeys" 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( make_chksum_8(seed), fmt_addr_list(addr_list), diff --git a/mmgen/license.py b/mmgen/license.py index cea8e8a2..8b02b61f 100755 --- a/mmgen/license.py +++ b/mmgen/license.py @@ -20,7 +20,7 @@ license.py: Show the license """ import sys -from mmgen.utils import msg, msg_r, get_char +from mmgen.util import msg, msg_r, get_char gpl = { 'warning': """ @@ -591,7 +591,7 @@ def do_license_msg(immed=False): while True: reply = get_char(prompt, immed_chars="wc" if immed else "") if reply == 'w': - from mmgen.utils import do_pager + from mmgen.util import do_pager do_pager(gpl['conditions']) elif reply == 'c': msg(""); break diff --git a/mmgen/mnemonic.py b/mmgen/mnemonic.py index b9e06cf5..bd32ae73 100755 --- a/mmgen/mnemonic.py +++ b/mmgen/mnemonic.py @@ -31,7 +31,7 @@ def mn_len(hexnum): return len(hexnum) * 3 / 8 import sys -from mmgen.utils import msg,make_chksum_8 +from mmgen.util import msg,make_chksum_8 import mmgen.config as g # These universal base-conversion routines work for any base diff --git a/mmgen/rpc/connection.py b/mmgen/rpc/connection.py index 0fe6fc82..443f3857 100755 --- a/mmgen/rpc/connection.py +++ b/mmgen/rpc/connection.py @@ -66,7 +66,7 @@ class BitcoinConnection(object): return self.proxy.importaddress(address,label) except JSONRPCException as e: if e.error['message'] == "Method not found": - from mmgen.utils import msg_r + from mmgen.util import msg_r msg_r(""" ERROR: 'importaddress' method not found. Is your bitcoind enabled for watch-only addresses?""") raise _wrap_exception(e.error) diff --git a/mmgen/rpc/proxy.py b/mmgen/rpc/proxy.py index 6e13fdda..ec0e436d 100755 --- a/mmgen/rpc/proxy.py +++ b/mmgen/rpc/proxy.py @@ -104,7 +104,7 @@ class AuthServiceProxy(object): 'Authorization' : self.__authhdr, 'Content-type' : 'application/json' }) except: - from mmgen.utils import msg + from mmgen.util import msg import sys msg("\nUnable to connect to bitcoind.") sys.exit(2) diff --git a/tests/__init__.py b/mmgen/tests/__init__.py similarity index 100% rename from tests/__init__.py rename to mmgen/tests/__init__.py diff --git a/tests/addr.py b/mmgen/tests/addr.py similarity index 99% rename from tests/addr.py rename to mmgen/tests/addr.py index e706cbd1..ae6a7c05 100755 --- a/tests/addr.py +++ b/mmgen/tests/addr.py @@ -2,17 +2,17 @@ # # mmgen = Multi-Mode GENerator, command-line Bitcoin cold storage solution # Copyright (C) 2013 by philemon -# +# # 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 # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. -# +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. -# +# # You should have received a copy of the GNU General Public License # along with this program. If not, see . """ diff --git a/tests/bitcoin.py b/mmgen/tests/bitcoin.py similarity index 99% rename from tests/bitcoin.py rename to mmgen/tests/bitcoin.py index 020ffd95..1c19e82d 100755 --- a/tests/bitcoin.py +++ b/mmgen/tests/bitcoin.py @@ -2,17 +2,17 @@ # # mmgen = Multi-Mode GENerator, command-line Bitcoin cold storage solution # Copyright (C) 2013 by philemon -# +# # 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 # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. -# +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. -# +# # You should have received a copy of the GNU General Public License # along with this program. If not, see . """ @@ -20,7 +20,7 @@ bitcoin.py: Test suite for mmgen.bitcoin module """ from mmgen.bitcoin import * -from mmgen.utils import msg +from mmgen.util import msg from test import * import sys diff --git a/tests/mn_electrum.py b/mmgen/tests/mn_electrum.py similarity index 99% rename from tests/mn_electrum.py rename to mmgen/tests/mn_electrum.py index 78b1cac2..cae7bbd2 100755 --- a/tests/mn_electrum.py +++ b/mmgen/tests/mn_electrum.py @@ -2,17 +2,17 @@ # # mmgen = Multi-Mode GENerator, command-line Bitcoin cold storage solution # Copyright (C) 2013 by philemon -# +# # 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 # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. -# +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. -# +# # You should have received a copy of the GNU General Public License # along with this program. If not, see . """ diff --git a/tests/mn_tirosh.py b/mmgen/tests/mn_tirosh.py similarity index 99% rename from tests/mn_tirosh.py rename to mmgen/tests/mn_tirosh.py index d5f20da4..bfd513ac 100755 --- a/tests/mn_tirosh.py +++ b/mmgen/tests/mn_tirosh.py @@ -2,17 +2,17 @@ # # mmgen = Multi-Mode GENerator, command-line Bitcoin cold storage solution # Copyright (C) 2013 by philemon -# +# # 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 # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. -# +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. -# +# # You should have received a copy of the GNU General Public License # along with this program. If not, see . """ diff --git a/tests/mnemonic.py b/mmgen/tests/mnemonic.py similarity index 96% rename from tests/mnemonic.py rename to mmgen/tests/mnemonic.py index f1b7391d..9727bf5d 100755 --- a/tests/mnemonic.py +++ b/mmgen/tests/mnemonic.py @@ -2,17 +2,17 @@ # # mmgen = Multi-Mode GENerator, command-line Bitcoin cold storage solution # Copyright (C) 2013 by philemon -# +# # 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 # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. -# +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. -# +# # You should have received a copy of the GNU General Public License # along with this program. If not, see . """ @@ -66,7 +66,9 @@ def random192(): do_random_tests(24) def random256(): do_random_tests(32) def random512(): do_random_tests(64) def electrum(): check_wordlist(el,"electrum") +def electrum_print(): print "%s" % el.strip() def tirosh(): check_wordlist(tl,"tirosh") +def tirosh_print(): print "%s" % tl.strip() def base10tohex(num,quiet=False): enc,dec = baseNtohex_test(num,10,"0123456789",quiet) @@ -99,6 +101,8 @@ tests = { "random512": [], "electrum": [], "tirosh": [], + "electrum_print": [], + "tirosh_print": [], "base10tohex": ['base10num [int]','quiet [bool=False]'], "hextobase10": ['hexnum [str]', 'quiet [bool=False]'], "base8tohex": ['base8num [int]', 'quiet [bool=False]'], diff --git a/tests/test.py b/mmgen/tests/test.py similarity index 97% rename from tests/test.py rename to mmgen/tests/test.py index 747b0da5..3125d257 100755 --- a/tests/test.py +++ b/mmgen/tests/test.py @@ -2,17 +2,17 @@ # # mmgen = Multi-Mode GENerator, command-line Bitcoin cold storage solution # Copyright (C) 2013 by philemon -# +# # 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 # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. -# +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. -# +# # You should have received a copy of the GNU General Public License # along with this program. If not, see . """ @@ -20,7 +20,7 @@ test.py: Shared routines for mmgen test suite """ import sys -from mmgen.utils import msg +from mmgen.util import msg def nomsg(s): pass @@ -55,7 +55,7 @@ def process_test_args(argv, tests): print "'%s': no such test" % argv[1] sys.exit(2) else: - cargs = tests[argv[1]] + cargs = tests[argv[1]] uargs = argv[2:] if len(uargs) > len(cargs): print "Too many arguments\nUsage: %s(%s)" % \ diff --git a/tests/utils.py b/mmgen/tests/utils.py similarity index 91% rename from tests/utils.py rename to mmgen/tests/utils.py index 6f590199..3541e790 100755 --- a/tests/utils.py +++ b/mmgen/tests/utils.py @@ -2,24 +2,24 @@ # # mmgen = Multi-Mode GENerator, command-line Bitcoin cold storage solution # Copyright (C) 2013 by philemon -# +# # 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 # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. -# +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. -# +# # You should have received a copy of the GNU General Public License # along with this program. If not, see . """ -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", diff --git a/tests/walletgen.py b/mmgen/tests/walletgen.py similarity index 99% rename from tests/walletgen.py rename to mmgen/tests/walletgen.py index 93345ce5..c4a7ffe4 100755 --- a/tests/walletgen.py +++ b/mmgen/tests/walletgen.py @@ -2,17 +2,17 @@ # # mmgen = Multi-Mode GENerator, command-line Bitcoin cold storage solution # Copyright (C) 2013 by philemon -# +# # 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 # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. -# +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. -# +# # You should have received a copy of the GNU General Public License # along with this program. If not, see . """ diff --git a/mmgen/tx.py b/mmgen/tx.py index 18f5d3f1..398a5817 100755 --- a/mmgen/tx.py +++ b/mmgen/tx.py @@ -20,7 +20,7 @@ tx.py: Bitcoin transaction routines """ from binascii import unhexlify -from mmgen.utils import * +from mmgen.util import * import sys, os from decimal import Decimal 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) +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 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 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 + print_to_file_msg = "" msg("") + while True: out = deepcopy(unspent) 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] - 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: amt = str(trim_exponent(i.amount)) @@ -210,81 +237,72 @@ def sort_and_view(unspent): i.amt = " "*lfill + amt 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: if show_mmaddr: if verify_mmgen_label(i.account): - addr = "%s.. %s" % (i.address[:4],i.account) + i.addr = "%s.. %s" % (i.address[:4],i.account) else: - addr = i.address + i.addr = i.address else: - addr = i.address - txid = " |..." if i.skip == "t" else i.txid[:8]+"..." + i.addr = i.address - output.append(fs % (str(n+1)+")",txid,i.vout,addr,i.amt,i.days)) + i.tx = " |..." if i.skip == "txid" else i.txid[:8]+"..." + + 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: - 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(prompt, immed_chars=immed_chars) - 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 + 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': - reverse = False if reverse else True 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': - 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") - if reply in 'q': break + if reply == 'q': break return tuple(unspent) @@ -401,7 +419,7 @@ def select_outputs(unspent,prompt): 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) if not selected: continue diff --git a/mmgen/utils.py b/mmgen/util.py similarity index 99% rename from mmgen/utils.py rename to mmgen/util.py index bf030b69..cce59503 100755 --- a/mmgen/utils.py +++ b/mmgen/util.py @@ -16,7 +16,7 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . """ -utils.py: Shared routines for the mmgen suite +util.py: Shared routines for the mmgen suite """ import sys @@ -964,4 +964,4 @@ def do_pager(text): else: print text+end if __name__ == "__main__": - print "utils.py" + print "util.py" diff --git a/mmgen/walletgen.py b/mmgen/walletgen.py index 38c1c756..7d6dd91a 100755 --- a/mmgen/walletgen.py +++ b/mmgen/walletgen.py @@ -20,7 +20,7 @@ walletgen.py: Routines used for seed generation and wallet creation """ 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 def get_random_data_from_user(opts): diff --git a/setup.py b/setup.py index 6ffa88bb..5dee17ef 100755 --- a/setup.py +++ b/setup.py @@ -31,15 +31,15 @@ setup( 'mmgen.rpc.proxy', '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=[ 'mmgen-addrgen',