Exemple #1
0
        public async void Run()
        {
            Program.DisbleQuickEditMode();
            Console.Clear();
            Console.CursorVisible = false;
            Console.Title         = $" address:{address} number:{number}  poolUrl:{poolUrl}";

            await Task.Delay(1000);

            //创建后台工作线程
            for (int ii = 0; ii < 16; ii++)
            {
                System.Threading.Thread thread = new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(Mining));
                thread.IsBackground = true;//设置为后台线程
                thread.Start(this);
            }

            HttpMessage quest = new HttpMessage();

            quest.map = new Dictionary <string, string>();

            while (true)
            {
                try
                {
                    if (timePass.IsPassSet())
                    {
                        string hash = CryptoHelper.Sha256(hashmining + random);
                        Log.Debug($"\n height:{height}, taskid:{taskid}, random:{random}, diff:{diff_max}, power:{calculatePower.GetPower()} hash:{hash}");
                    }

                    quest.map.Clear();
                    quest.map.Add("cmd", "submit");
                    quest.map.Add("height", height.ToString());
                    quest.map.Add("address", address);
                    quest.map.Add("number", number);
                    quest.map.Add("random", random);
                    quest.map.Add("taskid", taskid);
                    HttpMessage result = await ComponentNetworkHttp.Query(poolUrl, quest);

                    if (result.map != null)
                    {
                        if (result.map.ContainsKey("taskID"))
                        {
                            long.TryParse(result.map["height"], out long tempheight);
                            taskid = result.map["taskID"];
                            string temphash = result.map["hashmining"];
                            if (temphash == null || temphash == "" || temphash != hashmining)
                            {
                                if (diff_max != 0)
                                {
                                    calculatePower.Insert(diff_max);
                                }

                                diff_max   = 0;
                                hashmining = temphash;
                                height     = tempheight;
                                random     = "";
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    Log.Error(e);
                }
                await Task.Delay(1000);
            }
        }
Exemple #2
0
        public async void Run()
        {
            Program.DisbleQuickEditMode();
            Console.Clear();
            Console.CursorVisible = false;
            Console.Title         = $" address:{address},thread:{thread}, number:{number}, poolUrl:{poolUrl}";

            Log.Info($"start mining...");

            await Task.Delay(1000);

            //创建后台工作线程
            for (int ii = 0; ii < thread; ii++)
            {
                System.Threading.Thread thread = new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(Mining));
                thread.IsBackground = true;//设置为后台线程
                thread.Start(this);
            }

            HttpMessage quest = new HttpMessage();

            quest.map = new Dictionary <string, string>();

            while (true)
            {
                try
                {
                    if (timePassInfo.IsPassSet())
                    {
                        string hash = CryptoHelper.Sha256(hashmining + random);
                        Log.Info($"\n height:{height}, taskid:{taskid}, random:{random}, diff:{diff_max}, power:{calculatePower.GetPower()} hash:{hash}");
                    }

                    quest.map.Clear();
                    quest.map.Add("cmd", "submit");
                    quest.map.Add("height", height.ToString());
                    quest.map.Add("address", address);
                    quest.map.Add("number", number);
                    quest.map.Add("random", random);
                    quest.map.Add("taskid", taskid);
                    quest.map.Add("average", calculatePower.GetPowerDouble().ToString());
                    HttpMessage result = null;
                    try
                    {
                        result = await ComponentNetworkHttp.Query($"http://{poolUrl}/mining", quest);
                    }
                    catch (Exception)
                    {
                        if (timePassDebug.IsPassSet())
                        {
                            Log.Warning($"\n Unable to open the network connection http://{poolUrl}/mining");
                        }
                    }
                    if (result != null && result.map != null)
                    {
                        if (result.map.ContainsKey("taskid"))
                        {
                            if (result.map.ContainsKey("number"))
                            {
                                number        = result.map["number"];
                                Console.Title = $" address:{address},thread:{thread}, number:{number}, poolUrl:{poolUrl}";
                            }

                            long.TryParse(result.map["height"], out long tempheight);
                            taskid = result.map["taskid"];
                            string temphash = result.map["hashmining"];

                            if (temphash == null || temphash == "" || temphash != hashmining)
                            {
                                if (diff_max != 0)
                                {
                                    calculatePower.Insert(diff_max);
                                }

                                diff_max   = 0;
                                hashmining = temphash;
                                height     = tempheight;
                                random     = "";

                                result.map.TryGetValue("power", out poolPower);
                                changeCallback?.Invoke();
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    Log.Error(e);
                }
                await Task.Delay(intervalTime);
            }
        }