lnwallet: update CommitScriptToSelf to add taproot awareness
This commit is contained in:
1 file changed
+54
-14
+54
-14
@@ -202,28 +202,47 @@ func CommitScriptToSelf(chanType channeldb.ChannelType, initiator bool,
|
|||||||
selfKey, revokeKey *btcec.PublicKey, csvDelay, leaseExpiry uint32) (
|
selfKey, revokeKey *btcec.PublicKey, csvDelay, leaseExpiry uint32) (
|
||||||
*ScriptInfo, error) {
|
*ScriptInfo, error) {
|
||||||
|
|
||||||
var (
|
|
||||||
toLocalRedeemScript []byte
|
|
||||||
err error
|
|
||||||
)
|
|
||||||
switch {
|
switch {
|
||||||
// If we are the initiator of a leased channel, then we have an
|
// For taproot scripts, we'll need to make a slightly modified script
|
||||||
// additional CLTV requirement in addition to the usual CSV requirement.
|
// where a NUMS key is used to force a script path reveal of either the
|
||||||
case initiator && chanType.HasLeaseExpiration():
|
// revocation or the CSV timeout.
|
||||||
toLocalRedeemScript, err = input.LeaseCommitScriptToSelf(
|
//
|
||||||
selfKey, revokeKey, csvDelay, leaseExpiry,
|
// Our "redeem" script here is just the taproot witness program.
|
||||||
)
|
case chanType.IsTaproot():
|
||||||
|
toLocalOutputKey, err := input.TaprootCommitScriptToSelf(
|
||||||
default:
|
|
||||||
toLocalRedeemScript, err = input.CommitScriptToSelf(
|
|
||||||
csvDelay, selfKey, revokeKey,
|
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 {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
toLocalScriptHash, err := input.WitnessScriptHash(toLocalRedeemScript)
|
toLocalScriptHash, err := input.WitnessScriptHash(
|
||||||
|
toLocalRedeemScript,
|
||||||
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -232,6 +251,27 @@ func CommitScriptToSelf(chanType channeldb.ChannelType, initiator bool,
|
|||||||
PkScript: toLocalScriptHash,
|
PkScript: toLocalScriptHash,
|
||||||
WitnessScript: toLocalRedeemScript,
|
WitnessScript: toLocalRedeemScript,
|
||||||
}, nil
|
}, 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
|
// CommitScriptToRemote derives the appropriate to_remote script based on the
|
||||||
|
|||||||
Reference in new issue
Block a user