mirror of
https://github.com/getAlby/lndhub.go.git
synced 2026-01-07 15:05:37 +01:00
more flexible checkpending func signature
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user