@@ -17,6 +17,7 @@ import (
1717 "github.com/lightninglabs/taproot-assets/proof"
1818 "github.com/lightninglabs/taproot-assets/tapchannelmsg"
1919 "github.com/lightninglabs/taproot-assets/tapfreighter"
20+ "github.com/lightninglabs/taproot-assets/tapgarden"
2021 "github.com/lightninglabs/taproot-assets/tappsbt"
2122 "github.com/lightninglabs/taproot-assets/tapsend"
2223 lfn "github.com/lightningnetwork/lnd/fn"
@@ -45,6 +46,22 @@ type AuxChanCloserCfg struct {
4546 // DefaultCourierAddr is the default address we'll use to send/receive
4647 // proofs for the co-op close process
4748 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
4865}
4966
5067// assetCloseInfo houses the information we need to finalize the close of an
@@ -624,6 +641,37 @@ func (a *AuxChanCloser) FinalizeClose(desc chancloser.AuxCloseDesc,
624641 desc .ChanPoint )
625642 }
626643
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+
627675 log .Infof ("Finalizing close for ChannelPoint(%v): " , desc .ChanPoint )
628676
629677 defer delete (a .closeInfo , desc .ChanPoint )
0 commit comments