mirror of
https://github.com/lightninglabs/loop.git
synced 2026-08-13 12:33:03 +02:00
swap: refactor htlc construction to allow passing of internal keys
This commit is a refactor of how we construct htlcs to make it possible to pass in internal keys for the sender and receiver when creating P2TR htlcs. Furthermore the commit also cleans up constructors to not pass in script versions and output types to make the code more readable.
This commit is contained in:
parent
35e0120e8f
commit
bdb4b773ed
9 changed files with 212 additions and 182 deletions
|
|
@ -284,16 +284,26 @@ func testLoopOutResume(t *testing.T, confs uint32, expired, preimageRevealed,
|
|||
|
||||
// Assert that the loopout htlc equals to the expected one.
|
||||
scriptVersion := GetHtlcScriptVersion(protocolVersion)
|
||||
var htlc *swap.Htlc
|
||||
|
||||
outputType := swap.HtlcP2TR
|
||||
if scriptVersion != swap.HtlcV3 {
|
||||
outputType = swap.HtlcP2WSH
|
||||
switch scriptVersion {
|
||||
case swap.HtlcV2:
|
||||
htlc, err = swap.NewHtlcV2(
|
||||
pendingSwap.Contract.CltvExpiry, senderKey,
|
||||
receiverKey, hash, &chaincfg.TestNet3Params,
|
||||
)
|
||||
|
||||
case swap.HtlcV3:
|
||||
htlc, err = swap.NewHtlcV3(
|
||||
pendingSwap.Contract.CltvExpiry, senderKey,
|
||||
receiverKey, senderKey, receiverKey, hash,
|
||||
&chaincfg.TestNet3Params,
|
||||
)
|
||||
|
||||
default:
|
||||
t.Fatalf(swap.ErrInvalidScriptVersion.Error())
|
||||
}
|
||||
|
||||
htlc, err := swap.NewHtlc(
|
||||
scriptVersion, pendingSwap.Contract.CltvExpiry, senderKey,
|
||||
receiverKey, hash, outputType, &chaincfg.TestNet3Params,
|
||||
)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, htlc.PkScript, confIntent.PkScript)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue