Skip to content

Commit 8f23c67

Browse files
authored
Merge pull request #477 from bhandras/taproot-htlc
multi: changes to the taproot HTLC required for both client and server
2 parents 0f9abbc + c7ef429 commit 8f23c67

File tree

10 files changed

+264
-169
lines changed

10 files changed

+264
-169
lines changed

client.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ func (s *Client) FetchSwaps() ([]*SwapInfo, error) {
195195
htlc, err := swap.NewHtlc(
196196
GetHtlcScriptVersion(swp.Contract.ProtocolVersion),
197197
swp.Contract.CltvExpiry, swp.Contract.SenderKey,
198-
swp.Contract.ReceiverKey, nil, swp.Hash, swap.HtlcP2WSH,
198+
swp.Contract.ReceiverKey, swp.Hash, swap.HtlcP2WSH,
199199
s.lndServices.ChainParams,
200200
)
201201
if err != nil {
@@ -216,7 +216,7 @@ func (s *Client) FetchSwaps() ([]*SwapInfo, error) {
216216
htlcNP2WSH, err := swap.NewHtlc(
217217
GetHtlcScriptVersion(swp.Contract.ProtocolVersion),
218218
swp.Contract.CltvExpiry, swp.Contract.SenderKey,
219-
swp.Contract.ReceiverKey, nil, swp.Hash, swap.HtlcNP2WSH,
219+
swp.Contract.ReceiverKey, swp.Hash, swap.HtlcNP2WSH,
220220
s.lndServices.ChainParams,
221221
)
222222
if err != nil {
@@ -226,7 +226,7 @@ func (s *Client) FetchSwaps() ([]*SwapInfo, error) {
226226
htlcP2WSH, err := swap.NewHtlc(
227227
GetHtlcScriptVersion(swp.Contract.ProtocolVersion),
228228
swp.Contract.CltvExpiry, swp.Contract.SenderKey,
229-
swp.Contract.ReceiverKey, nil, swp.Hash, swap.HtlcP2WSH,
229+
swp.Contract.ReceiverKey, swp.Hash, swap.HtlcP2WSH,
230230
s.lndServices.ChainParams,
231231
)
232232
if err != nil {

client_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ func testResume(t *testing.T, confs uint32, expired, preimageRevealed,
284284
scriptVersion := GetHtlcScriptVersion(protocolVersion)
285285
htlc, err := swap.NewHtlc(
286286
scriptVersion, pendingSwap.Contract.CltvExpiry, senderKey,
287-
receiverKey, nil, hash, swap.HtlcP2WSH, &chaincfg.TestNet3Params,
287+
receiverKey, hash, swap.HtlcP2WSH, &chaincfg.TestNet3Params,
288288
)
289289
require.NoError(t, err)
290290
require.Equal(t, htlc.PkScript, confIntent.PkScript)

loopd/view.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ func viewOut(swapClient *loop.Client, chainParams *chaincfg.Params) error {
5454
s.Contract.CltvExpiry,
5555
s.Contract.SenderKey,
5656
s.Contract.ReceiverKey,
57-
nil, s.Hash, swap.HtlcP2WSH, chainParams,
57+
s.Hash, swap.HtlcP2WSH, chainParams,
5858
)
5959
if err != nil {
6060
return err
@@ -106,7 +106,7 @@ func viewIn(swapClient *loop.Client, chainParams *chaincfg.Params) error {
106106
s.Contract.CltvExpiry,
107107
s.Contract.SenderKey,
108108
s.Contract.ReceiverKey,
109-
nil, s.Hash, swap.HtlcNP2WSH, chainParams,
109+
s.Hash, swap.HtlcNP2WSH, chainParams,
110110
)
111111
if err != nil {
112112
return err

loopin.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -945,14 +945,18 @@ func (s *loopInSwap) publishTimeoutTx(ctx context.Context,
945945
return 0, err
946946
}
947947

948+
// Create a function that will assemble our timeout witness.
948949
witnessFunc := func(sig []byte) (wire.TxWitness, error) {
949950
return s.htlc.GenTimeoutWitness(sig)
950951
}
951952

953+
// Retrieve the full script required to unlock the output.
954+
redeemScript := s.htlc.TimeoutScript()
955+
952956
sequence := uint32(0)
953957
timeoutTx, err := s.sweeper.CreateSweepTx(
954958
ctx, s.height, sequence, s.htlc, *htlcOutpoint, s.SenderKey,
955-
witnessFunc, htlcValue, fee, s.timeoutAddr,
959+
redeemScript, witnessFunc, htlcValue, fee, s.timeoutAddr,
956960
)
957961
if err != nil {
958962
return 0, err

loopin_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ func testLoopInResume(t *testing.T, state loopdb.SwapState, expired bool,
399399

400400
htlc, err := swap.NewHtlc(
401401
scriptVersion, contract.CltvExpiry, contract.SenderKey,
402-
contract.ReceiverKey, nil, testPreimage.Hash(), swap.HtlcNP2WSH,
402+
contract.ReceiverKey, testPreimage.Hash(), swap.HtlcNP2WSH,
403403
cfg.lnd.ChainParams,
404404
)
405405
if err != nil {

loopout.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1240,6 +1240,9 @@ func (s *loopOutSwap) sweep(ctx context.Context,
12401240
return s.htlc.GenSuccessWitness(sig, s.Preimage)
12411241
}
12421242

1243+
// Retrieve the full script required to unlock the output.
1244+
redeemScript := s.htlc.SuccessScript()
1245+
12431246
remainingBlocks := s.CltvExpiry - s.height
12441247
blocksToLastReveal := remainingBlocks - MinLoopOutPreimageRevealDelta
12451248
preimageRevealed := s.state == loopdb.StatePreimageRevealed
@@ -1296,7 +1299,8 @@ func (s *loopOutSwap) sweep(ctx context.Context,
12961299
// Create sweep tx.
12971300
sweepTx, err := s.sweeper.CreateSweepTx(
12981301
ctx, s.height, s.htlc.SuccessSequence(), s.htlc, htlcOutpoint,
1299-
s.ReceiverKey, witnessFunc, htlcValue, fee, s.DestAddr,
1302+
s.ReceiverKey, redeemScript, witnessFunc, htlcValue, fee,
1303+
s.DestAddr,
13001304
)
13011305
if err != nil {
13021306
return err

swap.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ func (s *swapKit) getHtlc(outputType swap.HtlcOutputType) (*swap.Htlc, error) {
7272
return swap.NewHtlc(
7373
GetHtlcScriptVersion(s.contract.ProtocolVersion),
7474
s.contract.CltvExpiry, s.contract.SenderKey,
75-
s.contract.ReceiverKey, nil, s.hash, outputType,
75+
s.contract.ReceiverKey, s.hash, outputType,
7676
s.swapConfig.lnd.ChainParams,
7777
)
7878
}

0 commit comments

Comments
 (0)