Skip to content

Commit

Permalink
temp: split up input script gen
Browse files Browse the repository at this point in the history
  • Loading branch information
ellemouton committed Aug 17, 2023
1 parent 2f6a97d commit 5a5359c
Showing 1 changed file with 26 additions and 14 deletions.
40 changes: 26 additions & 14 deletions input/script_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -2096,34 +2096,46 @@ func (c *CommitScriptTree) CtrlBlockForPath(path ScriptPath,
}
}

// NewLocalCommitScriptTree returns a new CommitScript tree that can be used to
// create and spend the commitment output for the local party.
func NewLocalCommitScriptTree(csvTimeout uint32,
selfKey, revokeKey *btcec.PublicKey) (*CommitScriptTree, error) {
func NewLocalCommitDelayScript(csvTimeout uint32,
selfKey *btcec.PublicKey) ([]byte, error) {

// 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()
if err != nil {
return nil, err
}
return builder.Script()
}

// Next, we'll need to construct the revocation path, which is just a
// simple checksig script.
builder = txscript.NewScriptBuilder()
func NewLocalCommitRevokeScript(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)

revokeScript, err := builder.Script()
return builder.Script()
}

// NewLocalCommitScriptTree returns a new CommitScript tree that can be used to
// create and spend the commitment output for the local party.
func NewLocalCommitScriptTree(csvTimeout uint32,
selfKey, revokeKey *btcec.PublicKey) (*CommitScriptTree, error) {

// First, we'll need to construct the tapLeaf that'll be our delay CSV
// clause.
delayScript, err := NewLocalCommitDelayScript(csvTimeout, selfKey)
if err != nil {
return nil, err
}

// Next, we'll need to construct the revocation path, which is just a
// simple checksig script.
revokeScript, err := NewLocalCommitRevokeScript(selfKey, revokeKey)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit 5a5359c

Please sign in to comment.