Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions swaps/swaps_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,10 +191,9 @@ func (svc *swapsService) EnableAutoSwapOut() error {
logger.Logger.Info("Starting auto swap workflow")

go func() {
ticker := time.NewTicker(1 * time.Hour)
for {
select {
case <-ticker.C:
case <-time.After(1 * time.Hour):
logger.Logger.Debug("Checking to see if we can swap")
balance, err := svc.lnClient.GetBalances(ctx, false)
if err != nil {
Expand Down Expand Up @@ -347,7 +346,13 @@ func (svc *swapsService) SwapOut(amount uint64, destination string, autoSwap boo

logger.Logger.WithField("swapId", swap.Id).Info("Swap created")

go svc.startSwapOutListener(&dbSwap)
if autoSwap {
// block until the swap finishes to ensure we can't do multiple concurrent auto swaps
svc.startSwapOutListener(&dbSwap)
} else {
// run in parallel as we need to return the swap ID in the HTTP response
go svc.startSwapOutListener(&dbSwap)
}

return &SwapResponse{
SwapId: swap.Id,
Expand Down
Loading