From 138d9b68f0a2ff93c5ef61b8382d662a834ec0f1 Mon Sep 17 00:00:00 2001 From: Wilmer Paulino Date: Tue, 30 Apr 2019 16:06:19 -0700 Subject: [PATCH] lnwallet+sweep: add String method to FeePreference --- lnwallet/fee_estimator.go | 10 ++++++++++ sweep/walletsweep.go | 8 ++++++++ 2 files changed, 18 insertions(+) diff --git a/lnwallet/fee_estimator.go b/lnwallet/fee_estimator.go index 65cbef04..bda93d63 100644 --- a/lnwallet/fee_estimator.go +++ b/lnwallet/fee_estimator.go @@ -54,6 +54,11 @@ func (s SatPerKVByte) FeePerKWeight() SatPerKWeight { return SatPerKWeight(s / blockchain.WitnessScaleFactor) } +// String returns a human-readable string of the fee rate. +func (s SatPerKVByte) String() string { + return fmt.Sprintf("%v sat/kb", int64(s)) +} + // SatPerKWeight represents a fee rate in sat/kw. type SatPerKWeight btcutil.Amount @@ -69,6 +74,11 @@ func (s SatPerKWeight) FeePerKVByte() SatPerKVByte { return SatPerKVByte(s * blockchain.WitnessScaleFactor) } +// String returns a human-readable string of the fee rate. +func (s SatPerKWeight) String() string { + return fmt.Sprintf("%v sat/kw", int64(s)) +} + // FeeEstimator provides the ability to estimate on-chain transaction fees for // various combinations of transaction sizes and desired confirmation time // (measured by number of blocks). diff --git a/sweep/walletsweep.go b/sweep/walletsweep.go index 1abb6c48..19ffd986 100644 --- a/sweep/walletsweep.go +++ b/sweep/walletsweep.go @@ -30,6 +30,14 @@ type FeePreference struct { FeeRate lnwallet.SatPerKWeight } +// String returns a human-readable string of the fee preference. +func (p FeePreference) String() string { + if p.ConfTarget != 0 { + return fmt.Sprintf("%v blocks", p.ConfTarget) + } + return p.FeeRate.String() +} + // DetermineFeePerKw will determine the fee in sat/kw that should be paid given // an estimator, a confirmation target, and a manual value for sat/byte. A // value is chosen based on the two free parameters as one, or both of them can