Example #1
0
        public void DoPoolLogin(PoolClient poolClient)
        {
            Log.Verbose("Authorizing with pool {0}", poolClient.poolEndPoint);
            switch (_pool.poolProtocol)
            {
            case 0:
                _pool.SendToPool(string.Format("{{\"id\":1,\"jsonrpc\":\"2.0\",\"method\":\"login\",\"params\":{{\"login\":\"{0}\",\"pass\":\"{1}\",\"agent\":\"XMRig/2.6.3 (Windows NT 10.0; Win64; x64) libuv/1.20.3 msvc/2017\",\"algo\":[\"cn/1\",\"cn/0\",\"cn/xtl\",\"cn/msr\",\"cn\"]}}}}", _pool.poolWallet, _pool.poolPassword));
                break;

            case 1:
                _pool.SendToPool(string.Format("{{\"id\":1,\"jsonrpc\":\"2.0\",\"method\":\"login\",\"params\":{{\"login\":\"{0}.{1}\",\"pass\":\"{2}\",\"agent\":\"XMRig/2.6.3 (Windows NT 10.0; Win64; x64) libuv/1.20.3 msvc/2017\",\"algo\":[\"cn/1\",\"cn/0\",\"cn/xtl\",\"cn/msr\",\"cn\"]}}}}", _pool.poolWallet, _pool.poolWorkerName, _pool.poolPassword));

                break;

            case 2:
                _pool.SendToPool(string.Format("{{\"id\":1,\"jsonrpc\":\"2.0\",\"method\":\"login\",\"params\":{{\"login\":\"{0}+{1}\",\"pass\":\"{2}\",\"agent\":\"XMRig/2.6.3 (Windows NT 10.0; Win64; x64) libuv/1.20.3 msvc/2017\",\"algo\":[\"cn/1\",\"cn/0\",\"cn/xtl\",\"cn/msr\",\"cn\"]}}}}", _pool.poolWallet, _pool.poolWorkerName, _pool.poolPassword));

                break;
            }
        }
Example #2
0
 public void SendToPool(byte[] data)
 {
     _pool.SendToPool(data);
 }
        public void MinerDataReceived(byte[] data, TcpConnection connection)
        {
            Log.Verbose("{0} sent: {1}", connection.endPoint, data.GetString());

            Miner miner = _minerManager.GetMiner(connection);

            int    id         = -999;
            string jsonMethod = "";

            foreach (string s in data.GetString().Split('\r', '\n'))
            {
                if (s.Length <= 1)
                {
                    continue;
                }

                dynamic dyn = new object();

                try { dyn = JsonConvert.DeserializeObject(s.TrimNewLine()); } catch (Exception ex) { Log.Error(ex, "DeserializeObject Json error: " + s); continue; }

                if (Helpers.JsonHelper.DoesJsonObjectExist(dyn.id))
                {
                    id = (int)dyn.id;
                }

                if (JsonHelper.DoesJsonObjectExist(dyn.method))
                {
                    jsonMethod = dyn.method;

                    if (miner == null && !jsonMethod.ToLower().Contains("login"))
                    {
                        Log.Verbose("{0}: Miner does not exist; disconnecting..", connection.endPoint);
                        _minerServer.DisconnectConnection(connection);
                        return;
                    }

                    switch (jsonMethod.ToLower())
                    {
                    case "eth_getwork":
                        Log.Verbose("{0} requested work.", miner.workerIdentifier);

                        _minerManager.AddMinerID(miner, id);

                        if (_pool.currentPoolWork.Length > 0)
                        {
                            dyn.id = miner.minerID;
                            dynamic currentWork = _pool.currentPoolWorkDynamic;
                            currentWork.id = miner.minerID;
                            _minerServer.SendToMiner(JsonConvert.SerializeObject(currentWork), miner.connection);
                        }
                        else
                        {
                            _pool.DoPoolGetWork();
                        }
                        break;

                    case "eth_submitwork":
                        Log.Verbose("{0} found a share!", miner.workerIdentifier);
                        _pool.SubmitShareToPool(s.GetBytes(), miner);
                        break;

                    case "eth_submithashrate":
                        string hash     = dyn.@params[0];
                        long   hashrate = Convert.ToInt64(hash, 16);
                        _minerManager.UpdateMinerHashrate(hashrate, miner);
                        Log.Debug("{0} sent hashrate: {1}", miner.workerIdentifier, hashrate.ToString("#,##0,Mh/s").Replace(",", "."));
                        break;

                    case "eth_login":     // DevFee only?
                    case "eth_submitlogin":

                        string worker = dyn.@params[0];

                        if (worker.Contains("."))
                        {
                            worker = worker.Split(".")[1];
                        }
                        else if (worker != _pool.poolWallet)
                        {
                            worker = "DevFee";
                        }
                        else
                        {
                            worker = connection.endPoint.ToString();
                        }

                        miner = new Miner(worker, connection);

                        _minerManager.AddMiner(miner);
                        Log.Information("[{0}] new miner: {1}!", _pool.poolWorkerName, miner.workerIdentifier);
                        _minerServer.SendToMiner("{\"id\":" + id + ",\"jsonrpc\":\"2.0\",\"result\":true}", connection);
                        //_minerManager.AddMinerId(miner, id);

                        break;

                    default:
                        Log.Warning("MinerHandler Method Unhandled {0} ", s);
                        _pool.SendToPool(s.GetBytes());
                        break;
                    }

                    continue;
                }

                if (id > -999)
                {
                    switch (id)
                    {
                    default:
                        Log.Warning("MinerHandler id Unhandled {0} ", s);
                        _pool.SendToPool(s.GetBytes());
                        break;
                    }
                }
            }
        }
 public void DoPoolGetWork(PoolClient poolClient)
 {
     //Log.Debug("Requesting work from pool..");
     //_pool.SendToPool("{\"worker\": \"\", \"jsonrpc\": \"2.0\", \"params\": [], \"id\": 3, \"method\": \"eth_getWork\"}\n");
     _pool.SendToPool("{\"id\":5,\"jsonrpc\":\"2.0\",\"method\":\"eth_getWork\",\"params\":[]}");
 }