lnwallet: move FeeEstimator into distinct file
In this commit, we move the FeeEstimator interface into a distinct file as follow up commits will begin to flesh out the interface with additional implementations.
This commit is contained in:
parent
56c5959ee5
commit
6ef2770e57
40
lnwallet/fee_estimator.go
Normal file
40
lnwallet/fee_estimator.go
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
package lnwallet
|
||||||
|
|
||||||
|
// 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).
|
||||||
|
type FeeEstimator interface {
|
||||||
|
// EstimateFeePerByte takes in a target for the number of blocks until
|
||||||
|
// an initial confirmation and returns the estimated fee expressed in
|
||||||
|
// satoshis/byte.
|
||||||
|
EstimateFeePerByte(numBlocks uint32) uint64
|
||||||
|
|
||||||
|
// EstimateFeePerWeight takes in a target for the number of blocks
|
||||||
|
// until an initial confirmation and returns the estimated fee
|
||||||
|
// expressed in satoshis/weight.
|
||||||
|
EstimateFeePerWeight(numBlocks uint32) uint64
|
||||||
|
}
|
||||||
|
|
||||||
|
// StaticFeeEstimator will return a static value for all fee calculation
|
||||||
|
// requests. It is designed to be replaced by a proper fee calculation
|
||||||
|
// implementation.
|
||||||
|
type StaticFeeEstimator struct {
|
||||||
|
// FeeRate is the static fee rate in satoshis-per-byte that will be
|
||||||
|
// returned by this fee estimator. Queries for the fee rate in weight
|
||||||
|
// units will be scaled accordingly.
|
||||||
|
FeeRate uint64
|
||||||
|
}
|
||||||
|
|
||||||
|
// EstimateFeePerByte will return a static value for fee calculations.
|
||||||
|
func (e StaticFeeEstimator) EstimateFeePerByte(numBlocks uint32) uint64 {
|
||||||
|
return e.FeeRate
|
||||||
|
}
|
||||||
|
|
||||||
|
// EstimateFeePerWeight will return a static value for fee calculations.
|
||||||
|
func (e StaticFeeEstimator) EstimateFeePerWeight(numBlocks uint32) uint64 {
|
||||||
|
return e.FeeRate / 4
|
||||||
|
}
|
||||||
|
|
||||||
|
// A compile-time assertion to ensure that StaticFeeEstimator implements the
|
||||||
|
// FeeEstimator interface.
|
||||||
|
var _ FeeEstimator = (*StaticFeeEstimator)(nil)
|
@ -268,26 +268,6 @@ type MessageSigner interface {
|
|||||||
SignMessage(pubKey *btcec.PublicKey, msg []byte) (*btcec.Signature, error)
|
SignMessage(pubKey *btcec.PublicKey, msg []byte) (*btcec.Signature, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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).
|
|
||||||
type FeeEstimator interface {
|
|
||||||
// EstimateFeePerByte takes in a target for the number of blocks until
|
|
||||||
// an initial confirmation and returns the estimated fee expressed in
|
|
||||||
// satoshis/byte.
|
|
||||||
EstimateFeePerByte(numBlocks uint32) uint64
|
|
||||||
|
|
||||||
// EstimateFeePerWeight takes in a target for the number of blocks until
|
|
||||||
// an initial confirmation and returns the estimated fee expressed in
|
|
||||||
// satoshis/weight.
|
|
||||||
EstimateFeePerWeight(numBlocks uint32) uint64
|
|
||||||
|
|
||||||
// EstimateConfirmation will return the number of blocks expected for a
|
|
||||||
// transaction to be confirmed given a fee rate in satoshis per
|
|
||||||
// byte.
|
|
||||||
EstimateConfirmation(satPerByte int64) uint32
|
|
||||||
}
|
|
||||||
|
|
||||||
// WalletDriver represents a "driver" for a particular concrete
|
// WalletDriver represents a "driver" for a particular concrete
|
||||||
// WalletController implementation. A driver is identified by a globally unique
|
// WalletController implementation. A driver is identified by a globally unique
|
||||||
// string identifier along with a 'New()' method which is responsible for
|
// string identifier along with a 'New()' method which is responsible for
|
||||||
|
@ -1445,28 +1445,3 @@ func coinSelect(feeRatePerWeight uint64, amt btcutil.Amount,
|
|||||||
return selectedUtxos, changeAmt, nil
|
return selectedUtxos, changeAmt, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// StaticFeeEstimator will return a static value for all fee calculation
|
|
||||||
// requests. It is designed to be replaced by a proper fee calculation
|
|
||||||
// implementation.
|
|
||||||
type StaticFeeEstimator struct {
|
|
||||||
FeeRate uint64
|
|
||||||
Confirmation uint32
|
|
||||||
}
|
|
||||||
|
|
||||||
// EstimateFeePerByte will return a static value for fee calculations.
|
|
||||||
func (e StaticFeeEstimator) EstimateFeePerByte(numBlocks uint32) uint64 {
|
|
||||||
return e.FeeRate
|
|
||||||
}
|
|
||||||
|
|
||||||
// EstimateFeePerWeight will return a static value for fee calculations.
|
|
||||||
func (e StaticFeeEstimator) EstimateFeePerWeight(numBlocks uint32) uint64 {
|
|
||||||
return e.FeeRate / 4
|
|
||||||
}
|
|
||||||
|
|
||||||
// EstimateConfirmation will return a static value representing the estimated
|
|
||||||
// number of blocks that will be required to confirm a transaction for the
|
|
||||||
// given fee rate.
|
|
||||||
func (e StaticFeeEstimator) EstimateConfirmation(satPerByte int64) uint32 {
|
|
||||||
return e.Confirmation
|
|
||||||
}
|
|
||||||
|
Loading…
Reference in New Issue
Block a user