1
0

logging: basics

This commit is contained in:
SomberNight
2019-04-26 18:52:26 +02:00
parent 4d64e132d7
commit 3385a94753
68 changed files with 681 additions and 563 deletions

View File

@@ -28,7 +28,8 @@ from typing import NamedTuple, List
from .bitcoin import sha256, COIN, TYPE_ADDRESS, is_address
from .transaction import Transaction, TxOutput
from .util import NotEnoughFunds, PrintError
from .util import NotEnoughFunds
from .logging import Logger
# A simple deterministic PRNG. Used to deterministically shuffle a
@@ -92,10 +93,13 @@ def strip_unneeded(bkts, sufficient_funds):
raise Exception("keeping all buckets is still not enough")
class CoinChooserBase(PrintError):
class CoinChooserBase(Logger):
enable_output_value_rounding = False
def __init__(self):
Logger.__init__(self)
def keys(self, coins):
raise NotImplementedError
@@ -187,9 +191,9 @@ class CoinChooserBase(PrintError):
amounts = [amount for amount in amounts if amount >= dust_threshold]
change = [TxOutput(TYPE_ADDRESS, addr, amount)
for addr, amount in zip(change_addrs, amounts)]
self.print_error('change:', change)
self.logger.info(f'change: {change}')
if dust:
self.print_error('not keeping dust', dust)
self.logger.info(f'not keeping dust {dust}')
return change
def make_tx(self, coins, inputs, outputs, change_addrs, fee_estimator,
@@ -268,8 +272,8 @@ class CoinChooserBase(PrintError):
change = self.change_outputs(tx, change_addrs, fee, dust_threshold)
tx.add_outputs(change)
self.print_error("using %d inputs" % len(tx.inputs()))
self.print_error("using buckets:", [bucket.desc for bucket in buckets])
self.logger.info(f"using {len(tx.inputs())} inputs")
self.logger.info(f"using buckets: {[bucket.desc for bucket in buckets]}")
return tx
@@ -357,8 +361,8 @@ class CoinChooserRandom(CoinChooserBase):
candidates = self.bucket_candidates_prefer_confirmed(buckets, sufficient_funds)
penalties = [penalty_func(cand) for cand in candidates]
winner = candidates[penalties.index(min(penalties))]
self.print_error("Bucket sets:", len(buckets))
self.print_error("Winning penalty:", min(penalties))
self.logger.info(f"Bucket sets: {len(buckets)}")
self.logger.info(f"Winning penalty: {min(penalties)}")
return winner
class CoinChooserPrivacy(CoinChooserRandom):