Beispiel #1
0
            public static ServiceCustomSettings Defaults()
            {
                var nonDepricatedAlgorithms = Enum.GetValues(typeof(AlgorithmType))
                                              .Cast <AlgorithmType>()
                                              .Where(a => !a.IsObsolete())
                                              .Where(a => GetAlgorithmUrlName(a).ok)
                                              .Select(a => (algorithmType: a, name: GetAlgorithmUrlName(a).name))
                                              .ToArray();
                var stratumTemplates = new Dictionary <AlgorithmType, StratumTemplateEntry>();

                foreach (var(algorithmType, name) in nonDepricatedAlgorithms)
                {
                    stratumTemplates[algorithmType] = new StratumTemplateEntry
                    {
                        // we get something like this "{PREFIX://}daggerhashimoto.{LOCATION}.nicehash.com{:PORT}"
                        Template = $"{PREFIX_TEMPLATE}{name}.auto.nicehash.com{PORT_TEMPLATE}",
                        Port     = 9200 // 9200 or 443
                    };
                }
                return(new ServiceCustomSettings
                {
                    NhmSocketAddress = Nhmws.BuildTagNhmSocketAddress(),
                    StratumEndpointTemplatesByAlgorithmType = stratumTemplates
                });
            }
        static StratumServiceHelpers()
        {
            if (BuildOptions.CUSTOM_ENDPOINTS_ENABLED == false)
            {
                return;
            }
            var jsonSettings = new JsonSerializerSettings
            {
                NullValueHandling     = NullValueHandling.Ignore,
                MissingMemberHandling = MissingMemberHandling.Ignore,
                Culture = CultureInfo.InvariantCulture
            };
            const string customSettingsFile = "custom_endpoints_settings.json";

            if (File.Exists(customSettingsFile))
            {
                var customSettings = JsonConvert.DeserializeObject <ServiceCustomSettings>(File.ReadAllText(customSettingsFile), jsonSettings);
                if (customSettings != null)
                {
                    NhmSocketAddress = customSettings.NhmSocketAddress;
                    _stratumEndpointTemplatesByAlgorithmType = customSettings.StratumEndpointTemplatesByAlgorithmType;
                }
            }
            else
            {
                foreach (AlgorithmType algorithmType in Enum.GetValues(typeof(AlgorithmType)))
                {
                    if (algorithmType < 0)
                    {
                        continue;
                    }
                    var nPort            = 3333 + algorithmType;
                    var name             = GetAlgorithmUrlName(algorithmType).name;
                    var endpointTemplate = $"{PREFIX_TEMPLATE}{name}.{LOCATION_TEMPLATE}.nicehash.com{PORT_TEMPLATE}";
                    _stratumEndpointTemplatesByAlgorithmType[algorithmType] = new StratumTemplateEntry
                    {
                        Template = endpointTemplate,
                        Port     = (int)nPort
                    };
                }

                // create defaults
                var defaultCustomSettings = new ServiceCustomSettings
                {
                    NhmSocketAddress = Nhmws.BuildTagNhmSocketAddress(),
                    StratumEndpointTemplatesByAlgorithmType = _stratumEndpointTemplatesByAlgorithmType,
                };
                File.WriteAllText(customSettingsFile, JsonConvert.SerializeObject(defaultCustomSettings, Formatting.Indented));
            }
        }
            public static ServiceCustomSettings Defaults()
            {
                var ret = new ServiceCustomSettings
                {
                    NhmSocketAddress = Nhmws.BuildTagNhmSocketAddress()
                };

                foreach (AlgorithmType algorithmType in Enum.GetValues(typeof(AlgorithmType)))
                {
                    if (algorithmType < 0)
                    {
                        continue;
                    }
                    var name = GetAlgorithmUrlName(algorithmType).name;
                    // we get something like this "{PREFIX://}daggerhashimoto.{LOCATION}.nicehash.com{:PORT}"
                    ret.StratumEndpointTemplatesByAlgorithmType[algorithmType] = new StratumTemplateEntry
                    {
                        Template = $"{PREFIX_TEMPLATE}{name}.{LOCATION_TEMPLATE}.nicehash.com{PORT_TEMPLATE}",
                        Port     = (int)(3333 + algorithmType)
                    };
                }
                return(ret);
            }