Skip to content

Commit

Permalink
lnwallet: add TaprootInternalKey method to ShimIntent
Browse files Browse the repository at this point in the history
If this is a taproot channel, then we'll return the internal key which'll be useful to callers.
  • Loading branch information
Roasbeef authored and guggero committed Apr 24, 2024
1 parent f2ef2b4 commit 50f0e1d
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions lnwallet/chanfunding/canned_assembler.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,34 @@ func (s *ShimIntent) FundingOutput() ([]byte, *wire.TxOut, error) {
)
}

// TaprootInternalKey may return the internal key for a musig2 funding output,
// but only if this is actually a musig2 channel.
func (s *ShimIntent) TaprootInternalKey() fn.Option[*btcec.PublicKey] {
if !s.musig2 {
return fn.None[*btcec.PublicKey]()
}

// TODO(roasbeef): refactor

var scriptOpts []input.FundingScriptOpt
s.tapscriptRoot.WhenSome(func(root chainhash.Hash) {
scriptOpts = append(
scriptOpts, input.WithTapscriptRoot(root),
)
})

// Similar to the existing p2wsh script, we'll always ensure the keys
// are sorted before use.
//
// We ignore the eror here as this is only called afterr FundingOutput
// is called.
_, _, musig2Key, _ := input.GenTaprootFundingScript(
s.localKey.PubKey, s.remoteKey, 0, scriptOpts...,
)

return fn.Some(musig2Key.PreTweakedKey)
}

// Cancel allows the caller to cancel a funding Intent at any time. This will
// return any resources such as coins back to the eligible pool to be used in
// order channel fundings.
Expand Down

0 comments on commit 50f0e1d

Please sign in to comment.