mirror of
https://github.com/getAlby/lndhub.go.git
synced 2026-01-06 14:35:36 +01:00
internal keysend payments
This commit is contained in:
@@ -48,6 +48,14 @@ func (svc *LndhubService) FindInvoiceByPaymentHash(ctx context.Context, userId i
|
||||
|
||||
func (svc *LndhubService) SendInternalPayment(ctx context.Context, invoice *models.Invoice) (SendPaymentResponse, error) {
|
||||
sendPaymentResponse := SendPaymentResponse{}
|
||||
//Check if it's a keysend payment
|
||||
//If it is, an invoice will be created on-the-fly
|
||||
if invoice.Keysend {
|
||||
err := svc.HandleInternalKeysendPayment(ctx, invoice)
|
||||
if err != nil {
|
||||
return sendPaymentResponse, err
|
||||
}
|
||||
}
|
||||
// find invoice
|
||||
var incomingInvoice models.Invoice
|
||||
err := svc.DB.NewSelect().Model(&incomingInvoice).Where("type = ? AND payment_request = ? AND state = ? ", common.InvoiceTypeIncoming, invoice.PaymentRequest, common.InvoiceStateOpen).Limit(1).Scan(ctx)
|
||||
|
||||
@@ -17,6 +17,33 @@ import (
|
||||
"github.com/uptrace/bun"
|
||||
)
|
||||
|
||||
func (svc *LndhubService) HandleInternalKeysendPayment(ctx context.Context, invoice *models.Invoice) error {
|
||||
//Find the payee user
|
||||
user, err := svc.FindUserByLogin(ctx, string(invoice.DestinationCustomRecords[TLV_WALLET_ID]))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
expiry := time.Hour * 24
|
||||
incomingInvoice := models.Invoice{
|
||||
Type: common.InvoiceTypeIncoming,
|
||||
UserID: user.ID,
|
||||
Amount: invoice.Amount,
|
||||
Internal: true,
|
||||
Memo: "Keysend payment",
|
||||
State: common.InvoiceStateInitialized,
|
||||
ExpiresAt: bun.NullTime{Time: time.Now().Add(expiry)},
|
||||
Keysend: true,
|
||||
RHash: invoice.RHash,
|
||||
Preimage: invoice.Preimage,
|
||||
DestinationCustomRecords: invoice.DestinationCustomRecords,
|
||||
DestinationPubkeyHex: svc.IdentityPubkey,
|
||||
AddIndex: invoice.AddIndex,
|
||||
}
|
||||
//persist the incoming invoice
|
||||
_, err = svc.DB.NewInsert().Model(&incomingInvoice).Exec(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
func (svc *LndhubService) HandleKeysendPayment(ctx context.Context, rawInvoice *lnrpc.Invoice) error {
|
||||
var invoice models.Invoice
|
||||
rHashStr := hex.EncodeToString(rawInvoice.RHash)
|
||||
|
||||
Reference in New Issue
Block a user