diff --git a/utxonursery.go b/utxonursery.go index 7a4fafba..7c2bc93b 100644 --- a/utxonursery.go +++ b/utxonursery.go @@ -261,7 +261,11 @@ func (u *utxoNursery) Stop() error { // before its funds will be available to be moved into the user's wallet. The // struct includes a witnessGenerator closure which will be used to generate // the witness required to sweep the output once it's mature. +// +// TODO(roasbeef): rename to immatureOutput? type kidOutput struct { + originChanPoint wire.OutPoint + amt btcutil.Amount outPoint wire.OutPoint @@ -286,7 +290,7 @@ type incubationRequest struct { // incubateOutputs sends a request to utxoNursery to incubate the outputs // defined within the summary of a closed channel. Individually, as all outputs // reach maturity they'll be swept back into the wallet. -func (u *utxoNursery) incubateOutputs(closeSummary *lnwallet.ForceCloseSummary) { +func (u *utxoNursery) IncubateOutputs(closeSummary *lnwallet.ForceCloseSummary) { var incReq incubationRequest // It could be that our to-self output was below the dust limit. In that @@ -295,6 +299,7 @@ func (u *utxoNursery) incubateOutputs(closeSummary *lnwallet.ForceCloseSummary) if closeSummary.SelfOutputSignDesc != nil { outputAmt := btcutil.Amount(closeSummary.SelfOutputSignDesc.Output.Value) selfOutput := &kidOutput{ + originChanPoint: closeSummary.ChanPoint, amt: outputAmt, outPoint: closeSummary.SelfOutpoint, blocksToMaturity: closeSummary.SelfOutputMaturity, @@ -769,6 +774,9 @@ func serializeKidOutput(w io.Writer, kid *kidOutput) error { if err := writeOutpoint(w, &kid.outPoint); err != nil { return err } + if err := writeOutpoint(w, &kid.originChanPoint); err != nil { + return err + } byteOrder.PutUint32(scratch[:4], kid.blocksToMaturity) if _, err := w.Write(scratch[:4]); err != nil { @@ -824,6 +832,9 @@ func deserializeKidOutput(r io.Reader) (*kidOutput, error) { if err := readOutpoint(io.LimitReader(r, 40), &kid.outPoint); err != nil { return nil, err } + if err := readOutpoint(io.LimitReader(r, 40), &kid.originChanPoint); err != nil { + return nil, err + } if _, err := r.Read(scratch[:4]); err != nil { return nil, err diff --git a/utxonursery_test.go b/utxonursery_test.go index f21fcc7b..9938ca90 100644 --- a/utxonursery_test.go +++ b/utxonursery_test.go @@ -2,7 +2,6 @@ package main import ( "bytes" - "fmt" "reflect" "testing" @@ -166,23 +165,29 @@ var ( kidOutputs = []kidOutput{ { + originChanPoint: outPoints[1], amt: btcutil.Amount(13e7), outPoint: outPoints[0], blocksToMaturity: uint32(100), + witnessType: commitmentTimeLock, confHeight: uint32(1770001), }, { + originChanPoint: outPoints[0], amt: btcutil.Amount(24e7), outPoint: outPoints[1], blocksToMaturity: uint32(50), + witnessType: commitmentTimeLock, confHeight: uint32(22342321), }, { + originChanPoint: outPoints[2], amt: btcutil.Amount(2e5), outPoint: outPoints[2], blocksToMaturity: uint32(12), + witnessType: commitmentTimeLock, confHeight: uint32(34241), }, } @@ -236,7 +241,7 @@ func TestSerializeKidOutput(t *testing.T) { deserializedKid, err := deserializeKidOutput(&b) if err != nil { - fmt.Printf(err.Error()) + t.Fatalf(err.Error()) } if !reflect.DeepEqual(kid, deserializedKid) {