Match Lightning payment based on payment hash if BOLT11 is not the same. (#2773)

* Match Lightning payment based on payment hash if BOLT11 is not the same.

* Fixup

* Fixup

Co-authored-by: Nicolas Dorier <nicolas.dorier@gmail.com>
This commit is contained in:
Andrew Camilleri 2021-10-07 09:53:27 +02:00 committed by GitHub
parent d3f9eb38a9
commit 039f88d14c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 2 deletions

View File

@ -114,6 +114,7 @@ namespace BTCPayServer.Payments.Lightning
{
Activated = true,
BOLT11 = lightningInvoice.BOLT11,
PaymentHash = BOLT11PaymentRequest.Parse(lightningInvoice.BOLT11, network.NBitcoinNetwork).PaymentHash,
InvoiceId = lightningInvoice.Id,
NodeInfo = nodeInfo.First().ToString()
};

View File

@ -1,8 +1,12 @@
using BTCPayServer.Lightning;
using NBitcoin;
namespace BTCPayServer.Payments.Lightning
{
public class LightningLikePaymentMethodDetails : IPaymentMethodDetails
{
public string BOLT11 { get; set; }
public uint256 PaymentHash { get; set; }
public string InvoiceId { get; set; }
public string NodeInfo { get; set; }
@ -11,6 +15,11 @@ namespace BTCPayServer.Payments.Lightning
return BOLT11;
}
public uint256 GetPaymentHash(Network network)
{
return PaymentHash ?? BOLT11PaymentRequest.Parse(BOLT11, network).PaymentHash;
}
public PaymentType GetPaymentType()
{
return PaymentTypes.LightningLike;

View File

@ -344,7 +344,7 @@ namespace BTCPayServer.Payments.Lightning
internal async Task<LightningInvoiceStatus?> PollPayment(ListenedInvoice listenedInvoice, CancellationToken cancellation)
{
var client = _lightningClientFactory.Create(ConnectionString, _network);
LightningInvoice lightningInvoice = await client.GetInvoice(listenedInvoice.PaymentMethodDetails.InvoiceId);
LightningInvoice lightningInvoice = await client.GetInvoice(listenedInvoice.PaymentMethodDetails.InvoiceId, cancellation);
if (lightningInvoice?.Status is LightningInvoiceStatus.Paid &&
await AddPayment(lightningInvoice, listenedInvoice.InvoiceId))
{
@ -385,7 +385,9 @@ namespace BTCPayServer.Payments.Lightning
if (!_ListenedInvoices.TryGetValue(notification.Id, out var listenedInvoice))
continue;
if (notification.Id == listenedInvoice.PaymentMethodDetails.InvoiceId &&
notification.BOLT11 == listenedInvoice.PaymentMethodDetails.BOLT11)
(notification.BOLT11 == listenedInvoice.PaymentMethodDetails.BOLT11 ||
BOLT11PaymentRequest.Parse(notification.BOLT11, _network.NBitcoinNetwork).PaymentHash ==
listenedInvoice.PaymentMethodDetails.GetPaymentHash(_network.NBitcoinNetwork)))
{
if (notification.Status == LightningInvoiceStatus.Paid &&
notification.PaidAt.HasValue && notification.Amount != null)