diff --git a/controllers/payinvoice.ctrl.go b/controllers/payinvoice.ctrl.go index e885d49..b7eff34 100644 --- a/controllers/payinvoice.ctrl.go +++ b/controllers/payinvoice.ctrl.go @@ -64,7 +64,7 @@ func (controller *PayInvoiceController) PayInvoice(c echo.Context) error { } c.Logger().Info("%v", decodedPaymentRequest) - 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 diff --git a/db/models/invoice.go b/db/models/invoice.go index 17b705c..830f6b9 100644 --- a/db/models/invoice.go +++ b/db/models/invoice.go @@ -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"` diff --git a/lib/service/invoices.go b/lib/service/invoices.go index 33ddf23..db7cf14 100644 --- a/lib/service/invoices.go +++ b/lib/service/invoices.go @@ -194,17 +194,19 @@ func (svc *LndhubService) PayInvoice(invoice *models.Invoice) (*models.Transacti return &entry, 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()) invoice := models.Invoice{ Type: "outgoing", UserID: userID, - Memo: *decodedInvoice.Description, PaymentRequest: paymentRequest, State: "initialized", DestinationPubkeyHex: destinationPubkeyHex, } + if decodedInvoice.Description != nil { + invoice.Memo = *decodedInvoice.Description + } if decodedInvoice.DescriptionHash != nil { dh := *decodedInvoice.DescriptionHash invoice.DescriptionHash = hex.EncodeToString(dh[:])