ethereumjs-blockstream
Advanced tools
Comparing version 6.0.0 to 6.0.1
@@ -39,2 +39,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var utilities_1 = require("./utilities"); | ||
exports.reconcileBlockHistory = function (getBlockByHash, blockHistory, newBlock, onBlockAdded, onBlockRemoved, blockRetention) { | ||
@@ -108,3 +109,3 @@ if (blockRetention === void 0) { blockRetention = 100; } | ||
throw new Error("Failed to fetch parent block."); | ||
if (!(parseInt(parentBlock.number, 16) + blockRetention < parseInt(blockHistory.last().number, 16))) return [3 /*break*/, 5]; | ||
if (!(utilities_1.parseHexInt(parentBlock.number) + blockRetention < utilities_1.parseHexInt(blockHistory.last().number))) return [3 /*break*/, 5]; | ||
return [4 /*yield*/, rollback(blockHistory, onBlockRemoved)]; | ||
@@ -155,3 +156,3 @@ case 4: return [2 /*return*/, _a.sent()]; | ||
var isOlderThanOldestBlock = function (blockHistory, newBlock) { | ||
return parseInt(blockHistory.first().number, 16) > parseInt(newBlock.number, 16); | ||
return utilities_1.parseHexInt(blockHistory.first().number) > utilities_1.parseHexInt(newBlock.number); | ||
}; | ||
@@ -158,0 +159,0 @@ var isAlreadyInHistory = function (blockHistory, newBlock) { |
@@ -39,2 +39,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var utilities_1 = require("./utilities"); | ||
exports.reconcileLogHistoryWithAddedBlock = function (getLogs, logHistory, newBlock, onLogAdded, filters, historyBlockLength) { | ||
@@ -84,3 +85,3 @@ if (filters === void 0) { filters = []; } | ||
case 0: | ||
sortedLogs = newLogs.sort(function (logA, logB) { return parseInt(logA.logIndex, 16) - parseInt(logB.logIndex, 16); }); | ||
sortedLogs = newLogs.sort(function (logA, logB) { return utilities_1.parseHexInt(logA.logIndex) - utilities_1.parseHexInt(logB.logIndex); }); | ||
_loop_1 = function (logToAdd) { | ||
@@ -120,3 +121,3 @@ return __generator(this, function (_a) { | ||
// `log!` is required until the next major version of `immutable` is published to NPM (current version 3.8.2) which improves the type definitions | ||
return [2 /*return*/, logHistory.skipUntil(function (log) { return parseInt(newBlock.number, 16) - parseInt(log.blockNumber, 16) < historyBlockLength; }).toList()]; | ||
return [2 /*return*/, logHistory.skipUntil(function (log) { return utilities_1.parseHexInt(newBlock.number) - utilities_1.parseHexInt(log.blockNumber) < historyBlockLength; }).toList()]; | ||
}); | ||
@@ -141,4 +142,4 @@ }); }; | ||
return; | ||
var headBlockNumber = parseInt(headLog.blockNumber, 16); | ||
var newLogBlockNumber = parseInt(newLog.blockNumber, 16); | ||
var headBlockNumber = utilities_1.parseHexInt(headLog.blockNumber); | ||
var newLogBlockNumber = utilities_1.parseHexInt(newLog.blockNumber); | ||
if (headBlockNumber > newLogBlockNumber) | ||
@@ -148,4 +149,4 @@ throw new Error("received log for a block (" + newLogBlockNumber + ") older than current head log's block (" + headBlockNumber + ")"); | ||
return; | ||
var headLogIndex = parseInt(headLog.logIndex, 16); | ||
var newLogIndex = parseInt(newLog.logIndex, 16); | ||
var headLogIndex = utilities_1.parseHexInt(headLog.logIndex); | ||
var newLogIndex = utilities_1.parseHexInt(newLog.logIndex); | ||
if (headLogIndex >= newLogIndex) | ||
@@ -152,0 +153,0 @@ throw new Error("received log with same block number (" + newLogBlockNumber + ") but index (" + newLogIndex + ") is the same or older than previous index (" + headLogIndex + ")"); |
{ | ||
"name": "ethereumjs-blockstream", | ||
"version": "6.0.0", | ||
"version": "6.0.1", | ||
"description": "A library to turn an unreliable remote source of Ethereum blocks into a reliable stream of blocks with removals on re-orgs and backfills on skips.", | ||
@@ -5,0 +5,0 @@ "main": "output/source/index.js", |
import { Block } from "./models/block"; | ||
import { BlockHistory } from "./models/block-history"; | ||
import { parseHexInt } from "./utilities"; | ||
import { List as ImmutableList } from "immutable"; | ||
@@ -53,3 +54,3 @@ | ||
if (parentBlock === null) throw new Error("Failed to fetch parent block."); | ||
if (parseInt(parentBlock.number, 16) + blockRetention < parseInt(blockHistory.last().number, 16)) | ||
if (parseHexInt(parentBlock.number) + blockRetention < parseHexInt(blockHistory.last().number)) | ||
return await rollback(blockHistory, onBlockRemoved); | ||
@@ -81,3 +82,3 @@ blockHistory = await reconcileBlockHistory(getBlockByHash, blockHistory, parentBlock, onBlockAdded, onBlockRemoved, blockRetention); | ||
const isOlderThanOldestBlock = <TBlock extends Block>(blockHistory: BlockHistory<TBlock>, newBlock: TBlock): boolean => { | ||
return parseInt(blockHistory.first().number, 16) > parseInt(newBlock.number, 16); | ||
return parseHexInt(blockHistory.first().number) > parseHexInt(newBlock.number); | ||
} | ||
@@ -84,0 +85,0 @@ |
@@ -5,2 +5,3 @@ import { Block } from "./models/block"; | ||
import { LogHistory } from "./models/log-history"; | ||
import { parseHexInt } from "./utilities"; | ||
@@ -31,3 +32,3 @@ export const reconcileLogHistoryWithAddedBlock = async <TBlock extends Block, TLog extends Log>( | ||
const addNewLogsToHead = async <TLog extends Log>(logHistory: LogHistory<TLog>, newLogs: Array<TLog>, onLogAdded: (log: TLog) => Promise<void>): Promise<LogHistory<TLog>> => { | ||
const sortedLogs = newLogs.sort((logA, logB) => parseInt(logA.logIndex, 16) - parseInt(logB.logIndex, 16)); | ||
const sortedLogs = newLogs.sort((logA, logB) => parseHexInt(logA.logIndex) - parseHexInt(logB.logIndex)); | ||
for (const logToAdd of sortedLogs) { | ||
@@ -44,3 +45,3 @@ // we may already have this log because two filters can return the same log | ||
// `log!` is required until the next major version of `immutable` is published to NPM (current version 3.8.2) which improves the type definitions | ||
return logHistory.skipUntil(log => parseInt(newBlock.number, 16) - parseInt(log!.blockNumber, 16) < historyBlockLength).toList(); | ||
return logHistory.skipUntil(log => parseHexInt(newBlock.number) - parseHexInt(log!.blockNumber) < historyBlockLength).toList(); | ||
} | ||
@@ -57,8 +58,8 @@ | ||
if (headLog === undefined) return; | ||
const headBlockNumber = parseInt(headLog.blockNumber, 16); | ||
const newLogBlockNumber = parseInt(newLog.blockNumber, 16); | ||
const headBlockNumber = parseHexInt(headLog.blockNumber); | ||
const newLogBlockNumber = parseHexInt(newLog.blockNumber); | ||
if (headBlockNumber > newLogBlockNumber) throw new Error(`received log for a block (${newLogBlockNumber}) older than current head log's block (${headBlockNumber})`); | ||
if (headBlockNumber !== newLogBlockNumber) return; | ||
const headLogIndex = parseInt(headLog.logIndex, 16); | ||
const newLogIndex = parseInt(newLog.logIndex, 16); | ||
const headLogIndex = parseHexInt(headLog.logIndex); | ||
const newLogIndex = parseHexInt(newLog.logIndex); | ||
if (headLogIndex >= newLogIndex) throw new Error(`received log with same block number (${newLogBlockNumber}) but index (${newLogIndex}) is the same or older than previous index (${headLogIndex})`); | ||
@@ -65,0 +66,0 @@ } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
199280
54
2366