|
@@ -50,10 +50,17 @@ def connect_to_bitcoind():
|
|
|
return c
|
|
|
|
|
|
|
|
|
+<<<<<<< HEAD
|
|
|
def remove_exponent(d):
|
|
|
'''Remove exponent and trailing zeros.
|
|
|
'''
|
|
|
return d.quantize(Decimal(1)) if d == d.to_integral() else d.normalize()
|
|
|
+=======
|
|
|
+def trim_exponent(d):
|
|
|
+ '''Remove exponent and trailing zeros.
|
|
|
+ '''
|
|
|
+ return d.quantize(Decimal(1)) if d == d.to_integral() else d.normalize()
|
|
|
+>>>>>>> my
|
|
|
|
|
|
def check_address(rcpt_address):
|
|
|
from mmgen.bitcoin import verify_addr
|
|
@@ -73,7 +80,11 @@ def check_btc_amt(send_amt):
|
|
|
msg("%s: Too many decimal places in amount" % send_amt)
|
|
|
sys.exit(3)
|
|
|
|
|
|
+<<<<<<< HEAD
|
|
|
return remove_exponent(retval)
|
|
|
+=======
|
|
|
+ return trim_exponent(retval)
|
|
|
+>>>>>>> my
|
|
|
|
|
|
|
|
|
def get_cfg_options(cfg_keys):
|
|
@@ -109,15 +120,22 @@ def print_tx_to_file(tx,sel_unspent,send_amt,opts):
|
|
|
outfile = "%s[%s].tx" % (tx_id,send_amt)
|
|
|
if 'outdir' in opts:
|
|
|
outfile = "%s/%s" % (opts['outdir'], outfile)
|
|
|
+<<<<<<< HEAD
|
|
|
input_data = sel_unspent
|
|
|
data = "%s\n%s\n%s\n%s\n" % (
|
|
|
make_timestamp(), tx, repr(sig_data),
|
|
|
+=======
|
|
|
+ metadata = "%s %s %s" % (tx_id, send_amt, make_timestamp())
|
|
|
+ data = "%s\n%s\n%s\n%s\n" % (
|
|
|
+ metadata, tx, repr(sig_data),
|
|
|
+>>>>>>> my
|
|
|
repr([i.__dict__ for i in sel_unspent])
|
|
|
)
|
|
|
write_to_file(outfile,data,confirm=False)
|
|
|
msg("Transaction data saved to file '%s'" % outfile)
|
|
|
|
|
|
|
|
|
+<<<<<<< HEAD
|
|
|
def print_signed_tx_to_file(tx,sig_tx,opts):
|
|
|
tx_id = make_chksum_8(unhexlify(tx))
|
|
|
outfile = "%s.txsig" % tx_id
|
|
@@ -132,6 +150,26 @@ def print_sent_tx_to_file(tx):
|
|
|
write_to_file(outfile,tx+"\n",confirm=False)
|
|
|
msg("Transaction ID saved to file '%s'" % outfile)
|
|
|
|
|
|
+=======
|
|
|
+def print_signed_tx_to_file(tx,sig_tx,metadata,opts):
|
|
|
+ tx_id = make_chksum_8(unhexlify(tx))
|
|
|
+ outfile = "{}[{}].txsig".format(*metadata[:2])
|
|
|
+ if 'outdir' in opts:
|
|
|
+ outfile = "%s/%s" % (opts['outdir'], outfile)
|
|
|
+ data = "%s\n%s\n" % (" ".join(metadata),sig_tx)
|
|
|
+ write_to_file(outfile,data,confirm=False)
|
|
|
+ msg("Signed transaction saved to file '%s'" % outfile)
|
|
|
+
|
|
|
+
|
|
|
+def print_sent_tx_to_file(tx,metadata,opts):
|
|
|
+ outfile = "{}[{}].txout".format(*metadata[:2])
|
|
|
+ if 'outdir' in opts:
|
|
|
+ outfile = "%s/%s" % (opts['outdir'], outfile)
|
|
|
+ write_to_file(outfile,tx+"\n",confirm=False)
|
|
|
+ msg("Transaction ID saved to file '%s'" % outfile)
|
|
|
+
|
|
|
+
|
|
|
+>>>>>>> my
|
|
|
def sort_and_view(unspent):
|
|
|
|
|
|
def s_amt(a,b): return cmp(a.amount,b.amount)
|
|
@@ -140,10 +178,19 @@ def sort_and_view(unspent):
|
|
|
def s_addr(a,b): return cmp(a.address,b.address)
|
|
|
def s_age(a,b): return cmp(b.confirmations,a.confirmations)
|
|
|
|
|
|
+<<<<<<< HEAD
|
|
|
fs = "%-4s %-11s %-2s %-34s %13s"
|
|
|
sort,group,reverse = "",False,False
|
|
|
|
|
|
from copy import deepcopy
|
|
|
+=======
|
|
|
+ fs = " %-4s %-11s %-2s %-34s %13s %-s"
|
|
|
+ fs_hdr = " %-4s %-11s %-4s %-35s %-9s %-s"
|
|
|
+ sort,group,reverse = "",False,False
|
|
|
+
|
|
|
+ from copy import deepcopy
|
|
|
+ msg("")
|
|
|
+>>>>>>> my
|
|
|
while True:
|
|
|
out = deepcopy(unspent)
|
|
|
for i in out: i.skip = ""
|
|
@@ -156,11 +203,16 @@ def sort_and_view(unspent):
|
|
|
out[n+1].skip = "t"
|
|
|
|
|
|
output = []
|
|
|
+<<<<<<< HEAD
|
|
|
output.append("Sort order: %s%s%s" % (
|
|
|
+=======
|
|
|
+ output.append("UNSPENT OUTPUTS (sort order: %s%s%s)" % (
|
|
|
+>>>>>>> my
|
|
|
"reverse " if reverse else "",
|
|
|
sort if sort else "None",
|
|
|
" (grouped)" if group and (sort == "address" or sort == "txid") else ""
|
|
|
))
|
|
|
+<<<<<<< HEAD
|
|
|
output.append(fs % ("Num","TX id","Vout","Address","Amount "))
|
|
|
|
|
|
for n,i in enumerate(out):
|
|
@@ -170,6 +222,19 @@ def sort_and_view(unspent):
|
|
|
txid = " |---" if i.skip == "t" else i.txid[:8]+"..."
|
|
|
|
|
|
output.append(fs % (str(n+1)+")", txid,i.vout,addr,amt+(" "*fill)))
|
|
|
+=======
|
|
|
+ output.append(fs_hdr % ("Num","TX id","Vout","Address","Amount",
|
|
|
+ "Age (days)"))
|
|
|
+
|
|
|
+ for n,i in enumerate(out):
|
|
|
+ amt = str(trim_exponent(i.amount))
|
|
|
+ fill = 8 - len(amt.split(".")[-1]) if "." in amt else 9
|
|
|
+ addr = " |" + "-"*32 if i.skip == "d" else i.address
|
|
|
+ txid = " |---" if i.skip == "t" else i.txid[:8]+"..."
|
|
|
+ days = int(i.confirmations * mins_per_block / (60*24))
|
|
|
+
|
|
|
+ output.append(fs % (str(n+1)+")", txid,i.vout,addr,amt+(" "*fill),days))
|
|
|
+>>>>>>> my
|
|
|
|
|
|
while True:
|
|
|
reply = get_char("\n".join(output) +
|
|
@@ -194,47 +259,82 @@ Sort options: [t]xid, [a]mount, a[d]dress, [A]ge, [r]everse, [g]roup
|
|
|
return unspent
|
|
|
|
|
|
|
|
|
+<<<<<<< HEAD
|
|
|
def view_tx_data(c,inputs_data,tx_hex,timestamp=""):
|
|
|
+=======
|
|
|
+def view_tx_data(c,inputs_data,tx_hex,metadata=[]):
|
|
|
+>>>>>>> my
|
|
|
|
|
|
td = c.decoderawtransaction(tx_hex)
|
|
|
|
|
|
msg("TRANSACTION DATA:\n")
|
|
|
|
|
|
+<<<<<<< HEAD
|
|
|
if timestamp: msg("Timestamp: %s\n" % timestamp)
|
|
|
+=======
|
|
|
+ if metadata: msg(
|
|
|
+ "Header: [ID: {}] [Amount: {} BTC] [Time: {}]\n".format(*metadata))
|
|
|
+>>>>>>> my
|
|
|
|
|
|
msg("Inputs:")
|
|
|
total_in = 0
|
|
|
for n,i in enumerate(td['vin']):
|
|
|
for j in inputs_data:
|
|
|
if j['txid'] == i['txid'] and j['vout'] == i['vout']:
|
|
|
+<<<<<<< HEAD
|
|
|
days = j['confirmations'] * mins_per_block / (60*24)
|
|
|
total_in += j['amount']
|
|
|
msg("""
|
|
|
%-3s tx,vout: %s,%s
|
|
|
+=======
|
|
|
+ days = int(j['confirmations'] * mins_per_block / (60*24))
|
|
|
+ total_in += j['amount']
|
|
|
+ msg(" " + """
|
|
|
+%-2s tx,vout: %s,%s
|
|
|
+>>>>>>> my
|
|
|
address: %s
|
|
|
amount: %s BTC
|
|
|
confirmations: %s (around %s days)
|
|
|
""".strip() %
|
|
|
(n+1,i['txid'],i['vout'],j['address'],
|
|
|
+<<<<<<< HEAD
|
|
|
remove_exponent(j['amount']),j['confirmations'],days)+"\n")
|
|
|
break
|
|
|
|
|
|
msg("Total input: %s BTC\n" % remove_exponent(total_in))
|
|
|
+=======
|
|
|
+ trim_exponent(j['amount']),j['confirmations'],days)+"\n")
|
|
|
+ break
|
|
|
+
|
|
|
+ msg("Total input: %s BTC\n" % trim_exponent(total_in))
|
|
|
+>>>>>>> my
|
|
|
|
|
|
total_out = 0
|
|
|
msg("Outputs:")
|
|
|
for n,i in enumerate(td['vout']):
|
|
|
total_out += i['value']
|
|
|
+<<<<<<< HEAD
|
|
|
msg("""
|
|
|
%-3s address: %s
|
|
|
+=======
|
|
|
+ msg(" " + """
|
|
|
+%-2s address: %s
|
|
|
+>>>>>>> my
|
|
|
amount: %s BTC
|
|
|
""".strip() % (
|
|
|
n,
|
|
|
i['scriptPubKey']['addresses'][0],
|
|
|
+<<<<<<< HEAD
|
|
|
remove_exponent(i['value']))
|
|
|
+ "\n")
|
|
|
msg("Total output: %s BTC" % remove_exponent(total_out))
|
|
|
msg("TX fee: %s BTC\n" % remove_exponent(total_in-total_out))
|
|
|
+=======
|
|
|
+ trim_exponent(i['value']))
|
|
|
+ + "\n")
|
|
|
+ msg("Total output: %s BTC" % trim_exponent(total_out))
|
|
|
+ msg("TX fee: %s BTC\n" % trim_exponent(total_in-total_out))
|
|
|
+>>>>>>> my
|
|
|
|
|
|
|
|
|
def parse_tx_data(tx_data):
|
|
@@ -243,24 +343,47 @@ def parse_tx_data(tx_data):
|
|
|
msg("'%s': not a transaction file" % infile)
|
|
|
sys.exit(2)
|
|
|
|
|
|
+<<<<<<< HEAD
|
|
|
try: unhexlify(tx_data[1])
|
|
|
except:
|
|
|
msg("Transaction data is invalid")
|
|
|
+=======
|
|
|
+ err_fmt = "Transaction %s is invalid"
|
|
|
+
|
|
|
+ if len(tx_data[0].split()) != 3:
|
|
|
+ msg(err_fmt % "metadata")
|
|
|
+ sys.exit(2)
|
|
|
+
|
|
|
+ try: unhexlify(tx_data[1])
|
|
|
+ except:
|
|
|
+ msg(err_fmt % "hex data")
|
|
|
+>>>>>>> my
|
|
|
sys.exit(2)
|
|
|
|
|
|
try:
|
|
|
sig_data = eval(tx_data[2])
|
|
|
except:
|
|
|
+<<<<<<< HEAD
|
|
|
msg("Signature data is invalid")
|
|
|
+=======
|
|
|
+ msg(err_fmt % "signature data")
|
|
|
+>>>>>>> my
|
|
|
sys.exit(2)
|
|
|
|
|
|
try:
|
|
|
inputs_data = eval(tx_data[3])
|
|
|
except:
|
|
|
+<<<<<<< HEAD
|
|
|
msg("Inputs data is invalid")
|
|
|
sys.exit(2)
|
|
|
|
|
|
return tx_data[0],tx_data[1],sig_data,inputs_data
|
|
|
+=======
|
|
|
+ msg(err_fmt % "inputs data")
|
|
|
+ sys.exit(2)
|
|
|
+
|
|
|
+ return tx_data[0].split(),tx_data[1],sig_data,inputs_data
|
|
|
+>>>>>>> my
|
|
|
|
|
|
|
|
|
def select_outputs(unspent,prompt):
|