示例#1
0
        public MoneroJobParams CreateWorkerJob(IStratumClient client)
        {
            var context   = client.GetContextAs <MoneroWorkerContext>();
            var workerJob = new MoneroWorkerJob(_workerJobCounter.GetNext(), BlockTemplate.Height, context.Difficulty, ++extraNonce);

            var blob   = EncodeBlob(workerJob.ExtraNonce);
            var target = EncodeTarget(workerJob.Difficulty);

            return(null);
        }
        protected override async Task <MoneroJob> UpdateJob()
        {
            try
            {
                // cook our getblocktemplate() request.
                var request = new GetBlockTemplateRequest
                {
                    WalletAddress = PoolContext.PoolAddress,
                    ReserveSize   = MoneroConstants.ReserveSize
                };

                // call getblocktemplate() from daemon.
                var response = await PoolContext.Daemon.ExecuteCommandAsync <GetBlockTemplateResponse>(MoneroRpcCommands.GetBlockTemplate, request);

                // make sure we are free of errors.
                if (response.Error != null)
                {
                    _logger.Error($"New job creation failed as daemon responded with [{response.Error.Code}] {response.Error.Message}");
                }

                // get the response.
                var blockTemplate = response.Response;

                // check if we really got a new blocktemplate (for a new block).
                var gotNewBlockTemplate = (CurrentJob == null || CurrentJob.BlockTemplate.Height < blockTemplate.Height);

                // if we got a new block there, create a new job for it then.
                if (gotNewBlockTemplate)
                {
                    var jobId = _jobCounter.GetNext();                           // create a new job id.
                    var job   = new MoneroJob(jobId, blockTemplate, instanceId); // cook the job.
                    CurrentJob = job;                                            // set the current job.
                    return(job);
                }

                return(null);
            }
            catch (Exception e)
            {
                _logger.Error(e, "Error querying for a new job.");
                return(null);
            }
        }
 public void ShouldBeIncremented()
 {
     _jobCounter.GetNext().Should().Be(1);
     _jobCounter.GetNext().Should().Be(2);
 }