use np2wsh for loop in htlc

This commit is contained in:
Joost Jager 2019-04-04 12:20:45 +02:00
parent e765baa1f9
commit 30c7d71c57
No known key found for this signature in database
GPG key ID: A61B9D4C393C59C7
10 changed files with 219 additions and 113 deletions

View file

@ -36,6 +36,7 @@ func (s *Sweeper) CreateSweepTx(
// Add HTLC input.
sweepTx.AddTxIn(&wire.TxIn{
PreviousOutPoint: htlcOutpoint,
SignatureScript: htlc.SigScript,
})
// Add output for the destination address.
@ -85,9 +86,12 @@ func (s *Sweeper) CreateSweepTx(
return sweepTx, nil
}
// GetSweepFee calculates the required tx fee.
// GetSweepFee calculates the required tx fee to spend to P2WKH. It takes a
// function that is expected to add the weight of the input to the weight
// estimator.
func (s *Sweeper) GetSweepFee(ctx context.Context,
htlcSuccessWitnessSize int, sweepConfTarget int32) (
addInputEstimate func(*input.TxWeightEstimator),
sweepConfTarget int32) (
btcutil.Amount, error) {
// Get fee estimate from lnd.
@ -99,7 +103,7 @@ func (s *Sweeper) GetSweepFee(ctx context.Context,
// Calculate weight for this tx.
var weightEstimate input.TxWeightEstimator
weightEstimate.AddP2WKHOutput()
weightEstimate.AddWitnessInput(htlcSuccessWitnessSize)
addInputEstimate(&weightEstimate)
weight := weightEstimate.Weight()
return feeRate.FeeForWeight(int64(weight)), nil