Example #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;
            }
        }
Example #2
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 { }
        }