lnwallet: coalesce different supported output scripts into single method

This commit is contained in:
Wilmer Paulino authored and Olaoluwa Osuntokun committed 2021-10-19 18:30:30 -07:00
1 parent 652f841738
commit 01e9bb2bff
4 files changed
+88 -70

No files matched your search

+10 -15
View File
@@ -8,7 +8,6 @@ import (
"github.com/btcsuite/btcd/wire"
"github.com/btcsuite/btcutil"
"github.com/lightningnetwork/lnd/channeldb"
"github.com/lightningnetwork/lnd/input"
)
const (
@@ -65,12 +64,9 @@ func CreateHtlcSuccessTx(chanType channeldb.ChannelType,
// Next, we'll generate the script used as the output for all second
// level HTLC which forces a covenant w.r.t what can be done with all
// HTLC outputs.
witnessScript, err := input.SecondLevelHtlcScript(revocationKey, delayKey,
csvDelay)
if err != nil {
return nil, err
}
pkScript, err := input.WitnessScriptHash(witnessScript)
script, err := SecondLevelHtlcScript(
revocationKey, delayKey, csvDelay,
)
if err != nil {
return nil, err
}
@@ -79,7 +75,7 @@ func CreateHtlcSuccessTx(chanType channeldb.ChannelType,
// required fees), paying to the timeout script.
successTx.AddTxOut(&wire.TxOut{
Value: int64(htlcAmt),
PkScript: pkScript,
PkScript: script.PkScript,
})
return successTx, nil
@@ -117,6 +113,8 @@ func CreateHtlcTimeoutTx(chanType channeldb.ChannelType,
// sequence number based on the channel type.
txin := &wire.TxIn{
PreviousOutPoint: htlcOutput,
SignatureScript: []byte{},
Witness: [][]byte{},
Sequence: HtlcSecondLevelInputSequence(chanType),
}
timeoutTx.AddTxIn(txin)
@@ -124,12 +122,9 @@ func CreateHtlcTimeoutTx(chanType channeldb.ChannelType,
// Next, we'll generate the script used as the output for all second
// level HTLC which forces a covenant w.r.t what can be done with all
// HTLC outputs.
witnessScript, err := input.SecondLevelHtlcScript(revocationKey, delayKey,
csvDelay)
if err != nil {
return nil, err
}
pkScript, err := input.WitnessScriptHash(witnessScript)
script, err := SecondLevelHtlcScript(
revocationKey, delayKey, csvDelay,
)
if err != nil {
return nil, err
}
@@ -138,7 +133,7 @@ func CreateHtlcTimeoutTx(chanType channeldb.ChannelType,
// required fees), paying to the regular second level HTLC script.
timeoutTx.AddTxOut(&wire.TxOut{
Value: int64(htlcAmt),
PkScript: pkScript,
PkScript: script.PkScript,
})
return timeoutTx, nil