|
@@ -31,7 +31,7 @@ from mmgen.utils import *
|
|
help_data = {
|
|
help_data = {
|
|
'prog_name': sys.argv[0].split("/")[-1],
|
|
'prog_name': sys.argv[0].split("/")[-1],
|
|
'desc': "Sign a Bitcoin transaction generated by mmgen-txcreate",
|
|
'desc': "Sign a Bitcoin transaction generated by mmgen-txcreate",
|
|
- 'usage': "[opts] <transaction file> [mmgen wallet/seed/mnemonic file]",
|
|
|
|
|
|
+ 'usage': "[opts] <transaction file> [mmgen wallet/seed/words/brain file]...",
|
|
'options': """
|
|
'options': """
|
|
-h, --help Print this help message
|
|
-h, --help Print this help message
|
|
-d, --outdir d Specify an alternate directory 'd' for output
|
|
-d, --outdir d Specify an alternate directory 'd' for output
|
|
@@ -59,8 +59,15 @@ prompted to enter the data.
|
|
In cases of transactions with mixed mmgen and non-mmgen inputs, non-mmgen
|
|
In cases of transactions with mixed mmgen and non-mmgen inputs, non-mmgen
|
|
keys must be supplied in a separate file (WIF format, one key per line)
|
|
keys must be supplied in a separate file (WIF format, one key per line)
|
|
using the '--keys-from-file' option. Alternatively, one may import the
|
|
using the '--keys-from-file' option. Alternatively, one may import the
|
|
-required mmgen keys into wallet.dat and use the '--force-wallet-dat' option.
|
|
|
|
-""".format(seed_ext)
|
|
|
|
|
|
+required mmgen keys into the bitcoind wallet.dat and use the
|
|
|
|
+'--force-wallet-dat' option.
|
|
|
|
+
|
|
|
|
+Seed data supplied in files must have the following extensions:
|
|
|
|
+ wallet: '.{}'
|
|
|
|
+ seed: '.{}'
|
|
|
|
+ mnemonic: '.{}'
|
|
|
|
+ brainwallet: '.{}'
|
|
|
|
+""".format(seed_ext,wallet_ext,seed_ext,mn_ext,brain_ext)
|
|
}
|
|
}
|
|
|
|
|
|
short_opts = "hd:efik:qb:ms"
|
|
short_opts = "hd:efik:qb:ms"
|
|
@@ -77,15 +84,15 @@ if debug:
|
|
print "Processed options: %s" % repr(opts)
|
|
print "Processed options: %s" % repr(opts)
|
|
print "Cmd args: %s" % repr(cmd_args)
|
|
print "Cmd args: %s" % repr(cmd_args)
|
|
|
|
|
|
-if len(cmd_args) in (1,2):
|
|
|
|
- tx_file = cmd_args[0]
|
|
|
|
- check_infile(tx_file)
|
|
|
|
|
|
+if len(cmd_args) > 0:
|
|
|
|
+ for i in cmd_args: check_infile(i)
|
|
else: usage(help_data)
|
|
else: usage(help_data)
|
|
|
|
|
|
# Begin execution
|
|
# Begin execution
|
|
|
|
|
|
c = connect_to_bitcoind()
|
|
c = connect_to_bitcoind()
|
|
|
|
|
|
|
|
+tx_file = cmd_args.pop(0)
|
|
tx_data = get_lines_from_file(tx_file,"transaction data")
|
|
tx_data = get_lines_from_file(tx_file,"transaction data")
|
|
|
|
|
|
metadata,tx_hex,sig_data,inputs_data = parse_tx_data(tx_data,tx_file)
|
|
metadata,tx_hex,sig_data,inputs_data = parse_tx_data(tx_data,tx_file)
|
|
@@ -101,25 +108,8 @@ msg("Successfully opened transaction file '%s'" % tx_file)
|
|
if user_confirm("View transaction data? ",default_yes=False):
|
|
if user_confirm("View transaction data? ",default_yes=False):
|
|
view_tx_data(c,inputs_data,tx_hex,metadata)
|
|
view_tx_data(c,inputs_data,tx_hex,metadata)
|
|
|
|
|
|
-
|
|
|
|
-def sign_transaction(tx_hex,sig_data,keys=None):
|
|
|
|
-
|
|
|
|
- from mmgen.rpc import exceptions
|
|
|
|
-
|
|
|
|
- try:
|
|
|
|
- sig_tx = c.signrawtransaction(tx_hex,sig_data,keys)
|
|
|
|
- except exceptions.InvalidAddressOrKey:
|
|
|
|
- msg("Invalid address or key")
|
|
|
|
- sys.exit(3)
|
|
|
|
-# except:
|
|
|
|
-# msg("Failed to sign transaction")
|
|
|
|
-# sys.exit(3)
|
|
|
|
-
|
|
|
|
- return sig_tx
|
|
|
|
-
|
|
|
|
-
|
|
|
|
# Are inputs mmgen addresses?
|
|
# Are inputs mmgen addresses?
|
|
-infile,mmgen_addrs,other_addrs = "",[],[]
|
|
|
|
|
|
+infile,mmgen_addrs,other_addrs,keys = "",[],[],[]
|
|
|
|
|
|
for i in inputs_data:
|
|
for i in inputs_data:
|
|
if verify_mmgen_label(i['account']):
|
|
if verify_mmgen_label(i['account']):
|
|
@@ -129,32 +119,46 @@ for i in inputs_data:
|
|
|
|
|
|
if mmgen_addrs and not 'force_wallet_dat' in opts:
|
|
if mmgen_addrs and not 'force_wallet_dat' in opts:
|
|
# Check that all the seed IDs are the same:
|
|
# Check that all the seed IDs are the same:
|
|
- a_ids = list(set([i['account'][:8] for i in mmgen_addrs]))
|
|
|
|
- if len(a_ids) != 1:
|
|
|
|
- msg("Addresses come from different seeds! (%s)" % " ".join(a_ids))
|
|
|
|
- sys.exit(3)
|
|
|
|
-
|
|
|
|
- if len(cmd_args) == 2:
|
|
|
|
- infile = cmd_args[1]
|
|
|
|
- elif "from_brain" in opts or "from_mnemonic" in opts or "from_seed" in opts:
|
|
|
|
- infile = ""
|
|
|
|
- else:
|
|
|
|
- msg("Inputs contain mmgen addresses. An MMGen wallet file must be specified on the command line (or use the '-b', '-m' or '-s' options).".strip())
|
|
|
|
- sys.exit(2)
|
|
|
|
-
|
|
|
|
- seed = get_seed(infile,opts)
|
|
|
|
- seed_id = make_chksum_8(seed)
|
|
|
|
-
|
|
|
|
- if seed_id != a_ids[0]:
|
|
|
|
- msg("Seed ID of wallet (%s) doesn't match that of addresses (%s)"
|
|
|
|
- % (seed_id,a_ids[0]))
|
|
|
|
- sys.exit(3)
|
|
|
|
-
|
|
|
|
- addr_nums = [int(i['account'].split()[0][9:]) for i in mmgen_addrs]
|
|
|
|
|
|
+ seed_ids = list(set([i['account'][:8] for i in mmgen_addrs]))
|
|
|
|
+ while seed_ids:
|
|
|
|
+ if cmd_args:
|
|
|
|
+ infile = cmd_args.pop()
|
|
|
|
+ ext = infile.split(".")[-1]
|
|
|
|
+ for e,o in (
|
|
|
|
+ (wallet_ext, {}),
|
|
|
|
+ (mn_ext, {"from_mnemonic":True}),
|
|
|
|
+ (seed_ext, {"from_seed": True}),
|
|
|
|
+ (brain_ext, {})
|
|
|
|
+ ):
|
|
|
|
+ if e == ext:
|
|
|
|
+ if e == brain_ext:
|
|
|
|
+ if "from_brain" in opts: o = opts
|
|
|
|
+ else:
|
|
|
|
+ msg("'--from-brain' option must be specified for brainwallet file")
|
|
|
|
+ sys.exit(2)
|
|
|
|
+ seed = get_seed(infile,o)
|
|
|
|
+ elif "from_brain" in opts or "from_mnemonic" in opts or "from_seed" in opts:
|
|
|
|
+ msg("Need data for seed ID %s" % seed_ids[0])
|
|
|
|
+ seed = get_seed("",opts)
|
|
|
|
+ else:
|
|
|
|
+ msg("One of '-b', '-m' or '-s' must be specified for seed IDs: %s" %
|
|
|
|
+ " ".join(seed_ids))
|
|
|
|
+ sys.exit(2)
|
|
|
|
|
|
- from mmgen.addr import generate_addrs
|
|
|
|
- o = {'no_addresses': True, 'gen_what': "keys"}
|
|
|
|
- keys = [i['wif'] for i in generate_addrs(seed, addr_nums, o)]
|
|
|
|
|
|
+ seed_id = make_chksum_8(seed)
|
|
|
|
+ if seed_id in seed_ids:
|
|
|
|
+ seed_ids.remove(seed_id)
|
|
|
|
+ seed_id_addrs = []
|
|
|
|
+ for i in mmgen_addrs:
|
|
|
|
+ if i['account'][:8] == seed_id:
|
|
|
|
+ seed_id_addrs.append(int(i['account'].split()[0][9:]))
|
|
|
|
+
|
|
|
|
+ from mmgen.addr import generate_addrs
|
|
|
|
+ o = {'no_addresses': True, 'gen_what': "keys"}
|
|
|
|
+ keys += [i['wif'] for i in generate_addrs(seed, seed_id_addrs, o)]
|
|
|
|
+ else:
|
|
|
|
+ msg("Supplied seed ID (%s) is incorrect" % seed_id)
|
|
|
|
+ sys.exit(2)
|
|
|
|
|
|
if other_addrs:
|
|
if other_addrs:
|
|
if 'keys_from_file' in opts:
|
|
if 'keys_from_file' in opts:
|
|
@@ -169,12 +173,12 @@ address%s: %s""" % (
|
|
))
|
|
))
|
|
sys.exit(2)
|
|
sys.exit(2)
|
|
|
|
|
|
- sig_tx = sign_transaction(tx_hex,sig_data,keys)
|
|
|
|
|
|
+ sig_tx = sign_transaction(c,tx_hex,sig_data,keys)
|
|
|
|
|
|
elif 'keys_from_file' in opts:
|
|
elif 'keys_from_file' in opts:
|
|
keys = get_lines_from_file(opts['keys_from_file'],"key data")
|
|
keys = get_lines_from_file(opts['keys_from_file'],"key data")
|
|
|
|
|
|
- sig_tx = sign_transaction(tx_hex,sig_data,keys)
|
|
|
|
|
|
+ sig_tx = sign_transaction(c,tx_hex,sig_data,keys)
|
|
else:
|
|
else:
|
|
prompt = "Enter passphrase for bitcoind wallet: "
|
|
prompt = "Enter passphrase for bitcoind wallet: "
|
|
if 'echo_passphrase' in opts:
|
|
if 'echo_passphrase' in opts:
|
|
@@ -198,7 +202,7 @@ else:
|
|
else:
|
|
else:
|
|
msg("Passphrase OK")
|
|
msg("Passphrase OK")
|
|
|
|
|
|
- sig_tx = sign_transaction(tx_hex,sig_data)
|
|
|
|
|
|
+ sig_tx = sign_transaction(c,tx_hex,sig_data)
|
|
|
|
|
|
if wallet_enc:
|
|
if wallet_enc:
|
|
c.walletlock()
|
|
c.walletlock()
|
|
@@ -207,7 +211,7 @@ else:
|
|
if sig_tx['complete']:
|
|
if sig_tx['complete']:
|
|
msg("Signing completed")
|
|
msg("Signing completed")
|
|
else:
|
|
else:
|
|
- msg("Not all keys could be found to sign this transaction")
|
|
|
|
|
|
+ msg("Some keys were missing. Transaction could not be signed.")
|
|
sys.exit(3)
|
|
sys.exit(3)
|
|
|
|
|
|
prompt = "Save signed transaction?"
|
|
prompt = "Save signed transaction?"
|