File tree Expand file tree Collapse file tree 2 files changed +46
-0
lines changed
Expand file tree Collapse file tree 2 files changed +46
-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+ "github.com/lightningnetwork/lnd/input"
5+ "github.com/lightningnetwork/lnd/lnwallet"
6+ "github.com/stretchr/testify/require"
7+ "testing"
8+ )
9+
10+ type pkScriptGetter func ([]byte ) ([]byte , error )
11+
12+ // TestDustLimitForPkScript checks that the dust limit for a given script size
13+ // matches the calculation in lnwallet.DustLimitForSize.
14+ func TestDustLimitForPkScript (t * testing.T ) {
15+ getScripts := map [int ]pkScriptGetter {
16+ input .P2WPKHSize : input .WitnessPubKeyHash ,
17+ input .P2WSHSize : input .WitnessScriptHash ,
18+ input .P2SHSize : input .GenerateP2SH ,
19+ input .P2PKHSize : input .GenerateP2PKH ,
20+ }
21+
22+ for scriptSize , getPkScript := range getScripts {
23+ pkScript , err := getPkScript ([]byte {})
24+ require .NoError (t , err , "failed to generate pkScript" )
25+
26+ require .Equal (
27+ t , lnwallet .DustLimitForSize (scriptSize ),
28+ DustLimitForPkScript (pkScript ),
29+ )
30+ }
31+ }
You can’t perform that action at this time.
0 commit comments