diff --git a/integration_tests/outgoing_payment_test.go b/integration_tests/outgoing_payment_test.go index 776aacc..2ea3335 100644 --- a/integration_tests/outgoing_payment_test.go +++ b/integration_tests/outgoing_payment_test.go @@ -36,11 +36,10 @@ func (suite *PaymentTestSuite) TestOutGoingPayment() { } func (suite *PaymentTestSuite) TestOutGoingPaymentFailure() { - //TODO: use a dummy LND interface to test different scenarios + //TODO: use a new implementation of LNDClientWrapper interface to test different scenarios //might be better if this has it's own suite //because we need a different LND client - // - payment fails directly, no callback event - // - payment fails after some time, failure callback event - // - payment call never returns, success callback event - // - payment call never returns, failure callback event + // - payment fails directly + // - payment fails after some time, check that balance is locked in the meantime and is restored afterwards + // - payment call succeeds after some time, check that balance is locked in the meantime and is _not_ restored afterwards } diff --git a/lib/service/invoices.go b/lib/service/invoices.go index 25c58ef..503f3af 100644 --- a/lib/service/invoices.go +++ b/lib/service/invoices.go @@ -169,16 +169,18 @@ func (svc *LndhubService) PayInvoice(ctx context.Context, invoice *models.Invoic var paymentResponse SendPaymentResponse // Check the destination pubkey if it is an internal invoice and going to our node + // Here we start using context.Background because we want to complete these calls + // regardless of if the request's context is canceled or not. if svc.IdentityPubkey == invoice.DestinationPubkeyHex { - paymentResponse, err = svc.SendInternalPayment(ctx, invoice) + paymentResponse, err = svc.SendInternalPayment(context.Background(), invoice) if err != nil { svc.HandleFailedPayment(ctx, invoice, err) return nil, err } } else { - paymentResponse, err = svc.SendPaymentSync(ctx, invoice) + paymentResponse, err = svc.SendPaymentSync(context.Background(), invoice) if err != nil { - svc.HandleFailedPayment(ctx, invoice, err) + svc.HandleFailedPayment(context.Background(), invoice, err) return nil, err } } @@ -198,16 +200,7 @@ func (svc *LndhubService) PayInvoice(ctx context.Context, invoice *models.Invoic return &paymentResponse, err } -//this method should be called on 2 occasions: when the sendpayment calls returns with an error -//and in an async goroutine that subscribes to outgoing payments. func (svc *LndhubService) HandleFailedPayment(ctx context.Context, invoice *models.Invoice, err error) error { - //if the error was due to canceled ctx, we don't know anything - //about the payment, so we don't do anything here, it will be - //handled asynchronously in the goroutine that subscribes to - //outgoing payments - if err.Error() == context.Canceled.Error() { - return nil - } //if we get here, we can be sure that the payment actually failed //so we must 1) add a new transactionentry that transfers //funds back to the user's "current" balance 2) update the outgoing @@ -215,8 +208,6 @@ func (svc *LndhubService) HandleFailedPayment(ctx context.Context, invoice *mode return nil } -//this method should be called on 2 occasions: when the sendpayment calls returns without an error -//and in an async goroutine that subscribes to outgoing payments. func (svc *LndhubService) HandleSuccesfulPayment(ctx context.Context, invoice *models.Invoice, err error) error { //here we should just update the outgoing invoice as completed //so consolidate the last couple of lines from SendPaymentInternal/SendPaymentSync here diff --git a/lib/service/invoicesubscription.go b/lib/service/invoicesubscription.go index a1ec79a..e809be8 100644 --- a/lib/service/invoicesubscription.go +++ b/lib/service/invoicesubscription.go @@ -150,20 +150,3 @@ func (svc *LndhubService) InvoiceUpdateSubscription(ctx context.Context) error { } } } - -//TODO: implement payment update subscription -//make sure that we do not conflict if the sync -//handling is being done at the same time. -func (svc *LndhubService) PaymentUpdateSubscription(ctx context.Context) error { - // paymentSubscriptionStream, err := svc.ConnectPaymentSubscription(ctx) - // if err != nil { - // sentry.CaptureException(err) - // return err - // } - // for { - // payment, err := paymentSubscriptionStream.Recv() - // if payment success: svc.HandlePaymentSuccess - // if payment fail: svc.HandlePaymentFailure - // } - return nil -}