示例#1
0
        public async Task Submit(HttpMessage quest)
        {
            quest.map.Clear();
            quest.map.Add("cmd", "submit");
            quest.map.Add("version", version);
            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");
                    StopMining();
                    await Task.Delay(15000);
                }
            }
            if (result != null && result.map != null)
            {
                if (result.map.ContainsKey("tips"))
                {
                    Log.Warning($"{result.map["tips"]}");
                    await Task.Delay(5000);
                }

                if (result.map["report"] == "error")
                {
                    Log.Warning($"{result.map["tips"]}");
                    await Task.Delay(5000);
                }

                if (result.map.ContainsKey("minerLimit"))
                {
                    if (timePassDebug.IsPassSet())
                    {
                        Log.Warning($"\n http://{poolUrl}/mining is full");
                        StopMining();
                        await Task.Delay(15000);
                    }
                }
                else
                if (result.map.ContainsKey("taskid"))
                {
                    if (result.map.ContainsKey("number"))
                    {
                        number = result.map["number"];
                        SetTitle($" address:{address},thread:{thread}, number:{number}, poolUrl:{poolUrl}, version:{version}");
                    }

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

                    if (temphash == null || temphash == "" || temphash != hashmining)
                    {
                        if (result.map.TryGetValue("power", out string smypower) && double.TryParse(smypower, out double dmypower))
                        {
                            submitCount++;
                            calculatePower.InsertPower(dmypower);
                            if (dmypower != 0)
                            {
                                effectiveShare++;
                            }
                            else
                            {
                                //calculatePower.Clear();
                            }
                        }

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

                        for (int ii = 0; ii < thread; ii++)
                        {
                            lock (ThreadDataList[ii])
                            {
                                ThreadDataList[ii].diff_max   = 0;
                                ThreadDataList[ii].random     = "";
                                ThreadDataList[ii].hashmining = hashmining;
                            }
                        }

                        if (result.map.ContainsKey("nodeTime"))
                        {
                            long.TryParse(result.map["nodeTime"], out nodeTimeOffset);
                        }

                        result.map.TryGetValue("poolPower", out poolPower);
                        changeCallback?.Invoke();
                    }
                }
            }
        }
示例#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);
                        string hash = BlockDag.ToHash(height, 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.InsertPower(CalculatePower.Power(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);
            }
        }