Skip to content

Commit

Permalink
Merge pull request #255 from bhandras/htlc_v2
Browse files Browse the repository at this point in the history
preliminary work for integrating the v2 HTLC script
  • Loading branch information
bhandras authored Aug 27, 2020
2 parents 2cd2eb8 + 6499181 commit 02a16d0
Show file tree
Hide file tree
Showing 9 changed files with 629 additions and 71 deletions.
18 changes: 9 additions & 9 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,9 @@ func (s *Client) FetchSwaps() ([]*SwapInfo, error) {

for _, swp := range loopOutSwaps {
htlc, err := swap.NewHtlc(
swp.Contract.CltvExpiry, swp.Contract.SenderKey,
swp.Contract.ReceiverKey, swp.Hash, swap.HtlcP2WSH,
s.lndServices.ChainParams,
swap.HtlcV1, swp.Contract.CltvExpiry,
swp.Contract.SenderKey, swp.Contract.ReceiverKey,
swp.Hash, swap.HtlcP2WSH, s.lndServices.ChainParams,
)
if err != nil {
return nil, err
Expand All @@ -195,18 +195,18 @@ func (s *Client) FetchSwaps() ([]*SwapInfo, error) {

for _, swp := range loopInSwaps {
htlcNP2WSH, err := swap.NewHtlc(
swp.Contract.CltvExpiry, swp.Contract.SenderKey,
swp.Contract.ReceiverKey, swp.Hash, swap.HtlcNP2WSH,
s.lndServices.ChainParams,
swap.HtlcV1, swp.Contract.CltvExpiry,
swp.Contract.SenderKey, swp.Contract.ReceiverKey,
swp.Hash, swap.HtlcNP2WSH, s.lndServices.ChainParams,
)
if err != nil {
return nil, err
}

htlcP2WSH, err := swap.NewHtlc(
swp.Contract.CltvExpiry, swp.Contract.SenderKey,
swp.Contract.ReceiverKey, swp.Hash, swap.HtlcP2WSH,
s.lndServices.ChainParams,
swap.HtlcV1, swp.Contract.CltvExpiry,
swp.Contract.SenderKey, swp.Contract.ReceiverKey,
swp.Hash, swap.HtlcP2WSH, s.lndServices.ChainParams,
)
if err != nil {
return nil, err
Expand Down
2 changes: 2 additions & 0 deletions loopd/view.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ func viewOut(swapClient *loop.Client, chainParams *chaincfg.Params) error {

for _, s := range swaps {
htlc, err := swap.NewHtlc(
swap.HtlcV1,
s.Contract.CltvExpiry,
s.Contract.SenderKey,
s.Contract.ReceiverKey,
Expand Down Expand Up @@ -101,6 +102,7 @@ func viewIn(swapClient *loop.Client, chainParams *chaincfg.Params) error {

for _, s := range swaps {
htlc, err := swap.NewHtlc(
swap.HtlcV1,
s.Contract.CltvExpiry,
s.Contract.SenderKey,
s.Contract.ReceiverKey,
Expand Down
7 changes: 4 additions & 3 deletions loopin.go
Original file line number Diff line number Diff line change
Expand Up @@ -756,12 +756,13 @@ func (s *loopInSwap) publishTimeoutTx(ctx context.Context,
}

witnessFunc := func(sig []byte) (wire.TxWitness, error) {
return s.htlc.GenTimeoutWitness(sig)
return s.htlc.GenTimeoutWitness(sig), nil
}

sequence := uint32(0)
timeoutTx, err := s.sweeper.CreateSweepTx(
ctx, s.height, s.htlc, *htlcOutpoint, s.SenderKey, witnessFunc,
htlcValue, fee, s.timeoutAddr,
ctx, s.height, sequence, s.htlc, *htlcOutpoint, s.SenderKey,
witnessFunc, htlcValue, fee, s.timeoutAddr,
)
if err != nil {
return err
Expand Down
5 changes: 3 additions & 2 deletions loopin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -331,8 +331,9 @@ func testLoopInResume(t *testing.T, state loopdb.SwapState, expired bool) {
}

htlc, err := swap.NewHtlc(
contract.CltvExpiry, contract.SenderKey, contract.ReceiverKey,
testPreimage.Hash(), swap.HtlcNP2WSH, cfg.lnd.ChainParams,
swap.HtlcV1, contract.CltvExpiry, contract.SenderKey,
contract.ReceiverKey, testPreimage.Hash(), swap.HtlcNP2WSH,
cfg.lnd.ChainParams,
)
if err != nil {
t.Fatal(err)
Expand Down
4 changes: 2 additions & 2 deletions loopout.go
Original file line number Diff line number Diff line change
Expand Up @@ -937,8 +937,8 @@ func (s *loopOutSwap) sweep(ctx context.Context,

// Create sweep tx.
sweepTx, err := s.sweeper.CreateSweepTx(
ctx, s.height, s.htlc, htlcOutpoint, s.ReceiverKey, witnessFunc,
htlcValue, fee, s.DestAddr,
ctx, s.height, s.htlc.SuccessSequence(), s.htlc, htlcOutpoint,
s.ReceiverKey, witnessFunc, htlcValue, fee, s.DestAddr,
)
if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion swap.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func newSwapKit(hash lntypes.Hash, swapType swap.Type, cfg *swapConfig,
// getHtlc composes and returns the on-chain swap script.
func (s *swapKit) getHtlc(outputType swap.HtlcOutputType) (*swap.Htlc, error) {
return swap.NewHtlc(
s.contract.CltvExpiry, s.contract.SenderKey,
swap.HtlcV1, s.contract.CltvExpiry, s.contract.SenderKey,
s.contract.ReceiverKey, s.hash, outputType,
s.swapConfig.lnd.ChainParams,
)
Expand Down
Loading

0 comments on commit 02a16d0

Please sign in to comment.