mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-01-19 05:45:21 +01:00
7dfe4018ce
This commit was previously split into the following parts to ease review: - 2d746f68: replace imports - 4008f0fd: use ecdsa.Signature - 849e33d1: remove btcec.S256() - b8f6ebbd: use v2 library correctly - fa80bca9: bump go modules
59 lines
1.8 KiB
Go
59 lines
1.8 KiB
Go
package chainfee
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/btcsuite/btcd/blockchain"
|
|
"github.com/btcsuite/btcd/btcutil"
|
|
)
|
|
|
|
const (
|
|
// FeePerKwFloor is the lowest fee rate in sat/kw that we should use for
|
|
// estimating transaction fees before signing.
|
|
FeePerKwFloor SatPerKWeight = 253
|
|
|
|
// AbsoluteFeePerKwFloor is the lowest fee rate in sat/kw of a
|
|
// transaction that we should ever _create_. This is the the equivalent
|
|
// of 1 sat/byte in sat/kw.
|
|
AbsoluteFeePerKwFloor SatPerKWeight = 250
|
|
)
|
|
|
|
// SatPerKVByte represents a fee rate in sat/kb.
|
|
type SatPerKVByte btcutil.Amount
|
|
|
|
// FeeForVSize calculates the fee resulting from this fee rate and the given
|
|
// vsize in vbytes.
|
|
func (s SatPerKVByte) FeeForVSize(vbytes int64) btcutil.Amount {
|
|
return btcutil.Amount(s) * btcutil.Amount(vbytes) / 1000
|
|
}
|
|
|
|
// FeePerKWeight converts the current fee rate from sat/kb to sat/kw.
|
|
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
|
|
|
|
// FeeForWeight calculates the fee resulting from this fee rate and the given
|
|
// weight in weight units (wu).
|
|
func (s SatPerKWeight) FeeForWeight(wu int64) btcutil.Amount {
|
|
// The resulting fee is rounded down, as specified in BOLT#03.
|
|
return btcutil.Amount(s) * btcutil.Amount(wu) / 1000
|
|
}
|
|
|
|
// FeePerKVByte converts the current fee rate from sat/kw to sat/kb.
|
|
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))
|
|
}
|