Beispiel #1
0
        public static async Task <Macaroons> GetFromDirectoryAsync(string directoryPath)
        {
            ArgumentNullException.ThrowIfNull(directoryPath);
            Macaroons macaroons = new Macaroons();

            if (!Directory.Exists(directoryPath))
            {
                throw new DirectoryNotFoundException("Macaroons directory not found");
            }
            foreach (var file in Directory.GetFiles(directoryPath, "*.macaroon"))
            {
                try
                {
                    switch (Path.GetFileName(file))
                    {
                    case "admin.macaroon":
                        macaroons.AdminMacaroon = new Macaroon(await File.ReadAllBytesAsync(file));
                        break;

                    case "readonly.macaroon":
                        macaroons.ReadonlyMacaroon = new Macaroon(await File.ReadAllBytesAsync(file));
                        break;

                    case "invoice.macaroon":
                        macaroons.InvoiceMacaroon = new Macaroon(await File.ReadAllBytesAsync(file));
                        break;

                    default:
                        break;
                    }
                }
                catch { }
            }
            return(macaroons);
        }
Beispiel #2
0
        public async Task <IActionResult> LndServices(string cryptoCode, int index, uint?nonce)
        {
            if (!_dashBoard.IsFullySynched(cryptoCode, out var unusud))
            {
                StatusMessage = $"Error: {cryptoCode} is not fully synched";
                return(RedirectToAction(nameof(Services)));
            }
            var external = GetExternalLndConnectionString(cryptoCode, index);

            if (external == null)
            {
                return(NotFound());
            }
            var model = new LndGrpcServicesViewModel();

            if (external.ConnectionType == LightningConnectionType.LndGRPC)
            {
                model.Host                = $"{external.BaseUri.DnsSafeHost}:{external.BaseUri.Port}";
                model.SSL                 = external.BaseUri.Scheme == "https";
                model.ConnectionType      = "GRPC";
                model.GRPCSSLCipherSuites = "ECDHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES128-SHA256";
            }
            else if (external.ConnectionType == LightningConnectionType.LndREST)
            {
                model.Uri            = external.BaseUri.AbsoluteUri;
                model.ConnectionType = "REST";
            }

            if (external.CertificateThumbprint != null)
            {
                model.CertificateThumbprint = Encoders.Hex.EncodeData(external.CertificateThumbprint);
            }
            if (external.Macaroon != null)
            {
                model.Macaroon = Encoders.Hex.EncodeData(external.Macaroon);
            }
            var macaroons = external.MacaroonDirectoryPath == null ? null : await Macaroons.GetFromDirectoryAsync(external.MacaroonDirectoryPath);

            model.AdminMacaroon    = macaroons?.AdminMacaroon?.Hex;
            model.InvoiceMacaroon  = macaroons?.InvoiceMacaroon?.Hex;
            model.ReadonlyMacaroon = macaroons?.ReadonlyMacaroon?.Hex;

            if (nonce != null)
            {
                var configKey = GetConfigKey("lnd", cryptoCode, index, nonce.Value);
                var lnConfig  = _LnConfigProvider.GetConfig(configKey);
                if (lnConfig != null)
                {
                    model.QRCodeLink = $"{this.Request.GetAbsoluteRoot().WithTrailingSlash()}lnd-config/{configKey}/lnd.config";
                    model.QRCode     = $"config={model.QRCodeLink}";
                }
            }

            return(View(model));
        }
Beispiel #3
0
        public async Task <IActionResult> LndServicesPost(string cryptoCode, int index)
        {
            var external = GetExternalLndConnectionString(cryptoCode, index);

            if (external == null)
            {
                return(NotFound());
            }
            LightningConfigurations confs = new LightningConfigurations();
            var macaroons = external.MacaroonDirectoryPath == null ? null : await Macaroons.GetFromDirectoryAsync(external.MacaroonDirectoryPath);

            if (external.ConnectionType == LightningConnectionType.LndGRPC)
            {
                LightningConfiguration grpcConf = new LightningConfiguration();
                grpcConf.Type = "grpc";
                grpcConf.Host = external.BaseUri.DnsSafeHost;
                grpcConf.Port = external.BaseUri.Port;
                grpcConf.SSL  = external.BaseUri.Scheme == "https";
                confs.Configurations.Add(grpcConf);
            }
            else if (external.ConnectionType == LightningConnectionType.LndREST)
            {
                var restconf = new LNDRestConfiguration();
                restconf.Type = "lnd-rest";
                restconf.Uri  = external.BaseUri.AbsoluteUri;
                confs.Configurations.Add(restconf);
            }
            else
            {
                throw new NotSupportedException(external.ConnectionType.ToString());
            }
            var commonConf = (LNDConfiguration)confs.Configurations[confs.Configurations.Count - 1];

            commonConf.ChainType             = _Options.NetworkType.ToString();
            commonConf.CryptoCode            = cryptoCode;
            commonConf.Macaroon              = external.Macaroon == null ? null : Encoders.Hex.EncodeData(external.Macaroon);
            commonConf.CertificateThumbprint = external.CertificateThumbprint == null ? null : Encoders.Hex.EncodeData(external.CertificateThumbprint);
            commonConf.AdminMacaroon         = macaroons?.AdminMacaroon?.Hex;
            commonConf.ReadonlyMacaroon      = macaroons?.ReadonlyMacaroon?.Hex;
            commonConf.InvoiceMacaroon       = macaroons?.InvoiceMacaroon?.Hex;

            var nonce     = RandomUtils.GetUInt32();
            var configKey = GetConfigKey("lnd", cryptoCode, index, nonce);

            _LnConfigProvider.KeepConfig(configKey, confs);
            return(RedirectToAction(nameof(LndServices), new { cryptoCode = cryptoCode, nonce = nonce }));
        }