mirror of
https://github.com/getAlby/hub.git
synced 2026-08-13 12:33:39 +02:00
feat: add app id override to make invoice (#1388)
This commit is contained in:
parent
bb0b9c3257
commit
0c1a867c5e
2 changed files with 33 additions and 1 deletions
|
|
@ -30,13 +30,14 @@ func (controller *nip47Controller) HandleMakeInvoiceEvent(ctx context.Context, n
|
|||
}
|
||||
|
||||
logger.Logger.WithFields(logrus.Fields{
|
||||
"app_id": appId,
|
||||
"request_event_id": requestEventId,
|
||||
"amount": makeInvoiceParams.Amount,
|
||||
"description": makeInvoiceParams.Description,
|
||||
"description_hash": makeInvoiceParams.DescriptionHash,
|
||||
"expiry": makeInvoiceParams.Expiry,
|
||||
"metadata": makeInvoiceParams.Metadata,
|
||||
}).Info("Making invoice")
|
||||
}).Debug("Handling make_invoice request")
|
||||
|
||||
expiry := makeInvoiceParams.Expiry
|
||||
|
||||
|
|
|
|||
|
|
@ -139,6 +139,16 @@ func NewTransactionsService(db *gorm.DB, eventPublisher events.EventPublisher) *
|
|||
}
|
||||
|
||||
func (svc *transactionsService) 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) {
|
||||
logger.Logger.WithFields(logrus.Fields{
|
||||
"app_id": appId,
|
||||
"request_event_id": requestEventId,
|
||||
"amount": amount,
|
||||
"description": description,
|
||||
"description_hash": descriptionHash,
|
||||
"expiry": expiry,
|
||||
"metadata": metadata,
|
||||
}).Debug("Making invoice")
|
||||
|
||||
var metadataBytes []byte
|
||||
if metadata != nil {
|
||||
var err error
|
||||
|
|
@ -152,6 +162,16 @@ func (svc *transactionsService) MakeInvoice(ctx context.Context, amount uint64,
|
|||
}
|
||||
}
|
||||
|
||||
if metadata["app_id"] != nil {
|
||||
overwriteAppIdType, ok := metadata["app_id"].(float64)
|
||||
if !ok {
|
||||
return nil, errors.New("failed to overwrite app ID")
|
||||
}
|
||||
overwriteAppId := uint(overwriteAppIdType)
|
||||
logger.Logger.WithField("app_id", overwriteAppId).Info("Making invoice with overwritten app ID")
|
||||
appId = &overwriteAppId
|
||||
}
|
||||
|
||||
lnClientTransaction, err := lnClient.MakeInvoice(ctx, int64(amount), description, descriptionHash, int64(expiry))
|
||||
if err != nil {
|
||||
logger.Logger.WithError(err).Error("Failed to create transaction")
|
||||
|
|
@ -346,6 +366,17 @@ func (svc *transactionsService) SendPaymentSync(ctx context.Context, payReq stri
|
|||
return nil, err
|
||||
}
|
||||
|
||||
logger.Logger.WithFields(logrus.Fields{
|
||||
"app_id": appId,
|
||||
"request_event_id": requestEventId,
|
||||
"amount": paymentAmount,
|
||||
"description": paymentRequest.Description,
|
||||
"description_hash": paymentRequest.DescriptionHash,
|
||||
"expiry": paymentRequest.Expiry,
|
||||
"self_payment": selfPayment,
|
||||
"metadata": metadata,
|
||||
}).Debug("Initiating payment")
|
||||
|
||||
var response *lnclient.PayInvoiceResponse
|
||||
if selfPayment {
|
||||
response, err = svc.interceptSelfPayment(ctx, paymentRequest.PaymentHash, lnClient)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue