File tree Expand file tree Collapse file tree 2 files changed +19
-0
lines changed Expand file tree Collapse file tree 2 files changed +19
-0
lines changed Original file line number Diff line number Diff line change @@ -71,6 +71,14 @@ func (s SatPerKWeight) FeeForWeight(wu lntypes.WeightUnit) btcutil.Amount {
71
71
return btcutil .Amount (s ) * btcutil .Amount (wu ) / 1000
72
72
}
73
73
74
+ // FeeForWeightRoundUp calculates the fee resulting from this fee rate and the
75
+ // given weight in weight units (wu), rounding up to the nearest satoshi.
76
+ func (s SatPerKWeight ) FeeForWeightRoundUp (
77
+ wu lntypes.WeightUnit ) btcutil.Amount {
78
+
79
+ return (btcutil .Amount (s )* btcutil .Amount (wu ) + 999 ) / 1000
80
+ }
81
+
74
82
// FeeForVByte calculates the fee resulting from this fee rate and the given
75
83
// size in vbytes (vb).
76
84
func (s SatPerKWeight ) FeeForVByte (vb lntypes.VByte ) btcutil.Amount {
Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ package chainfee
3
3
import (
4
4
"testing"
5
5
6
+ "github.com/lightningnetwork/lnd/lntypes"
6
7
"github.com/stretchr/testify/require"
7
8
)
8
9
@@ -20,3 +21,13 @@ func TestSatPerVByteConversion(t *testing.T) {
20
21
// 1 sat/vb should be equal to 250 sat/kw.
21
22
require .Equal (t , SatPerKWeight (250 ), rate .FeePerKWeight ())
22
23
}
24
+
25
+ // TestFeeForWeightRoundUp checks that the FeeForWeightRoundUp method correctly
26
+ // rounds up the fee for a given weight.
27
+ func TestFeeForWeightRoundUp (t * testing.T ) {
28
+ feeRate := SatPerVByte (1 ).FeePerKWeight ()
29
+ txWeight := lntypes .WeightUnit (674 ) // 674 weight units is 168.5 vb.
30
+
31
+ require .EqualValues (t , 168 , feeRate .FeeForWeight (txWeight ))
32
+ require .EqualValues (t , 169 , feeRate .FeeForWeightRoundUp (txWeight ))
33
+ }
You can’t perform that action at this time.
0 commit comments