mirror of
https://github.com/getAlby/lndhub.go.git
synced 2025-12-20 14:14:47 +01:00
Pass invoice description hash string to LND
This commit is contained in:
@@ -22,7 +22,7 @@ func (controller *AddInvoiceController) AddInvoice(c echo.Context) error {
|
|||||||
type RequestBody struct {
|
type RequestBody struct {
|
||||||
Amount interface{} `json:"amt"` // amount in Satoshi
|
Amount interface{} `json:"amt"` // amount in Satoshi
|
||||||
Memo string `json:"memo"`
|
Memo string `json:"memo"`
|
||||||
DescriptionHash string `json:"description_hash"`
|
DescriptionHash string `json:"description_hash" validate:"omitempty,hexadecimal,len=64"`
|
||||||
}
|
}
|
||||||
|
|
||||||
var body RequestBody
|
var body RequestBody
|
||||||
@@ -59,7 +59,11 @@ func (controller *AddInvoiceController) AddInvoice(c echo.Context) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
c.Logger().Errorf("Error creating invoice: %v", err)
|
c.Logger().Errorf("Error creating invoice: %v", err)
|
||||||
// TODO: sentry notification
|
// TODO: sentry notification
|
||||||
return c.JSON(http.StatusInternalServerError, nil)
|
return c.JSON(http.StatusBadRequest, echo.Map{
|
||||||
|
"error": true,
|
||||||
|
"code": 8,
|
||||||
|
"message": "Bad arguments",
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
var responseBody struct {
|
var responseBody struct {
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ func (svc *LndhubService) SendInternalPayment(tx *bun.Tx, invoice *models.Invoic
|
|||||||
// TODO: logging
|
// TODO: logging
|
||||||
return sendPaymentResponse, err
|
return sendPaymentResponse, err
|
||||||
}
|
}
|
||||||
// Get the user's current and outgoing account for the transaction entry
|
// Get the user's current and incoming account for the transaction entry
|
||||||
recipientCreditAccount, err := svc.AccountFor(context.TODO(), "current", incomingInvoice.UserID)
|
recipientCreditAccount, err := svc.AccountFor(context.TODO(), "current", incomingInvoice.UserID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return sendPaymentResponse, err
|
return sendPaymentResponse, err
|
||||||
@@ -226,7 +226,7 @@ func (svc *LndhubService) AddOutgoingInvoice(userID int64, paymentRequest string
|
|||||||
return &invoice, nil
|
return &invoice, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (svc *LndhubService) AddIncomingInvoice(userID int64, amount int64, memo, descriptionHash string) (*models.Invoice, error) {
|
func (svc *LndhubService) AddIncomingInvoice(userID int64, amount int64, memo, descriptionHashStr string) (*models.Invoice, error) {
|
||||||
preimage := makePreimageHex()
|
preimage := makePreimageHex()
|
||||||
// Initialize new DB invoice
|
// Initialize new DB invoice
|
||||||
invoice := models.Invoice{
|
invoice := models.Invoice{
|
||||||
@@ -234,7 +234,7 @@ func (svc *LndhubService) AddIncomingInvoice(userID int64, amount int64, memo, d
|
|||||||
UserID: userID,
|
UserID: userID,
|
||||||
Amount: amount,
|
Amount: amount,
|
||||||
Memo: memo,
|
Memo: memo,
|
||||||
DescriptionHash: descriptionHash,
|
DescriptionHash: descriptionHashStr,
|
||||||
State: "initialized",
|
State: "initialized",
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -244,9 +244,14 @@ func (svc *LndhubService) AddIncomingInvoice(userID int64, amount int64, memo, d
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
descriptionHash, err := hex.DecodeString(descriptionHashStr)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
// Initialize lnrpc invoice
|
// Initialize lnrpc invoice
|
||||||
lnInvoice := lnrpc.Invoice{
|
lnInvoice := lnrpc.Invoice{
|
||||||
Memo: memo,
|
Memo: memo,
|
||||||
|
DescriptionHash: descriptionHash,
|
||||||
Value: amount,
|
Value: amount,
|
||||||
RPreimage: preimage,
|
RPreimage: preimage,
|
||||||
Expiry: 3600 * 24, // 24h // TODO: move to config
|
Expiry: 3600 * 24, // 24h // TODO: move to config
|
||||||
|
|||||||
Reference in New Issue
Block a user