From 21a0e499cf1540d76fbe427e71faf4ebf5706c61 Mon Sep 17 00:00:00 2001 From: Adam Gibson Date: Tue, 7 Feb 2017 20:46:24 +0200 Subject: [PATCH] Human readable tumbler log entries --- jmclient/jmclient/__init__.py | 2 +- jmclient/jmclient/schedule.py | 10 ++++++++++ scripts/sendpayment.py | 2 ++ scripts/tumbler.py | 21 +++++++++++++++------ 4 files changed, 28 insertions(+), 7 deletions(-) diff --git a/jmclient/jmclient/__init__.py b/jmclient/jmclient/__init__.py index 1895f9b..fe98f71 100644 --- a/jmclient/jmclient/__init__.py +++ b/jmclient/jmclient/__init__.py @@ -31,7 +31,7 @@ from .podle import (set_commitment_file, get_commitment_file, PoDLE, generate_podle, get_podle_commitments, update_commitments) from .schedule import (get_schedule, get_tumble_schedule, schedule_to_text, - tweak_tumble_schedule) + tweak_tumble_schedule, human_readable_schedule_entry) from .commitment_utils import get_utxo_info, validate_utxo_data, quit # Set default logging handler to avoid "No handler found" warnings. diff --git a/jmclient/jmclient/schedule.py b/jmclient/jmclient/schedule.py index 435591a..51c8554 100644 --- a/jmclient/jmclient/schedule.py +++ b/jmclient/jmclient/schedule.py @@ -176,5 +176,15 @@ def tweak_tumble_schedule(options, schedule, last_completed): new_schedule[last_completed + 1 + len(tobedone) - 1][1] = 0 return new_schedule +def human_readable_schedule_entry(se, amt=None, destn=None): + hrs = [] + hrs.append("From mixdepth " + str(se[0])) + amt_info = str(amt) if amt else str(se[1]) + hrs.append("sends amount: " + amt_info + " satoshis") + dest_info = destn if destn else str(se[3]) + hrs.append("to destination address: " + dest_info) + hrs.append("after coinjoin with " + str(se[2]) + " counterparties.") + return ", ".join(hrs) + def schedule_to_text(schedule): return "\n".join([",".join([str(y) for y in x]) for x in schedule]) \ No newline at end of file diff --git a/scripts/sendpayment.py b/scripts/sendpayment.py index 3c7428d..0a4cf11 100644 --- a/scripts/sendpayment.py +++ b/scripts/sendpayment.py @@ -98,6 +98,8 @@ def main(): #of a single transaction sweeping = False if options.schedule == '': + #note that sendpayment doesn't support fractional amounts, fractions throw + #here. amount = int(args[1]) if amount == 0: sweeping = True diff --git a/scripts/tumbler.py b/scripts/tumbler.py index 41b1fa8..fd540a5 100644 --- a/scripts/tumbler.py +++ b/scripts/tumbler.py @@ -16,7 +16,7 @@ from jmclient import (Taker, load_program_config, get_schedule, weighted_order_c validate_address, jm_single, WalletError, Wallet, sync_wallet, get_tumble_schedule, RegtestBitcoinCoreInterface, estimate_tx_fee, - tweak_tumble_schedule) + tweak_tumble_schedule, human_readable_schedule_entry) from jmbase.support import get_log, debug_dump_object, get_password from cli_options import get_tumbler_parser @@ -79,11 +79,15 @@ def main(): def taker_finished(res, fromtx=False, waittime=0.0): if fromtx: if res: - tumble_log.info("Completed successfully.") - tumble_log.info("We sent: " + str(taker.cjamount) + \ - " satoshis to address: " + taker.my_cj_addr + \ - " from mixdepth: " + \ - str(taker.schedule[taker.schedule_index][0])) + tumble_log.info("Completed successfully this entry:") + #the log output depends on if it's a sweep, and if it's to INTERNAL + hrdestn = None + if taker.schedule[taker.schedule_index][3] == "INTERNAL": + hrdestn = taker.my_cj_addr + #Whether sweep or not, the amt is not in satoshis; use taker data + hramt = taker.cjamount + tumble_log.info(human_readable_schedule_entry( + taker.schedule[taker.schedule_index], hramt, hrdestn)) waiting_message = "Waiting for: " + str(waittime) + " seconds." tumble_log.info(waiting_message) sync_wallet(wallet, fast=options['fastsync']) @@ -111,6 +115,11 @@ def main(): log.info("Did not complete successfully, shutting down") else: log.info("All transactions completed correctly") + tumble_log.info("Completed successfully the last entry:") + #Whether sweep or not, the amt is not in satoshis; use taker data + hramt = taker.cjamount + tumble_log.info(human_readable_schedule_entry( + taker.schedule[taker.schedule_index], hramt)) reactor.stop() #to allow testing of confirm/unconfirm callback for multiple txs