@@ -17,6 +17,7 @@ import (
17
17
"github.com/lightninglabs/taproot-assets/proof"
18
18
"github.com/lightninglabs/taproot-assets/tapchannelmsg"
19
19
"github.com/lightninglabs/taproot-assets/tapfreighter"
20
+ "github.com/lightninglabs/taproot-assets/tapgarden"
20
21
"github.com/lightninglabs/taproot-assets/tappsbt"
21
22
"github.com/lightninglabs/taproot-assets/tapsend"
22
23
lfn "github.com/lightningnetwork/lnd/fn"
@@ -45,6 +46,22 @@ type AuxChanCloserCfg struct {
45
46
// DefaultCourierAddr is the default address we'll use to send/receive
46
47
// proofs for the co-op close process
47
48
DefaultCourierAddr * url.URL
49
+
50
+ // ProofFetcher is used to fetch proofs needed to properly import the
51
+ // funding output into the database as our own.
52
+ ProofFetcher proof.CourierDispatch
53
+
54
+ // ProofArchive is used to store import funding output proofs.
55
+ ProofArchive proof.Archiver
56
+
57
+ // HeaderVerifier is used to verify headers in a proof.
58
+ HeaderVerifier proof.HeaderVerifier
59
+
60
+ // GroupVerifier is used to verify group keys in a proof.
61
+ GroupVerifier proof.GroupVerifier
62
+
63
+ // ChainBridge is used to fetch blocks from the main chain.
64
+ ChainBridge tapgarden.ChainBridge
48
65
}
49
66
50
67
// assetCloseInfo houses the information we need to finalize the close of an
@@ -624,6 +641,37 @@ func (a *AuxChanCloser) FinalizeClose(desc chancloser.AuxCloseDesc,
624
641
desc .ChanPoint )
625
642
}
626
643
644
+ // Before we finalize the close process, we'll make sure to also import
645
+ // a transfer for the funding outputs. This way we'll ensure that we're
646
+ // able to insert the transfer that spends these outputs. We only need
647
+ // to do this for the responder though, as the creator of the channel
648
+ // already has these proofs inserted.
649
+ if ! desc .Initiator {
650
+ fundingInfo , err := tapchannelmsg .DecodeOpenChannel (
651
+ desc .FundingBlob .UnwrapOr (nil ),
652
+ )
653
+ if err != nil {
654
+ return err
655
+ }
656
+
657
+ fundingInputProofs := fn .Map (
658
+ fundingInfo .FundedAssets .Val .Outputs ,
659
+ func (a * tapchannelmsg.AssetOutput ) * proof.Proof {
660
+ return & a .Proof .Val
661
+ },
662
+ )
663
+ err = importOutputProofs (
664
+ desc .ShortChanID , fundingInputProofs ,
665
+ a .cfg .DefaultCourierAddr , a .cfg .ProofFetcher ,
666
+ a .cfg .ChainBridge , a .cfg .HeaderVerifier ,
667
+ a .cfg .GroupVerifier , a .cfg .ProofArchive ,
668
+ )
669
+ if err != nil {
670
+ return fmt .Errorf ("unable to import output " +
671
+ "proofs: %w" , err )
672
+ }
673
+ }
674
+
627
675
log .Infof ("Finalizing close for ChannelPoint(%v): " , desc .ChanPoint )
628
676
629
677
defer delete (a .closeInfo , desc .ChanPoint )
0 commit comments