mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-09-14 10:29:29 +02:00
chainfee: add new unit SatPerVByte
This commit is contained in:
committed by
Olaoluwa Osuntokun
parent
60a44c3f53
commit
bea0ffdf81
@@ -18,6 +18,24 @@ const (
|
|||||||
AbsoluteFeePerKwFloor SatPerKWeight = 250
|
AbsoluteFeePerKwFloor SatPerKWeight = 250
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// SatPerVByte represents a fee rate in sat/vbyte.
|
||||||
|
type SatPerVByte btcutil.Amount
|
||||||
|
|
||||||
|
// FeePerKWeight converts the current fee rate from sat/vb to sat/kw.
|
||||||
|
func (s SatPerVByte) FeePerKWeight() SatPerKWeight {
|
||||||
|
return SatPerKWeight(s * 1000 / blockchain.WitnessScaleFactor)
|
||||||
|
}
|
||||||
|
|
||||||
|
// FeePerKVByte converts the current fee rate from sat/vb to sat/kvb.
|
||||||
|
func (s SatPerVByte) FeePerKVByte() SatPerKVByte {
|
||||||
|
return SatPerKVByte(s * 1000)
|
||||||
|
}
|
||||||
|
|
||||||
|
// String returns a human-readable string of the fee rate.
|
||||||
|
func (s SatPerVByte) String() string {
|
||||||
|
return fmt.Sprintf("%v sat/vb", int64(s))
|
||||||
|
}
|
||||||
|
|
||||||
// SatPerKVByte represents a fee rate in sat/kb.
|
// SatPerKVByte represents a fee rate in sat/kb.
|
||||||
type SatPerKVByte btcutil.Amount
|
type SatPerKVByte btcutil.Amount
|
||||||
|
|
||||||
|
22
lnwallet/chainfee/rates_test.go
Normal file
22
lnwallet/chainfee/rates_test.go
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
package chainfee
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
)
|
||||||
|
|
||||||
|
// TestSatPerVByteConversion checks that the conversion from sat/vb to either
|
||||||
|
// sat/kw or sat/kvb is correct.
|
||||||
|
func TestSatPerVByteConversion(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
// Create a test fee rate of 1 sat/vb.
|
||||||
|
rate := SatPerVByte(1)
|
||||||
|
|
||||||
|
// 1 sat/vb should be equal to 1000 sat/kvb.
|
||||||
|
require.Equal(t, SatPerKVByte(1000), rate.FeePerKVByte())
|
||||||
|
|
||||||
|
// 1 sat/vb should be equal to 250 sat/kw.
|
||||||
|
require.Equal(t, SatPerKWeight(250), rate.FeePerKWeight())
|
||||||
|
}
|
Reference in New Issue
Block a user