|
@@ -29,8 +29,8 @@ from mmgen.util import msg,qmsg
|
|
|
|
|
|
help_data = {
|
|
|
'prog_name': sys.argv[0].split("/")[-1],
|
|
|
- 'desc': "Sign a Bitcoin transaction generated by mmgen-txcreate",
|
|
|
- 'usage': "[opts] <transaction file> [mmgen wallet/seed/words/brain file]...",
|
|
|
+ 'desc': "Sign Bitcoin transactions generated by mmgen-txcreate",
|
|
|
+ 'usage': "[opts] <transaction file>,.. [mmgen wallet/seed/words/brainwallet file]...",
|
|
|
'options': """
|
|
|
-h, --help Print this help message
|
|
|
-d, --outdir d Specify an alternate directory 'd' for output
|
|
@@ -101,70 +101,77 @@ for i in infiles: check_infile(i)
|
|
|
|
|
|
c = connect_to_bitcoind()
|
|
|
|
|
|
-tx_file = infiles.pop(0)
|
|
|
-m = "" if 'tx_id' in opts else "transaction data"
|
|
|
-tx_data = get_lines_from_file(tx_file,m)
|
|
|
-
|
|
|
-metadata,tx_hex,inputs_data,b2m_map = parse_tx_data(tx_data,tx_file)
|
|
|
-
|
|
|
-if 'tx_id' in opts:
|
|
|
- msg(metadata[0])
|
|
|
- sys.exit(0)
|
|
|
-
|
|
|
-if 'info' in opts:
|
|
|
- view_tx_data(c,inputs_data,tx_hex,b2m_map,metadata)
|
|
|
- sys.exit(0)
|
|
|
-
|
|
|
-do_license_msg(immed=True)
|
|
|
-
|
|
|
-# Are inputs mmgen addresses?
|
|
|
-mmgen_addrs = [i for i in inputs_data if parse_mmgen_label(i['account'])[0]]
|
|
|
-other_addrs = [i for i in inputs_data if not parse_mmgen_label(i['account'])[0]]
|
|
|
-
|
|
|
-keys = get_lines_from_file(opts['keys_from_file'],"key data",remove_comments=True) \
|
|
|
- if 'keys_from_file' in opts else []
|
|
|
-
|
|
|
-if other_addrs and not keys and not 'use_wallet_dat' in opts:
|
|
|
- missing_keys_errormsg(other_addrs)
|
|
|
- sys.exit(2)
|
|
|
+seeds = {}
|
|
|
+tx_files = [i for i in set(infiles) if get_extension(i) == g.rawtx_ext]
|
|
|
+infiles = list(set(infiles) - set(tx_files))
|
|
|
|
|
|
-if other_addrs and keys and not 'skip_key_preverify' in opts:
|
|
|
- a = [i['address'] for i in other_addrs]
|
|
|
- preverify_keys(a, keys)
|
|
|
+if not "info" in opts: do_license_msg(immed=True)
|
|
|
|
|
|
-seeds = {}
|
|
|
-check_mmgen_to_btc_addr_mappings(inputs_data,b2m_map,infiles,seeds,opts)
|
|
|
+keys_from_file = get_lines_from_file(opts['keys_from_file'],"key data",
|
|
|
+ remove_comments=True) if 'keys_from_file' in opts else []
|
|
|
|
|
|
-qmsg("Successfully opened transaction file '%s'" % tx_file)
|
|
|
+for tx_file in tx_files:
|
|
|
+ m = "" if 'tx_id' in opts else "transaction data"
|
|
|
+ tx_data = get_lines_from_file(tx_file,m)
|
|
|
|
|
|
-prompt = "View transaction data? (y)es, (N)o, (v)iew in pager"
|
|
|
-reply = prompt_and_get_char(prompt,"YyNnVv",enter_ok=True)
|
|
|
-if reply and reply in "YyVv":
|
|
|
- p = True if reply in "Vv" else False
|
|
|
- view_tx_data(c,inputs_data,tx_hex,b2m_map,metadata,pager=p)
|
|
|
+ metadata,tx_hex,inputs_data,b2m_map = parse_tx_data(tx_data,tx_file)
|
|
|
|
|
|
-sig_data = [
|
|
|
- {"txid":i['txid'],"vout":i['vout'],"scriptPubKey":i['scriptPubKey']}
|
|
|
- for i in inputs_data]
|
|
|
+ if 'tx_id' in opts:
|
|
|
+ msg(metadata[0])
|
|
|
+ sys.exit(0)
|
|
|
|
|
|
-if mmgen_addrs:
|
|
|
- ml = [i['account'].split()[0] for i in mmgen_addrs]
|
|
|
- keys += get_keys_for_mmgen_addrs(ml,infiles,seeds,opts)
|
|
|
+ if 'info' in opts:
|
|
|
+ view_tx_data(c,inputs_data,tx_hex,b2m_map,metadata)
|
|
|
+ sys.exit(0)
|
|
|
|
|
|
- if 'use_wallet_dat' in opts:
|
|
|
- sig_tx = sign_tx_with_bitcoind_wallet(c,tx_hex,sig_data,keys,opts)
|
|
|
- else:
|
|
|
- sig_tx = sign_transaction(c,tx_hex,sig_data,keys)
|
|
|
-elif other_addrs:
|
|
|
- if keys:
|
|
|
- sig_tx = sign_transaction(c,tx_hex,sig_data,keys)
|
|
|
+# Are inputs mmgen addresses?
|
|
|
+ mmgen_addrs = [i for i in inputs_data if parse_mmgen_label(i['account'])[0]]
|
|
|
+ other_addrs = [i for i in inputs_data if not parse_mmgen_label(i['account'])[0]]
|
|
|
+
|
|
|
+ keys = keys_from_file
|
|
|
+
|
|
|
+ if other_addrs and not keys and not 'use_wallet_dat' in opts:
|
|
|
+ missing_keys_errormsg(other_addrs)
|
|
|
+ sys.exit(2)
|
|
|
+
|
|
|
+ if other_addrs and keys and not 'skip_key_preverify' in opts:
|
|
|
+ a = [i['address'] for i in other_addrs]
|
|
|
+ preverify_keys(a, keys)
|
|
|
+ opts['skip_key_preverify'] = True
|
|
|
+
|
|
|
+ check_mmgen_to_btc_addr_mappings(inputs_data,b2m_map,infiles,seeds,opts)
|
|
|
+
|
|
|
+ if len(tx_files) > 1: msg("\nTransaction #%s:" % (tx_files.index(tx_file)+1))
|
|
|
+ qmsg("Successfully opened transaction file '%s'" % tx_file)
|
|
|
+
|
|
|
+ prompt = "View transaction data? (y)es, (N)o, (v)iew in pager"
|
|
|
+ reply = prompt_and_get_char(prompt,"YyNnVv",enter_ok=True)
|
|
|
+ if reply and reply in "YyVv":
|
|
|
+ p = True if reply in "Vv" else False
|
|
|
+ view_tx_data(c,inputs_data,tx_hex,b2m_map,metadata,pager=p)
|
|
|
+
|
|
|
+ sig_data = [
|
|
|
+ {"txid":i['txid'],"vout":i['vout'],"scriptPubKey":i['scriptPubKey']}
|
|
|
+ for i in inputs_data]
|
|
|
+
|
|
|
+ if mmgen_addrs:
|
|
|
+ ml = [i['account'].split()[0] for i in mmgen_addrs]
|
|
|
+ keys += get_keys_for_mmgen_addrs(ml,infiles,seeds,opts)
|
|
|
+
|
|
|
+ if 'use_wallet_dat' in opts:
|
|
|
+ sig_tx = sign_tx_with_bitcoind_wallet(c,tx_hex,sig_data,keys,opts)
|
|
|
+ else:
|
|
|
+ sig_tx = sign_transaction(c,tx_hex,sig_data,keys)
|
|
|
+ elif other_addrs:
|
|
|
+ if keys:
|
|
|
+ sig_tx = sign_transaction(c,tx_hex,sig_data,keys)
|
|
|
+ else:
|
|
|
+ sig_tx = sign_tx_with_bitcoind_wallet(c,tx_hex,sig_data,keys,opts)
|
|
|
+
|
|
|
+ if sig_tx['complete']:
|
|
|
+ prompt = "OK\nSave signed transaction?"
|
|
|
+ if user_confirm(prompt,default_yes=True):
|
|
|
+ print_signed_tx_to_file(tx_hex,sig_tx['hex'],metadata,opts)
|
|
|
else:
|
|
|
- sig_tx = sign_tx_with_bitcoind_wallet(c,tx_hex,sig_data,keys,opts)
|
|
|
-
|
|
|
-if sig_tx['complete']:
|
|
|
- prompt = "OK\nSave signed transaction?"
|
|
|
- if user_confirm(prompt,default_yes=True):
|
|
|
- print_signed_tx_to_file(tx_hex,sig_tx['hex'],metadata,opts)
|
|
|
-else:
|
|
|
- msg("failed\nSome keys were missing. Transaction could not be signed.")
|
|
|
- sys.exit(3)
|
|
|
+ msg("failed\nSome keys were missing. Transaction could not be signed.")
|
|
|
+ sys.exit(3)
|