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
|
|
@ -455,22 +455,33 @@ func testLoopInResume(t *testing.T, state loopdb.SwapState, expired bool,
|
|||
pendSwap.Loop.Events[0].Cost = cost
|
||||
}
|
||||
|
||||
scriptVersion := GetHtlcScriptVersion(storedVersion)
|
||||
|
||||
outputType := swap.HtlcP2WSH
|
||||
if scriptVersion == swap.HtlcV3 {
|
||||
outputType = swap.HtlcP2TR
|
||||
}
|
||||
|
||||
htlc, err := swap.NewHtlc(
|
||||
scriptVersion, contract.CltvExpiry, contract.SenderKey,
|
||||
contract.ReceiverKey, testPreimage.Hash(), outputType,
|
||||
cfg.lnd.ChainParams,
|
||||
var (
|
||||
htlc *swap.Htlc
|
||||
err error
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
|
||||
switch GetHtlcScriptVersion(storedVersion) {
|
||||
case swap.HtlcV2:
|
||||
htlc, err = swap.NewHtlcV2(
|
||||
contract.CltvExpiry, contract.SenderKey,
|
||||
contract.ReceiverKey, testPreimage.Hash(),
|
||||
cfg.lnd.ChainParams,
|
||||
)
|
||||
|
||||
case swap.HtlcV3:
|
||||
htlc, err = swap.NewHtlcV3(
|
||||
contract.CltvExpiry, contract.SenderKey,
|
||||
contract.ReceiverKey, contract.SenderKey,
|
||||
contract.ReceiverKey, testPreimage.Hash(),
|
||||
cfg.lnd.ChainParams,
|
||||
)
|
||||
|
||||
default:
|
||||
t.Fatalf("unknown HTLC script version")
|
||||
}
|
||||
|
||||
require.NoError(t, err)
|
||||
|
||||
err = ctx.store.CreateLoopIn(testPreimage.Hash(), contract)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue