mirror of
https://github.com/aljazceru/btcpayserver.git
synced 2026-01-03 14:14:28 +01:00
Extracting fetching of PaymentHash to extension method like Nicolas asked
This commit is contained in:
@@ -1,12 +1,12 @@
|
||||
using BTCPayServer.Configuration;
|
||||
using BTCPayServer.Lightning;
|
||||
using BTCPayServer.Services;
|
||||
using NBitcoin;
|
||||
|
||||
namespace BTCPayServer.Payments.Lightning
|
||||
{
|
||||
public static class LightningExtensions
|
||||
{
|
||||
|
||||
public static bool IsConfigured(this LightningPaymentMethodConfig supportedPaymentMethod, BTCPayNetwork network, LightningNetworkOptions options)
|
||||
{
|
||||
return supportedPaymentMethod.GetExternalLightningUrl() is not null || (supportedPaymentMethod.IsInternalNode && options.InternalLightningByCryptoCode.ContainsKey(network.CryptoCode));
|
||||
@@ -25,5 +25,12 @@ namespace BTCPayServer.Payments.Lightning
|
||||
return connectionString;
|
||||
}
|
||||
}
|
||||
|
||||
public static uint256? GetPaymentHash(this LightningInvoice lightningInvoice, Network btcpayNetwork)
|
||||
{
|
||||
return lightningInvoice.PaymentHash != null ?
|
||||
uint256.Parse(lightningInvoice.PaymentHash) :
|
||||
BOLT11PaymentRequest.Parse(lightningInvoice.BOLT11, btcpayNetwork).PaymentHash;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -128,13 +128,9 @@ namespace BTCPayServer.Payments.Lightning
|
||||
}
|
||||
|
||||
paymentPrompt.Destination = lightningInvoice.BOLT11;
|
||||
var paymentHash = lightningInvoice.PaymentHash != null ?
|
||||
uint256.Parse(lightningInvoice.PaymentHash) :
|
||||
BOLT11PaymentRequest.Parse(lightningInvoice.BOLT11, _Network.NBitcoinNetwork).PaymentHash;
|
||||
|
||||
var details = new LigthningPaymentPromptDetails
|
||||
{
|
||||
PaymentHash = paymentHash,
|
||||
PaymentHash = lightningInvoice.GetPaymentHash(_Network.NBitcoinNetwork),
|
||||
Preimage = string.IsNullOrEmpty(lightningInvoice.Preimage) ? null : uint256.Parse(lightningInvoice.Preimage),
|
||||
InvoiceId = lightningInvoice.Id,
|
||||
NodeInfo = (await nodeInfo).FirstOrDefault()?.ToString()
|
||||
|
||||
@@ -527,8 +527,7 @@ retry:
|
||||
continue;
|
||||
if (notification.Id == listenedInvoice.PaymentMethodDetails.InvoiceId &&
|
||||
(notification.BOLT11 == listenedInvoice.PaymentMethod.Destination ||
|
||||
BOLT11PaymentRequest.Parse(notification.BOLT11, _network.NBitcoinNetwork).PaymentHash ==
|
||||
GetPaymentHash(listenedInvoice)))
|
||||
notification.GetPaymentHash(_network.NBitcoinNetwork) == GetPaymentHash(listenedInvoice)))
|
||||
{
|
||||
if (notification.Status == LightningInvoiceStatus.Paid &&
|
||||
notification.PaidAt.HasValue && notification.Amount != null)
|
||||
@@ -559,7 +558,8 @@ retry:
|
||||
|
||||
private uint256? GetPaymentHash(ListenedInvoice listenedInvoice)
|
||||
{
|
||||
return listenedInvoice.PaymentMethodDetails.PaymentHash ?? BOLT11PaymentRequest.Parse(listenedInvoice.PaymentMethod.Destination, _network.NBitcoinNetwork).PaymentHash;
|
||||
return listenedInvoice.PaymentMethodDetails.PaymentHash ??
|
||||
BOLT11PaymentRequest.Parse(listenedInvoice.PaymentMethod.Destination, _network.NBitcoinNetwork).PaymentHash;
|
||||
}
|
||||
|
||||
public DateTimeOffset? LastFullPoll { get; set; }
|
||||
@@ -591,9 +591,7 @@ retry:
|
||||
return false;
|
||||
|
||||
var handler = _handlers[paymentMethodId];
|
||||
var paymentHash = notification.PaymentHash != null ?
|
||||
uint256.Parse(notification.PaymentHash) :
|
||||
BOLT11PaymentRequest.Parse(notification.BOLT11, _network.NBitcoinNetwork).PaymentHash;
|
||||
var paymentHash = notification.GetPaymentHash(_network.NBitcoinNetwork);
|
||||
var paymentData = new PaymentData()
|
||||
{
|
||||
Id = paymentHash?.ToString() ?? notification.BOLT11,
|
||||
|
||||
Reference in New Issue
Block a user