-
Notifications
You must be signed in to change notification settings - Fork 12
/
resolve-block-height.js
20 lines (15 loc) · 835 Bytes
/
resolve-block-height.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
const storage = require('./storage');
const { FastNEARError } = require('./error');
const START_BLOCK_HEIGHT = process.env.FAST_NEAR_START_BLOCK_HEIGHT || '0';
async function resolveBlockHeight(blockHeight) {
const latestBlockHeight = await storage.getLatestBlockHeight();
blockHeight = blockHeight || latestBlockHeight;
if (parseInt(blockHeight, 10) > parseInt(latestBlockHeight, 10)) {
throw new FastNEARError('blockHeightTooHigh', `Block height not found: ${blockHeight}`, { blockHeight, latestBlockHeight });
}
if (parseInt(blockHeight, 10) < parseInt(START_BLOCK_HEIGHT, 10)) {
throw new FastNEARError('blockHeightTooLow', `Block height not found: ${blockHeight}`, { blockHeight, startBlockHeight: START_BLOCK_HEIGHT });
}
return blockHeight;
}
module.exports = resolveBlockHeight;