Merge pull request #8067 from lightningnetwork/0-18-staging-rebased

branch: merge 0.18 staging branch into master
This commit is contained in:
Olaoluwa Osuntokun authored and GitHub committed 2023-10-09 11:20:11 -07:00
commit 4f346060df
110 files changed
+8138 -5454

No files matched your search

+18
View File
@@ -18,6 +18,24 @@ const (
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.
type SatPerKVByte btcutil.Amount
+22
View 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())
}