Skip to content

Commit 76f5f21

Browse files
committed
feat: .getNthNextSuperblock()
1 parent 91f8711 commit 76f5f21

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

dashgov.js

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,6 @@ var DashGov = ("object" === typeof module && exports) || {};
242242
secondsPerBlock = 0,
243243
cycles = 3,
244244
) {
245-
console.log("CURRENT HEIGHT:", currentBlock);
246245
if (!currentBlock) {
247246
let d = new Date(MONTHLY_SUPERBLOCK_61_DATE);
248247
let then = d.valueOf();
@@ -269,7 +268,6 @@ var DashGov = ("object" === typeof module && exports) || {};
269268
/** @type {Array<Estimate>} */
270269
let estimates = [];
271270
for (let i = -1; i < cycles; i += 1) {
272-
console.log("HEIGHT:", currentBlock);
273271
let estimate = GObj.estimateNthGovCycle(
274272
{ block: currentBlock, ms: now },
275273
secondsPerBlock,
@@ -298,15 +296,14 @@ var DashGov = ("object" === typeof module && exports) || {};
298296

299297
/**
300298
* @param {Uint53} height
299+
* @param {Uint53} offset - 0 (current / previous), 1 (next), 2, 3, nth
301300
* @returns {Uint53} - the superblock after the given height
302301
*/
303-
GObj.getNextSuperblock = function (height) {
304-
let isSuperblock = height % SUPERBLOCK_INTERVAL === 0;
305-
if (isSuperblock) {
306-
height += SUPERBLOCK_INTERVAL;
307-
}
302+
GObj.getNthNextSuperblock = function (height, offset) {
308303
let superblockCount = height / SUPERBLOCK_INTERVAL;
309-
superblockCount = Math.ceil(superblockCount);
304+
superblockCount = Math.floor(superblockCount);
305+
306+
superblockCount += offset;
310307
let superblockHeight = superblockCount * SUPERBLOCK_INTERVAL;
311308

312309
return superblockHeight;
@@ -325,7 +322,7 @@ var DashGov = ("object" === typeof module && exports) || {};
325322
) {
326323
let blockOffset = offset * SUPERBLOCK_INTERVAL;
327324
let blockTarget = block + blockOffset;
328-
let superblockHeight = GObj.getNextSuperblock(blockTarget);
325+
let superblockHeight = GObj.getNthNextSuperblock(blockTarget, offset);
329326

330327
let superblockDelta = superblockHeight - block;
331328
// let superblockDeltaMs = superblockDelta * SECONDS_PER_BLOCK_ESTIMATE * 1000;

0 commit comments

Comments
 (0)