Skip to content

Commit 02a16d0

Browse files
authored
Merge pull request #255 from bhandras/htlc_v2
preliminary work for integrating the v2 HTLC script
2 parents 2cd2eb8 + 6499181 commit 02a16d0

File tree

9 files changed

+629
-71
lines changed

9 files changed

+629
-71
lines changed

client.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -175,9 +175,9 @@ func (s *Client) FetchSwaps() ([]*SwapInfo, error) {
175175

176176
for _, swp := range loopOutSwaps {
177177
htlc, err := swap.NewHtlc(
178-
swp.Contract.CltvExpiry, swp.Contract.SenderKey,
179-
swp.Contract.ReceiverKey, swp.Hash, swap.HtlcP2WSH,
180-
s.lndServices.ChainParams,
178+
swap.HtlcV1, swp.Contract.CltvExpiry,
179+
swp.Contract.SenderKey, swp.Contract.ReceiverKey,
180+
swp.Hash, swap.HtlcP2WSH, s.lndServices.ChainParams,
181181
)
182182
if err != nil {
183183
return nil, err
@@ -195,18 +195,18 @@ func (s *Client) FetchSwaps() ([]*SwapInfo, error) {
195195

196196
for _, swp := range loopInSwaps {
197197
htlcNP2WSH, err := swap.NewHtlc(
198-
swp.Contract.CltvExpiry, swp.Contract.SenderKey,
199-
swp.Contract.ReceiverKey, swp.Hash, swap.HtlcNP2WSH,
200-
s.lndServices.ChainParams,
198+
swap.HtlcV1, swp.Contract.CltvExpiry,
199+
swp.Contract.SenderKey, swp.Contract.ReceiverKey,
200+
swp.Hash, swap.HtlcNP2WSH, s.lndServices.ChainParams,
201201
)
202202
if err != nil {
203203
return nil, err
204204
}
205205

206206
htlcP2WSH, err := swap.NewHtlc(
207-
swp.Contract.CltvExpiry, swp.Contract.SenderKey,
208-
swp.Contract.ReceiverKey, swp.Hash, swap.HtlcP2WSH,
209-
s.lndServices.ChainParams,
207+
swap.HtlcV1, swp.Contract.CltvExpiry,
208+
swp.Contract.SenderKey, swp.Contract.ReceiverKey,
209+
swp.Hash, swap.HtlcP2WSH, s.lndServices.ChainParams,
210210
)
211211
if err != nil {
212212
return nil, err

loopd/view.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ func viewOut(swapClient *loop.Client, chainParams *chaincfg.Params) error {
5050

5151
for _, s := range swaps {
5252
htlc, err := swap.NewHtlc(
53+
swap.HtlcV1,
5354
s.Contract.CltvExpiry,
5455
s.Contract.SenderKey,
5556
s.Contract.ReceiverKey,
@@ -101,6 +102,7 @@ func viewIn(swapClient *loop.Client, chainParams *chaincfg.Params) error {
101102

102103
for _, s := range swaps {
103104
htlc, err := swap.NewHtlc(
105+
swap.HtlcV1,
104106
s.Contract.CltvExpiry,
105107
s.Contract.SenderKey,
106108
s.Contract.ReceiverKey,

loopin.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -756,12 +756,13 @@ func (s *loopInSwap) publishTimeoutTx(ctx context.Context,
756756
}
757757

758758
witnessFunc := func(sig []byte) (wire.TxWitness, error) {
759-
return s.htlc.GenTimeoutWitness(sig)
759+
return s.htlc.GenTimeoutWitness(sig), nil
760760
}
761761

762+
sequence := uint32(0)
762763
timeoutTx, err := s.sweeper.CreateSweepTx(
763-
ctx, s.height, s.htlc, *htlcOutpoint, s.SenderKey, witnessFunc,
764-
htlcValue, fee, s.timeoutAddr,
764+
ctx, s.height, sequence, s.htlc, *htlcOutpoint, s.SenderKey,
765+
witnessFunc, htlcValue, fee, s.timeoutAddr,
765766
)
766767
if err != nil {
767768
return err

loopin_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -331,8 +331,9 @@ func testLoopInResume(t *testing.T, state loopdb.SwapState, expired bool) {
331331
}
332332

333333
htlc, err := swap.NewHtlc(
334-
contract.CltvExpiry, contract.SenderKey, contract.ReceiverKey,
335-
testPreimage.Hash(), swap.HtlcNP2WSH, cfg.lnd.ChainParams,
334+
swap.HtlcV1, contract.CltvExpiry, contract.SenderKey,
335+
contract.ReceiverKey, testPreimage.Hash(), swap.HtlcNP2WSH,
336+
cfg.lnd.ChainParams,
336337
)
337338
if err != nil {
338339
t.Fatal(err)

loopout.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -937,8 +937,8 @@ func (s *loopOutSwap) sweep(ctx context.Context,
937937

938938
// Create sweep tx.
939939
sweepTx, err := s.sweeper.CreateSweepTx(
940-
ctx, s.height, s.htlc, htlcOutpoint, s.ReceiverKey, witnessFunc,
941-
htlcValue, fee, s.DestAddr,
940+
ctx, s.height, s.htlc.SuccessSequence(), s.htlc, htlcOutpoint,
941+
s.ReceiverKey, witnessFunc, htlcValue, fee, s.DestAddr,
942942
)
943943
if err != nil {
944944
return err

swap.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ func newSwapKit(hash lntypes.Hash, swapType swap.Type, cfg *swapConfig,
5151
// getHtlc composes and returns the on-chain swap script.
5252
func (s *swapKit) getHtlc(outputType swap.HtlcOutputType) (*swap.Htlc, error) {
5353
return swap.NewHtlc(
54-
s.contract.CltvExpiry, s.contract.SenderKey,
54+
swap.HtlcV1, s.contract.CltvExpiry, s.contract.SenderKey,
5555
s.contract.ReceiverKey, s.hash, outputType,
5656
s.swapConfig.lnd.ChainParams,
5757
)

0 commit comments

Comments
 (0)