LNURL: Add missing logic from lnurl merges and rebases

This commit is contained in:
Kukks
2021-08-16 10:07:49 +02:00
parent fccbbb6fb7
commit 1ecd1c1e54
7 changed files with 23 additions and 6 deletions

View File

@@ -4,6 +4,7 @@
{ {
public string ConnectionString { get; set; } public string ConnectionString { get; set; }
public bool DisableBOLT11PaymentOption { get; set; }
public LightningNetworkPaymentMethodBaseData() public LightningNetworkPaymentMethodBaseData()
{ {

View File

@@ -16,12 +16,13 @@ namespace BTCPayServer.Client.Models
{ {
} }
public LightningNetworkPaymentMethodData(string cryptoCode, string connectionString, bool enabled, string paymentMethod) public LightningNetworkPaymentMethodData(string cryptoCode, string connectionString, bool enabled, string paymentMethod, bool disableBOLT11PaymentOption)
{ {
Enabled = enabled; Enabled = enabled;
CryptoCode = cryptoCode; CryptoCode = cryptoCode;
ConnectionString = connectionString; ConnectionString = connectionString;
PaymentMethod = paymentMethod; PaymentMethod = paymentMethod;
DisableBOLT11PaymentOption = disableBOLT11PaymentOption;
} }
public string PaymentMethod { get; set; } public string PaymentMethod { get; set; }

View File

@@ -59,7 +59,8 @@ namespace BTCPayServer.Controllers.GreenField
paymentMethod.GetExternalLightningUrl()?.ToString() ?? paymentMethod.GetExternalLightningUrl()?.ToString() ??
paymentMethod.GetDisplayableConnectionString(), paymentMethod.GetDisplayableConnectionString(),
!excludedPaymentMethods.Match(paymentMethod.PaymentId), !excludedPaymentMethods.Match(paymentMethod.PaymentId),
paymentMethod.PaymentId.ToStringNormalized() paymentMethod.PaymentId.ToStringNormalized(),
paymentMethod.DisableBOLT11PaymentOption
) )
) )
.Where((result) => enabled is null || enabled == result.Enabled) .Where((result) => enabled is null || enabled == result.Enabled)
@@ -206,7 +207,7 @@ namespace BTCPayServer.Controllers.GreenField
? null ? null
: new LightningNetworkPaymentMethodData(paymentMethod.PaymentId.CryptoCode, : new LightningNetworkPaymentMethodData(paymentMethod.PaymentId.CryptoCode,
paymentMethod.GetDisplayableConnectionString(), !excluded, paymentMethod.GetDisplayableConnectionString(), !excluded,
paymentMethod.PaymentId.ToStringNormalized()); paymentMethod.PaymentId.ToStringNormalized(), paymentMethod.DisableBOLT11PaymentOption);
} }
private bool GetNetwork(string cryptoCode, [MaybeNullWhen(false)] out BTCPayNetwork network) private bool GetNetwork(string cryptoCode, [MaybeNullWhen(false)] out BTCPayNetwork network)

View File

@@ -60,7 +60,8 @@ namespace BTCPayServer.Controllers
} }
paymentMethod = new LightningSupportedPaymentMethod paymentMethod = new LightningSupportedPaymentMethod
{ {
CryptoCode = paymentMethodId.CryptoCode CryptoCode = paymentMethodId.CryptoCode,
DisableBOLT11PaymentOption = vm.LNURLEnabled && vm.LNURLStandardInvoiceEnabled && vm.DisableBolt11PaymentMethod
}; };
paymentMethod.SetInternalNode(); paymentMethod.SetInternalNode();
} }
@@ -89,7 +90,8 @@ namespace BTCPayServer.Controllers
paymentMethod = new LightningSupportedPaymentMethod paymentMethod = new LightningSupportedPaymentMethod
{ {
CryptoCode = paymentMethodId.CryptoCode CryptoCode = paymentMethodId.CryptoCode,
DisableBOLT11PaymentOption = vm.LNURLEnabled && vm.LNURLStandardInvoiceEnabled && vm.DisableBolt11PaymentMethod
}; };
paymentMethod.SetLightningUrl(connectionString); paymentMethod.SetLightningUrl(connectionString);
@@ -184,6 +186,8 @@ namespace BTCPayServer.Controllers
{ {
vm.LightningNodeType = lightning.IsInternalNode ? LightningNodeType.Internal : LightningNodeType.Custom; vm.LightningNodeType = lightning.IsInternalNode ? LightningNodeType.Internal : LightningNodeType.Custom;
vm.ConnectionString = lightning.GetDisplayableConnectionString(); vm.ConnectionString = lightning.GetDisplayableConnectionString();
vm.DisableBolt11PaymentMethod = lightning.DisableBOLT11PaymentOption;
} }
else else
{ {

View File

@@ -55,6 +55,10 @@ namespace BTCPayServer.Payments.Lightning
LightningSupportedPaymentMethod supportedPaymentMethod, PaymentMethod paymentMethod, Data.StoreData store, LightningSupportedPaymentMethod supportedPaymentMethod, PaymentMethod paymentMethod, Data.StoreData store,
BTCPayNetwork network, object preparePaymentObject) BTCPayNetwork network, object preparePaymentObject)
{ {
if (supportedPaymentMethod.DisableBOLT11PaymentOption)
{
throw new PaymentMethodUnavailableException("BOLT11 payment method is disabled");
}
if (paymentMethod.ParentEntity.Type == InvoiceType.TopUp) { if (paymentMethod.ParentEntity.Type == InvoiceType.TopUp) {
throw new PaymentMethodUnavailableException("Lightning Network payment method is not available for top-up invoices"); throw new PaymentMethodUnavailableException("Lightning Network payment method is not available for top-up invoices");
} }
@@ -66,7 +70,6 @@ namespace BTCPayServer.Payments.Lightning
Activated = false Activated = false
}; };
} }
//direct casting to (BTCPayNetwork) is fixed in other pull requests with better generic interfacing for handlers
var storeBlob = store.GetStoreBlob(); var storeBlob = store.GetStoreBlob();
var nodeInfo = GetNodeInfo(supportedPaymentMethod, network, logs, paymentMethod.PreferOnion); var nodeInfo = GetNodeInfo(supportedPaymentMethod, network, logs, paymentMethod.PreferOnion);

View File

@@ -17,6 +17,8 @@ namespace BTCPayServer.Payments.Lightning
[JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] [JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)]
public string? LightningConnectionString { get; set; } public string? LightningConnectionString { get; set; }
public bool DisableBOLT11PaymentOption { get; set; } = false;
public LightningConnectionString? GetExternalLightningUrl() public LightningConnectionString? GetExternalLightningUrl()
{ {
#pragma warning disable CS0618 // Type or member is obsolete #pragma warning disable CS0618 // Type or member is obsolete

View File

@@ -255,6 +255,11 @@
"type": "string", "type": "string",
"description": "The lightning connection string. Set to 'Internal Node' to use the internal node. (See [this doc](https://github.com/btcpayserver/BTCPayServer.Lightning/blob/master/README.md#examples) for some example)", "description": "The lightning connection string. Set to 'Internal Node' to use the internal node. (See [this doc](https://github.com/btcpayserver/BTCPayServer.Lightning/blob/master/README.md#examples) for some example)",
"example": "type=clightning;server=..." "example": "type=clightning;server=..."
},
"disableBOLT11PaymentOption": {
"type": "boolean",
"description": "Whether to disable generation of bolt11 invoices. Useful when wanting to only use LNURL Pay exclusively."
} }
} }
}, },