@@ -2,6 +2,7 @@ package funding
22
33import (
44 "github.com/btcsuite/btcd/chaincfg/chainhash"
5+ "github.com/lightningnetwork/lnd/channeldb"
56 "github.com/lightningnetwork/lnd/fn"
67 "github.com/lightningnetwork/lnd/lnwallet"
78 "github.com/lightningnetwork/lnd/protofsm"
@@ -17,16 +18,45 @@ type AuxFundingController interface {
1718 // handle custom messages specific to the funding type.
1819 protofsm.MsgEndpoint
1920
20- // DescPendingChanID takes a pending channel ID, that may already be
21+ // DescFromPendingChanID takes a pending channel ID, that may already be
2122 // known due to prior custom channel messages, and maybe returns an aux
2223 // funding desc which can be used to modify how a channel is funded.
23- //
24- // TODO(roasbeef): erorr on validation if fail due to invalid root
25- // match?
26- DescFromPendingChanID (PendingChanID ) fn.Option [lnwallet.AuxFundingDesc ]
24+ DescFromPendingChanID (PendingChanID ,
25+ * channeldb.OpenChannel , lnwallet.CommitmentKeyRing ,
26+ bool ) (fn.Option [lnwallet.AuxFundingDesc ], error )
2727
2828 // DeriveTapscriptRoot takes a pending channel ID and maybe returns a
2929 // tapscript root that should be used when creating any musig2 sessions
3030 // for a channel.
31- DeriveTapscriptRoot (PendingChanID ) fn.Option [chainhash.Hash ]
31+ DeriveTapscriptRoot (PendingChanID ) (fn.Option [chainhash.Hash ], error )
32+ }
33+
34+ // descFromPendingChanID takes a pending channel ID, that may already be
35+ // known due to prior custom channel messages, and maybe returns an aux
36+ // funding desc which can be used to modify how a channel is funded.
37+ func descFromPendingChanID (controller fn.Option [AuxFundingController ],
38+ chanID PendingChanID , openChan * channeldb.OpenChannel ,
39+ keyRing lnwallet.CommitmentKeyRing ,
40+ initiator bool ) (fn.Option [lnwallet.AuxFundingDesc ], error ) {
41+
42+ if controller .IsNone () {
43+ return fn .None [lnwallet.AuxFundingDesc ](), nil
44+ }
45+
46+ return controller .UnsafeFromSome ().DescFromPendingChanID (
47+ chanID , openChan , keyRing , initiator ,
48+ )
49+ }
50+
51+ // deriveTapscriptRoot takes a pending channel ID and maybe returns a
52+ // tapscript root that should be used when creating any musig2 sessions
53+ // for a channel.
54+ func deriveTapscriptRoot (controller fn.Option [AuxFundingController ],
55+ chanID PendingChanID ) (fn.Option [chainhash.Hash ], error ) {
56+
57+ if controller .IsNone () {
58+ return fn .None [chainhash.Hash ](), nil
59+ }
60+
61+ return controller .UnsafeFromSome ().DeriveTapscriptRoot (chanID )
3262}
0 commit comments