Skip to content

Commit

Permalink
Merge pull request #187 from getAlby/fix/keysend-payments
Browse files Browse the repository at this point in the history
Fix/keysend-payments
  • Loading branch information
kiwiidb authored Jun 9, 2022
2 parents 4a3b548 + aaa7911 commit 5a35d7c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
11 changes: 6 additions & 5 deletions lib/service/invoices.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func (svc *LndhubService) SendInternalPayment(ctx context.Context, invoice *mode
InvoiceID: incomingInvoice.ID,
CreditAccountID: recipientCreditAccount.ID,
DebitAccountID: recipientDebitAccount.ID,
Amount: invoice.Amount,
Amount: incomingInvoice.Amount,
}
_, err = svc.DB.NewInsert().Model(&recipientEntry).Exec(ctx)
if err != nil {
Expand All @@ -93,11 +93,11 @@ func (svc *LndhubService) SendInternalPayment(ctx context.Context, invoice *mode
preimage, _ := hex.DecodeString(incomingInvoice.Preimage)
sendPaymentResponse.PaymentPreimageStr = incomingInvoice.Preimage
sendPaymentResponse.PaymentPreimage = preimage
sendPaymentResponse.Invoice = invoice
paymentHash, _ := hex.DecodeString(invoice.RHash)
sendPaymentResponse.PaymentHashStr = invoice.RHash
sendPaymentResponse.Invoice = &incomingInvoice
paymentHash, _ := hex.DecodeString(incomingInvoice.RHash)
sendPaymentResponse.PaymentHashStr = incomingInvoice.RHash
sendPaymentResponse.PaymentHash = paymentHash
sendPaymentResponse.PaymentRoute = &Route{TotalAmt: invoice.Amount, TotalFees: 0}
sendPaymentResponse.PaymentRoute = &Route{TotalAmt: incomingInvoice.Amount, TotalFees: 0}

incomingInvoice.Internal = true // mark incoming invoice as internal, just for documentation/debugging
incomingInvoice.State = common.InvoiceStateSettled
Expand Down Expand Up @@ -244,6 +244,7 @@ func (svc *LndhubService) PayInvoice(ctx context.Context, invoice *models.Invoic
// These changes to the invoice are persisted in the `HandleSuccessfulPayment` function
invoice.Preimage = paymentResponse.PaymentPreimageStr
invoice.Fee = paymentResponse.PaymentRoute.TotalFees
invoice.RHash = paymentResponse.PaymentHashStr
err = svc.HandleSuccessfulPayment(context.Background(), invoice, entry)
return &paymentResponse, err
}
Expand Down
4 changes: 2 additions & 2 deletions lib/service/invoicesubscription.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func (svc *LndhubService) HandleInternalKeysendPayment(ctx context.Context, invo
UserID: user.ID,
Amount: invoice.Amount,
Internal: true,
Memo: "Keysend payment",
Memo: "",
State: common.InvoiceStateInitialized,
ExpiresAt: bun.NullTime{Time: time.Now().Add(expiry)},
Keysend: true,
Expand Down Expand Up @@ -200,7 +200,7 @@ func (svc *LndhubService) createKeysendInvoice(ctx context.Context, rawInvoice *
Type: common.InvoiceTypeIncoming,
UserID: user.ID,
Amount: rawInvoice.AmtPaidSat,
Memo: "Keysend payment", //TODO: also extract this from the custom records?
Memo: "",
State: common.InvoiceStateInitialized,
ExpiresAt: bun.NullTime{Time: time.Now().Add(expiry)},
Keysend: true,
Expand Down

0 comments on commit 5a35d7c

Please sign in to comment.