mirror of
https://github.com/lightninglabs/loop.git
synced 2026-08-13 12:33:03 +02:00
swap_server_client: let the SwapPublicationDeadline be set during LoopOuts
This commit is contained in:
parent
2d1e41de5d
commit
c70d0deecb
4 changed files with 32 additions and 17 deletions
|
|
@ -66,6 +66,10 @@ type OutRequest struct {
|
|||
// LoopOutChannel optionally specifies the short channel id of the
|
||||
// channel to loop out.
|
||||
LoopOutChannel *uint64
|
||||
|
||||
// SwapPublicationDeadline can be set by the client to allow the server
|
||||
// delaying publication of the swap HTLC to save on chain fees.
|
||||
SwapPublicationDeadline time.Time
|
||||
}
|
||||
|
||||
// Out contains the full details of a loop out request. This includes things
|
||||
|
|
|
|||
29
loopout.go
29
loopout.go
|
|
@ -79,29 +79,36 @@ func newLoopOutSwap(globalCtx context.Context, cfg *swapConfig,
|
|||
// the server revocation key and the swap and prepay invoices.
|
||||
log.Infof("Initiating swap request at height %v", currentHeight)
|
||||
|
||||
swapResp, err := cfg.server.NewLoopOutSwap(globalCtx, swapHash,
|
||||
request.Amount, receiverKey,
|
||||
// The swap deadline will be given to the server for it to use as the
|
||||
// latest swap publication time.
|
||||
swapResp, err := cfg.server.NewLoopOutSwap(
|
||||
globalCtx, swapHash, request.Amount, receiverKey,
|
||||
request.SwapPublicationDeadline,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("cannot initiate swap: %v", err)
|
||||
}
|
||||
|
||||
err = validateLoopOutContract(cfg.lnd, currentHeight, request, swapHash, swapResp)
|
||||
err = validateLoopOutContract(
|
||||
cfg.lnd, currentHeight, request, swapHash, swapResp,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Instantiate a struct that contains all required data to start the swap.
|
||||
// Instantiate a struct that contains all required data to start the
|
||||
// swap.
|
||||
initiationTime := time.Now()
|
||||
|
||||
contract := loopdb.LoopOutContract{
|
||||
SwapInvoice: swapResp.swapInvoice,
|
||||
DestAddr: request.DestAddr,
|
||||
MaxSwapRoutingFee: request.MaxSwapRoutingFee,
|
||||
SweepConfTarget: request.SweepConfTarget,
|
||||
UnchargeChannel: request.LoopOutChannel,
|
||||
PrepayInvoice: swapResp.prepayInvoice,
|
||||
MaxPrepayRoutingFee: request.MaxPrepayRoutingFee,
|
||||
SwapInvoice: swapResp.swapInvoice,
|
||||
DestAddr: request.DestAddr,
|
||||
MaxSwapRoutingFee: request.MaxSwapRoutingFee,
|
||||
SweepConfTarget: request.SweepConfTarget,
|
||||
UnchargeChannel: request.LoopOutChannel,
|
||||
PrepayInvoice: swapResp.prepayInvoice,
|
||||
MaxPrepayRoutingFee: request.MaxPrepayRoutingFee,
|
||||
SwapPublicationDeadline: request.SwapPublicationDeadline,
|
||||
SwapContract: loopdb.SwapContract{
|
||||
InitiationHeight: currentHeight,
|
||||
InitiationTime: initiationTime,
|
||||
|
|
|
|||
|
|
@ -53,7 +53,7 @@ func newServerMock() *serverMock {
|
|||
|
||||
func (s *serverMock) NewLoopOutSwap(ctx context.Context,
|
||||
swapHash lntypes.Hash, amount btcutil.Amount,
|
||||
receiverKey [33]byte) (
|
||||
receiverKey [33]byte, _ time.Time) (
|
||||
*newLoopOutResponse, error) {
|
||||
|
||||
_, senderKey := test.CreateKey(100)
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import (
|
|||
"encoding/hex"
|
||||
"errors"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/lightninglabs/loop/looprpc"
|
||||
"github.com/lightningnetwork/lnd/lntypes"
|
||||
|
|
@ -31,7 +32,8 @@ type swapServerClient interface {
|
|||
|
||||
NewLoopOutSwap(ctx context.Context,
|
||||
swapHash lntypes.Hash, amount btcutil.Amount,
|
||||
receiverKey [33]byte) (
|
||||
receiverKey [33]byte,
|
||||
swapPublicationDeadline time.Time) (
|
||||
*newLoopOutResponse, error)
|
||||
|
||||
NewLoopInSwap(ctx context.Context,
|
||||
|
|
@ -153,15 +155,17 @@ func (s *grpcSwapServerClient) GetLoopInQuote(ctx context.Context,
|
|||
|
||||
func (s *grpcSwapServerClient) NewLoopOutSwap(ctx context.Context,
|
||||
swapHash lntypes.Hash, amount btcutil.Amount,
|
||||
receiverKey [33]byte) (*newLoopOutResponse, error) {
|
||||
receiverKey [33]byte, swapPublicationDeadline time.Time) (
|
||||
*newLoopOutResponse, error) {
|
||||
|
||||
rpcCtx, rpcCancel := context.WithTimeout(ctx, serverRPCTimeout)
|
||||
defer rpcCancel()
|
||||
swapResp, err := s.server.NewLoopOutSwap(rpcCtx,
|
||||
&looprpc.ServerLoopOutRequest{
|
||||
SwapHash: swapHash[:],
|
||||
Amt: uint64(amount),
|
||||
ReceiverKey: receiverKey[:],
|
||||
SwapHash: swapHash[:],
|
||||
Amt: uint64(amount),
|
||||
ReceiverKey: receiverKey[:],
|
||||
SwapPublicationDeadline: swapPublicationDeadline.Unix(),
|
||||
},
|
||||
)
|
||||
if err != nil {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue