Example #1
0
        public MiningParameters GetMiningParameters()
        {
            Program.Print("[INFO] Checking latest parameters from pool...");

            var getPoolEthAddress             = GetPoolParameter("getPoolEthAddress");
            var getPoolChallengeNumber        = GetPoolParameter("getChallengeNumber");
            var getPoolMinimumShareDifficulty = GetPoolParameter("getMinimumShareDifficulty", s_MinerAddress);
            var getPoolMinimumShareTarget     = GetPoolParameter("getMinimumShareTarget", s_MinerAddress);

            bool success = true;

            try
            {
                m_cacheParameters = MiningParameters.GetPoolMiningParameters(s_PoolURL, getPoolEthAddress, getPoolChallengeNumber,
                                                                             getPoolMinimumShareDifficulty, getPoolMinimumShareTarget);

                return(m_cacheParameters);
            }
            catch (AggregateException ex)
            {
                success = false;
                m_retryCount++;

                string errorMsg = ex.Message;
                foreach (var iEx in ex.InnerExceptions)
                {
                    errorMsg += ("\n " + iEx.Message);
                }

                Program.Print("[ERROR] " + errorMsg);
            }
            catch (Exception ex)
            {
                success = false;
                m_retryCount++;

                string errorMsg = ex.Message;
                if (ex.InnerException != null)
                {
                    errorMsg += ("\n " + ex.InnerException.Message);
                }
                Program.Print("[ERROR] " + errorMsg);
            }

            if (!success && SecondaryPool != null && m_retryCount >= m_maxScanRetry)
            {
                m_runFailover = true;
                Program.Print("[INFO] Checking mining parameters from secondary pool...");
                return(SecondaryPool.GetMiningParameters());
            }

            return(null);
        }
        public MiningParameters GetMiningParameters()
        {
            Program.Print(string.Format("[INFO] Checking latest parameters from {0} pool...", IsSecondaryPool ? "secondary" : "primary"));

            var getPoolEthAddress             = GetPoolParameter("getPoolEthAddress");
            var getPoolChallengeNumber        = GetPoolParameter("getChallengeNumber");
            var getPoolMinimumShareDifficulty = GetPoolParameter("getMinimumShareDifficulty", MinerAddress);
            var getPoolMinimumShareTarget     = GetPoolParameter("getMinimumShareTarget", MinerAddress);

            bool success   = true;
            var  startTime = DateTime.Now;

            try
            {
                return(MiningParameters.GetPoolMiningParameters(s_PoolURL, getPoolEthAddress, getPoolChallengeNumber,
                                                                getPoolMinimumShareDifficulty, getPoolMinimumShareTarget));
            }
            catch (AggregateException ex)
            {
                success = false;
                m_retryCount++;

                Program.Print("[ERROR] " + ex.Message);
            }
            catch (Exception ex)
            {
                success = false;
                m_retryCount++;

                string errorMsg = ex.Message;
                if (ex.InnerException != null)
                {
                    errorMsg += ("\n " + ex.InnerException.Message);
                }
                Program.Print("[ERROR] " + errorMsg);
            }
            finally
            {
                if (success)
                {
                    m_runFailover = false;
                    var tempLatency = (int)(DateTime.Now - startTime).TotalMilliseconds;
                    try
                    {
                        using (var ping = new Ping())
                        {
                            var poolURL = s_PoolURL.Contains("://") ? s_PoolURL.Split("://")[1] : s_PoolURL;
                            try
                            {
                                var response = ping.Send(poolURL);
                                if (response.RoundtripTime > 0)
                                {
                                    tempLatency = (int)response.RoundtripTime;
                                }
                            }
                            catch
                            {
                                try
                                {
                                    poolURL = poolURL.Split('/').First();
                                    var response = ping.Send(poolURL);
                                    if (response.RoundtripTime > 0)
                                    {
                                        tempLatency = (int)response.RoundtripTime;
                                    }
                                }
                                catch
                                {
                                    try
                                    {
                                        poolURL = poolURL.Split(':').First();
                                        var response = ping.Send(poolURL);
                                        if (response.RoundtripTime > 0)
                                        {
                                            tempLatency = (int)response.RoundtripTime;
                                        }
                                    }
                                    catch { }
                                }
                            }
                        }
                    }
                    catch { }
                    Latency = tempLatency;
                }
            }

            var runFailover = (!success && SecondaryPool != null && m_maxScanRetry > -1 && m_retryCount >= m_maxScanRetry);

            try
            {
                if (runFailover)
                {
                    return(SecondaryPool.GetMiningParameters());
                }
            }
            finally { m_runFailover = runFailover; }

            return(null);
        }