diff --git a/integration_tests/hodl_invoice_test.go b/integration_tests/hodl_invoice_test.go index 8c7f3f8..3e58e28 100644 --- a/integration_tests/hodl_invoice_test.go +++ b/integration_tests/hodl_invoice_test.go @@ -121,7 +121,10 @@ func (suite *HodlInvoiceSuite) TestHodlInvoice() { //start payment checking loop go func() { - err = suite.service.CheckAllPendingOutgoingPayments(context.Background()) + ctx := context.Background() + pending, err := suite.service.GetAllPendingPayments(ctx) + assert.NoError(suite.T(), err) + err = suite.service.CheckPendingOutgoingPayments(ctx, pending) assert.NoError(suite.T(), err) }() //wait a bit for routine to start @@ -194,7 +197,10 @@ func (suite *HodlInvoiceSuite) TestHodlInvoice() { assert.Equal(suite.T(), common.InvoiceStateInitialized, inv.State) //start payment checking loop go func() { - err = suite.service.CheckAllPendingOutgoingPayments(context.Background()) + ctx := context.Background() + pending, err := suite.service.GetAllPendingPayments(ctx) + assert.NoError(suite.T(), err) + err = suite.service.CheckPendingOutgoingPayments(ctx, pending) assert.NoError(suite.T(), err) }() //wait a bit for routine to start @@ -273,7 +279,10 @@ func (suite *HodlInvoiceSuite) TestNegativeBalanceWithHodl() { //start payment checking loop go func() { - err = suite.service.CheckAllPendingOutgoingPayments(context.Background()) + ctx := context.Background() + pending, err := suite.service.GetAllPendingPayments(ctx) + assert.NoError(suite.T(), err) + err = suite.service.CheckPendingOutgoingPayments(ctx, pending) assert.NoError(suite.T(), err) }() //wait a bit for routine to start diff --git a/lib/service/background_routines.go b/lib/service/background_routines.go index 11cc270..59921ef 100644 --- a/lib/service/background_routines.go +++ b/lib/service/background_routines.go @@ -27,6 +27,10 @@ func (svc *LndhubService) StartPendingPaymentRoutine(ctx context.Context) (err e if svc.RabbitMQClient != nil { return svc.RabbitMQClient.FinalizeInitializedPayments(ctx, svc) } else { - return svc.CheckAllPendingOutgoingPayments(ctx) + pending, err := svc.GetAllPendingPayments(ctx) + if err != nil { + return err + } + return svc.CheckPendingOutgoingPayments(ctx, pending) } } diff --git a/lib/service/checkpayments.go b/lib/service/checkpayments.go index e97125f..2905fb4 100644 --- a/lib/service/checkpayments.go +++ b/lib/service/checkpayments.go @@ -19,12 +19,7 @@ func (svc *LndhubService) GetAllPendingPayments(ctx context.Context) ([]models.I err := svc.DB.NewSelect().Model(&payments).Where("state = 'initialized'").Where("type = 'outgoing'").Where("r_hash != ''").Where("created_at >= (now() - interval '2 weeks') ").Scan(ctx) return payments, err } -func (svc *LndhubService) CheckAllPendingOutgoingPayments(ctx context.Context) (err error) { - pendingPayments, err := svc.GetAllPendingPayments(ctx) - if err != nil { - return err - } - +func (svc *LndhubService) CheckPendingOutgoingPayments(ctx context.Context, pendingPayments []models.Invoice) (err error) { svc.Logger.Infof("Found %d pending payments", len(pendingPayments)) //call trackoutgoingpaymentstatus for each one var wg sync.WaitGroup