mirror of
https://github.com/getAlby/lndhub.go.git
synced 2026-02-23 13:54:25 +01:00
Merge pull request #69 from getAlby/bugfix/fix-invoices-without-description
Do not fail if invoice does not have a description
This commit is contained in:
@@ -56,7 +56,7 @@ func (controller *PayInvoiceController) PayInvoice(c echo.Context) error {
|
||||
}
|
||||
*/
|
||||
|
||||
invoice, err := controller.svc.AddOutgoingInvoice(userID, paymentRequest, *decodedPaymentRequest)
|
||||
invoice, err := controller.svc.AddOutgoingInvoice(userID, paymentRequest, decodedPaymentRequest)
|
||||
if err != nil {
|
||||
c.Logger().Errorf("Error creating invoice: %v", err)
|
||||
// TODO: sentry notification
|
||||
|
||||
@@ -16,7 +16,7 @@ type Invoice struct {
|
||||
UserID int64 `json:"user_id" validate:"required"`
|
||||
User *User `bun:"rel:belongs-to,join:user_id=id"`
|
||||
Amount int64 `json:"amount" validate:"gte=0"`
|
||||
Memo string `json:"memo"`
|
||||
Memo string `json:"memo" bun:",nullzero"`
|
||||
DescriptionHash string `json:"description_hash" bun:",nullzero"`
|
||||
PaymentRequest string `json:"payment_request" bun:",nullzero"`
|
||||
DestinationPubkeyHex string `json:"destination_pubkey_hex" bun:",notnull"`
|
||||
|
||||
@@ -220,19 +220,21 @@ func (svc *LndhubService) PayInvoice(invoice *models.Invoice) (*SendPaymentRespo
|
||||
return &paymentResponse, err
|
||||
}
|
||||
|
||||
func (svc *LndhubService) AddOutgoingInvoice(userID int64, paymentRequest string, decodedInvoice zpay32.Invoice) (*models.Invoice, error) {
|
||||
func (svc *LndhubService) AddOutgoingInvoice(userID int64, paymentRequest string, decodedInvoice *zpay32.Invoice) (*models.Invoice, error) {
|
||||
// Initialize new DB invoice
|
||||
destinationPubkeyHex := hex.EncodeToString(decodedInvoice.Destination.SerializeCompressed())
|
||||
expiresAt := decodedInvoice.Timestamp.Add(decodedInvoice.Expiry())
|
||||
invoice := models.Invoice{
|
||||
Type: "outgoing",
|
||||
UserID: userID,
|
||||
Memo: *decodedInvoice.Description,
|
||||
PaymentRequest: paymentRequest,
|
||||
State: "initialized",
|
||||
DestinationPubkeyHex: destinationPubkeyHex,
|
||||
ExpiresAt: bun.NullTime{Time: expiresAt},
|
||||
}
|
||||
if decodedInvoice.Description != nil {
|
||||
invoice.Memo = *decodedInvoice.Description
|
||||
}
|
||||
if decodedInvoice.DescriptionHash != nil {
|
||||
dh := *decodedInvoice.DescriptionHash
|
||||
invoice.DescriptionHash = hex.EncodeToString(dh[:])
|
||||
|
||||
Reference in New Issue
Block a user