mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-01-19 05:45:21 +01:00
input: extract to_local script builders
Factor out the building of the delay and revoke scripts from NewLocalCommitScriptTree so that they can be re-used later on.
This commit is contained in:
parent
ba4021cad9
commit
fde982ad78
@ -2124,27 +2124,14 @@ func NewLocalCommitScriptTree(csvTimeout uint32,
|
||||
|
||||
// First, we'll need to construct the tapLeaf that'll be our delay CSV
|
||||
// clause.
|
||||
builder := txscript.NewScriptBuilder()
|
||||
builder.AddData(schnorr.SerializePubKey(selfKey))
|
||||
builder.AddOp(txscript.OP_CHECKSIG)
|
||||
builder.AddInt64(int64(csvTimeout))
|
||||
builder.AddOp(txscript.OP_CHECKSEQUENCEVERIFY)
|
||||
builder.AddOp(txscript.OP_DROP)
|
||||
|
||||
delayScript, err := builder.Script()
|
||||
delayScript, err := TaprootLocalCommitDelayScript(csvTimeout, selfKey)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Next, we'll need to construct the revocation path, which is just a
|
||||
// simple checksig script.
|
||||
builder = txscript.NewScriptBuilder()
|
||||
builder.AddData(schnorr.SerializePubKey(selfKey))
|
||||
builder.AddOp(txscript.OP_DROP)
|
||||
builder.AddData(schnorr.SerializePubKey(revokeKey))
|
||||
builder.AddOp(txscript.OP_CHECKSIG)
|
||||
|
||||
revokeScript, err := builder.Script()
|
||||
revokeScript, err := TaprootLocalCommitRevokeScript(selfKey, revokeKey)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -2176,6 +2163,35 @@ func NewLocalCommitScriptTree(csvTimeout uint32,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// TaprootLocalCommitDelayScript builds the tap leaf with the CSV delay script
|
||||
// for the to-local output.
|
||||
func TaprootLocalCommitDelayScript(csvTimeout uint32,
|
||||
selfKey *btcec.PublicKey) ([]byte, error) {
|
||||
|
||||
builder := txscript.NewScriptBuilder()
|
||||
builder.AddData(schnorr.SerializePubKey(selfKey))
|
||||
builder.AddOp(txscript.OP_CHECKSIG)
|
||||
builder.AddInt64(int64(csvTimeout))
|
||||
builder.AddOp(txscript.OP_CHECKSEQUENCEVERIFY)
|
||||
builder.AddOp(txscript.OP_DROP)
|
||||
|
||||
return builder.Script()
|
||||
}
|
||||
|
||||
// TaprootLocalCommitRevokeScript builds the tap leaf with the revocation path
|
||||
// for the to-local output.
|
||||
func TaprootLocalCommitRevokeScript(selfKey, revokeKey *btcec.PublicKey) (
|
||||
[]byte, error) {
|
||||
|
||||
builder := txscript.NewScriptBuilder()
|
||||
builder.AddData(schnorr.SerializePubKey(selfKey))
|
||||
builder.AddOp(txscript.OP_DROP)
|
||||
builder.AddData(schnorr.SerializePubKey(revokeKey))
|
||||
builder.AddOp(txscript.OP_CHECKSIG)
|
||||
|
||||
return builder.Script()
|
||||
}
|
||||
|
||||
// TaprootCommitScriptToSelf creates the taproot witness program that commits
|
||||
// to the revocation (script path) and delay path (script path) in a single
|
||||
// taproot output key. Both the delay script and the revocation script are part
|
||||
|
Loading…
Reference in New Issue
Block a user