Example #1
0
        public void SendShareResultFailed(object id, string msg)
        {
            StratumMessageServerResult smsr = new StratumMessageServerResult();

            smsr.id     = id;
            smsr.result = false;
            smsr.error  = StratumMessageServerResult.CreateError(0, msg);

            Send(smsr);
        }
Example #2
0
        public void SendShareResultOK(object id)
        {
            StratumMessageServerResult smsr = new StratumMessageServerResult();

            smsr.id     = id;
            smsr.result = true;
            smsr.error  = false;

            Send(smsr);
        }
        private bool ProcessClientMessage(Miner m, StratumMessageClient smc)
        {
            StratumMessageServerResult smsr;

            switch (smc.type)
            {
            case StratumMessageClientType.Subscribe:
                if (!m.isSubscribed &&
                    smc.parameters != null &&
                    smc.parameters.Length > 1 &&
                    smc.parameters[1] == Config.ETHEREUM_STRATUM_VERSION)
                {
                    m.isSubscribed = true;

                    m.extraNonce = GetExtraNonce();

                    smsr        = new StratumMessageServerResult();
                    smsr.id     = smc.id;
                    smsr.error  = null;
                    smsr.result = StratumMessageServerResult.CreateMiningNotifyResult(m.extraNonce);

                    m.Send(smsr);

                    break;
                }
                else
                {
                    return(false);
                }

            case StratumMessageClientType.SubscribeExtranonce:
                smsr        = new StratumMessageServerResult();
                smsr.id     = smc.id;
                smsr.error  = null;
                smsr.result = true;
                m.Send(smsr);
                break;

            case StratumMessageClientType.Authorize:
                if (!m.isAuthorized &&
                    smc.parameters != null &&
                    smc.parameters.Length == 2)
                {
                    // accept all miners with all usernames for now
                    m.userName     = smc.parameters[0];
                    m.isAuthorized = true;

                    smsr        = new StratumMessageServerResult();
                    smsr.id     = smc.id;
                    smsr.error  = null;
                    smsr.result = true;

                    m.Send(smsr);
                    break;
                }
                else
                {
                    return(false);
                }

            case StratumMessageClientType.Submit:
                if (m.initialWorkSent &&
                    smc.parameters != null &&
                    smc.parameters.Length == 3)
                {
                    if (smc.parameters[0] == m.userName)
                    {
                        ProcessShare(m, smc.id, smc.parameters[1], smc.parameters[2]);
                    }
                }
                break;
            }

            if (!m.initialWorkSent && m.isSubscribed && m.isAuthorized)
            {
                double minerDiff = Config.ConfigData.StratumDifficulty;
                if (currentJob.difficulty < minerDiff)
                {
                    minerDiff = currentJob.difficulty;
                }

                if (m.isAuthorized && m.isSubscribed)
                {
                    m.SetDifficultyAndJob(minerDiff, currentJob);
                }

                m.initialWorkSent = true;
            }

            return(true);
        }