示例#1
0
        private static byte[] CalcSHA256(string text)
        {
            byte[]       bytes  = Encoding.UTF8.GetBytes(text);
            Sha256Digest digest = new Sha256Digest();

            digest.BlockUpdate(bytes, 0, bytes.Length);
            byte[] result = new byte[digest.GetDigestSize()];
            digest.DoFinal(result, 0);
            //increment global counter
            GlobalCounter.Increment();
            return(result);
        }
示例#2
0
        static void Main(string[] args)
        {
            //string minerAddress = Console.ReadLine();
            //private keys for miner address to TEST
            //string privateKey = "8f3ed57916ab3f6e672b77ca09fb80d1bedccc255ad14ee07a676803fe93e977";
            //string pubKey = "2be3c6750dc1bfca520afc66bb44760505883c05488e3a62e7721fe06a9bccc9d";
            var   availableThreads = Environment.ProcessorCount;
            ulong startingNonce    = ulong.MinValue + 1;

            string minerAddress = "ca406724d901bc69e9f75d34f15563a03e163db9";

            blockToMine = GetBlock(minerAddress);

            while (true)
            {
                cancelTasks = new CancellationTokenSource();
                var taskList = new List <Task <ResultWrapper> >();

                GlobalCounter.Reset();
                var sw = Stopwatch.StartNew();


                for (int i = 0; i < availableThreads; i++)
                {
                    taskList.Add(Task.Run(() =>
                    {
                        return(StartMining(blockToMine, minerAddress, startingNonce += 1000000));
                    }, cancelTasks.Token));
                }

                Task.WaitAny(taskList.ToArray());
                var foundHash = taskList.FirstOrDefault(x => x.Result != null);
                cancelTasks.Cancel();

                if (foundHash != null)
                {
                    SubmitPoW(foundHash.Result);
                }

                sw.Stop();
                var kiloHashesPerSecond = (GlobalCounter.Value / sw.Elapsed.TotalSeconds) / 1000;
                Console.WriteLine("kHs => {0} ", kiloHashesPerSecond);
                blockToMine = GetBlock(minerAddress);
            }
        }