private async Task <IActionResult> LightningWalletServicesCore <T>(string cryptoCode, bool showQR, string walletName) where T : ExternalService, IAccessKeyService { if (!_dashBoard.IsFullySynched(cryptoCode, out var unusud)) { StatusMessage = $"Error: {cryptoCode} is not fully synched"; return(RedirectToAction(nameof(Services))); } var external = _Options.ExternalServicesByCryptoCode.GetServices <T>(cryptoCode).Where(c => c?.ConnectionString?.Server != null).FirstOrDefault(); if (external == null) { return(NotFound()); } LightningWalletServices vm = new LightningWalletServices(); vm.ShowQR = showQR; vm.WalletName = walletName; try { vm.ServiceLink = $"{external.ConnectionString.Server.AbsoluteUri}?access-key={await external.ExtractAccessKey()}"; } catch (Exception ex) { StatusMessage = $"Error: {ex.Message}"; return(RedirectToAction(nameof(Services))); } return(View("LightningWalletServices", vm)); }
public async Task <IActionResult> Service(string serviceName, string cryptoCode, bool showQR = false, uint?nonce = null) { if (!_dashBoard.IsFullySynched(cryptoCode, out var unusud)) { StatusMessage = $"Error: {cryptoCode} is not fully synched"; return(RedirectToAction(nameof(Services))); } var service = GetService(serviceName, cryptoCode); if (service == null) { return(NotFound()); } try { if (service.Type == ExternalServiceTypes.P2P) { return(View("P2PService", new LightningWalletServices() { ShowQR = showQR, WalletName = service.ServiceName, ServiceLink = service.ConnectionString.Server.AbsoluteUri.WithoutEndingSlash() })); } var connectionString = await service.ConnectionString.Expand(this.Request.GetAbsoluteUriNoPathBase(), service.Type, _Options.NetworkType); switch (service.Type) { case ExternalServiceTypes.Charge: return(LightningChargeServices(service, connectionString, showQR)); case ExternalServiceTypes.RTL: case ExternalServiceTypes.Spark: if (connectionString.AccessKey == null) { StatusMessage = $"Error: The access key of the service is not set"; return(RedirectToAction(nameof(Services))); } LightningWalletServices vm = new LightningWalletServices(); vm.ShowQR = showQR; vm.WalletName = service.DisplayName; vm.ServiceLink = $"{connectionString.Server}?access-key={connectionString.AccessKey}"; return(View("LightningWalletServices", vm)); case ExternalServiceTypes.LNDGRPC: case ExternalServiceTypes.LNDRest: return(LndServices(service, connectionString, nonce)); default: throw new NotSupportedException(service.Type.ToString()); } } catch (Exception ex) { StatusMessage = $"Error: {ex.Message}"; return(RedirectToAction(nameof(Services))); } }
public async Task <IActionResult> Service(string serviceName, string cryptoCode, bool showQR = false, uint?nonce = null) { var service = GetService(serviceName, cryptoCode); if (service == null) { return(NotFound()); } if (!string.IsNullOrEmpty(cryptoCode) && !_dashBoard.IsFullySynched(cryptoCode, out _) && service.Type != ExternalServiceTypes.RPC) { TempData[WellKnownTempData.ErrorMessage] = $"{cryptoCode} is not fully synched"; return(RedirectToAction(nameof(Services))); } try { if (service.Type == ExternalServiceTypes.P2P) { return(View("P2PService", new LightningWalletServices() { ShowQR = showQR, WalletName = service.ServiceName, ServiceLink = service.ConnectionString.Server.AbsoluteUri.WithoutEndingSlash() })); } if (service.Type == ExternalServiceTypes.LNDSeedBackup) { var model = LndSeedBackupViewModel.Parse(service.ConnectionString.CookieFilePath); if (!model.IsWalletUnlockPresent) { TempData.SetStatusMessageModel(new StatusMessageModel() { Severity = StatusMessageModel.StatusSeverity.Warning, Html = "Your LND does not seem to allow seed backup.<br />" + "It's recommended, but not required, that you migrate as instructed by <a href=\"https://blog.btcpayserver.org/btcpay-lnd-migration\">our migration blog post</a>.<br />" + "You will need to close all of your channels, and migrate your funds as <a href=\"https://blog.btcpayserver.org/btcpay-lnd-migration\">we documented</a>." }); } return(View("LndSeedBackup", model)); } if (service.Type == ExternalServiceTypes.RPC) { return(View("RPCService", new LightningWalletServices() { ShowQR = showQR, WalletName = service.ServiceName, ServiceLink = service.ConnectionString.Server.AbsoluteUri.WithoutEndingSlash() })); } var connectionString = await service.ConnectionString.Expand(this.Request.GetAbsoluteUriNoPathBase(), service.Type, _Options.NetworkType); switch (service.Type) { case ExternalServiceTypes.Charge: return(LightningChargeServices(service, connectionString, showQR)); case ExternalServiceTypes.RTL: case ExternalServiceTypes.ThunderHub: case ExternalServiceTypes.Spark: if (connectionString.AccessKey == null) { TempData[WellKnownTempData.ErrorMessage] = $"The access key of the service is not set"; return(RedirectToAction(nameof(Services))); } LightningWalletServices vm = new LightningWalletServices(); vm.ShowQR = showQR; vm.WalletName = service.DisplayName; string tokenParam = "access-key"; if (service.Type == ExternalServiceTypes.ThunderHub) { tokenParam = "token"; } vm.ServiceLink = $"{connectionString.Server}?{tokenParam}={connectionString.AccessKey}"; return(View("LightningWalletServices", vm)); case ExternalServiceTypes.CLightningRest: return(LndServices(service, connectionString, nonce, "CLightningRestServices")); case ExternalServiceTypes.LNDGRPC: case ExternalServiceTypes.LNDRest: return(LndServices(service, connectionString, nonce)); case ExternalServiceTypes.Configurator: return(View("ConfiguratorService", new LightningWalletServices() { ShowQR = showQR, WalletName = service.ServiceName, ServiceLink = $"{connectionString.Server}?password={connectionString.AccessKey}" })); default: throw new NotSupportedException(service.Type.ToString()); } } catch (Exception ex) { TempData[WellKnownTempData.ErrorMessage] = ex.Message; return(RedirectToAction(nameof(Services))); } }