diff --git a/src/Miningcore/Api/Controllers/PoolApiController.cs b/src/Miningcore/Api/Controllers/PoolApiController.cs index ff09cfe5c..d84de8f7e 100644 --- a/src/Miningcore/Api/Controllers/PoolApiController.cs +++ b/src/Miningcore/Api/Controllers/PoolApiController.cs @@ -1,5 +1,10 @@ +using System.Collections.Concurrent; +using System.Data; +using System.Globalization; +using System.Net; using Autofac; using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.ActionConstraints; using Microsoft.AspNetCore.Mvc.Infrastructure; using Miningcore.Api.Extensions; using Miningcore.Api.Responses; @@ -11,11 +16,6 @@ using Miningcore.Persistence.Model.Projections; using Miningcore.Persistence.Repositories; using Miningcore.Time; -using System.Collections.Concurrent; -using System.Data; -using System.Globalization; -using System.Net; -using Microsoft.AspNetCore.Mvc.ActionConstraints; using NLog; namespace Miningcore.Api.Controllers; @@ -50,7 +50,7 @@ public PoolApiController(IComponentContext ctx, IActionDescriptorCollectionProvi #region Actions [HttpGet] - public async Task Get(CancellationToken ct, [FromQuery] uint? topMinersRange) + public async Task Get(CancellationToken ct, [FromQuery] uint topMinersRange = 24) { var response = new GetPoolsResponse { @@ -75,10 +75,11 @@ public async Task Get(CancellationToken ct, [FromQuery] uint? { var startTime = lastBlockTime.Value; var poolEffort = await cf.Run(con => shareRepo.GetEffortBetweenCreatedAsync(con, config.Id, pool.ShareMultiplier, startTime, clock.Now)); - result.PoolEffort = poolEffort.Value; + if(poolEffort.HasValue) + result.PoolEffort = poolEffort.Value; } - var from = topMinersRange.HasValue ? clock.Now.AddHours(-topMinersRange.Value) : clock.Now; + var from = clock.Now.AddHours(-topMinersRange); var minersByHashrate = await cf.Run(con => statsRepo.PagePoolMinersByHashrateAsync(con, config.Id, from, 0, 15, ct)); @@ -141,9 +142,10 @@ public async Task GetPoolInfoAsync(string poolId, CancellationT if(lastBlockTime.HasValue) { - DateTime startTime = lastBlockTime.Value; + var startTime = lastBlockTime.Value; var poolEffort = await cf.Run(con => shareRepo.GetEffortBetweenCreatedAsync(con, pool.Id, poolInstance.ShareMultiplier, startTime, clock.Now)); - response.Pool.PoolEffort = poolEffort.Value; + if(poolEffort.HasValue) + response.Pool.PoolEffort = poolEffort.Value; } var from = clock.Now.AddHours(-topMinersRange); @@ -587,7 +589,7 @@ public async Task> PageMinerEarningsByDayV2A if(pool.Template.Family == CoinFamily.Ethereum) address = address.ToLower(); - var result = await cf.Run(con=> minerRepo.GetSettingsAsync(con, null, pool.Id, address)); + var result = await cf.Run(con => minerRepo.GetSettingsAsync(con, null, pool.Id, address)); if(result == null) throw new ApiException("No settings found", HttpStatusCode.NotFound); @@ -614,14 +616,14 @@ public async Task> PageMinerEarningsByDayV2A throw new ApiException("Invalid IP address", HttpStatusCode.BadRequest); // fetch recent IPs - var ips = await cf.Run(con=> shareRepo.GetRecentyUsedIpAddressesAsync(con, null, poolId, address, ct)); + var ips = await cf.Run(con => shareRepo.GetRecentyUsedIpAddressesAsync(con, null, poolId, address, ct)); // any known ips? if(ips == null || ips.Length == 0) throw new ApiException("Address not recently used for mining", HttpStatusCode.NotFound); // match? - if(!ips.Any(x=> IPAddress.TryParse(x, out var ipAddress) && ipAddress.IsEqual(requestIp))) + if(!ips.Any(x => IPAddress.TryParse(x, out var ipAddress) && ipAddress.IsEqual(requestIp))) throw new ApiException("None of the recently used IP addresses matches the request", HttpStatusCode.Forbidden); // map settings @@ -639,7 +641,7 @@ public async Task> PageMinerEarningsByDayV2A { await minerRepo.UpdateSettingsAsync(con, tx, mapped); - logger.Info(()=> $"Updated settings for pool {pool.Id}, miner {address}"); + logger.Info(() => $"Updated settings for pool {pool.Id}, miner {address}"); var result = await minerRepo.GetSettingsAsync(con, tx, mapped.PoolId, mapped.Address); return mapper.Map(result);