Пример #1
0
        private void ztratum_GotResponse(object sender, ZtratumEventArgs e)
        {
            ZtratumResponse Response = (ZtratumResponse)e.MiningEventArg;

            WriteLog("Got Response to " + (string)sender);

            switch ((string)sender)
            {
            case "mining.authorize":
                if ((bool)Response.result)
                {
                    WriteLog("Worker authorized");
                }
                else
                {
                    WriteLog("Worker rejected");
                    return;
                }
                break;

            case "mining.subscribe":
                ztratum.ExtraNonce1 = (string)((object[])Response.result)[1];
                WriteLog("Subscribed. ExtraNonce1 set to " + ztratum.ExtraNonce1);
                break;

            case "mining.submit":
                if (Response.result != null && (bool)Response.result)
                {
                    SharesAccepted++;
                    totalShareAccepted++;
                    WriteLog("Share accepted (" + SharesAccepted + " of " + SharesSubmitted + ")");
                }
                else
                {
                    totalShareRejected++;
                    WriteLog("Share rejected. " + Response.error[1]);

                    if (Response.error[1].ToString().Contains("not found"))
                    {
                        CDigger.done = true;
                    }

                    if (Response.error[1].ToString().Contains("duplicate"))
                    {
                    }
                }
                Action a;
                a = () => pictureBox1.Image = GV.eyeUP; pictureBox1.Invoke(a);
                //a = () => txtLog.BackColor = System.Drawing.Color.White; txtLog.Invoke(a);

                break;

            default:
                break;
            }
        }
Пример #2
0
        private void ztratum_GotSetDifficulty(object sender, ZtratumEventArgs e)
        {
            ZtratumCommand Command = (ZtratumCommand)e.MiningEventArg;

            GV.CurrentDifficulty = Convert.ToDouble(Command.parameters[0]);
            double diff = Convert.ToDouble(GV.CurrentDifficulty);

            diff             = 65536d / diff;
            GV.CurrentTarget = Convert.ToUInt32(diff);

            WriteLog("Got Set_Difficulty " + GV.CurrentDifficulty);
        }
Пример #3
0
        private void ztratum_GotNotify(object sender, ZtratumEventArgs e)
        {
            Job            ThisJob = new Job();
            ZtratumCommand Command = (ZtratumCommand)e.MiningEventArg;

            ThisJob.JobID = (string)Command.parameters[0];

            lastJob = ThisJob.JobID;


            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;
            }


            if (ThisJob.CleanJobs)
            {
                WriteLog("Detected a new block. Stopping old threads.");

                IncomingJobs.Clear();
                CDigger.done = true;

                submitList = new List <uint>();
            }
            else
            {
                WriteLog("Detected a new job. Stopping old threads.");
                WriteLog("Job: " + ThisJob.JobID);

                IncomingJobs.Clear();
                CDigger.done = true;
            }

            IncomingJobs.Enqueue(ThisJob);
        }
Пример #4
0
        private void ReadCallback(IAsyncResult result)
        {
            try
            {
                NetworkStream networkStream;
                int           bytesread;

                byte[] buffer = result.AsyncState as byte[];

                try
                {
                    networkStream = tcpClient.GetStream();
                    bytesread     = networkStream.EndRead(result);
                }
                catch (Exception ex)
                {
                    if (!GV.StopMining)
                    {
                        main.WriteLog("Socket error:" + ex.Message);
                    }
                    return;
                }

                if (bytesread == 0)
                {
                    main.WriteLog("Disconnected. Reconnecting...");

                    tcpClient.Close();
                    tcpClient = null;
                    PendingACKs.Clear();

                    if (!GV.StopMining)
                    {
                        ConnectToServer(Server, Port, Username, Password);
                    }
                    return;
                }


                string data = ASCIIEncoding.ASCII.GetString(buffer, 0, bytesread);


                page = page + data;

                int FoundClose = page.IndexOf('}');

                while (FoundClose > 0)
                {
                    string CurrentString = page.Substring(0, FoundClose + 1);


                    ZtratumCommand  Command  = Utilities.JsonDeserialize <ZtratumCommand>(CurrentString);
                    ZtratumResponse Response = Utilities.JsonDeserialize <ZtratumResponse>(CurrentString);

                    ZtratumEventArgs e = new ZtratumEventArgs();

                    if (Command.method != null)
                    {
                        e.MiningEventArg = Command;

                        switch (Command.method)
                        {
                        case "mining.notify":
                            if (GotNotify != null)
                            {
                                GotNotify(this, e);
                            }
                            break;

                        case "mining.set_difficulty":
                            if (GotSetDifficulty != null)
                            {
                                GotSetDifficulty(this, e);
                            }
                            break;
                        }
                    }
                    else if (Response.error != null || Response.result != null)
                    {
                        e.MiningEventArg = Response;



                        string Cmd = "";
                        for (int i = 0; i < PendingACKs.Count; i++)
                        {
                            if (PendingACKs[i].id == Response.id)
                            {
                                Cmd = PendingACKs[i].method;
                                PendingACKs.RemoveAt(i);
                                break;
                            }
                        }

                        if (Cmd == null)
                        {
                            main.WriteLog("Unexpected Response");
                        }
                        else if (GotResponse != null)
                        {
                            GotResponse(Cmd, e);
                        }
                    }

                    page       = page.Remove(0, FoundClose + 2);
                    FoundClose = page.IndexOf('}');
                }


                networkStream.BeginRead(buffer, 0, buffer.Length, ReadCallback, buffer);
            }
            catch { }
        }