public void PoolDataReceived(byte[] data, PoolClient poolClient) { //Log.Debug("Pool {0} sent: {1}", poolClient.poolEndPoint, data.GetString()); string work; string poolData = data.GetString(); dynamic dyn = JsonConvert.DeserializeObject(poolData.TrimNewLine()); if (Helpers.JsonHelper.DoesJsonObjectExist(dyn.id)) { //This still needs to be converted to dyn.method switch ((int)dyn.id) { case 0: //new target try { work = dyn.result[0] + dyn.result[1] + dyn.result[2] + dyn.result[3]; } catch { work = dyn.result[0] + dyn.result[1] + dyn.result[2]; } if (_pool.currentPoolTarget != work) { Log.Debug("[{0}] sent new target", poolClient.poolWorkerName); lock (_minerManager.MinerManagerLock) { foreach (Miner m in _minerManager.GetMinerList()) { //Log.Debug("Modifying getWork ID {0} to ID {1}", (int)dyn.id, m.minerID); dyn.id = m.minerID; _minerServer.SendToMiner(JsonConvert.SerializeObject(dyn), m.connection); } } _pool.currentPoolTarget = work; } //_minerServer.BroadcastToMiners(); break; case 1: case 2: if (JsonHelper.DoesJsonObjectExist(dyn.error) && !JsonHelper.DoesJsonObjectExist(dyn.result)) { Log.Fatal("Server error for {0}: {1} {2}", poolClient.poolEndPoint, Convert.ToString(dyn.error.code), Convert.ToString(dyn.error.message)); _pool.Stop(); _minerServer.StopListening(); return; } else if (JsonHelper.DoesJsonObjectExist(dyn.result)) { if (dyn.result == false) { Log.Fatal("Server error2 for {0}: {1} {2}", poolClient.poolEndPoint, Convert.ToString(dyn.error.code), Convert.ToString(dyn.error.message)); _pool.Stop(); _minerServer.StopListening(); return; } } Log.Information("[{0}] authorized with {1}!", _pool.poolWorkerName, poolClient.poolEndPoint); break; case 5: case 3: //Log.Debug("{0} sent new work.", _pool.poolEndPoint); if (JsonHelper.DoesJsonObjectExist(dyn.error)) { Log.Fatal("Server error3 for {0}: {1} {2}", poolClient.poolEndPoint, Convert.ToString(dyn.error.code), Convert.ToString(dyn.error.message)); return; } try { work = dyn.result[0] + dyn.result[1] + dyn.result[2] + dyn.result[3]; } catch { work = dyn.result[0] + dyn.result[1] + dyn.result[2]; } if (_pool.currentPoolWork != work) { Log.Debug("[{0}] sent new work", poolClient.poolWorkerName); _pool.ClearSubmittedSharesHistory(); lock (_minerManager.MinerManagerLock) { foreach (Miner m in _minerManager.GetMinerList()) { //Log.Debug("Modifying getWork ID {0} to ID {1} for {3}", (int)dyn.id, m.minerID, m.workerIdentifier); dyn.id = m.minerID; _minerServer.SendToMiner(JsonConvert.SerializeObject(dyn), m.connection); } } _pool.currentPoolWork = work; _pool.currentPoolWorkDynamic = dyn; } break; case int i when(i >= 7 && i != 999): case 4: bool result = false; if (JsonHelper.DoesJsonObjectExist(dyn.result)) { result = dyn.result; } Miner miner = _minerManager.GetNextShare(result); if (miner != null) { _minerServer.SendToMiner(poolData, miner.connection); if (result) { _pool.acceptedSharesCount++; } else { _pool.rejectedSharesCount++; } Log.Information("[{0}] {1}'s share was {2}! ({3})", _pool.poolWorkerName, miner.workerIdentifier, result ? "accepted" : "rejected", _minerManager.ResetMinerShareSubmittedTime(miner)); if (!result) { Log.Debug("Pool: " + poolData); } } break; case 6: Log.Verbose("Hashrate accepted by {0}", poolClient.poolEndPoint); //_minerServer.BroadcastToMiners(s); break; case 999: if (JsonHelper.DoesJsonObjectExist(dyn.error) && !JsonHelper.DoesJsonObjectExist(dyn.result)) { Log.Fatal("Server error for {0}: {1}", poolClient.poolEndPoint, Convert.ToString(dyn.error)); _pool.Stop(); _minerServer.StopListening(); return; } else if (JsonHelper.DoesJsonObjectExist(dyn.result)) { if (dyn.result == false) //no dyn.error.code { Log.Fatal("Server error2 for {0}: {1}", poolClient.poolEndPoint, Convert.ToString(dyn.error)); _pool.Stop(); _minerServer.StopListening(); return; } } break; default: Log.Warning("EthPoolHandler Unhandled: {0}", poolData); break; } } /* else if (dyn.error != null && dyn.result == null) * { * Log.Error("Server sent Error: " + dyn.error.code + ": " + dyn.error.message); * } */ }