Skip to content

Commit

Permalink
Fix cell on maxNBlocksPerDay (3.X) (#142)
Browse files Browse the repository at this point in the history
* Fix cell on maxNBlocksPerDay

uint (86400/15000*10000) equals 5000 but not 5760 because ```maxNBlocksPerDay``` is uint but not float.

* Delete incoverable code

Delete incoverable code since unint can't be <0,. For example: uint(-1) = uint 4294967295.

* Fix nBlocks == 0

Fix nBlocks == 0
  • Loading branch information
superboyiii authored and vncoelho committed Nov 13, 2019
1 parent 90c15dc commit 7ca6354
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions CoreMetrics/CoreMetrics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public void PostProcess(HttpContext context, string method, JArray _params, JObj
private JObject GetBlocksTime(uint nBlocks, uint lastHeight)
{
// It is currently limited to query blocks generated in the last 24hours (86400 seconds)
uint maxNBlocksPerDay = 86400 / Blockchain.MillisecondsPerBlock * 1000;
uint maxNBlocksPerDay = 86400 / (Blockchain.MillisecondsPerBlock / 1000);
if (lastHeight != 0)
{
if (lastHeight >= Blockchain.Singleton.Height)
Expand All @@ -60,13 +60,13 @@ private JObject GetBlocksTime(uint nBlocks, uint lastHeight)
JObject json = new JObject();
return json["error"] = "Requested number of blocks timestamps " + nBlocks + " exceeds quantity of known blocks " + Blockchain.Singleton.Height;
}

if (nBlocks <= 0)
if (nBlocks == 0)
{
JObject json = new JObject();
return json["error"] = "Requested number of block times can not be <= 0";
return json["error"] = "Requested number of block times can not be = 0";
}

JArray array = new JArray();
uint heightToBegin = lastHeight > 0 ? lastHeight - nBlocks : (Blockchain.Singleton.Height - 1) - nBlocks;
for (uint i = heightToBegin; i <= heightToBegin + nBlocks; i++)
Expand Down

0 comments on commit 7ca6354

Please sign in to comment.