LNURL controller refactoring

By moving the `amount is null` check up, this prevents cases in which the `paymentMethodDetails.GeneratedBoltAmount != amount` check fails because of amount being null.
This commit is contained in:
Dennis Reimann 2022-08-12 20:10:44 +02:00
parent 8c8a5a4f5e
commit de24a6e71b
No known key found for this signature in database
GPG key ID: 5009E1797F03F8D0

View file

@ -524,8 +524,21 @@ namespace BTCPayServer
Url = _linkGenerator.GetUriByAction(HttpContext, "InvoiceReceipt", "UIInvoice", new { invoiceId})
};
}
if (amount.HasValue && string.IsNullOrEmpty(paymentMethodDetails.BOLT11) ||
paymentMethodDetails.GeneratedBoltAmount != amount)
if (amount is null)
{
return Ok(new LNURLPayRequest
{
Tag = "payRequest",
MinSendable = min,
MaxSendable = max,
CommentAllowed = lnurlSupportedPaymentMethod.LUD12Enabled ? 2000 : 0,
Metadata = metadata,
Callback = new Uri(Request.GetCurrentUrl())
});
}
if (string.IsNullOrEmpty(paymentMethodDetails.BOLT11) || paymentMethodDetails.GeneratedBoltAmount != amount)
{
var client =
_lightningLikePaymentHandler.CreateLightningClient(
@ -589,7 +602,7 @@ namespace BTCPayServer
});
}
if (amount.HasValue && paymentMethodDetails.GeneratedBoltAmount == amount)
if (paymentMethodDetails.GeneratedBoltAmount == amount)
{
if (lnurlSupportedPaymentMethod.LUD12Enabled && paymentMethodDetails.ProvidedComment != comment)
{
@ -604,19 +617,6 @@ namespace BTCPayServer
SuccessAction = successAction
});
}
if (amount is null)
{
return Ok(new LNURLPayRequest
{
Tag = "payRequest",
MinSendable = min,
MaxSendable = max,
CommentAllowed = lnurlSupportedPaymentMethod.LUD12Enabled ? 2000 : 0,
Metadata = metadata,
Callback = new Uri(Request.GetCurrentUrl())
});
}
}
return BadRequest(new LNUrlStatusResponse