예제 #1
0
        static void stratum_GotSetDifficulty(object sender, StratumEventArgs e)
        {
            StratumCommand Command = (StratumCommand)e.MiningEventArg;

            //Vagabondan 2017-07-26: difficulty type should be modified!
            Console.WriteLine("Program.stratum_GotSetDifficulty: this should be MODIFIED!!! CurrentDiffficulty should not be integer!");
            CurrentDifficulty = Convert.ToInt32(Command.Parameters[0]);

            Console.WriteLine("Got Set_Difficulty " + CurrentDifficulty);
        }
예제 #2
0
        static void stratum_GotResponse(object sender, StratumEventArgs e)
        {
            StratumResponse Response = (StratumResponse)e.MiningEventArg;

            Console.Write("Got Response to {0} - ", (string)sender);

            switch ((string)sender)
            {
            case "mining.authorize":
                if ((bool)Response.Result)
                {
                    Console.WriteLine("Worker authorized");
                }
                else
                {
                    Console.WriteLine("Worker rejected");
                    Environment.Exit(-1);
                }
                break;

            case "mining.subscribe":
                Stratum.ExtraNonce1 = (string)((object[])Response.Result)[1];
                Console.WriteLine("Subscribed. ExtraNonce1 set to " + Stratum.ExtraNonce1);
                break;

            case "mining.submit":
                try
                {
                    //Should be careful here!
                    if ((bool)(Response.Result ?? false))
                    {
                        SharesAccepted++;
                        Console.WriteLine("Share accepted ({0} of {1})", SharesAccepted, SharesSubmitted);
                    }
                    else
                    {
                        Console.WriteLine("Share rejected: {0}", Response.Error.Message);
                    }
                    //Console.WriteLine("Share rejected. {0}", Response.error.Count >0 ? Response.error[1] : "No error message provided.");
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Exception inside event: " + ex.Message);
                }
                break;
            }
        }
예제 #3
0
        static void stratum_GotNotify(object sender, StratumEventArgs e)
        {
            Job            ThisJob = new Job();
            StratumCommand Command = (StratumCommand)e.MiningEventArg;

            ThisJob.JobID        = (string)Command.Parameters[0];
            ThisJob.PreviousHash = (string)Command.Parameters[1];
            ThisJob.Coinb1       = (string)Command.Parameters[2];
            ThisJob.Coinb2       = (string)Command.Parameters[3];
            Array a = (Array)Command.Parameters[4];

            ThisJob.Version           = (string)Command.Parameters[5];
            ThisJob.NetworkDifficulty = (string)Command.Parameters[6];
            ThisJob.NetworkTime       = (string)Command.Parameters[7];
            ThisJob.CleanJobs         = (bool)Command.Parameters[8];

            ThisJob.MerkleNumbers = new string[a.Length];

            int i = 0;

            foreach (string s in a)
            {
                ThisJob.MerkleNumbers[i++] = s;
            }

            // Cancel the existing mining threads and clear the queue if CleanJobs = true
            if (ThisJob.CleanJobs)
            {
                Console.WriteLine("Stratum detected a new block. Stopping old threads.");

                IncomingJobs.Clear();
                //CoinMiner.done = true;
            }

            // Add the new job to the queue
            IncomingJobs.Enqueue(ThisJob);
        }