mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-02-22 06:21:40 +01:00
lnwallet: update CommitScriptToSelf to add taproot awareness
This commit is contained in:
parent
f7ba08e147
commit
0e7e29455a
1 changed files with 65 additions and 25 deletions
|
@ -202,28 +202,47 @@ func CommitScriptToSelf(chanType channeldb.ChannelType, initiator bool,
|
|||
selfKey, revokeKey *btcec.PublicKey, csvDelay, leaseExpiry uint32) (
|
||||
*ScriptInfo, error) {
|
||||
|
||||
var (
|
||||
toLocalRedeemScript []byte
|
||||
err error
|
||||
)
|
||||
switch {
|
||||
// If we are the initiator of a leased channel, then we have an
|
||||
// additional CLTV requirement in addition to the usual CSV requirement.
|
||||
case initiator && chanType.HasLeaseExpiration():
|
||||
toLocalRedeemScript, err = input.LeaseCommitScriptToSelf(
|
||||
selfKey, revokeKey, csvDelay, leaseExpiry,
|
||||
)
|
||||
|
||||
default:
|
||||
toLocalRedeemScript, err = input.CommitScriptToSelf(
|
||||
// For taproot scripts, we'll need to make a slightly modified script
|
||||
// where a NUMS key is used to force a script path reveal of either the
|
||||
// revocation or the CSV timeout.
|
||||
//
|
||||
// Our "redeem" script here is just the taproot witness program.
|
||||
case chanType.IsTaproot():
|
||||
toLocalOutputKey, err := input.TaprootCommitScriptToSelf(
|
||||
csvDelay, selfKey, revokeKey,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("unable to generate taproot "+
|
||||
"key: %w", err)
|
||||
}
|
||||
|
||||
toLocalPkScript, err := input.PayToTaprootScript(
|
||||
toLocalOutputKey,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("unable to gen taproot "+
|
||||
"pkscript: %w", err)
|
||||
}
|
||||
|
||||
return &ScriptInfo{
|
||||
PkScript: toLocalPkScript,
|
||||
}, nil
|
||||
|
||||
// If we are the initiator of a leased channel, then we have an
|
||||
// additional CLTV requirement in addition to the usual CSV
|
||||
// requirement.
|
||||
case initiator && chanType.HasLeaseExpiration():
|
||||
toLocalRedeemScript, err := input.LeaseCommitScriptToSelf(
|
||||
selfKey, revokeKey, csvDelay, leaseExpiry,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
toLocalScriptHash, err := input.WitnessScriptHash(toLocalRedeemScript)
|
||||
toLocalScriptHash, err := input.WitnessScriptHash(
|
||||
toLocalRedeemScript,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -232,6 +251,27 @@ func CommitScriptToSelf(chanType channeldb.ChannelType, initiator bool,
|
|||
PkScript: toLocalScriptHash,
|
||||
WitnessScript: toLocalRedeemScript,
|
||||
}, nil
|
||||
|
||||
default:
|
||||
toLocalRedeemScript, err := input.CommitScriptToSelf(
|
||||
csvDelay, selfKey, revokeKey,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
toLocalScriptHash, err := input.WitnessScriptHash(
|
||||
toLocalRedeemScript,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &ScriptInfo{
|
||||
PkScript: toLocalScriptHash,
|
||||
WitnessScript: toLocalRedeemScript,
|
||||
}, nil
|
||||
}
|
||||
}
|
||||
|
||||
// CommitScriptToRemote derives the appropriate to_remote script based on the
|
||||
|
|
Loading…
Add table
Reference in a new issue