File tree Expand file tree Collapse file tree 2 files changed +47
-0
lines changed Expand file tree Collapse file tree 2 files changed +47
-0
lines changed Original file line number Diff line number Diff line change
1
+ package utils
2
+
3
+ import (
4
+ "github.com/btcsuite/btcd/btcutil"
5
+ "github.com/btcsuite/btcd/mempool"
6
+ "github.com/btcsuite/btcd/wire"
7
+ )
8
+
9
+ // DustLimitForPkScript returns the dust limit for a given pkScript. An output
10
+ // must be greater or equal to this value.
11
+ func DustLimitForPkScript (pkscript []byte ) btcutil.Amount {
12
+ return btcutil .Amount (mempool .GetDustThreshold (& wire.TxOut {
13
+ PkScript : pkscript ,
14
+ }))
15
+ }
Original file line number Diff line number Diff line change
1
+ package utils
2
+
3
+ import (
4
+ "testing"
5
+
6
+ "github.com/lightningnetwork/lnd/input"
7
+ "github.com/lightningnetwork/lnd/lnwallet"
8
+ "github.com/stretchr/testify/require"
9
+ )
10
+
11
+ type pkScriptGetter func ([]byte ) ([]byte , error )
12
+
13
+ // TestDustLimitForPkScript checks that the dust limit for a given script size
14
+ // matches the calculation in lnwallet.DustLimitForSize.
15
+ func TestDustLimitForPkScript (t * testing.T ) {
16
+ getScripts := map [int ]pkScriptGetter {
17
+ input .P2WPKHSize : input .WitnessPubKeyHash ,
18
+ input .P2WSHSize : input .WitnessScriptHash ,
19
+ input .P2SHSize : input .GenerateP2SH ,
20
+ input .P2PKHSize : input .GenerateP2PKH ,
21
+ }
22
+
23
+ for scriptSize , getPkScript := range getScripts {
24
+ pkScript , err := getPkScript ([]byte {})
25
+ require .NoError (t , err , "failed to generate pkScript" )
26
+
27
+ require .Equal (
28
+ t , lnwallet .DustLimitForSize (scriptSize ),
29
+ DustLimitForPkScript (pkScript ),
30
+ )
31
+ }
32
+ }
You can’t perform that action at this time.
0 commit comments