Skip to content

Commit

Permalink
add pool disable / enable using api
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaolin1579 committed Aug 12, 2024
1 parent 3660d06 commit 736e006
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 3 deletions.
36 changes: 34 additions & 2 deletions src/Miningcore/Api/Controllers/AdminApiController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public ActionResult<string> 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")]
Expand All @@ -142,8 +142,40 @@ public ActionResult<string> 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<string> 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<string> 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<Responses.AdminGcStats> GetGcStats()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public async Task DeleteSharesBeforeAsync(IDbConnection con, IDbTransaction tx,

public Task<double?> 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<double?>(new CommandDefinition(query, new { poolId, start, end }, cancellationToken: ct));
}
Expand Down

0 comments on commit 736e006

Please sign in to comment.