Prevent an NRE in LNURL (#4908)

* Prevent an NRE in LNURL

In addition to f05a7f9f14. Fixes #4904.

* Revert "Prevent an NRE in LNURL"

This reverts commit 0b241d61ab.

* Fix NRE

---------

Co-authored-by: nicolas.dorier <nicolas.dorier@gmail.com>
This commit is contained in:
d11n 2023-04-24 14:50:31 +02:00 committed by GitHub
parent cb3c5e56fd
commit 47f5d97eaf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 7 additions and 9 deletions

View File

@ -468,6 +468,8 @@ namespace BTCPayServer
lnUrlMetadata ??= new Dictionary<string, string>(); lnUrlMetadata ??= new Dictionary<string, string>();
var pm = i.GetPaymentMethod(pmi); var pm = i.GetPaymentMethod(pmi);
if (pm is null)
return null;
var paymentMethodDetails = (LNURLPayPaymentMethodDetails)pm.GetPaymentMethodDetails(); var paymentMethodDetails = (LNURLPayPaymentMethodDetails)pm.GetPaymentMethodDetails();
bool updatePaymentMethodDetails = false; bool updatePaymentMethodDetails = false;
if (lnUrlMetadata?.TryGetValue("text/identifier", out var lnAddress) is true && lnAddress is not null) if (lnUrlMetadata?.TryGetValue("text/identifier", out var lnAddress) is true && lnAddress is not null)
@ -494,7 +496,7 @@ namespace BTCPayServer
lnurlRequest.Metadata = JsonConvert.SerializeObject(lnUrlMetadata.Select(kv => new[] { kv.Key, kv.Value })); lnurlRequest.Metadata = JsonConvert.SerializeObject(lnUrlMetadata.Select(kv => new[] { kv.Key, kv.Value }));
if (i.Type != InvoiceType.TopUp) if (i.Type != InvoiceType.TopUp)
{ {
lnurlRequest.MinSendable = new LightMoney(i.GetPaymentMethod(pmi).Calculate().Due.ToDecimal(MoneyUnit.Satoshi), LightMoneyUnit.Satoshi); lnurlRequest.MinSendable = new LightMoney(pm.Calculate().Due.ToDecimal(MoneyUnit.Satoshi), LightMoneyUnit.Satoshi);
if (!allowOverpay) if (!allowOverpay)
lnurlRequest.MaxSendable = lnurlRequest.MinSendable; lnurlRequest.MaxSendable = lnurlRequest.MinSendable;
} }

View File

@ -90,11 +90,6 @@ namespace BTCPayServer.Payments
}; };
} }
public PaymentMethod GetPaymentMethodInInvoice(InvoiceEntity invoice, PaymentMethodId paymentMethodId)
{
return invoice.GetPaymentMethod(paymentMethodId);
}
public virtual object PreparePayment(TSupportedPaymentMethod supportedPaymentMethod, StoreData store, public virtual object PreparePayment(TSupportedPaymentMethod supportedPaymentMethod, StoreData store,
BTCPayNetworkBase network) BTCPayNetworkBase network)
{ {

View File

@ -299,9 +299,8 @@ namespace BTCPayServer.Payments.PayJoin
if (walletReceiveMatch is null && invoice is not null) if (walletReceiveMatch is null && invoice is not null)
{ {
var paymentMethod = invoice.GetPaymentMethod(paymentMethodId); var paymentMethod = invoice.GetPaymentMethod(paymentMethodId);
var paymentDetails = var paymentDetails = paymentMethod?.GetPaymentMethodDetails() as Payments.Bitcoin.BitcoinLikeOnChainPaymentMethod;
paymentMethod.GetPaymentMethodDetails() as Payments.Bitcoin.BitcoinLikeOnChainPaymentMethod; if (paymentMethod is null || paymentDetails is null || !paymentDetails.PayjoinEnabled)
if (paymentDetails is null || !paymentDetails.PayjoinEnabled)
continue; continue;
due = paymentMethod.Calculate().TotalDue - output.Value; due = paymentMethod.Calculate().TotalDue - output.Value;
if (due > Money.Zero) if (due > Money.Zero)

View File

@ -44,6 +44,8 @@ namespace BTCPayServer.Services.Invoices
return null; return null;
InvoiceEntity invoiceEntity = invoice.GetBlob(_btcPayNetworkProvider); InvoiceEntity invoiceEntity = invoice.GetBlob(_btcPayNetworkProvider);
PaymentMethod paymentMethod = invoiceEntity.GetPaymentMethod(new PaymentMethodId(network.CryptoCode, paymentData.GetPaymentType())); PaymentMethod paymentMethod = invoiceEntity.GetPaymentMethod(new PaymentMethodId(network.CryptoCode, paymentData.GetPaymentType()));
if (paymentMethod is null)
return null;
IPaymentMethodDetails paymentMethodDetails = paymentMethod.GetPaymentMethodDetails(); IPaymentMethodDetails paymentMethodDetails = paymentMethod.GetPaymentMethodDetails();
PaymentEntity entity = new PaymentEntity PaymentEntity entity = new PaymentEntity
{ {