示例#1
0
        private void FoundBlocks(string namepool, bool task)
        {
            if (!task)
            {
                Console.WriteLine("{0} : Search blocks in {1}.", DateTime.Now, namepool);
                Mining.Write(String.Format("{0} : Search blocks in {1}.", DateTime.Now, namepool));
                const int           n          = 2;
                const int           countblock = n * 5;
                EFBlockRepository   eFBlock    = new EFBlockRepository();
                IEnumerable <Block> countbl    = eFBlock.Blocks.OrderByDescending(x => x.height).Take(countblock - 1);
                int        maxheight           = eFBlock.Blocks.OrderByDescending(x => x.height).Select(x => x.height).FirstOrDefault();
                List <int> cntbl = new List <int>();
                int        n5    = countbl.Where(x => x.height <= maxheight && x.height >= maxheight - (n - 1) && x.poolname == namepool).Count();
                int        n4    = countbl.Where(x => x.height < maxheight - (n - 1) && x.height >= maxheight - (n * 2 - 1) && x.poolname == namepool).Count();
                int        n3    = countbl.Where(x => x.height < maxheight - (n * 2 - 1) && x.height >= maxheight - (n * 3 - 1) && x.poolname == namepool).Count();
                int        n2    = countbl.Where(x => x.height < maxheight - (n * 3 - 1) && x.height >= maxheight - (n * 4 - 1) && x.poolname == namepool).Count();
                int        n1    = countbl.Where(x => x.height < maxheight - (n * 4 - 1) && x.height >= maxheight - (n * 5 - 1) && x.poolname == namepool).Count();

                if (n5 == 0 && n4 == 0 && n3 == 0 && n2 == 0 && n1 == 0)
                {
                    Console.WriteLine("{0} : Not found blocks in {1}.", DateTime.Now, namepool);
                    Mining.Write(String.Format("{0} : Not found blocks in {1}.", DateTime.Now, namepool));
                    Request.ChangePool change = new Request.ChangePool();
                    change.Change(namepool);
                    FoundBlockSuccess = false;
                    TaskChangePool    = true;
                    BlockStartWork    = maxheight;
                    PoolStartWork     = namepool;
                    return;
                }
                else
                {
                    Console.WriteLine("{0} : Found blocks in {1}.", DateTime.Now, namepool);
                    Mining.Write(String.Format("{0} : Found blocks in {1}.", DateTime.Now, namepool));
                    FoundBlockSuccess = true;
                }
            }
            else
            {
                EFBlockRepository eFBlock = new EFBlockRepository();
                int maxheight             = eFBlock.Blocks.OrderByDescending(x => x.height).Select(x => x.height).FirstOrDefault();
                int WorkFindBlock         = eFBlock.Blocks.OrderByDescending(x => x.height).Where(x => x.height <= maxheight && x.height >= BlockStartWork && x.poolname == namepool).Count();
                if (WorkFindBlock >= 6 && namepool == "ViaBTC")
                {
                    TaskChangePool = false;
                    Console.WriteLine("{0} : Work on {1} stopped.", DateTime.Now, namepool);
                    Mining.Write(String.Format("{0} : Work on {1} stopped.", DateTime.Now, namepool));
                    return;
                }
                else if (WorkFindBlock >= 3 && namepool != "ViaBTC")
                {
                    TaskChangePool = false;
                    Console.WriteLine("{0} : Work on {1} stopped.", DateTime.Now, namepool);
                    Mining.Write(String.Format("{0} : Work on {1} stopped.", DateTime.Now, namepool));
                    return;
                }
                Console.WriteLine("{0} : Work on {1} continue.", DateTime.Now, namepool);
                Mining.Write(String.Format("{0} : Work on {1} continue.", DateTime.Now, namepool));
            }
        }
示例#2
0
        public async Task <List <float> > CalculateLuck(int countblock)
        {
            HashRate hashRate      = new HashRate();
            float    hrn           = float.Parse(await hashRate.Rate()) / 1000;
            Pool     pool          = new Pool();
            string   viabtc        = "ViaBTC";
            string   slushpool     = "SlushPool";
            string   viabtchash    = pool.Parse(viabtc);
            string   slushpoolhash = pool.Parse(slushpool);

            viabtchash    = viabtchash.Substring(0, viabtchash.Length - 5).Replace(",", "").Replace(".", ",");
            slushpoolhash = slushpoolhash.Substring(0, slushpoolhash.Length - 5).Replace(",", "").Replace(".", ",");
            //Console.WriteLine(viabtchash);
            float               viabtcpie    = (((float.Parse(viabtchash) * 100 / hrn)) * countblock) / 100;
            float               slushpoolpie = (((float.Parse(slushpoolhash) * 100 / hrn)) * countblock) / 100;
            EFBlockRepository   eFBlock      = new EFBlockRepository();
            IEnumerable <Block> countb       = eFBlock.Blocks.OrderByDescending(x => x.height).Take(countblock);
            int   countviabtc    = countb.Where(x => x.poolname == viabtc).Count();
            int   countslushpool = countb.Where(x => x.poolname == slushpool).Count();
            float luckviabtc     = 100 * countviabtc / viabtcpie;
            float luckslushpool  = 100 * countslushpool / slushpoolpie;

            Console.WriteLine(luckviabtc);
            Console.WriteLine(luckslushpool);
            List <float> luck = new List <float>()
            {
                luckviabtc, luckslushpool
            };

            return(luck);
        }
示例#3
0
        public async void CalculateProbability(string namepool)//Task<List<double>> CalculateProbability(string namepool,int countblock, int forecastblock)
        {
            int                countblock    = 1000;
            int                forecastblock = 100;
            HashRate           hashRate      = new HashRate();
            EFMinearRepository eFMinear      = new EFMinearRepository();
            //network hrt
            float hrn = float.Parse(await hashRate.Rate()) / 1000;

            Pool pool = new Pool();

            //pool hrt
            string hashs = pool.Parse(namepool);

            //string hashs = pool.Parse("ViaBTC");
            hashs = hashs.Substring(0, hashs.Length - 5).Replace(",", "").Replace(".", ",");
            double hash = double.Parse(hashs);

            //T
            double T = forecastblock * 10 / 60;
            //double T = 100 * 10 / 60;

            //BTC.com
            double btc     = (T / 24) * 1.6 * 1000 * double.Parse(eFMinear.Minears.OrderBy(x => x.date).Select(x => x.fpps_mining_earnings).LastOrDefault(), CultureInfo.InvariantCulture);
            int    countfb = (int)Math.Ceiling(btc / 1.6 * hash / 12.8);
            //Console.WriteLine("Необходимое количество найденных блоков для прибыли : {0} ", countfb);
            EFBlockRepository   eFBlock = new EFBlockRepository();
            IEnumerable <Block> countb  = eFBlock.Blocks.OrderByDescending(x => x.height).Take(countblock);
            int count = countb.Where(x => x.poolname == namepool).Count();
            //IEnumerable<Block> countb = eFBlock.Blocks.OrderByDescending(x => x.height).Take(1000);
            //int count = countb.Where(x => x.poolname == "ViaBTC").Count();

            //P
            double P = Calc(hrn, hash, countblock, forecastblock, countfb, count);

            //double P = Calc(hrn, hash, 1000, 100, countfb, count);
            Console.WriteLine("{3} : Вероятность {1} для {2} и более блоков за {4} блоков : {0}%", P, namepool, countfb, DateTime.Now, forecastblock);
            //Console.WriteLine("Вероятность {1} : {0}%", P, namepool);

            //Revenue
            //double revenue1 = findblock * 1.6 / viabtchash * 12.8;
            //double revenue2 = findblock * 1.6 / slushpoolhash * 12.8;
            double revenue = (countfb * 1.6 / hash * 12.8) - btc;

            //Console.WriteLine("Доход {1} : {0} BTC", revenue, "ViaBTC");
            Console.WriteLine("{3} : Доход {1} при {2} блоков : {0} BTC", revenue, namepool, countfb, DateTime.Now);
            //List<double> ret = new List<double> { P, revenue };
            //return ret;


            //laplas
            double matwait              = (hash / hrn) * 144;
            int    maxheight            = eFBlock.Blocks.OrderByDescending(x => x.height).Select(x => x.height).FirstOrDefault();
            IEnumerable <Block> countbl = eFBlock.Blocks.OrderByDescending(x => x.height).Take(countblock);
            List <int>          cntbl   = new List <int>();

            cntbl.Add(countbl.Where(x => x.height <= maxheight && x.height >= maxheight - 143 && x.poolname == namepool).Count());
            cntbl.Add(countbl.Where(x => x.height < maxheight - 143 && x.height >= maxheight - 287 && x.poolname == namepool).Count());
            cntbl.Add(countbl.Where(x => x.height < maxheight - 287 && x.height >= maxheight - 431 && x.poolname == namepool).Count());
            cntbl.Add(countbl.Where(x => x.height < maxheight - 431 && x.height >= maxheight - 575 && x.poolname == namepool).Count());
            cntbl.Add(countbl.Where(x => x.height < maxheight - 575 && x.height >= maxheight - 719 && x.poolname == namepool).Count());
            Console.WriteLine("{3} : Вероятность {1} для {2} и более блоков : {0}%", Function.Function.FuncLaplas(cntbl, matwait, countfb) * 100, namepool, countfb, DateTime.Now);
        }
示例#4
0
        public async void GetBlocks()
        {
            Initialized = true;
            Console.WriteLine("{0} : Launch checking the relevance of the database blocks.", DateTime.Now);
            //DateTime date = DateTime.Parse("20.09.2019");
            //for (DateTime i = date; i < DateTime.Now; i = i.AddDays(1))
            //{
            try
            {
                EFBlockRepository blockRepository = new EFBlockRepository();
                int    minheight = blockRepository.Blocks.OrderBy(x => x.height).Select(x => x.height).LastOrDefault();
                string ID        = await GetHeight(minheight);

                if (ID != minheight.ToString())
                {
                    Console.WriteLine("{0} : Starting block loading.", DateTime.Now);
                    ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
                    Console.WriteLine("https://chain.api.btc.com/v3/block/" + ID);
                    var req = WebRequest.Create(@"https://chain.api.btc.com/v3/block/" + ID);
                    //var req = WebRequest.Create(@"https://chain.api.btc.com/v3/block/date/" + i.ToString("yyyyMMdd"));
                    req.ContentType = "application/json";
                    var r = await req.GetResponseAsync();

                    StreamReader responseReader = new StreamReader(r.GetResponseStream());
                    var          responseData   = await responseReader.ReadToEndAsync();

                    JObject obj    = JObject.Parse(responseData);
                    dynamic jsonDe = JsonConvert.DeserializeObject(obj["data"].ToString());
                    if (jsonDe.GetType().ToString() == "Newtonsoft.Json.Linq.JArray")
                    {
                        foreach (JObject typeStr in jsonDe)
                        {
                            //Console.WriteLine("Current Height " + typeStr["height"].ToString());
                            if (blockRepository.Blocks.Where(x => x.height == int.Parse(typeStr["height"].ToString())).Count() == 0)
                            {
                                await blockRepository.Create(int.Parse(typeStr["height"].ToString()), int.Parse(typeStr["timestamp"].ToString()), typeStr["extras"]["pool_name"].ToString());

                                Console.WriteLine("{1} : Add Block Height {0}.", typeStr["height"].ToString(), DateTime.Now);
                            }
                        }
                    }
                    else
                    {
                        //Console.WriteLine("Current Height " + jsonDe["height"].ToString());
                        if (blockRepository.Blocks.Where(x => x.height == int.Parse(jsonDe["height"].ToString())).Count() == 0)
                        {
                            await blockRepository.Create(int.Parse(jsonDe["height"].ToString()), int.Parse(jsonDe["timestamp"].ToString()), jsonDe["extras"]["pool_name"].ToString());

                            Console.WriteLine("{1} : Add Block Height {0}.", jsonDe["height"].ToString(), DateTime.Now);
                        }
                    }
                }

                else
                {
                    Console.WriteLine("{0} : The base of blocks is relevant.", DateTime.Now);
                }
                Console.WriteLine("{0} : Stop checking the relevance of the block database.", DateTime.Now);
            }
            catch (Exception ex)
            {
                Console.WriteLine("{0} : Error block loading", DateTime.Now);
            }
            //Probability probability = new Probability();
            //probability.CalculateProbability("ViaBTC");
            //probability.CalculateProbability("SlushPool");
            FoundBlock foundBlock = new FoundBlock();

            foundBlock.SwitchPool();
            Initialized = false;
            //Thread.Sleep(3000);
            //Task.WaitAll(blockRepository.Create());
            //}
        }
示例#5
0
        public async void Get()
        {
            try
            {
                Initialized = true;
                Console.WriteLine("{0} : Launch checking the relevance of the database blocks.", DateTime.Now);
                EFBlockRepository blockRepository = new EFBlockRepository();
                try
                {
                    minheight = blockRepository.Blocks.OrderBy(x => x.height).Select(x => x.height).LastOrDefault();
                }
                catch
                {
                }
                List <string> id = await GetHeight(minheight);

                if (id.Count != 0)
                {
                    Console.WriteLine("{0} : Starting block loading.", DateTime.Now);
                    foreach (string ID in id)
                    {
                        ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
                        var req = WebRequest.Create(@"https://api.blockchair.com/bitcoin/blocks?q=id" + ID);
                        req.ContentType = "application/json";
                        var r = await req.GetResponseAsync();

                        StreamReader responseReader = new StreamReader(r.GetResponseStream());
                        var          responseData   = await responseReader.ReadToEndAsync();

                        JObject obj    = JObject.Parse(responseData);
                        dynamic jsonDe = JsonConvert.DeserializeObject(obj["data"].ToString());
                        try
                        {
                            if (jsonDe.GetType().ToString() == "Newtonsoft.Json.Linq.JArray")
                            {
                                foreach (JObject typeStr in jsonDe)
                                {
                                    if (blockRepository.Blocks.Where(x => x.height == int.Parse(typeStr["id"].ToString())).Count() == 0)
                                    {
                                        await blockRepository.Create(int.Parse(typeStr["id"].ToString()), (int)DateTime.Parse(typeStr["median_time"].ToString()).Subtract(new DateTime(1970, 1, 1)).TotalSeconds, typeStr["guessed_miner"].ToString());

                                        Console.WriteLine("{1} : Add Block Height {0}.", typeStr["id"].ToString(), DateTime.Now);
                                    }
                                }
                            }
                        }
                        catch (Microsoft.CSharp.RuntimeBinder.RuntimeBinderException ex)
                        {
                            Console.WriteLine(ex);
                        }
                    }
                }
                else
                {
                    Console.WriteLine("{0} : The base of blocks is relevant.", DateTime.Now);
                }
                Console.WriteLine("{0} : Stop checking the relevance of the block database.", DateTime.Now);

                FoundBlock foundBlock = new FoundBlock();
                foundBlock.SwitchPool();
                Initialized = false;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
        }