Example #1
0
        private async Task SendClaimRequest(PlotManager plotManager)
        {
            var request = new HttpRequestMessage(HttpMethod.Post, $"https://{ServerOptions.PoolHost}:{ServerOptions.ManagerPort}/miner/claim");

            request.Headers.Authorization = new AuthenticationHeaderValue(AuthOptions.Token);

            int plotCount = await plotManager.GetPlotCountAsync();

            request.Content = new FormUrlEncodedContent(new Dictionary <string, string>()
            {
                ["activePlots"] = $"{plotCount}",
            });

            try
            {
                var response = await Client.SendAsync(request);

                if (response.IsSuccessStatusCode)
                {
                    return;
                }

                switch (response.StatusCode)
                {
                case HttpStatusCode.NotFound:
                    Logger.LogCritical("Could not claim PM: The server could not identify your ip!");
                    break;

                case HttpStatusCode.Unauthorized:
                    Logger.LogCritical("Could not claim PM: Your miner token is invalid!");
                    break;

                case HttpStatusCode.Conflict:
                    Logger.LogError("Could not claim PM: Are you using the same token for multiple miners?");
                    break;

                default:
                    Logger.LogError($"Could not claim PM: The server responded with {response.StatusCode}");
                    break;
                }
            }
            catch (HttpRequestException)
            {
                Logger.LogError($"Could not claim PM: There was a connection error, are you connected to the internet?");
            }
            catch (Exception ex)
            {
                Logger.LogError(ex, $"Could not claim PM: An error occured");
            }
        }