cnct: reuse sweep tx logic for commit resolver

Removes duplicate sweep tx code from commit resolver
and delegates generation to UtxoSweeper in the sweep
package.
This commit is contained in:
Joost Jager
2018-09-26 09:46:48 -07:00
parent 7d69df77ed
commit c1d845aa0d
4 changed files with 23 additions and 42 deletions

View File

@@ -73,11 +73,17 @@ func (s *UtxoSweeper) CreateSweepTx(inputs []Input,
// outputs.
csvCount := 0
cltvCount := 0
unknownCount := 0
for i := range inputs {
input := inputs[i]
switch input.WitnessType() {
// Outputs on a remote commitment transaction that pay directly
// to us.
case lnwallet.CommitmentNoDelay:
weightEstimate.AddP2WKHInput()
// Outputs on a past commitment transaction that pay directly
// to us.
case lnwallet.CommitmentTimeLock:
@@ -113,8 +119,7 @@ func (s *UtxoSweeper) CreateSweepTx(inputs []Input,
cltvCount++
default:
// TODO: Also add non-timelocked outputs
unknownCount++
log.Warnf("kindergarten output in nursery store "+
"contains unexpected witness type: %v",
input.WitnessType())
@@ -123,7 +128,7 @@ func (s *UtxoSweeper) CreateSweepTx(inputs []Input,
}
log.Infof("Creating sweep transaction for %v inputs (%v CSV, %v CLTV)",
csvCount+cltvCount, csvCount, cltvCount)
len(inputs)-unknownCount, csvCount, cltvCount)
txWeight := int64(weightEstimate.Weight())
return s.populateSweepTx(txWeight, currentBlockHeight, inputs)