From 3c4c99ee4263ad23e566322e3fdb59edc60646fc Mon Sep 17 00:00:00 2001 From: rockstardev Date: Sat, 23 Jun 2018 23:16:39 -0500 Subject: [PATCH] Saving of Macaroon and Tls for LND connection --- .../StoresController.LightningLike.cs | 2 +- BTCPayServer/Controllers/StoresController.cs | 2 +- .../Lightning/LightningConnectionString.cs | 19 ++++++++++++++- .../LightningSupportedPaymentMethod.cs | 23 ++++++++++++++----- 4 files changed, 37 insertions(+), 9 deletions(-) diff --git a/BTCPayServer/Controllers/StoresController.LightningLike.cs b/BTCPayServer/Controllers/StoresController.LightningLike.cs index 9fdd24ec9..621614964 100644 --- a/BTCPayServer/Controllers/StoresController.LightningLike.cs +++ b/BTCPayServer/Controllers/StoresController.LightningLike.cs @@ -27,7 +27,7 @@ namespace BTCPayServer.Controllers LightningNodeViewModel vm = new LightningNodeViewModel(); vm.CryptoCode = cryptoCode; vm.InternalLightningNode = GetInternalLighningNode(cryptoCode)?.UriWithCreds?.AbsoluteUri; - vm.Url = GetExistingLightningSupportedPaymentMethod(vm.CryptoCode, store)?.GetLightningUrl()?.UriWithCreds.AbsoluteUri; + vm.Url = GetExistingLightningSupportedPaymentMethod(vm.CryptoCode, store)?.GetLightningUrl()?.ToFullEditString(); return View(vm); } diff --git a/BTCPayServer/Controllers/StoresController.cs b/BTCPayServer/Controllers/StoresController.cs index 9bd1cb218..12b7cf005 100644 --- a/BTCPayServer/Controllers/StoresController.cs +++ b/BTCPayServer/Controllers/StoresController.cs @@ -461,7 +461,7 @@ namespace BTCPayServer.Controllers vm.LightningNodes.Add(new StoreViewModel.LightningNode() { CryptoCode = network.CryptoCode, - Address = lightning?.GetLightningUrl()?.UriPlain.AbsoluteUri ?? string.Empty + Address = lightning?.GetLightningUrl()?.BaseUri.AbsoluteUri ?? string.Empty }); } } diff --git a/BTCPayServer/Payments/Lightning/LightningConnectionString.cs b/BTCPayServer/Payments/Lightning/LightningConnectionString.cs index 13c5ac210..559ed488f 100644 --- a/BTCPayServer/Payments/Lightning/LightningConnectionString.cs +++ b/BTCPayServer/Payments/Lightning/LightningConnectionString.cs @@ -25,8 +25,8 @@ namespace BTCPayServer.Payments.Lightning public LightningConnectionType ConnectionType { get; private set; } // Extract this to LndConnectionString class - public string Tls { get; set; } public string Macaroon { get; set; } + public string Tls { get; set; } // public Uri UriWithCreds @@ -44,6 +44,23 @@ namespace BTCPayServer.Payments.Lightning return UriWithCreds.AbsoluteUri; } + public string ToFullEditString() + { + var dict = new Dictionary(); + if (!String.IsNullOrEmpty(Macaroon)) + dict.Add("macaroon", Macaroon); + if (!String.IsNullOrEmpty(Tls)) + dict.Add("tls", Tls); + + if (dict.Count > 0) + { + var qs = dict.Select(a => $"{a.Key}={a.Value}"); + return UriWithCreds.AbsoluteUri + "?" + String.Join("&", qs); +} + else + return UriWithCreds.AbsoluteUri; + } + // public static bool TryParse(string str, out LightningConnectionString connectionString) { diff --git a/BTCPayServer/Payments/Lightning/LightningSupportedPaymentMethod.cs b/BTCPayServer/Payments/Lightning/LightningSupportedPaymentMethod.cs index e1b100e9e..3debf76e9 100644 --- a/BTCPayServer/Payments/Lightning/LightningSupportedPaymentMethod.cs +++ b/BTCPayServer/Payments/Lightning/LightningSupportedPaymentMethod.cs @@ -8,9 +8,21 @@ namespace BTCPayServer.Payments.Lightning public class LightningSupportedPaymentMethod : ISupportedPaymentMethod { public string CryptoCode { get; set; } + public PaymentMethodId PaymentId => new PaymentMethodId(CryptoCode, PaymentTypes.LightningLike); + [Obsolete("Use Get/SetLightningUrl")] public string LightningChargeUrl { get; set; } + [Obsolete("Use Get/SetLightningUrl")] + public string Username { get; set; } + [Obsolete("Use Get/SetLightningUrl")] + public string Password { get; set; } + + [Obsolete("Use Get/SetLightningUrl")] + public string Macaroon { get; set; } + [Obsolete("Use Get/SetLightningUrl")] + public string Tls { get; set; } + public LightningConnectionString GetLightningUrl() { #pragma warning disable CS0618 // Type or member is obsolete @@ -19,6 +31,8 @@ namespace BTCPayServer.Payments.Lightning { throw new FormatException(error); } + connectionString.Macaroon = Macaroon; + connectionString.Tls = Tls; return connectionString; #pragma warning restore CS0618 // Type or member is obsolete } @@ -31,14 +45,11 @@ namespace BTCPayServer.Payments.Lightning #pragma warning disable CS0618 // Type or member is obsolete Username = connectionString.Username; Password = connectionString.Password; + Macaroon = connectionString.Macaroon; + Tls = connectionString.Tls; + LightningChargeUrl = connectionString.BaseUri.AbsoluteUri; #pragma warning restore CS0618 // Type or member is obsolete } - - [Obsolete("Use Get/SetLightningUrl")] - public string Username { get; set; } - [Obsolete("Use Get/SetLightningUrl")] - public string Password { get; set; } - public PaymentMethodId PaymentId => new PaymentMethodId(CryptoCode, PaymentTypes.LightningLike); } }