Пример #1
0
        public void CheckStakeKernelHashTest()
        {
            var result = Mint.CheckStakeKernelHash(new PeercoinUtils.MintTemplate(
                                                       "totest",
                                                       "Pxxxx",
                                                       1394219584,
                                                       160,
                                                       1394219584,
                                                       1,
                                                       210090000,
                                                       471087779
                                                       ),
                                                   1411634680,
                                                   15161125480764745506);

            bool isValid = result.success;

            Assert.IsTrue(isValid);

            var tpl0Hash = new List <byte> {
                0x00, 0x00, 0x00, 0xdb, 0x33, 0x30, 0x88, 0x15,
                0x19, 0xa4, 0xf3, 0x2b, 0x90, 0x91, 0xb0, 0x93,
                0x0f, 0x24, 0xec, 0x6f, 0xb0, 0x90, 0x0a, 0xcf,
                0xbf, 0xb0, 0xc2, 0x26, 0xc7, 0xbc, 0x31, 0x92,
            };

            //little endian
            tpl0Hash.Reverse();

            for (int i = 0; i < result.hash.Length; i++)
            {
                isValid = result.hash[i] == tpl0Hash[i];
                Assert.IsTrue(isValid);
            }


            // check if template satisfies min target
            var minbits = Mint.IncCompact(Mint.BigToCompact(result.minTarget));

            var minresult = Mint.CheckStakeKernelHash(new PeercoinUtils.MintTemplate(
                                                          "totest",
                                                          "Pxxx",
                                                          1394219584,
                                                          160,
                                                          1394219584,
                                                          1,
                                                          210090000,
                                                          minbits
                                                          ),
                                                      1411634680,
                                                      15161125480764745506);


            isValid = minresult.success;

            Assert.IsTrue(isValid);
        }
Пример #2
0
        private void TickTimer(object state)
        {
            //stop the timer
            syncTimer.Change(Timeout.Infinite, Timeout.Infinite);
            var start = this.currentTime;
            var end   = Math.Min(this.currentTime + 1000, this.lastblocktime + PeercoinConstants.Findstakelimit);

            for (uint timestamp = start; timestamp < end; timestamp++)
            {
                var modifier = Mint.GetModifier(this.blockModifiers, timestamp);

                if (modifier.HasValue)
                {
                    foreach (var template in templates)
                    {
                        if (this.formclosing || this.token.IsCancellationRequested)
                        {
                            return;
                        }

                        var result = Mint.CheckStakeKernelHash(template, timestamp, modifier.Value);
                        if (result.success)
                        {
                            if (this.results.All(r => r.Id != template.Id && r.txTime != timestamp))
                            {
                                results.Add(new CheckStakeResult()
                                {
                                    Id                = template.Id,
                                    OfAddress         = template.OfAddress,
                                    minimumDifficulty = result.minimumDifficulty,
                                    txTime            = timestamp
                                });
                                FillGrid(true);
                            }
                        }
                    }
                }
                if (this.formclosing || this.token.IsCancellationRequested)
                {
                    return;
                }


                this.currentTime++;
            }

            const int hour = 3600;

            if (!this.formclosing)
            {
                SetProgress(
                    Convert.ToInt32(this.currentTime / hour),
                    Convert.ToInt32((this.lastblocktime + PeercoinConstants.Findstakelimit) / hour),
                    Convert.ToInt32(this.lastblocktime / hour));
            }


            if (!this.formclosing && !this.token.IsCancellationRequested &&
                syncTimer != null && this.currentTime < this.lastblocktime + PeercoinConstants.Findstakelimit)
            {
                syncTimer.Change(50, Timeout.Infinite);
            }
            else
            {
                SetProgress(0, 100);
                SetStatus("Done");
            }
        }
Пример #3
0
        public static void Findstake(Options o)
        {
            var blockRepository       = new BlockRepository();
            var transactionRepository = new TransactionRepository(blockRepository);

            var rpcclient = new RPCClient("http://127.0.0.1:" + o.Port, o.User, o.Password);
            var parser    = new BlockChainParser(rpcclient, blockRepository, transactionRepository);

            var blockcount = rpcclient.GetBlockCount();
            var difficulty = rpcclient.GetDifficulty().pos;

            if (blockcount < 999)
            {
                Console.WriteLine("Not connected to wallet" + blockcount);
                return;
            }

            var unspents  = new List <UnspentTransactionData>();
            var templates = new List <MintTemplate>();

            try
            {
                var listunspents = JsonConvert.DeserializeObject <List <Unspent> >(File.ReadAllText(System.IO.Directory.GetCurrentDirectory() + Path.DirectorySeparatorChar + o.FileListUnspent));
                unspents = listunspents
                           .Select(unspent => new UnspentTransactionData {
                    txid    = unspent.txid,
                    vout    = unspent.vout,
                    address = unspent.address
                })
                           .ToList();

                Console.WriteLine("");
                Console.Write("Importing blocks");
                using (var progress = new ProgressBar())
                {
                    var max     = unspents.Count;
                    var counter = 0;
                    unspents.ForEach(unspent => {
                        unspent.blockhash   = parser.GetBlockHash(unspent.txid);
                        unspent.blockheight = parser.Parse(unspent.blockhash);
                        parser.Parse(unspent.blockhash);
                        progress.Report((double)counter / max);
                        counter++;
                    });
                }

                float minMarginDifficulty = 2.0f;
                Console.WriteLine("");
                Console.Write("Importing adresses");
                using (var progress = new ProgressBar())
                {
                    var addresses = unspents.Select(un => un.address).Distinct().ToList();
                    var max       = addresses.Count;
                    var counter   = 0;

                    addresses.ForEach(address => {
                        progress.Report((double)counter / max);
                        var unspentsbyaddress = transactionRepository.GetUnspents(address);
                        unspentsbyaddress.ForEach(unspent => {
                            var m = new MintTemplate(
                                unspent.Id,
                                address,
                                unspent.BlockFromTime,
                                unspent.PrevTxOffset,
                                unspent.PrevTxTime,
                                unspent.PrevTxOutIndex,
                                (uint)unspent.PrevTxOutValue);

                            m.SetBitsWithDifficulty(((Convert.ToSingle(difficulty) - minMarginDifficulty)));

                            if (templates.All(t => t.Id != m.Id))
                            {
                                templates.Add(m);
                            }
                        });
                        counter++;
                    });
                }
            }
            catch (Exception)
            {
                //show error

                Console.WriteLine("Loading " + System.IO.Directory.GetCurrentDirectory() + Path.DirectorySeparatorChar + o.FileListUnspent + " listunspent data not succeeded");
                return;
            }


            Console.WriteLine("");
            Console.Write("Loading stakemodifiers");
            using (var progress = new ProgressBar())
            {
                var start = blockcount - (6 * 24 * 31) - 10;
                var end   = blockcount;
                for (uint i = start; i < end; i++)
                {
                    progress.Report((double)(i - start) / (end - start));
                    parser.Parse(i);
                }
            }

            var lastblock      = blockRepository.GetBlockState(blockcount - 6);     //not the very last
            var lastblocktime  = lastblock.bt;
            var blockModifiers = blockRepository.GetStakeModifiers(lastblock.h);

            var currentTime   = ConvertToUnixTimestamp(DateTime.UtcNow);
            var results       = new List <CheckStakeResult>();
            var resultsStakes = new List <PossibleStake>();

            Console.WriteLine("");
            Console.Write("Searching");
            using (var progress = new ProgressBar())
            {
                var start = currentTime;
                var end   = lastblocktime + PeercoinConstants.Findstakelimit;
                for (uint timestamp = start; timestamp < end; timestamp++)
                {
                    progress.Report((double)(timestamp - start) / (end - start));
                    var modifier = Mint.GetModifier(blockModifiers, timestamp);

                    foreach (var template in templates)
                    {
                        var result = Mint.CheckStakeKernelHash(template, timestamp, modifier.Value);
                        if (result.success)
                        {
                            if (results.All(r => r.Id != template.Id && r.txTime != timestamp))
                            {
                                Console.WriteLine(" " + template.OfAddress + ": " + ConvertFromUnixTimestamp(timestamp) + " difficulty: " + result.minimumDifficulty.ToString("0.00"));
                                results.Add(new CheckStakeResult()
                                {
                                    Id                = template.Id,
                                    OfAddress         = template.OfAddress,
                                    minimumDifficulty = result.minimumDifficulty,
                                    txTime            = timestamp
                                });
                                resultsStakes = Enrich(resultsStakes, templates, results);
                                ExportResults(resultsStakes, results);
                            }
                        }
                    }
                }
            }
            Console.WriteLine("Done");
            if (results.Count > 0)
            {
                Console.WriteLine("Findstake results exported to StakeDates.csv");
            }
        }//end