Fix: use LNClient payment context (#1728)

* fix: mark failed payment as settled

* fix: use lnclient context for paying instead of request context
This commit is contained in:
Roland 2025-09-16 20:53:02 +07:00 committed by GitHub
parent 6fb08d2dac
commit 3787f54006
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
21 changed files with 146 additions and 214 deletions

View file

@ -124,7 +124,7 @@ func (api *api) RebalanceChannel(ctx context.Context, rebalanceChannelRequest *R
"order_id": rebalanceCreateOrderResponse.OrderId,
}
payRebalanceInvoiceResponse, err := api.svc.GetTransactionsService().SendPaymentSync(ctx, rebalanceCreateOrderResponse.PayRequest, nil, payMetadata, api.svc.GetLNClient(), nil, nil)
payRebalanceInvoiceResponse, err := api.svc.GetTransactionsService().SendPaymentSync(rebalanceCreateOrderResponse.PayRequest, nil, payMetadata, api.svc.GetLNClient(), nil, nil)
if err != nil {
logger.Logger.WithError(err).Error("failed to pay rebalance invoice")

View file

@ -64,7 +64,7 @@ func (api *api) SendPayment(ctx context.Context, invoice string, amountMsat *uin
if api.svc.GetLNClient() == nil {
return nil, errors.New("LNClient not started")
}
transaction, err := api.svc.GetTransactionsService().SendPaymentSync(ctx, invoice, amountMsat, metadata, api.svc.GetLNClient(), nil, nil)
transaction, err := api.svc.GetTransactionsService().SendPaymentSync(invoice, amountMsat, metadata, api.svc.GetLNClient(), nil, nil)
if err != nil {
return nil, err
}
@ -150,7 +150,7 @@ func (api *api) Transfer(ctx context.Context, fromAppId *uint, toAppId *uint, am
return err
}
_, err = api.svc.GetTransactionsService().SendPaymentSync(ctx, transaction.PaymentRequest, nil, nil, api.svc.GetLNClient(), fromAppId, nil)
_, err = api.svc.GetTransactionsService().SendPaymentSync(transaction.PaymentRequest, nil, nil, api.svc.GetLNClient(), fromAppId, nil)
return err
}

View file

@ -72,7 +72,7 @@ func (cs *CashuService) Shutdown() error {
return cs.wallet.Shutdown()
}
func (cs *CashuService) SendPaymentSync(ctx context.Context, invoice string, amount *uint64) (response *lnclient.PayInvoiceResponse, err error) {
func (cs *CashuService) SendPaymentSync(invoice string, amount *uint64) (response *lnclient.PayInvoiceResponse, err error) {
// TODO: support 0-amount invoices
if amount != nil {
return nil, errors.New("0-amount invoices not supported")
@ -101,7 +101,7 @@ func (cs *CashuService) SendPaymentSync(ctx context.Context, invoice string, amo
}, nil
}
func (cs *CashuService) SendKeysend(ctx context.Context, amount uint64, destination string, custom_records []lnclient.TLVRecord, preimage string) (*lnclient.PayKeysendResponse, error) {
func (cs *CashuService) SendKeysend(amount uint64, destination string, custom_records []lnclient.TLVRecord, preimage string) (*lnclient.PayKeysendResponse, error) {
return nil, errors.New("keysend not supported")
}

View file

@ -42,6 +42,7 @@ type LDKService struct {
node *ldk_node.Node
ldkEventBroadcaster LDKEventBroadcaster
cancel context.CancelFunc
ctx context.Context
network string
eventPublisher events.EventPublisher
syncing bool
@ -225,6 +226,7 @@ func NewLDKService(ctx context.Context, cfg config.Config, eventPublisher events
eventPublisher: eventPublisher,
cfg: cfg,
pubkey: nodeId,
ctx: ldkCtx,
}
eventPublisher.RegisterSubscriber(&ls)
@ -510,7 +512,7 @@ func (ls *LDKService) MakeOffer(ctx context.Context, description string) (string
return offer, nil
}
func (ls *LDKService) SendPaymentSync(ctx context.Context, invoice string, amount *uint64) (*lnclient.PayInvoiceResponse, error) {
func (ls *LDKService) SendPaymentSync(invoice string, amount *uint64) (*lnclient.PayInvoiceResponse, error) {
paymentRequest, err := decodepay.Decodepay(invoice)
if err != nil {
logger.Logger.WithFields(logrus.Fields{
@ -573,8 +575,8 @@ func (ls *LDKService) SendPaymentSync(ctx context.Context, invoice string, amoun
for {
select {
case <-ctx.Done():
return nil, ctx.Err()
case <-ls.ctx.Done():
return nil, ls.ctx.Err()
case ev := <-ldkEventSubscription:
switch event := (*ev).(type) {
@ -620,7 +622,7 @@ func (ls *LDKService) SendPaymentSync(ctx context.Context, invoice string, amoun
}
}
func (ls *LDKService) SendKeysend(ctx context.Context, amount uint64, destination string, custom_records []lnclient.TLVRecord, preimage string) (*lnclient.PayKeysendResponse, error) {
func (ls *LDKService) SendKeysend(amount uint64, destination string, custom_records []lnclient.TLVRecord, preimage string) (*lnclient.PayKeysendResponse, error) {
paymentStart := time.Now()
customTlvs := []ldk_node.TlvEntry{}
@ -655,39 +657,42 @@ func (ls *LDKService) SendKeysend(ctx context.Context, amount uint64, destinatio
}
fee := uint64(0)
for {
event := <-ldkEventSubscription
select {
case <-ls.ctx.Done():
return nil, ls.ctx.Err()
case event := <-ldkEventSubscription:
eventPaymentSuccessful, isEventPaymentSuccessfulEvent := (*event).(ldk_node.EventPaymentSuccessful)
eventPaymentFailed, isEventPaymentFailedEvent := (*event).(ldk_node.EventPaymentFailed)
eventPaymentSuccessful, isEventPaymentSuccessfulEvent := (*event).(ldk_node.EventPaymentSuccessful)
eventPaymentFailed, isEventPaymentFailedEvent := (*event).(ldk_node.EventPaymentFailed)
if isEventPaymentSuccessfulEvent && eventPaymentSuccessful.PaymentHash == paymentHash {
logger.Logger.Info("Got payment success event")
if isEventPaymentSuccessfulEvent && eventPaymentSuccessful.PaymentHash == paymentHash {
logger.Logger.Info("Got payment success event")
if eventPaymentSuccessful.FeePaidMsat != nil {
fee = *eventPaymentSuccessful.FeePaidMsat
if eventPaymentSuccessful.FeePaidMsat != nil {
fee = *eventPaymentSuccessful.FeePaidMsat
}
logger.Logger.WithFields(logrus.Fields{
"duration": time.Since(paymentStart).Milliseconds(),
"fee": fee,
}).Info("Successful keysend payment")
return &lnclient.PayKeysendResponse{
Fee: fee,
}, nil
}
break
}
if isEventPaymentFailedEvent && eventPaymentFailed.PaymentHash != nil && *eventPaymentFailed.PaymentHash == paymentHash {
if isEventPaymentFailedEvent && eventPaymentFailed.PaymentHash != nil && *eventPaymentFailed.PaymentHash == paymentHash {
failureReasonMessage := ls.getPaymentFailReason(&eventPaymentFailed)
failureReasonMessage := ls.getPaymentFailReason(&eventPaymentFailed)
logger.Logger.WithFields(logrus.Fields{
"payment_hash": paymentHash,
"reason": failureReasonMessage,
}).Error("Received payment failed event")
logger.Logger.WithFields(logrus.Fields{
"payment_hash": paymentHash,
"reason": failureReasonMessage,
}).Error("Received payment failed event")
return nil, fmt.Errorf("payment failed event: %s", failureReasonMessage)
return nil, fmt.Errorf("payment failed event: %s", failureReasonMessage)
}
}
}
logger.Logger.WithFields(logrus.Fields{
"duration": time.Since(paymentStart).Milliseconds(),
"fee": fee,
}).Info("Successful keysend payment")
return &lnclient.PayKeysendResponse{
Fee: fee,
}, nil
}
func (ls *LDKService) getMaxReceivable() int64 {

View file

@ -430,7 +430,7 @@ func (svc *LNDService) Shutdown() error {
return nil
}
func (svc *LNDService) SendPaymentSync(ctx context.Context, payReq string, amount *uint64) (*lnclient.PayInvoiceResponse, error) {
func (svc *LNDService) SendPaymentSync(payReq string, amount *uint64) (*lnclient.PayInvoiceResponse, error) {
const MAX_PARTIAL_PAYMENTS = 16
paymentRequest, err := decodepay.Decodepay(payReq)
@ -455,7 +455,7 @@ func (svc *LNDService) SendPaymentSync(ctx context.Context, payReq string, amoun
sendRequest.AmtMsat = int64(*amount)
}
payStream, err := svc.client.SendPayment(ctx, sendRequest)
payStream, err := svc.client.SendPayment(svc.ctx, sendRequest)
if err != nil {
logger.Logger.WithField("bolt11", payReq).WithError(err).Error("SendPayment failed")
return nil, err
@ -491,7 +491,7 @@ func (svc *LNDService) SendPaymentSync(ctx context.Context, payReq string, amoun
}, nil
}
func (svc *LNDService) SendKeysend(ctx context.Context, amount uint64, destination string, custom_records []lnclient.TLVRecord, preimage string) (*lnclient.PayKeysendResponse, error) {
func (svc *LNDService) SendKeysend(amount uint64, destination string, custom_records []lnclient.TLVRecord, preimage string) (*lnclient.PayKeysendResponse, error) {
destBytes, err := hex.DecodeString(destination)
if err != nil {
logger.Logger.WithFields(logrus.Fields{
@ -541,7 +541,7 @@ func (svc *LNDService) SendKeysend(ctx context.Context, amount uint64, destinati
FeeLimitMsat: int64(transactions.CalculateFeeReserveMsat(amount)),
}
payStream, err := svc.client.SendPayment(ctx, sendPaymentRequest)
payStream, err := svc.client.SendPayment(svc.ctx, sendPaymentRequest)
if err != nil {
logger.Logger.WithFields(logrus.Fields{
"payment_hash": paymentHash,

View file

@ -11,7 +11,7 @@ import (
type LightningClientWrapper interface {
ListChannels(ctx context.Context, req *lnrpc.ListChannelsRequest, options ...grpc.CallOption) (*lnrpc.ListChannelsResponse, error)
SendPaymentSync(ctx context.Context, req *lnrpc.SendRequest, options ...grpc.CallOption) (*lnrpc.SendResponse, error)
SendPaymentSync(req *lnrpc.SendRequest, options ...grpc.CallOption) (*lnrpc.SendResponse, error)
ChannelBalance(ctx context.Context, req *lnrpc.ChannelBalanceRequest, options ...grpc.CallOption) (*lnrpc.ChannelBalanceResponse, error)
AddInvoice(ctx context.Context, req *lnrpc.Invoice, options ...grpc.CallOption) (*lnrpc.AddInvoiceResponse, error)
AddHoldInvoice(ctx context.Context, req *invoicesrpc.AddHoldInvoiceRequest, options ...grpc.CallOption) (*invoicesrpc.AddHoldInvoiceResp, error)

View file

@ -57,8 +57,8 @@ type NodeConnectionInfo struct {
}
type LNClient interface {
SendPaymentSync(ctx context.Context, payReq string, amount *uint64) (*PayInvoiceResponse, error)
SendKeysend(ctx context.Context, amount uint64, destination string, customRecords []TLVRecord, preimage string) (*PayKeysendResponse, error)
SendPaymentSync(payReq string, amount *uint64) (*PayInvoiceResponse, error)
SendKeysend(amount uint64, destination string, customRecords []TLVRecord, preimage string) (*PayKeysendResponse, error)
GetPubkey() string
GetInfo(ctx context.Context) (info *NodeInfo, err error)
MakeInvoice(ctx context.Context, amount int64, description string, descriptionHash string, expiry int64) (transaction *Transaction, err error)

View file

@ -71,6 +71,7 @@ type PhoenixService struct {
Authorization string
pubkey string
nodeInfo *lnclient.NodeInfo
ctx context.Context
}
func NewPhoenixService(ctx context.Context, address string, authorization string) (result lnclient.LNClient, err error) {
@ -80,7 +81,7 @@ func NewPhoenixService(ctx context.Context, address string, authorization string
if !strings.HasPrefix(address, "http") {
address = "http://" + address
}
phoenixService := &PhoenixService{Address: address, Authorization: authorizationBase64}
phoenixService := &PhoenixService{ctx: ctx, Address: address, Authorization: authorizationBase64}
info, err := fetchNodeInfo(ctx, phoenixService)
if err != nil {
@ -362,14 +363,14 @@ func (svc *PhoenixService) LookupInvoice(ctx context.Context, paymentHash string
return transaction, nil
}
func (svc *PhoenixService) SendPaymentSync(ctx context.Context, payReq string, amount *uint64) (*lnclient.PayInvoiceResponse, error) {
func (svc *PhoenixService) SendPaymentSync(payReq string, amount *uint64) (*lnclient.PayInvoiceResponse, error) {
// TODO: support 0-amount invoices
if amount != nil {
return nil, errors.New("0-amount invoices not supported")
}
form := url.Values{}
form.Add("invoice", payReq)
req, err := http.NewRequestWithContext(ctx, http.MethodPost, svc.Address+"/payinvoice", strings.NewReader(form.Encode()))
req, err := http.NewRequestWithContext(svc.ctx, http.MethodPost, svc.Address+"/payinvoice", strings.NewReader(form.Encode()))
if err != nil {
return nil, err
}
@ -393,7 +394,7 @@ func (svc *PhoenixService) SendPaymentSync(ctx context.Context, payReq string, a
}, nil
}
func (svc *PhoenixService) SendKeysend(ctx context.Context, amount uint64, destination string, custom_records []lnclient.TLVRecord, preimage string) (*lnclient.PayKeysendResponse, error) {
func (svc *PhoenixService) SendKeysend(amount uint64, destination string, custom_records []lnclient.TLVRecord, preimage string) (*lnclient.PayKeysendResponse, error) {
return nil, errors.New("not implemented")
}

View file

@ -69,7 +69,7 @@ func (controller *nip47Controller) HandleMultiPayInvoiceEvent(ctx context.Contex
dTag := []string{"d", invoiceDTagValue}
controller.
pay(ctx, bolt11, invoiceInfo.Amount, metadata, &paymentRequest, nip47Request, requestEventId, app, publishResponse, nostr.Tags{dTag})
pay(bolt11, invoiceInfo.Amount, metadata, &paymentRequest, nip47Request, requestEventId, app, publishResponse, nostr.Tags{dTag})
}(invoiceInfo)
}

View file

@ -49,17 +49,17 @@ func (controller *nip47Controller) HandlePayInvoiceEvent(ctx context.Context, ni
return
}
controller.pay(ctx, bolt11, payParams.Amount, payParams.Metadata, &paymentRequest, nip47Request, requestEventId, app, publishResponse, tags)
controller.pay(bolt11, payParams.Amount, payParams.Metadata, &paymentRequest, nip47Request, requestEventId, app, publishResponse, tags)
}
func (controller *nip47Controller) pay(ctx context.Context, bolt11 string, amount *uint64, metadata map[string]interface{}, paymentRequest *decodepay.Bolt11, nip47Request *models.Request, requestEventId uint, app *db.App, publishResponse publishFunc, tags nostr.Tags) {
func (controller *nip47Controller) pay(bolt11 string, amount *uint64, metadata map[string]interface{}, paymentRequest *decodepay.Bolt11, nip47Request *models.Request, requestEventId uint, app *db.App, publishResponse publishFunc, tags nostr.Tags) {
logger.Logger.WithFields(logrus.Fields{
"request_event_id": requestEventId,
"app_id": app.ID,
"bolt11": bolt11,
}).Info("Sending payment")
transaction, err := controller.transactionsService.SendPaymentSync(ctx, bolt11, amount, metadata, controller.lnClient, &app.ID, &requestEventId)
transaction, err := controller.transactionsService.SendPaymentSync(bolt11, amount, metadata, controller.lnClient, &app.ID, &requestEventId)
if err != nil {
logger.Logger.WithFields(logrus.Fields{
"request_event_id": requestEventId,

View file

@ -35,7 +35,7 @@ func (controller *nip47Controller) payKeysend(ctx context.Context, payKeysendPar
"senderPubkey": payKeysendParams.Pubkey,
}).Info("Sending keysend payment")
transaction, err := controller.transactionsService.SendKeysend(ctx, payKeysendParams.Amount, payKeysendParams.Pubkey, payKeysendParams.TLVRecords, payKeysendParams.Preimage, controller.lnClient, &app.ID, &requestEventId)
transaction, err := controller.transactionsService.SendKeysend(payKeysendParams.Amount, payKeysendParams.Pubkey, payKeysendParams.TLVRecords, payKeysendParams.Preimage, controller.lnClient, &app.ID, &requestEventId)
if err != nil {
logger.Logger.WithFields(logrus.Fields{
"request_event_id": requestEventId,

View file

@ -1140,7 +1140,7 @@ func (svc *swapsService) startSwapOutListener(swap *db.Swap) {
"swap_id": swap.SwapId,
}
logger.Logger.WithField("swapId", swap.SwapId).Info("Initiating swap invoice payment")
_, err = svc.transactionsService.SendPaymentSync(svc.ctx, swap.Invoice, nil, metadata, svc.lnClient, nil, nil)
_, err = svc.transactionsService.SendPaymentSync(swap.Invoice, nil, metadata, svc.lnClient, nil, nil)
if err != nil {
logger.Logger.WithError(err).WithFields(logrus.Fields{
"swapId": swap.SwapId,

View file

@ -89,7 +89,7 @@ func NewMockLn() (*MockLn, error) {
return &MockLn{}, nil
}
func (mln *MockLn) SendPaymentSync(ctx context.Context, payReq string, amount *uint64) (*lnclient.PayInvoiceResponse, error) {
func (mln *MockLn) SendPaymentSync(payReq string, amount *uint64) (*lnclient.PayInvoiceResponse, error) {
if len(mln.PayInvoiceResponses) > 0 {
response := mln.PayInvoiceResponses[0]
err := mln.PayInvoiceErrors[0]
@ -106,7 +106,7 @@ func (mln *MockLn) SendPaymentSync(ctx context.Context, payReq string, amount *u
}, nil
}
func (mln *MockLn) SendKeysend(ctx context.Context, amount uint64, destination string, custom_records []lnclient.TLVRecord, preimage string) (*lnclient.PayKeysendResponse, error) {
func (mln *MockLn) SendKeysend(amount uint64, destination string, custom_records []lnclient.TLVRecord, preimage string) (*lnclient.PayKeysendResponse, error) {
return &lnclient.PayKeysendResponse{
Fee: 1,
}, nil

View file

@ -1598,8 +1598,8 @@ func (_c *MockLNClient_ResetRouter_Call) RunAndReturn(run func(key string) error
}
// SendKeysend provides a mock function for the type MockLNClient
func (_mock *MockLNClient) SendKeysend(ctx context.Context, amount uint64, destination string, customRecords []lnclient.TLVRecord, preimage string) (*lnclient.PayKeysendResponse, error) {
ret := _mock.Called(ctx, amount, destination, customRecords, preimage)
func (_mock *MockLNClient) SendKeysend(amount uint64, destination string, customRecords []lnclient.TLVRecord, preimage string) (*lnclient.PayKeysendResponse, error) {
ret := _mock.Called(amount, destination, customRecords, preimage)
if len(ret) == 0 {
panic("no return value specified for SendKeysend")
@ -1607,18 +1607,18 @@ func (_mock *MockLNClient) SendKeysend(ctx context.Context, amount uint64, desti
var r0 *lnclient.PayKeysendResponse
var r1 error
if returnFunc, ok := ret.Get(0).(func(context.Context, uint64, string, []lnclient.TLVRecord, string) (*lnclient.PayKeysendResponse, error)); ok {
return returnFunc(ctx, amount, destination, customRecords, preimage)
if returnFunc, ok := ret.Get(0).(func(uint64, string, []lnclient.TLVRecord, string) (*lnclient.PayKeysendResponse, error)); ok {
return returnFunc(amount, destination, customRecords, preimage)
}
if returnFunc, ok := ret.Get(0).(func(context.Context, uint64, string, []lnclient.TLVRecord, string) *lnclient.PayKeysendResponse); ok {
r0 = returnFunc(ctx, amount, destination, customRecords, preimage)
if returnFunc, ok := ret.Get(0).(func(uint64, string, []lnclient.TLVRecord, string) *lnclient.PayKeysendResponse); ok {
r0 = returnFunc(amount, destination, customRecords, preimage)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).(*lnclient.PayKeysendResponse)
}
}
if returnFunc, ok := ret.Get(1).(func(context.Context, uint64, string, []lnclient.TLVRecord, string) error); ok {
r1 = returnFunc(ctx, amount, destination, customRecords, preimage)
if returnFunc, ok := ret.Get(1).(func(uint64, string, []lnclient.TLVRecord, string) error); ok {
r1 = returnFunc(amount, destination, customRecords, preimage)
} else {
r1 = ret.Error(1)
}
@ -1631,18 +1631,17 @@ type MockLNClient_SendKeysend_Call struct {
}
// SendKeysend is a helper method to define mock.On call
// - ctx
// - amount
// - destination
// - customRecords
// - preimage
func (_e *MockLNClient_Expecter) SendKeysend(ctx interface{}, amount interface{}, destination interface{}, customRecords interface{}, preimage interface{}) *MockLNClient_SendKeysend_Call {
return &MockLNClient_SendKeysend_Call{Call: _e.mock.On("SendKeysend", ctx, amount, destination, customRecords, preimage)}
func (_e *MockLNClient_Expecter) SendKeysend(amount interface{}, destination interface{}, customRecords interface{}, preimage interface{}) *MockLNClient_SendKeysend_Call {
return &MockLNClient_SendKeysend_Call{Call: _e.mock.On("SendKeysend", amount, destination, customRecords, preimage)}
}
func (_c *MockLNClient_SendKeysend_Call) Run(run func(ctx context.Context, amount uint64, destination string, customRecords []lnclient.TLVRecord, preimage string)) *MockLNClient_SendKeysend_Call {
func (_c *MockLNClient_SendKeysend_Call) Run(run func(amount uint64, destination string, customRecords []lnclient.TLVRecord, preimage string)) *MockLNClient_SendKeysend_Call {
_c.Call.Run(func(args mock.Arguments) {
run(args[0].(context.Context), args[1].(uint64), args[2].(string), args[3].([]lnclient.TLVRecord), args[4].(string))
run(args[0].(uint64), args[1].(string), args[2].([]lnclient.TLVRecord), args[3].(string))
})
return _c
}
@ -1652,7 +1651,7 @@ func (_c *MockLNClient_SendKeysend_Call) Return(payKeysendResponse *lnclient.Pay
return _c
}
func (_c *MockLNClient_SendKeysend_Call) RunAndReturn(run func(ctx context.Context, amount uint64, destination string, customRecords []lnclient.TLVRecord, preimage string) (*lnclient.PayKeysendResponse, error)) *MockLNClient_SendKeysend_Call {
func (_c *MockLNClient_SendKeysend_Call) RunAndReturn(run func(amount uint64, destination string, customRecords []lnclient.TLVRecord, preimage string) (*lnclient.PayKeysendResponse, error)) *MockLNClient_SendKeysend_Call {
_c.Call.Return(run)
return _c
}
@ -1704,8 +1703,8 @@ func (_c *MockLNClient_SendPaymentProbes_Call) RunAndReturn(run func(ctx context
}
// SendPaymentSync provides a mock function for the type MockLNClient
func (_mock *MockLNClient) SendPaymentSync(ctx context.Context, payReq string, amount *uint64) (*lnclient.PayInvoiceResponse, error) {
ret := _mock.Called(ctx, payReq, amount)
func (_mock *MockLNClient) SendPaymentSync(payReq string, amount *uint64) (*lnclient.PayInvoiceResponse, error) {
ret := _mock.Called(payReq, amount)
if len(ret) == 0 {
panic("no return value specified for SendPaymentSync")
@ -1713,18 +1712,18 @@ func (_mock *MockLNClient) SendPaymentSync(ctx context.Context, payReq string, a
var r0 *lnclient.PayInvoiceResponse
var r1 error
if returnFunc, ok := ret.Get(0).(func(context.Context, string, *uint64) (*lnclient.PayInvoiceResponse, error)); ok {
return returnFunc(ctx, payReq, amount)
if returnFunc, ok := ret.Get(0).(func(string, *uint64) (*lnclient.PayInvoiceResponse, error)); ok {
return returnFunc(payReq, amount)
}
if returnFunc, ok := ret.Get(0).(func(context.Context, string, *uint64) *lnclient.PayInvoiceResponse); ok {
r0 = returnFunc(ctx, payReq, amount)
if returnFunc, ok := ret.Get(0).(func(string, *uint64) *lnclient.PayInvoiceResponse); ok {
r0 = returnFunc(payReq, amount)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).(*lnclient.PayInvoiceResponse)
}
}
if returnFunc, ok := ret.Get(1).(func(context.Context, string, *uint64) error); ok {
r1 = returnFunc(ctx, payReq, amount)
if returnFunc, ok := ret.Get(1).(func(string, *uint64) error); ok {
r1 = returnFunc(payReq, amount)
} else {
r1 = ret.Error(1)
}
@ -1737,16 +1736,15 @@ type MockLNClient_SendPaymentSync_Call struct {
}
// SendPaymentSync is a helper method to define mock.On call
// - ctx
// - payReq
// - amount
func (_e *MockLNClient_Expecter) SendPaymentSync(ctx interface{}, payReq interface{}, amount interface{}) *MockLNClient_SendPaymentSync_Call {
return &MockLNClient_SendPaymentSync_Call{Call: _e.mock.On("SendPaymentSync", ctx, payReq, amount)}
func (_e *MockLNClient_Expecter) SendPaymentSync(payReq interface{}, amount interface{}) *MockLNClient_SendPaymentSync_Call {
return &MockLNClient_SendPaymentSync_Call{Call: _e.mock.On("SendPaymentSync", payReq, amount)}
}
func (_c *MockLNClient_SendPaymentSync_Call) Run(run func(ctx context.Context, payReq string, amount *uint64)) *MockLNClient_SendPaymentSync_Call {
func (_c *MockLNClient_SendPaymentSync_Call) Run(run func(payReq string, amount *uint64)) *MockLNClient_SendPaymentSync_Call {
_c.Call.Run(func(args mock.Arguments) {
run(args[0].(context.Context), args[1].(string), args[2].(*uint64))
run(args[0].(string), args[1].(*uint64))
})
return _c
}
@ -1756,7 +1754,7 @@ func (_c *MockLNClient_SendPaymentSync_Call) Return(payInvoiceResponse *lnclient
return _c
}
func (_c *MockLNClient_SendPaymentSync_Call) RunAndReturn(run func(ctx context.Context, payReq string, amount *uint64) (*lnclient.PayInvoiceResponse, error)) *MockLNClient_SendPaymentSync_Call {
func (_c *MockLNClient_SendPaymentSync_Call) RunAndReturn(run func(payReq string, amount *uint64) (*lnclient.PayInvoiceResponse, error)) *MockLNClient_SendPaymentSync_Call {
_c.Call.Return(run)
return _c
}

View file

@ -1,7 +1,6 @@
package transactions
import (
"context"
"testing"
"time"
@ -14,8 +13,6 @@ import (
)
func TestSendPaymentSync_App_NoPermission(t *testing.T) {
ctx := context.TODO()
svc, err := tests.CreateTestService(t)
require.NoError(t, err)
defer svc.Remove()
@ -28,15 +25,13 @@ func TestSendPaymentSync_App_NoPermission(t *testing.T) {
assert.NoError(t, err)
transactionsService := NewTransactionsService(svc.DB, svc.EventPublisher)
transaction, err := transactionsService.SendPaymentSync(ctx, tests.MockLNClientTransaction.Invoice, nil, nil, svc.LNClient, &app.ID, &dbRequestEvent.ID)
transaction, err := transactionsService.SendPaymentSync(tests.MockLNClientTransaction.Invoice, nil, nil, svc.LNClient, &app.ID, &dbRequestEvent.ID)
assert.Error(t, err)
assert.Equal(t, "app does not have pay_invoice scope", err.Error())
assert.Nil(t, transaction)
}
func TestSendPaymentSync_App_WithPermission(t *testing.T) {
ctx := context.TODO()
svc, err := tests.CreateTestService(t)
require.NoError(t, err)
defer svc.Remove()
@ -57,7 +52,7 @@ func TestSendPaymentSync_App_WithPermission(t *testing.T) {
assert.NoError(t, err)
transactionsService := NewTransactionsService(svc.DB, svc.EventPublisher)
transaction, err := transactionsService.SendPaymentSync(ctx, tests.MockLNClientTransaction.Invoice, nil, nil, svc.LNClient, &app.ID, &dbRequestEvent.ID)
transaction, err := transactionsService.SendPaymentSync(tests.MockLNClientTransaction.Invoice, nil, nil, svc.LNClient, &app.ID, &dbRequestEvent.ID)
assert.NoError(t, err)
assert.Equal(t, uint64(123000), transaction.AmountMsat)
@ -68,8 +63,6 @@ func TestSendPaymentSync_App_WithPermission(t *testing.T) {
}
func TestSendPaymentSync_App_BudgetExceeded(t *testing.T) {
ctx := context.TODO()
svc, err := tests.CreateTestService(t)
require.NoError(t, err)
defer svc.Remove()
@ -94,7 +87,7 @@ func TestSendPaymentSync_App_BudgetExceeded(t *testing.T) {
svc.EventPublisher.RegisterSubscriber(mockEventConsumer)
transactionsService := NewTransactionsService(svc.DB, svc.EventPublisher)
transaction, err := transactionsService.SendPaymentSync(ctx, tests.MockLNClientTransaction.Invoice, nil, nil, svc.LNClient, &app.ID, &dbRequestEvent.ID)
transaction, err := transactionsService.SendPaymentSync(tests.MockLNClientTransaction.Invoice, nil, nil, svc.LNClient, &app.ID, &dbRequestEvent.ID)
assert.Error(t, err)
assert.ErrorIs(t, err, NewQuotaExceededError())
@ -109,8 +102,6 @@ func TestSendPaymentSync_App_BudgetExceeded(t *testing.T) {
}
func TestSendPaymentSync_App_BudgetExceeded_SettledPayment(t *testing.T) {
ctx := context.TODO()
svc, err := tests.CreateTestService(t)
require.NoError(t, err)
defer svc.Remove()
@ -141,15 +132,13 @@ func TestSendPaymentSync_App_BudgetExceeded_SettledPayment(t *testing.T) {
assert.NoError(t, err)
transactionsService := NewTransactionsService(svc.DB, svc.EventPublisher)
transaction, err := transactionsService.SendPaymentSync(ctx, tests.MockLNClientTransaction.Invoice, nil, nil, svc.LNClient, &app.ID, &dbRequestEvent.ID)
transaction, err := transactionsService.SendPaymentSync(tests.MockLNClientTransaction.Invoice, nil, nil, svc.LNClient, &app.ID, &dbRequestEvent.ID)
assert.Error(t, err)
assert.ErrorIs(t, err, NewQuotaExceededError())
assert.Nil(t, transaction)
}
func TestSendPaymentSync_App_BudgetExceeded_UnsettledPayment(t *testing.T) {
ctx := context.TODO()
svc, err := tests.CreateTestService(t)
require.NoError(t, err)
defer svc.Remove()
@ -180,7 +169,7 @@ func TestSendPaymentSync_App_BudgetExceeded_UnsettledPayment(t *testing.T) {
assert.NoError(t, err)
transactionsService := NewTransactionsService(svc.DB, svc.EventPublisher)
transaction, err := transactionsService.SendPaymentSync(ctx, tests.MockLNClientTransaction.Invoice, nil, nil, svc.LNClient, &app.ID, &dbRequestEvent.ID)
transaction, err := transactionsService.SendPaymentSync(tests.MockLNClientTransaction.Invoice, nil, nil, svc.LNClient, &app.ID, &dbRequestEvent.ID)
assert.Error(t, err)
assert.ErrorIs(t, err, NewQuotaExceededError())
@ -188,8 +177,6 @@ func TestSendPaymentSync_App_BudgetExceeded_UnsettledPayment(t *testing.T) {
}
func TestSendPaymentSync_App_BudgetNotExceeded_FailedPayment(t *testing.T) {
ctx := context.TODO()
svc, err := tests.CreateTestService(t)
require.NoError(t, err)
defer svc.Remove()
@ -220,7 +207,7 @@ func TestSendPaymentSync_App_BudgetNotExceeded_FailedPayment(t *testing.T) {
assert.NoError(t, err)
transactionsService := NewTransactionsService(svc.DB, svc.EventPublisher)
transaction, err := transactionsService.SendPaymentSync(ctx, tests.MockLNClientTransaction.Invoice, nil, nil, svc.LNClient, &app.ID, &dbRequestEvent.ID)
transaction, err := transactionsService.SendPaymentSync(tests.MockLNClientTransaction.Invoice, nil, nil, svc.LNClient, &app.ID, &dbRequestEvent.ID)
assert.NoError(t, err)
assert.Equal(t, uint64(123000), transaction.AmountMsat)

View file

@ -1,7 +1,6 @@
package transactions
import (
"context"
"testing"
"github.com/stretchr/testify/assert"
@ -13,8 +12,6 @@ import (
)
func TestSendPaymentSync_IsolatedApp_NoBalance(t *testing.T) {
ctx := context.TODO()
svc, err := tests.CreateTestService(t)
require.NoError(t, err)
defer svc.Remove()
@ -37,7 +34,7 @@ func TestSendPaymentSync_IsolatedApp_NoBalance(t *testing.T) {
assert.NoError(t, err)
transactionsService := NewTransactionsService(svc.DB, svc.EventPublisher)
transaction, err := transactionsService.SendPaymentSync(ctx, tests.MockLNClientTransaction.Invoice, nil, nil, svc.LNClient, &app.ID, &dbRequestEvent.ID)
transaction, err := transactionsService.SendPaymentSync(tests.MockLNClientTransaction.Invoice, nil, nil, svc.LNClient, &app.ID, &dbRequestEvent.ID)
assert.Error(t, err)
assert.ErrorIs(t, err, NewInsufficientBalanceError())
@ -45,8 +42,6 @@ func TestSendPaymentSync_IsolatedApp_NoBalance(t *testing.T) {
}
func TestSendPaymentSync_IsolatedApp_BalanceInsufficient(t *testing.T) {
ctx := context.TODO()
svc, err := tests.CreateTestService(t)
require.NoError(t, err)
defer svc.Remove()
@ -79,7 +74,7 @@ func TestSendPaymentSync_IsolatedApp_BalanceInsufficient(t *testing.T) {
svc.EventPublisher.RegisterSubscriber(mockEventConsumer)
transactionsService := NewTransactionsService(svc.DB, svc.EventPublisher)
transaction, err := transactionsService.SendPaymentSync(ctx, tests.MockLNClientTransaction.Invoice, nil, nil, svc.LNClient, &app.ID, &dbRequestEvent.ID)
transaction, err := transactionsService.SendPaymentSync(tests.MockLNClientTransaction.Invoice, nil, nil, svc.LNClient, &app.ID, &dbRequestEvent.ID)
assert.Error(t, err)
assert.ErrorIs(t, err, NewInsufficientBalanceError())
@ -94,8 +89,6 @@ func TestSendPaymentSync_IsolatedApp_BalanceInsufficient(t *testing.T) {
}
func TestSendPaymentSync_IsolatedApp_BalanceSufficient(t *testing.T) {
ctx := context.TODO()
svc, err := tests.CreateTestService(t)
require.NoError(t, err)
defer svc.Remove()
@ -125,7 +118,7 @@ func TestSendPaymentSync_IsolatedApp_BalanceSufficient(t *testing.T) {
})
transactionsService := NewTransactionsService(svc.DB, svc.EventPublisher)
transaction, err := transactionsService.SendPaymentSync(ctx, tests.MockLNClientTransaction.Invoice, nil, nil, svc.LNClient, &app.ID, &dbRequestEvent.ID)
transaction, err := transactionsService.SendPaymentSync(tests.MockLNClientTransaction.Invoice, nil, nil, svc.LNClient, &app.ID, &dbRequestEvent.ID)
assert.NoError(t, err)
assert.Equal(t, uint64(123000), transaction.AmountMsat)
@ -136,8 +129,6 @@ func TestSendPaymentSync_IsolatedApp_BalanceSufficient(t *testing.T) {
}
func TestSendPaymentSync_IsolatedApp_BalanceInsufficient_OutstandingPayment(t *testing.T) {
ctx := context.TODO()
svc, err := tests.CreateTestService(t)
require.NoError(t, err)
defer svc.Remove()
@ -174,7 +165,7 @@ func TestSendPaymentSync_IsolatedApp_BalanceInsufficient_OutstandingPayment(t *t
})
transactionsService := NewTransactionsService(svc.DB, svc.EventPublisher)
transaction, err := transactionsService.SendPaymentSync(ctx, tests.MockLNClientTransaction.Invoice, nil, nil, svc.LNClient, &app.ID, &dbRequestEvent.ID)
transaction, err := transactionsService.SendPaymentSync(tests.MockLNClientTransaction.Invoice, nil, nil, svc.LNClient, &app.ID, &dbRequestEvent.ID)
assert.Error(t, err)
assert.ErrorIs(t, err, NewInsufficientBalanceError())
@ -182,8 +173,6 @@ func TestSendPaymentSync_IsolatedApp_BalanceInsufficient_OutstandingPayment(t *t
}
func TestSendPaymentSync_IsolatedApp_BalanceInsufficient_SettledPayment(t *testing.T) {
ctx := context.TODO()
svc, err := tests.CreateTestService(t)
require.NoError(t, err)
defer svc.Remove()
@ -220,7 +209,7 @@ func TestSendPaymentSync_IsolatedApp_BalanceInsufficient_SettledPayment(t *testi
})
transactionsService := NewTransactionsService(svc.DB, svc.EventPublisher)
transaction, err := transactionsService.SendPaymentSync(ctx, tests.MockLNClientTransaction.Invoice, nil, nil, svc.LNClient, &app.ID, &dbRequestEvent.ID)
transaction, err := transactionsService.SendPaymentSync(tests.MockLNClientTransaction.Invoice, nil, nil, svc.LNClient, &app.ID, &dbRequestEvent.ID)
assert.Error(t, err)
assert.ErrorIs(t, err, NewInsufficientBalanceError())
@ -228,8 +217,6 @@ func TestSendPaymentSync_IsolatedApp_BalanceInsufficient_SettledPayment(t *testi
}
func TestSendPaymentSync_IsolatedApp_BalanceSufficient_UnrelatedPayment(t *testing.T) {
ctx := context.TODO()
svc, err := tests.CreateTestService(t)
require.NoError(t, err)
defer svc.Remove()
@ -265,7 +252,7 @@ func TestSendPaymentSync_IsolatedApp_BalanceSufficient_UnrelatedPayment(t *testi
})
transactionsService := NewTransactionsService(svc.DB, svc.EventPublisher)
transaction, err := transactionsService.SendPaymentSync(ctx, tests.MockLNClientTransaction.Invoice, nil, nil, svc.LNClient, &app.ID, &dbRequestEvent.ID)
transaction, err := transactionsService.SendPaymentSync(tests.MockLNClientTransaction.Invoice, nil, nil, svc.LNClient, &app.ID, &dbRequestEvent.ID)
assert.NoError(t, err)
assert.Equal(t, uint64(123000), transaction.AmountMsat)
@ -276,8 +263,6 @@ func TestSendPaymentSync_IsolatedApp_BalanceSufficient_UnrelatedPayment(t *testi
}
func TestSendPaymentSync_IsolatedApp_BalanceSufficient_FailedPayment(t *testing.T) {
ctx := context.TODO()
svc, err := tests.CreateTestService(t)
require.NoError(t, err)
defer svc.Remove()
@ -313,7 +298,7 @@ func TestSendPaymentSync_IsolatedApp_BalanceSufficient_FailedPayment(t *testing.
})
transactionsService := NewTransactionsService(svc.DB, svc.EventPublisher)
transaction, err := transactionsService.SendPaymentSync(ctx, tests.MockLNClientTransaction.Invoice, nil, nil, svc.LNClient, &app.ID, &dbRequestEvent.ID)
transaction, err := transactionsService.SendPaymentSync(tests.MockLNClientTransaction.Invoice, nil, nil, svc.LNClient, &app.ID, &dbRequestEvent.ID)
assert.NoError(t, err)
assert.Equal(t, uint64(123000), transaction.AmountMsat)
@ -324,8 +309,6 @@ func TestSendPaymentSync_IsolatedApp_BalanceSufficient_FailedPayment(t *testing.
}
func TestSendPaymentSync_IsolatedApp_BalanceInsufficientThenSufficient(t *testing.T) {
ctx := context.TODO()
svc, err := tests.CreateTestService(t)
require.NoError(t, err)
defer svc.Remove()
@ -355,7 +338,7 @@ func TestSendPaymentSync_IsolatedApp_BalanceInsufficientThenSufficient(t *testin
})
transactionsService := NewTransactionsService(svc.DB, svc.EventPublisher)
transaction, err := transactionsService.SendPaymentSync(ctx, tests.MockLNClientTransaction.Invoice, nil, nil, svc.LNClient, &app.ID, &dbRequestEvent.ID)
transaction, err := transactionsService.SendPaymentSync(tests.MockLNClientTransaction.Invoice, nil, nil, svc.LNClient, &app.ID, &dbRequestEvent.ID)
assert.Error(t, err)
assert.ErrorIs(t, err, NewInsufficientBalanceError())
@ -368,7 +351,7 @@ func TestSendPaymentSync_IsolatedApp_BalanceInsufficientThenSufficient(t *testin
AmountMsat: 10000, // add extra to cover fee reserves max of(10 sats or 1%)
})
transaction, err = transactionsService.SendPaymentSync(ctx, tests.MockLNClientTransaction.Invoice, nil, nil, svc.LNClient, &app.ID, &dbRequestEvent.ID)
transaction, err = transactionsService.SendPaymentSync(tests.MockLNClientTransaction.Invoice, nil, nil, svc.LNClient, &app.ID, &dbRequestEvent.ID)
assert.NoError(t, err)
assert.Equal(t, uint64(123000), transaction.AmountMsat)

View file

@ -18,8 +18,6 @@ import (
)
func TestSendKeysend(t *testing.T) {
ctx := context.TODO()
svc, err := tests.CreateTestService(t)
require.NoError(t, err)
defer svc.Remove()
@ -28,7 +26,7 @@ func TestSendKeysend(t *testing.T) {
svc.EventPublisher.RegisterSubscriber(mockEventConsumer)
transactionsService := NewTransactionsService(svc.DB, svc.EventPublisher)
transaction, err := transactionsService.SendKeysend(ctx, uint64(1000), "fake destination", nil, "", svc.LNClient, nil, nil)
transaction, err := transactionsService.SendKeysend(uint64(1000), "fake destination", nil, "", svc.LNClient, nil, nil)
assert.NoError(t, err)
var metadata lnclient.Metadata
@ -50,15 +48,13 @@ func TestSendKeysend(t *testing.T) {
assert.Equal(t, transaction, settledTransaction)
}
func TestSendKeysend_CustomPreimage(t *testing.T) {
ctx := context.TODO()
svc, err := tests.CreateTestService(t)
require.NoError(t, err)
defer svc.Remove()
customPreimage := "018465013e2337234a7e5530a21c4a8cf70d84231f4a8ff0b1e2cce3cb2bd03b"
transactionsService := NewTransactionsService(svc.DB, svc.EventPublisher)
transaction, err := transactionsService.SendKeysend(ctx, uint64(1000), "fake destination", nil, customPreimage, svc.LNClient, nil, nil)
transaction, err := transactionsService.SendKeysend(uint64(1000), "fake destination", nil, customPreimage, svc.LNClient, nil, nil)
assert.NoError(t, err)
var metadata lnclient.Metadata
@ -76,8 +72,6 @@ func TestSendKeysend_CustomPreimage(t *testing.T) {
}
func TestSendKeysend_App_NoPermission(t *testing.T) {
ctx := context.TODO()
svc, err := tests.CreateTestService(t)
require.NoError(t, err)
defer svc.Remove()
@ -90,7 +84,7 @@ func TestSendKeysend_App_NoPermission(t *testing.T) {
assert.NoError(t, err)
transactionsService := NewTransactionsService(svc.DB, svc.EventPublisher)
transaction, err := transactionsService.SendKeysend(ctx, uint64(1000), "fake destination", nil, "", svc.LNClient, &app.ID, &dbRequestEvent.ID)
transaction, err := transactionsService.SendKeysend(uint64(1000), "fake destination", nil, "", svc.LNClient, &app.ID, &dbRequestEvent.ID)
assert.Error(t, err)
assert.Equal(t, "app does not have pay_invoice scope", err.Error())
@ -98,8 +92,6 @@ func TestSendKeysend_App_NoPermission(t *testing.T) {
}
func TestSendKeysend_App_WithPermission(t *testing.T) {
ctx := context.TODO()
svc, err := tests.CreateTestService(t)
require.NoError(t, err)
defer svc.Remove()
@ -120,7 +112,7 @@ func TestSendKeysend_App_WithPermission(t *testing.T) {
assert.NoError(t, err)
transactionsService := NewTransactionsService(svc.DB, svc.EventPublisher)
transaction, err := transactionsService.SendKeysend(ctx, uint64(1000), "fake destination", nil, "", svc.LNClient, &app.ID, &dbRequestEvent.ID)
transaction, err := transactionsService.SendKeysend(uint64(1000), "fake destination", nil, "", svc.LNClient, &app.ID, &dbRequestEvent.ID)
assert.NoError(t, err)
var metadata lnclient.Metadata
@ -140,8 +132,6 @@ func TestSendKeysend_App_WithPermission(t *testing.T) {
}
func TestSendKeysend_App_BudgetExceeded(t *testing.T) {
ctx := context.TODO()
svc, err := tests.CreateTestService(t)
require.NoError(t, err)
defer svc.Remove()
@ -166,7 +156,7 @@ func TestSendKeysend_App_BudgetExceeded(t *testing.T) {
svc.EventPublisher.RegisterSubscriber(mockEventConsumer)
transactionsService := NewTransactionsService(svc.DB, svc.EventPublisher)
transaction, err := transactionsService.SendKeysend(ctx, uint64(1000), "fake destination", nil, "", svc.LNClient, &app.ID, &dbRequestEvent.ID)
transaction, err := transactionsService.SendKeysend(uint64(1000), "fake destination", nil, "", svc.LNClient, &app.ID, &dbRequestEvent.ID)
assert.ErrorIs(t, err, NewQuotaExceededError())
assert.Nil(t, transaction)
@ -178,8 +168,6 @@ func TestSendKeysend_App_BudgetExceeded(t *testing.T) {
assert.Equal(t, NewQuotaExceededError().Error(), mockEventConsumer.GetConsumedEvents()[0].Properties.(map[string]interface{})["message"])
}
func TestSendKeysend_App_BudgetNotExceeded(t *testing.T) {
ctx := context.TODO()
svc, err := tests.CreateTestService(t)
require.NoError(t, err)
defer svc.Remove()
@ -201,7 +189,7 @@ func TestSendKeysend_App_BudgetNotExceeded(t *testing.T) {
assert.NoError(t, err)
transactionsService := NewTransactionsService(svc.DB, svc.EventPublisher)
transaction, err := transactionsService.SendKeysend(ctx, uint64(1000), "fake destination", nil, "", svc.LNClient, &app.ID, &dbRequestEvent.ID)
transaction, err := transactionsService.SendKeysend(uint64(1000), "fake destination", nil, "", svc.LNClient, &app.ID, &dbRequestEvent.ID)
assert.NoError(t, err)
var metadata lnclient.Metadata
@ -221,8 +209,6 @@ func TestSendKeysend_App_BudgetNotExceeded(t *testing.T) {
}
func TestSendKeysend_App_BalanceExceeded(t *testing.T) {
ctx := context.TODO()
svc, err := tests.CreateTestService(t)
require.NoError(t, err)
defer svc.Remove()
@ -252,15 +238,13 @@ func TestSendKeysend_App_BalanceExceeded(t *testing.T) {
})
transactionsService := NewTransactionsService(svc.DB, svc.EventPublisher)
transaction, err := transactionsService.SendKeysend(ctx, uint64(1000), "fake destination", nil, "", svc.LNClient, &app.ID, &dbRequestEvent.ID)
transaction, err := transactionsService.SendKeysend(uint64(1000), "fake destination", nil, "", svc.LNClient, &app.ID, &dbRequestEvent.ID)
assert.ErrorIs(t, err, NewInsufficientBalanceError())
assert.Nil(t, transaction)
}
func TestSendKeysend_App_BalanceSufficient(t *testing.T) {
ctx := context.TODO()
svc, err := tests.CreateTestService(t)
require.NoError(t, err)
defer svc.Remove()
@ -290,7 +274,7 @@ func TestSendKeysend_App_BalanceSufficient(t *testing.T) {
})
transactionsService := NewTransactionsService(svc.DB, svc.EventPublisher)
transaction, err := transactionsService.SendKeysend(ctx, uint64(1000), "fake destination", nil, "", svc.LNClient, &app.ID, &dbRequestEvent.ID)
transaction, err := transactionsService.SendKeysend(uint64(1000), "fake destination", nil, "", svc.LNClient, &app.ID, &dbRequestEvent.ID)
assert.NoError(t, err)
var metadata lnclient.Metadata
@ -310,14 +294,12 @@ func TestSendKeysend_App_BalanceSufficient(t *testing.T) {
}
func TestSendKeysend_TLVs(t *testing.T) {
ctx := context.TODO()
svc, err := tests.CreateTestService(t)
require.NoError(t, err)
defer svc.Remove()
transactionsService := NewTransactionsService(svc.DB, svc.EventPublisher)
transaction, err := transactionsService.SendKeysend(ctx, uint64(1000), "fake destination", []lnclient.TLVRecord{
transaction, err := transactionsService.SendKeysend(uint64(1000), "fake destination", []lnclient.TLVRecord{
{
Type: 7629169,
Value: "7b22616374696f6e223a22626f6f7374222c2276616c75655f6d736174223a313030302c2276616c75655f6d7361745f746f74616c223a313030302c226170705f6e616d65223a22e29aa1205765624c4e2044656d6f222c226170705f76657273696f6e223a22312e30222c22666565644944223a2268747470733a2f2f66656564732e706f6463617374696e6465782e6f72672f706332302e786d6c222c22706f6463617374223a22506f6463617374696e6720322e30222c22657069736f6465223a22457069736f6465203130343a2041204e65772044756d70222c227473223a32312c226e616d65223a22e29aa1205765624c4e2044656d6f222c2273656e6465725f6e616d65223a225361746f736869204e616b616d6f746f222c226d657373616765223a22476f20706f6463617374696e6721227d",
@ -358,8 +340,6 @@ func TestSendKeysend_TLVs(t *testing.T) {
}
func TestSendKeysend_IsolatedAppToNoApp(t *testing.T) {
ctx := context.TODO()
svc, err := tests.CreateTestService(t)
require.NoError(t, err)
defer svc.Remove()
@ -396,7 +376,7 @@ func TestSendKeysend_IsolatedAppToNoApp(t *testing.T) {
mockPreimage := "c8aeb44ae8eb269c8dbfb7ec5c263f0bfa3d755bc0ca641b8ee118673afda657"
transactionsService := NewTransactionsService(svc.DB, svc.EventPublisher)
transaction, err := transactionsService.SendKeysend(ctx, 123000, "03cbd788f5b22bd56e2714bff756372d2293504c064e03250ed16a4dd80ad70e2c", []lnclient.TLVRecord{}, mockPreimage, svc.LNClient, &app.ID, &dbRequestEvent.ID)
transaction, err := transactionsService.SendKeysend(123000, "03cbd788f5b22bd56e2714bff756372d2293504c064e03250ed16a4dd80ad70e2c", []lnclient.TLVRecord{}, mockPreimage, svc.LNClient, &app.ID, &dbRequestEvent.ID)
assert.NoError(t, err)
assert.NotNil(t, transaction)
@ -408,7 +388,7 @@ func TestSendKeysend_IsolatedAppToNoApp(t *testing.T) {
assert.True(t, transaction.SelfPayment)
transactionType := constants.TRANSACTION_TYPE_INCOMING
incomingTransaction, err := transactionsService.LookupTransaction(ctx, transaction.PaymentHash, &transactionType, svc.LNClient, nil)
incomingTransaction, err := transactionsService.LookupTransaction(context.TODO(), transaction.PaymentHash, &transactionType, svc.LNClient, nil)
assert.NoError(t, err)
assert.Equal(t, uint64(123000), incomingTransaction.AmountMsat)
assert.Equal(t, constants.TRANSACTION_STATE_SETTLED, incomingTransaction.State)
@ -423,8 +403,6 @@ func TestSendKeysend_IsolatedAppToNoApp(t *testing.T) {
}
func TestSendKeysend_IsolatedAppToIsolatedApp(t *testing.T) {
ctx := context.TODO()
svc, err := tests.CreateTestService(t)
require.NoError(t, err)
defer svc.Remove()
@ -482,7 +460,7 @@ func TestSendKeysend_IsolatedAppToIsolatedApp(t *testing.T) {
svc.EventPublisher.RegisterSubscriber(mockEventConsumer)
transactionsService := NewTransactionsService(svc.DB, svc.EventPublisher)
transaction, err := transactionsService.SendKeysend(ctx, 123000, "03cbd788f5b22bd56e2714bff756372d2293504c064e03250ed16a4dd80ad70e2c", tlvRecords, mockPreimage, svc.LNClient, &app.ID, &dbRequestEvent.ID)
transaction, err := transactionsService.SendKeysend(123000, "03cbd788f5b22bd56e2714bff756372d2293504c064e03250ed16a4dd80ad70e2c", tlvRecords, mockPreimage, svc.LNClient, &app.ID, &dbRequestEvent.ID)
assert.NoError(t, err)
assert.NotNil(t, transaction)
@ -494,7 +472,7 @@ func TestSendKeysend_IsolatedAppToIsolatedApp(t *testing.T) {
assert.True(t, transaction.SelfPayment)
transactionType := constants.TRANSACTION_TYPE_INCOMING
incomingTransaction, err := transactionsService.LookupTransaction(ctx, transaction.PaymentHash, &transactionType, svc.LNClient, &app2.ID)
incomingTransaction, err := transactionsService.LookupTransaction(context.TODO(), transaction.PaymentHash, &transactionType, svc.LNClient, &app2.ID)
assert.NoError(t, err)
assert.Equal(t, uint64(123000), incomingTransaction.AmountMsat)
assert.Equal(t, constants.TRANSACTION_STATE_SETTLED, incomingTransaction.State)

View file

@ -21,8 +21,6 @@ import (
)
func TestSendPaymentSync_NoApp(t *testing.T) {
ctx := context.TODO()
svc, err := tests.CreateTestService(t)
require.NoError(t, err)
defer svc.Remove()
@ -32,7 +30,7 @@ func TestSendPaymentSync_NoApp(t *testing.T) {
}
transactionsService := NewTransactionsService(svc.DB, svc.EventPublisher)
transaction, err := transactionsService.SendPaymentSync(ctx, tests.MockLNClientTransaction.Invoice, nil, metadata, svc.LNClient, nil, nil)
transaction, err := transactionsService.SendPaymentSync(tests.MockLNClientTransaction.Invoice, nil, metadata, svc.LNClient, nil, nil)
assert.NoError(t, err)
assert.Equal(t, uint64(123000), transaction.AmountMsat)
@ -50,8 +48,6 @@ func TestSendPaymentSync_NoApp(t *testing.T) {
}
func TestSendPaymentSync_ZeroAmount(t *testing.T) {
ctx := context.TODO()
svc, err := tests.CreateTestService(t)
require.NoError(t, err)
defer svc.Remove()
@ -62,7 +58,7 @@ func TestSendPaymentSync_ZeroAmount(t *testing.T) {
transactionsService := NewTransactionsService(svc.DB, svc.EventPublisher)
amount := uint64(1234)
transaction, err := transactionsService.SendPaymentSync(ctx, tests.MockZeroAmountInvoice, &amount, metadata, svc.LNClient, nil, nil)
transaction, err := transactionsService.SendPaymentSync(tests.MockZeroAmountInvoice, &amount, metadata, svc.LNClient, nil, nil)
assert.NoError(t, err)
assert.Equal(t, amount, transaction.AmountMsat)
@ -72,8 +68,6 @@ func TestSendPaymentSync_ZeroAmount(t *testing.T) {
}
func TestSendPaymentSync_AmountOnNonZeroAmountInvoice(t *testing.T) {
ctx := context.TODO()
svc, err := tests.CreateTestService(t)
require.NoError(t, err)
defer svc.Remove()
@ -84,7 +78,7 @@ func TestSendPaymentSync_AmountOnNonZeroAmountInvoice(t *testing.T) {
transactionsService := NewTransactionsService(svc.DB, svc.EventPublisher)
amount := uint64(1234)
transaction, err := transactionsService.SendPaymentSync(ctx, tests.MockInvoice, &amount, metadata, svc.LNClient, nil, nil)
transaction, err := transactionsService.SendPaymentSync(tests.MockInvoice, &amount, metadata, svc.LNClient, nil, nil)
assert.NoError(t, err)
// amount is from the invoice, not what was specified
@ -95,8 +89,6 @@ func TestSendPaymentSync_AmountOnNonZeroAmountInvoice(t *testing.T) {
}
func TestSendPaymentSync_MetadataTooLarge(t *testing.T) {
ctx := context.TODO()
svc, err := tests.CreateTestService(t)
require.NoError(t, err)
defer svc.Remove()
@ -105,7 +97,7 @@ func TestSendPaymentSync_MetadataTooLarge(t *testing.T) {
metadata["randomkey"] = strings.Repeat("a", constants.INVOICE_METADATA_MAX_LENGTH-15) // json encoding adds 16 characters
transactionsService := NewTransactionsService(svc.DB, svc.EventPublisher)
transaction, err := transactionsService.SendPaymentSync(ctx, tests.MockLNClientTransaction.Invoice, nil, metadata, svc.LNClient, nil, nil)
transaction, err := transactionsService.SendPaymentSync(tests.MockLNClientTransaction.Invoice, nil, metadata, svc.LNClient, nil, nil)
assert.Error(t, err)
assert.Equal(t, fmt.Sprintf("encoded payment metadata provided is too large. Limit: %d Received: %d", constants.INVOICE_METADATA_MAX_LENGTH, constants.INVOICE_METADATA_MAX_LENGTH+1), err.Error())
@ -113,8 +105,6 @@ func TestSendPaymentSync_MetadataTooLarge(t *testing.T) {
}
func TestSendPaymentSync_Duplicate_AlreadyPaid(t *testing.T) {
ctx := context.TODO()
svc, err := tests.CreateTestService(t)
require.NoError(t, err)
defer svc.Remove()
@ -127,7 +117,7 @@ func TestSendPaymentSync_Duplicate_AlreadyPaid(t *testing.T) {
})
transactionsService := NewTransactionsService(svc.DB, svc.EventPublisher)
transaction, err := transactionsService.SendPaymentSync(ctx, tests.MockLNClientTransaction.Invoice, nil, nil, svc.LNClient, nil, nil)
transaction, err := transactionsService.SendPaymentSync(tests.MockLNClientTransaction.Invoice, nil, nil, svc.LNClient, nil, nil)
assert.Error(t, err)
assert.Equal(t, "this invoice has already been paid", err.Error())
@ -135,8 +125,6 @@ func TestSendPaymentSync_Duplicate_AlreadyPaid(t *testing.T) {
}
func TestSendPaymentSync_Duplicate_Pending(t *testing.T) {
ctx := context.TODO()
svc, err := tests.CreateTestService(t)
require.NoError(t, err)
defer svc.Remove()
@ -149,7 +137,7 @@ func TestSendPaymentSync_Duplicate_Pending(t *testing.T) {
})
transactionsService := NewTransactionsService(svc.DB, svc.EventPublisher)
transaction, err := transactionsService.SendPaymentSync(ctx, tests.MockLNClientTransaction.Invoice, nil, nil, svc.LNClient, nil, nil)
transaction, err := transactionsService.SendPaymentSync(tests.MockLNClientTransaction.Invoice, nil, nil, svc.LNClient, nil, nil)
assert.Error(t, err)
assert.Equal(t, "there is already a payment pending for this invoice", err.Error())
@ -157,8 +145,6 @@ func TestSendPaymentSync_Duplicate_Pending(t *testing.T) {
}
func TestSendPaymentSync_Duplicate_Failed(t *testing.T) {
ctx := context.TODO()
svc, err := tests.CreateTestService(t)
require.NoError(t, err)
defer svc.Remove()
@ -171,7 +157,7 @@ func TestSendPaymentSync_Duplicate_Failed(t *testing.T) {
})
transactionsService := NewTransactionsService(svc.DB, svc.EventPublisher)
_, err = transactionsService.SendPaymentSync(ctx, tests.MockLNClientTransaction.Invoice, nil, nil, svc.LNClient, nil, nil)
_, err = transactionsService.SendPaymentSync(tests.MockLNClientTransaction.Invoice, nil, nil, svc.LNClient, nil, nil)
assert.NoError(t, err)
}
@ -318,8 +304,6 @@ func TestDoNotMarkFailedTwice(t *testing.T) {
}
func TestSendPaymentSync_FailedRemovesFeeReserve(t *testing.T) {
ctx := context.TODO()
svc, err := tests.CreateTestService(t)
require.NoError(t, err)
defer svc.Remove()
@ -331,13 +315,13 @@ func TestSendPaymentSync_FailedRemovesFeeReserve(t *testing.T) {
svc.EventPublisher.RegisterSubscriber(mockEventConsumer)
transactionsService := NewTransactionsService(svc.DB, svc.EventPublisher)
transaction, err := transactionsService.SendPaymentSync(ctx, tests.MockLNClientTransaction.Invoice, nil, nil, svc.LNClient, nil, nil)
transaction, err := transactionsService.SendPaymentSync(tests.MockLNClientTransaction.Invoice, nil, nil, svc.LNClient, nil, nil)
assert.Error(t, err)
assert.Nil(t, transaction)
transactionType := constants.TRANSACTION_TYPE_OUTGOING
transaction, err = transactionsService.LookupTransaction(ctx, tests.MockLNClientTransaction.PaymentHash, &transactionType, svc.LNClient, nil)
transaction, err = transactionsService.LookupTransaction(context.TODO(), tests.MockLNClientTransaction.PaymentHash, &transactionType, svc.LNClient, nil)
assert.NoError(t, err)
assert.Equal(t, uint64(123000), transaction.AmountMsat)
@ -350,8 +334,6 @@ func TestSendPaymentSync_FailedRemovesFeeReserve(t *testing.T) {
}
func TestSendPaymentSync_PendingHasFeeReserve(t *testing.T) {
ctx := context.TODO()
svc, err := tests.CreateTestService(t)
require.NoError(t, err)
defer svc.Remove()
@ -362,13 +344,13 @@ func TestSendPaymentSync_PendingHasFeeReserve(t *testing.T) {
transactionsService := NewTransactionsService(svc.DB, svc.EventPublisher)
go func() {
transactionsService.SendPaymentSync(ctx, tests.MockLNClientTransaction.Invoice, nil, nil, svc.LNClient, nil, nil)
transactionsService.SendPaymentSync(tests.MockLNClientTransaction.Invoice, nil, nil, svc.LNClient, nil, nil)
}()
// ensure the goroutine above runs first
time.Sleep(10 * time.Millisecond)
transactionType := constants.TRANSACTION_TYPE_OUTGOING
transaction, err := transactionsService.LookupTransaction(ctx, tests.MockLNClientTransaction.PaymentHash, &transactionType, svc.LNClient, nil)
transaction, err := transactionsService.LookupTransaction(context.TODO(), tests.MockLNClientTransaction.PaymentHash, &transactionType, svc.LNClient, nil)
assert.NoError(t, err)
assert.Equal(t, uint64(123000), transaction.AmountMsat)
@ -378,8 +360,6 @@ func TestSendPaymentSync_PendingHasFeeReserve(t *testing.T) {
}
func TestConsumeEvent_FailedMarkedAsSuccessful(t *testing.T) {
ctx := context.TODO()
svc, err := tests.CreateTestService(t)
require.NoError(t, err)
defer svc.Remove()
@ -389,7 +369,7 @@ func TestConsumeEvent_FailedMarkedAsSuccessful(t *testing.T) {
svc.LNClient.(*tests.MockLn).PayInvoiceErrors = append(svc.LNClient.(*tests.MockLn).PayInvoiceErrors, errors.New("some error"))
svc.LNClient.(*tests.MockLn).PayInvoiceResponses = append(svc.LNClient.(*tests.MockLn).PayInvoiceResponses, nil)
transaction, err := transactionsService.SendPaymentSync(ctx, tests.MockLNClientTransaction.Invoice, nil, nil, svc.LNClient, nil, nil)
transaction, err := transactionsService.SendPaymentSync(tests.MockLNClientTransaction.Invoice, nil, nil, svc.LNClient, nil, nil)
assert.Error(t, err)
assert.Nil(t, transaction)
@ -409,7 +389,7 @@ func TestConsumeEvent_FailedMarkedAsSuccessful(t *testing.T) {
// This should be marked as successful as long as there are no pending payments for the
// same payment hash
transactionsService.ConsumeEvent(ctx, &events.Event{
transactionsService.ConsumeEvent(context.TODO(), &events.Event{
Event: "nwc_lnclient_payment_sent",
Properties: &lnclient.Transaction{
Type: tests.MockLNClientTransaction.Type,

View file

@ -35,7 +35,7 @@ func TestSelfHoldPaymentSettled(t *testing.T) {
wg.Add(1)
go func() {
defer wg.Done()
result, err := transactionsService.SendPaymentSync(ctx, transaction.PaymentRequest, nil, nil, svc.LNClient, nil, nil)
result, err := transactionsService.SendPaymentSync(transaction.PaymentRequest, nil, nil, svc.LNClient, nil, nil)
assert.NoError(t, err)
require.NotNil(t, result)
assert.Equal(t, constants.TRANSACTION_STATE_SETTLED, result.State)
@ -73,7 +73,7 @@ func TestSelfHoldPaymentCanceled(t *testing.T) {
wg.Add(1)
go func() {
defer wg.Done()
result, err := transactionsService.SendPaymentSync(ctx, transaction.PaymentRequest, nil, nil, svc.LNClient, nil, nil)
result, err := transactionsService.SendPaymentSync(transaction.PaymentRequest, nil, nil, svc.LNClient, nil, nil)
assert.ErrorIs(t, err, lnclient.NewHoldInvoiceCanceledError())
assert.Nil(t, result)

View file

@ -34,7 +34,7 @@ func TestSendPaymentSync_SelfPayment_NoAppToNoApp(t *testing.T) {
})
transactionsService := NewTransactionsService(svc.DB, svc.EventPublisher)
transaction, err := transactionsService.SendPaymentSync(ctx, tests.MockInvoice, nil, nil, svc.LNClient, nil, nil)
transaction, err := transactionsService.SendPaymentSync(tests.MockInvoice, nil, nil, svc.LNClient, nil, nil)
assert.NoError(t, err)
assert.Equal(t, uint64(123000), transaction.AmountMsat)
@ -86,7 +86,7 @@ func TestSendPaymentSync_SelfPayment_NoAppToIsolatedApp(t *testing.T) {
})
transactionsService := NewTransactionsService(svc.DB, svc.EventPublisher)
transaction, err := transactionsService.SendPaymentSync(ctx, tests.MockInvoice, nil, nil, svc.LNClient, nil, nil)
transaction, err := transactionsService.SendPaymentSync(tests.MockInvoice, nil, nil, svc.LNClient, nil, nil)
assert.NoError(t, err)
assert.Equal(t, uint64(123000), transaction.AmountMsat)
@ -139,7 +139,7 @@ func TestSendPaymentSync_SelfPayment_NoAppToApp(t *testing.T) {
})
transactionsService := NewTransactionsService(svc.DB, svc.EventPublisher)
transaction, err := transactionsService.SendPaymentSync(ctx, tests.MockInvoice, nil, nil, svc.LNClient, nil, nil)
transaction, err := transactionsService.SendPaymentSync(tests.MockInvoice, nil, nil, svc.LNClient, nil, nil)
assert.NoError(t, err)
assert.Equal(t, uint64(123000), transaction.AmountMsat)
@ -208,7 +208,7 @@ func TestSendPaymentSync_SelfPayment_IsolatedAppToNoApp(t *testing.T) {
})
transactionsService := NewTransactionsService(svc.DB, svc.EventPublisher)
transaction, err := transactionsService.SendPaymentSync(ctx, tests.MockInvoice, nil, nil, svc.LNClient, &app.ID, &dbRequestEvent.ID)
transaction, err := transactionsService.SendPaymentSync(tests.MockInvoice, nil, nil, svc.LNClient, &app.ID, &dbRequestEvent.ID)
assert.NoError(t, err)
assert.Equal(t, uint64(123000), transaction.AmountMsat)
@ -283,7 +283,7 @@ func TestSendPaymentSync_SelfPayment_IsolatedAppToApp(t *testing.T) {
})
transactionsService := NewTransactionsService(svc.DB, svc.EventPublisher)
transaction, err := transactionsService.SendPaymentSync(ctx, tests.MockInvoice, nil, nil, svc.LNClient, &app.ID, &dbRequestEvent.ID)
transaction, err := transactionsService.SendPaymentSync(tests.MockInvoice, nil, nil, svc.LNClient, &app.ID, &dbRequestEvent.ID)
assert.NoError(t, err)
assert.Equal(t, uint64(123000), transaction.AmountMsat)
@ -365,7 +365,7 @@ func TestSendPaymentSync_SelfPayment_IsolatedAppToIsolatedApp(t *testing.T) {
svc.EventPublisher.RegisterSubscriber(mockEventConsumer)
transactionsService := NewTransactionsService(svc.DB, svc.EventPublisher)
transaction, err := transactionsService.SendPaymentSync(ctx, tests.MockInvoice, nil, nil, svc.LNClient, &app.ID, &dbRequestEvent.ID)
transaction, err := transactionsService.SendPaymentSync(tests.MockInvoice, nil, nil, svc.LNClient, &app.ID, &dbRequestEvent.ID)
assert.NoError(t, err)
assert.Equal(t, uint64(123000), transaction.AmountMsat)
@ -457,7 +457,7 @@ func TestSendPaymentSync_SelfPayment_IsolatedAppToSelf(t *testing.T) {
})
transactionsService := NewTransactionsService(svc.DB, svc.EventPublisher)
transaction, err := transactionsService.SendPaymentSync(ctx, tests.MockInvoice, nil, nil, svc.LNClient, &app.ID, &dbRequestEvent.ID)
transaction, err := transactionsService.SendPaymentSync(tests.MockInvoice, nil, nil, svc.LNClient, &app.ID, &dbRequestEvent.ID)
assert.NoError(t, err)
assert.Equal(t, uint64(123000), transaction.AmountMsat)
@ -537,7 +537,7 @@ func TestSendPaymentSync_SelfPayment_IsolatedAppToApp_AmountProvidedIgnoredOnNon
// this amount is wrong, it will just be ignored
amountMsat := uint64(1000)
transaction, err := transactionsService.SendPaymentSync(ctx, tests.MockInvoice, &amountMsat, nil, svc.LNClient, &app.ID, &dbRequestEvent.ID)
transaction, err := transactionsService.SendPaymentSync(tests.MockInvoice, &amountMsat, nil, svc.LNClient, &app.ID, &dbRequestEvent.ID)
assert.NoError(t, err)
assert.Equal(t, uint64(123000), transaction.AmountMsat)

View file

@ -38,8 +38,8 @@ type TransactionsService interface {
MakeInvoice(ctx context.Context, amount uint64, description string, descriptionHash string, expiry uint64, metadata map[string]interface{}, lnClient lnclient.LNClient, appId *uint, requestEventId *uint) (*Transaction, error)
LookupTransaction(ctx context.Context, paymentHash string, transactionType *string, lnClient lnclient.LNClient, appId *uint) (*Transaction, error)
ListTransactions(ctx context.Context, from, until, limit, offset uint64, unpaidOutgoing bool, unpaidIncoming bool, transactionType *string, lnClient lnclient.LNClient, appId *uint, forceFilterByAppId bool) (transactions []Transaction, totalCount uint64, err error)
SendPaymentSync(ctx context.Context, payReq string, amountMsat *uint64, metadata map[string]interface{}, lnClient lnclient.LNClient, appId *uint, requestEventId *uint) (*Transaction, error)
SendKeysend(ctx context.Context, amount uint64, destination string, customRecords []lnclient.TLVRecord, preimage string, lnClient lnclient.LNClient, appId *uint, requestEventId *uint) (*Transaction, error)
SendPaymentSync(payReq string, amountMsat *uint64, metadata map[string]interface{}, lnClient lnclient.LNClient, appId *uint, requestEventId *uint) (*Transaction, error)
SendKeysend(amount uint64, destination string, customRecords []lnclient.TLVRecord, preimage string, lnClient lnclient.LNClient, appId *uint, requestEventId *uint) (*Transaction, error)
MakeHoldInvoice(ctx context.Context, amount uint64, description string, descriptionHash string, expiry uint64, paymentHash string, metadata map[string]interface{}, lnClient lnclient.LNClient, appId *uint, requestEventId *uint) (*Transaction, error)
SettleHoldInvoice(ctx context.Context, preimage string, lnClient lnclient.LNClient) (*Transaction, error)
CancelHoldInvoice(ctx context.Context, paymentHash string, lnClient lnclient.LNClient) error
@ -266,7 +266,7 @@ func (svc *transactionsService) MakeHoldInvoice(ctx context.Context, amount uint
return &dbTransaction, nil
}
func (svc *transactionsService) SendPaymentSync(ctx context.Context, payReq string, amountMsat *uint64, metadata map[string]interface{}, lnClient lnclient.LNClient, appId *uint, requestEventId *uint) (*Transaction, error) {
func (svc *transactionsService) SendPaymentSync(payReq string, amountMsat *uint64, metadata map[string]interface{}, lnClient lnclient.LNClient, appId *uint, requestEventId *uint) (*Transaction, error) {
var metadataBytes []byte
if metadata != nil {
var err error
@ -380,9 +380,9 @@ func (svc *transactionsService) SendPaymentSync(ctx context.Context, payReq stri
var response *lnclient.PayInvoiceResponse
if selfPayment {
response, err = svc.interceptSelfPayment(ctx, paymentRequest.PaymentHash, lnClient)
response, err = svc.interceptSelfPayment(paymentRequest.PaymentHash, lnClient)
} else {
response, err = lnClient.SendPaymentSync(ctx, payReq, amountMsat)
response, err = lnClient.SendPaymentSync(payReq, amountMsat)
}
if err != nil {
@ -410,7 +410,7 @@ func (svc *transactionsService) SendPaymentSync(ctx context.Context, payReq stri
return settledTransaction, nil
}
func (svc *transactionsService) SendKeysend(ctx context.Context, amount uint64, destination string, customRecords []lnclient.TLVRecord, preimage string, lnClient lnclient.LNClient, appId *uint, requestEventId *uint) (*Transaction, error) {
func (svc *transactionsService) SendKeysend(amount uint64, destination string, customRecords []lnclient.TLVRecord, preimage string, lnClient lnclient.LNClient, appId *uint, requestEventId *uint) (*Transaction, error) {
if preimage == "" {
preImageBytes, err := makePreimageHex()
if err != nil {
@ -509,14 +509,14 @@ func (svc *transactionsService) SendKeysend(ctx context.Context, amount uint64,
return nil, err
}
_, err = svc.interceptSelfPayment(ctx, paymentHash, lnClient)
_, err = svc.interceptSelfPayment(paymentHash, lnClient)
if err == nil {
payKeysendResponse = &lnclient.PayKeysendResponse{
Fee: 0,
}
}
} else {
payKeysendResponse, err = lnClient.SendKeysend(ctx, amount, destination, customRecords, preimage)
payKeysendResponse, err = lnClient.SendKeysend(amount, destination, customRecords, preimage)
}
if err != nil {
@ -940,7 +940,7 @@ func (svc *transactionsService) markHoldInvoiceAccepted(paymentHash string, sett
}
}
func (svc *transactionsService) interceptSelfPayment(ctx context.Context, paymentHash string, lnClient lnclient.LNClient) (*lnclient.PayInvoiceResponse, error) {
func (svc *transactionsService) interceptSelfPayment(paymentHash string, lnClient lnclient.LNClient) (*lnclient.PayInvoiceResponse, error) {
logger.Logger.WithField("payment_hash", paymentHash).Debug("Intercepting self payment")
incomingTransaction := db.Transaction{}
result := svc.db.Limit(1).Find(&incomingTransaction, &db.Transaction{
@ -957,7 +957,7 @@ func (svc *transactionsService) interceptSelfPayment(ctx context.Context, paymen
}
if incomingTransaction.Hold {
return svc.interceptSelfHoldPayment(ctx, paymentHash, lnClient)
return svc.interceptSelfHoldPayment(paymentHash, lnClient)
}
if incomingTransaction.Preimage == nil {
@ -979,7 +979,7 @@ func (svc *transactionsService) interceptSelfPayment(ctx context.Context, paymen
}, nil
}
func (svc *transactionsService) interceptSelfHoldPayment(ctx context.Context, paymentHash string, lnClient lnclient.LNClient) (*lnclient.PayInvoiceResponse, error) {
func (svc *transactionsService) interceptSelfHoldPayment(paymentHash string, lnClient lnclient.LNClient) (*lnclient.PayInvoiceResponse, error) {
settledChannel := make(chan *db.Transaction)
canceledChannel := make(chan *db.Transaction)
@ -988,7 +988,7 @@ func (svc *transactionsService) interceptSelfHoldPayment(ctx context.Context, pa
svc.eventPublisher.RegisterSubscriber(holdInvoiceUpdatedConsumer)
defer svc.eventPublisher.RemoveSubscriber(holdInvoiceUpdatedConsumer)
clientInfo, err := lnClient.GetInfo(ctx)
clientInfo, err := lnClient.GetInfo(context.Background())
if err != nil {
return nil, errors.New("failed to get client info")
}