public async Task <Responses.MinerStats> GetMinerInfoAsync( string poolId, string address, [FromQuery] SampleRange perfMode = SampleRange.Day) { var pool = GetPool(poolId); if (string.IsNullOrEmpty(address)) { throw new ApiException($"Invalid or missing miner address", HttpStatusCode.NotFound); } var statsResult = await cf.RunTx((con, tx) => statsRepo.GetMinerStatsAsync(con, tx, pool.Id, address), true, IsolationLevel.Serializable); Responses.MinerStats stats = null; if (statsResult != null) { stats = mapper.Map <Responses.MinerStats>(statsResult); // optional fields if (statsResult.LastPayment != null) { // Set timestamp of last payment stats.LastPayment = statsResult.LastPayment.Created; // Compute info link var baseUrl = pool.Template.ExplorerTxLink; if (!string.IsNullOrEmpty(baseUrl)) { stats.LastPaymentLink = string.Format(baseUrl, statsResult.LastPayment.TransactionConfirmationData); } } stats.PerformanceSamples = await GetMinerPerformanceInternal(perfMode, pool, address); var shareEnd = clock.Now; var shareStart = shareEnd.AddDays(-1); stats.Shares = await cf.Run(con => shareRepo.CountSharesBetweenCreatedAsync(con, pool.Id, address, shareStart, shareEnd)); stats.InvalidShares = await cf.Run(con => invalidShareRepo.CountInvalidSharesBetweenCreated(con, pool.Id, address, shareStart, shareEnd)); } return(stats); }
public async Task <Responses.MinerStats> GetMinerInfoAsync( string poolId, string address, [FromQuery] SampleRange perfMode = SampleRange.Day) { var pool = GetPool(poolId); if (string.IsNullOrEmpty(address)) { throw new ApiException("Invalid or missing miner address", HttpStatusCode.NotFound); } if (pool.Template.Family == CoinFamily.Ethereum) { address = address.ToLower(); } var statsResult = await cf.RunTx((con, tx) => statsRepo.GetMinerStatsAsync(con, tx, pool.Id, address), true, IsolationLevel.Serializable); Responses.MinerStats stats = null; if (statsResult != null) { stats = mapper.Map <Responses.MinerStats>(statsResult); // optional fields if (statsResult.LastPayment != null) { // Set timestamp of last payment stats.LastPayment = statsResult.LastPayment.Created; // Compute info link var baseUrl = pool.Template.ExplorerTxLink; if (!string.IsNullOrEmpty(baseUrl)) { stats.LastPaymentLink = string.Format(baseUrl, statsResult.LastPayment.TransactionConfirmationData); } } stats.PerformanceSamples = await GetMinerPerformanceInternal(perfMode, pool, address); } return(stats); }