From b5daf205a0d67826452238f55b03a1d42491936d Mon Sep 17 00:00:00 2001 From: nymkappa Date: Sat, 9 Jul 2022 16:02:43 +0200 Subject: [PATCH] Fix pagination issue in blocks list --- backend/src/api/blocks.ts | 6 +----- backend/src/routes.ts | 2 +- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/backend/src/api/blocks.ts b/backend/src/api/blocks.ts index b259f701d..62f3efa88 100644 --- a/backend/src/api/blocks.ts +++ b/backend/src/api/blocks.ts @@ -579,17 +579,13 @@ class Blocks { } public async $getBlocks(fromHeight?: number, limit: number = 15): Promise { - let currentHeight = fromHeight !== undefined ? fromHeight : this.getCurrentBlockHeight(); + let currentHeight = fromHeight !== undefined ? fromHeight : await blocksRepository.$mostRecentBlockHeight(); const returnBlocks: BlockExtended[] = []; if (currentHeight < 0) { return returnBlocks; } - if (currentHeight === 0 && Common.indexingEnabled()) { - currentHeight = await blocksRepository.$mostRecentBlockHeight(); - } - // Check if block height exist in local cache to skip the hash lookup const blockByHeight = this.getBlocks().find((b) => b.height === currentHeight); let startFromHash: string | null = null; diff --git a/backend/src/routes.ts b/backend/src/routes.ts index 57c64ddf5..3fae91e39 100644 --- a/backend/src/routes.ts +++ b/backend/src/routes.ts @@ -790,7 +790,7 @@ class Routes { public async getBlocks(req: Request, res: Response) { try { - if (['mainnet', 'testnet', 'signet', 'regtest'].includes(config.MEMPOOL.NETWORK)) { // Bitcoin + if (['mainnet', 'testnet', 'signet'].includes(config.MEMPOOL.NETWORK)) { // Bitcoin const height = req.params.height === undefined ? undefined : parseInt(req.params.height, 10); res.setHeader('Expires', new Date(Date.now() + 1000 * 60).toUTCString()); res.json(await blocks.$getBlocks(height, 15));