Browse Source

Better handling of non-standard tx'es, less extra output for csv and

other small improvements
master
Kristaps Kaupe 5 years ago
parent
commit
f361c98dba
No known key found for this signature in database
GPG Key ID: 33E472FE870C7E5D
  1. 39
      jmclient/jmclient/wallet_utils.py

39
jmclient/jmclient/wallet_utils.py

@ -775,7 +775,7 @@ def wallet_fetch_history(wallet, options):
def print_row(index, time, tx_type, amount, delta, balance, cj_n,
total_fees, utxo_count, mixdepth_src, mixdepth_dst, txid):
data = [index, datetime.fromtimestamp(time).strftime("%Y-%m-%d %H:%M"),
tx_type, btc.sat_to_str(amount), btc.sat_to_str_p(delta),
tx_type, btc.sat_to_str(abs(amount)), btc.sat_to_str_p(delta),
btc.sat_to_str(balance), skip_n1(cj_n), sat_to_str_na(total_fees),
'% 3d' % utxo_count, skip_n1(mixdepth_src), skip_n1(mixdepth_dst)]
if options.verbosity % 2 == 0: data += [txid]
@ -787,7 +787,7 @@ def wallet_fetch_history(wallet, options):
'utxo-count', 'mixdepth-from', 'mixdepth-to']
if options.verbosity % 2 == 0: field_names += ['txid']
if options.csv:
jmprint('Bumping verbosity level to 4 due to --csv flag', "debug")
#jmprint('Bumping verbosity level to 4 due to --csv flag', "debug")
options.verbosity = 4
if options.verbosity > 0: jmprint(s().join(field_names), "info")
if options.verbosity <= 2: cj_batch = [0]*8 + [[]]*2
@ -888,22 +888,33 @@ def wallet_fetch_history(wallet, options):
fees = 0
delta_balance = our_output_value - our_input_value
mixdepth_src = wallet.get_script_mixdepth(list(our_input_scripts)[0])
elif len(our_input_scripts) > 0 and len(our_output_scripts) == 2:
#payment to self
elif len(our_input_scripts) > 0 and len(our_output_scripts) == 2 and is_coinjoin:
out_value = sum([output_script_values[a] for a in our_output_scripts])
if not is_coinjoin:
jmprint('this is wrong TODO handle non-coinjoin internal', "warning")
tx_type = 'cj internal'
amount = cj_amount
delta_balance = out_value - our_input_value
mixdepth_src = wallet.get_script_mixdepth(list(our_input_scripts)[0])
tx_type = 'cj internal'
cj_script = list(set([a for a, v in output_script_values.items()
if v == cj_amount]).intersection(our_output_scripts))[0]
mixdepth_dst = wallet.get_script_mixdepth(cj_script)
elif len(our_input_scripts) > 0 and len(our_output_scripts) == len(output_script_values):
out_value = sum([output_script_values[a] for a in our_output_scripts])
amount = sum([output_script_values[a] for a in our_output_scripts])
delta_balance = out_value - our_input_value
mixdepth_src = wallet.get_script_mixdepth(list(our_input_scripts)[0])
tx_type = 'internal '
mixdepth_dst = wallet.get_script_mixdepth(list(our_output_scripts)[0])
else:
tx_type = 'unknown type'
jmprint('our utxos: ' + str(len(our_input_scripts)) \
+ ' in, ' + str(len(our_output_scripts)) + ' out')
tx_type = 'unknown '
out_value = sum([output_script_values[a] for a in our_output_scripts])
amount = out_value
delta_balance = out_value - our_input_value
mixdepth_src = wallet.get_script_mixdepth(
list(our_input_scripts)[0])
mixdepth_dst = wallet.get_script_mixdepth(
list(our_output_scripts)[0])
#jmprint('our utxos: ' + str(len(our_input_scripts)) \
# + ' in, ' + str(len(our_output_scripts)) + ' out')
if is_confirmed:
balance += delta_balance
@ -925,7 +936,7 @@ def wallet_fetch_history(wallet, options):
cj_batch[7] += utxo_count
cj_batch[8] += [mixdepth_src]
cj_batch[9] += [mixdepth_dst]
elif tx_type != 'unknown type':
else:
if n > 0:
# print the previously-accumulated batch
print_row('N='+"%2d"%n, cj_batch[1]/n, 'cj batch ',
@ -937,8 +948,7 @@ def wallet_fetch_history(wallet, options):
print_row(index, blocktime, tx_type, amount,
delta_balance, balance, cj_n, fees, utxo_count,
mixdepth_src, mixdepth_dst, tx['txid'])
elif options.verbosity >= 5 or \
(options.verbosity >= 3 and tx_type != 'unknown type'):
elif options.verbosity >= 3:
print_row(index, blocktime, tx_type, amount,
delta_balance, balance, cj_n, fees, utxo_count,
mixdepth_src, mixdepth_dst, tx['txid'])
@ -959,6 +969,9 @@ def wallet_fetch_history(wallet, options):
cj_batch[3], cj_batch[4], cj_batch[5]/n, cj_batch[6],
cj_batch[7]/n, min(cj_batch[8]), max(cj_batch[9]), '...')
# don't display summaries if csv export
if options.csv:
return ''
bestblockhash = jm_single().bc_interface.get_best_block_hash()
now = jm_single().bc_interface.get_block_time(bestblockhash)

Loading…
Cancel
Save