chanfunding: factor out sanity check for change that is dust

This commit is contained in:
Bjarne Magnussen 2021-04-11 21:38:42 +02:00
parent 59c40ec8b4
commit 6ab625d69b
No known key found for this signature in database
GPG Key ID: B0A9ADF6B24CE67F

@ -1,6 +1,7 @@
package chanfunding package chanfunding
import ( import (
"fmt"
"math" "math"
"github.com/btcsuite/btcd/btcec" "github.com/btcsuite/btcd/btcec"
@ -299,11 +300,18 @@ func (w *WalletAssembler) ProvisionChannel(r *Request) (Intent, error) {
} }
} }
// Sanity check: The addition of the outputs should not lead to the
// creation of dust.
if changeAmt != 0 && changeAmt <= w.cfg.DustLimit {
return fmt.Errorf("change amount(%v) after coin "+
"select is below dust limit(%v)", changeAmt,
w.cfg.DustLimit)
}
// Record any change output(s) generated as a result of the // Record any change output(s) generated as a result of the
// coin selection, but only if the addition of the output won't // coin selection.
// lead to the creation of dust.
var changeOutput *wire.TxOut var changeOutput *wire.TxOut
if changeAmt != 0 && changeAmt > w.cfg.DustLimit { if changeAmt != 0 {
changeAddr, err := r.ChangeAddr() changeAddr, err := r.ChangeAddr()
if err != nil { if err != nil {
return err return err