From 736e0065e14eb66f95ff9f4706b25d0a5e20f53d Mon Sep 17 00:00:00 2001 From: Decho Kocharin Date: Mon, 12 Aug 2024 10:14:34 +0700 Subject: [PATCH] add pool disable / enable using api --- .../Api/Controllers/AdminApiController.cs | 36 +++++++++++++++++-- .../Postgres/Repositories/ShareRepository.cs | 2 +- 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/src/Miningcore/Api/Controllers/AdminApiController.cs b/src/Miningcore/Api/Controllers/AdminApiController.cs index 24fc289b1..aa54e54d7 100644 --- a/src/Miningcore/Api/Controllers/AdminApiController.cs +++ b/src/Miningcore/Api/Controllers/AdminApiController.cs @@ -127,7 +127,7 @@ public ActionResult EnablePoolPaymentProcessing(string poolId) poolInstance.Config.PaymentProcessing.Enabled = true; logger.Info(()=> $"Enabled payment processing for pool {poolId}"); - return "Ok"; + return "Payment Enabled Successfully"; } [HttpGet("payment/processing/{poolId}/disable")] @@ -142,8 +142,40 @@ public ActionResult DisablePoolPaymentProcessing(string poolId) poolInstance.Config.PaymentProcessing.Enabled = false; logger.Info(()=> $"Disabled payment processing for pool {poolId}"); - return "Ok"; + return "Payment Disable Successfully"; + } + + // testing pool id enable / disable on admin api start here + [HttpGet("{poolId}/enable")] + public ActionResult EnablePoolId(string poolId) + { + if (string.IsNullOrEmpty(poolId)) + throw new ApiException("Missing pool ID", HttpStatusCode.BadRequest); + + pools.TryGetValue(poolId, out var poolInstance); + if(poolInstance == null) + return "-1"; + + poolInstance.Config.Enabled = true; + logger.Info(()=> $"Enabled pool ID{poolId}"); + return "{poolId} Enabled Successfully"; + } + + [HttpGet("{poolId}/disable")] + public ActionResult DisablePoolId(string poolId) + { + if (string.IsNullOrEmpty(poolId)) + throw new ApiException("Missing pool ID", HttpStatusCode.BadRequest); + + pools.TryGetValue(poolId, out var poolInstance); + if(poolInstance == null) + return "-1"; + + poolInstance.Config.Enabled = false; + logger.Info(()=> $"Disabled pool Id{poolId}"); + return "{poolId} Disabled Successfully"; } + // testing pool id enable / disable on admin api end here [HttpGet("stats/gc")] public ActionResult GetGcStats() diff --git a/src/Miningcore/Persistence/Postgres/Repositories/ShareRepository.cs b/src/Miningcore/Persistence/Postgres/Repositories/ShareRepository.cs index 6484bf829..1f2113c80 100644 --- a/src/Miningcore/Persistence/Postgres/Repositories/ShareRepository.cs +++ b/src/Miningcore/Persistence/Postgres/Repositories/ShareRepository.cs @@ -119,7 +119,7 @@ public async Task DeleteSharesBeforeAsync(IDbConnection con, IDbTransaction tx, public Task GetEffectiveAccumulatedShareDifficultyBetweenAsync(IDbConnection con, string poolId, DateTime start, DateTime end, CancellationToken ct) { - const string query = "SELECT SUM(difficulty / networkdifficulty) FROM shares WHERE poolid = @poolId AND created > @start AND created < @end"; + const string query = "SELECT SUM(difficulty / NULLIF(networkdifficulty, 0)) FROM shares WHERE poolid = @poolId AND created > @start AND created <= @end AND networkdifficulty > 0"; return con.QuerySingleAsync(new CommandDefinition(query, new { poolId, start, end }, cancellationToken: ct)); }