Skip to content

Commit b36885f

Browse files
committed
loopd: correct htlc output type on view command
Previously view may have set the output type wrongly for internal p2wsh and p2tr loop-in swaps which is corrected in this commit.
1 parent f5806ae commit b36885f

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

loopd/view.go

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,27 @@ func viewOut(swapClient *loop.Client, chainParams *chaincfg.Params) error {
4949
}
5050

5151
for _, s := range swaps {
52+
scriptVersion := loop.GetHtlcScriptVersion(
53+
s.Contract.ProtocolVersion,
54+
)
55+
56+
var outputType swap.HtlcOutputType
57+
switch scriptVersion {
58+
case swap.HtlcV1:
59+
outputType = swap.HtlcNP2WSH
60+
61+
case swap.HtlcV2:
62+
outputType = swap.HtlcP2WSH
63+
64+
case swap.HtlcV3:
65+
outputType = swap.HtlcP2TR
66+
}
5267
htlc, err := swap.NewHtlc(
5368
loop.GetHtlcScriptVersion(s.Contract.ProtocolVersion),
5469
s.Contract.CltvExpiry,
5570
s.Contract.SenderKey,
5671
s.Contract.ReceiverKey,
57-
s.Hash, swap.HtlcP2WSH, chainParams,
72+
s.Hash, outputType, chainParams,
5873
)
5974
if err != nil {
6075
return err
@@ -106,7 +121,7 @@ func viewIn(swapClient *loop.Client, chainParams *chaincfg.Params) error {
106121
s.Contract.CltvExpiry,
107122
s.Contract.SenderKey,
108123
s.Contract.ReceiverKey,
109-
s.Hash, swap.HtlcNP2WSH, chainParams,
124+
s.Hash, swap.HtlcP2WSH, chainParams,
110125
)
111126
if err != nil {
112127
return err

0 commit comments

Comments
 (0)