ethereumjs-blockstream
Advanced tools
Comparing version 3.1.0 to 4.0.0
@@ -11,4 +11,4 @@ "use strict"; | ||
var __generator = (this && this.__generator) || function (thisArg, body) { | ||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t; | ||
return { next: verb(0), "throw": verb(1), "return": verb(2) }; | ||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; | ||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; | ||
function verb(n) { return function (v) { return step([n, v]); }; } | ||
@@ -43,3 +43,3 @@ function step(op) { | ||
var createUuid = require("uuid"); | ||
var BlockAndLogStreamer = (function () { | ||
var BlockAndLogStreamer = /** @class */ (function () { | ||
function BlockAndLogStreamer(getBlockByHash, getLogs, configuration) { | ||
@@ -190,26 +190,26 @@ var _this = this; | ||
} | ||
return BlockAndLogStreamer; | ||
}()); | ||
BlockAndLogStreamer.createCallbackStyle = function (getBlockByHash, getLogs, configuration) { | ||
var wrappedGetBlockByHash = function (hash) { | ||
return new Promise(function (resolve, reject) { | ||
getBlockByHash(hash, function (error, block) { | ||
BlockAndLogStreamer.createCallbackStyle = function (getBlockByHash, getLogs, configuration) { | ||
var wrappedGetBlockByHash = function (hash) { | ||
return new Promise(function (resolve, reject) { | ||
getBlockByHash(hash, function (error, block) { | ||
if (error) | ||
throw error; | ||
else | ||
resolve(block); | ||
}); | ||
}); | ||
}; | ||
var wrappedGetLogs = function (filterOptions) { return new Promise(function (resolve, reject) { | ||
getLogs(filterOptions, function (error, logs) { | ||
if (error) | ||
throw error; | ||
else | ||
resolve(block); | ||
if (!logs) | ||
throw new Error("Received null/undefined logs and no error."); | ||
resolve(logs); | ||
}); | ||
}); | ||
}); }; | ||
return new BlockAndLogStreamer(wrappedGetBlockByHash, wrappedGetLogs, configuration); | ||
}; | ||
var wrappedGetLogs = function (filterOptions) { return new Promise(function (resolve, reject) { | ||
getLogs(filterOptions, function (error, logs) { | ||
if (error) | ||
throw error; | ||
if (!logs) | ||
throw new Error("Received null/undefined logs and no error."); | ||
resolve(logs); | ||
}); | ||
}); }; | ||
return new BlockAndLogStreamer(wrappedGetBlockByHash, wrappedGetLogs, configuration); | ||
}; | ||
return BlockAndLogStreamer; | ||
}()); | ||
exports.BlockAndLogStreamer = BlockAndLogStreamer; | ||
@@ -216,0 +216,0 @@ function logAndSwallowWrapper(callback) { |
@@ -11,4 +11,4 @@ "use strict"; | ||
var __generator = (this && this.__generator) || function (thisArg, body) { | ||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t; | ||
return { next: verb(0), "throw": verb(1), "return": verb(2) }; | ||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; | ||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; | ||
function verb(n) { return function (v) { return step([n, v]); }; } | ||
@@ -15,0 +15,0 @@ function step(op) { |
@@ -0,1 +1,2 @@ | ||
"use strict"; | ||
// NOTE -- | ||
@@ -8,3 +9,2 @@ // Commented out to avoid cross origin error produced when running again webpack | ||
// sourceMapSupport.install(); | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -11,0 +11,0 @@ var block_and_log_streamer_1 = require("./block-and-log-streamer"); |
@@ -11,4 +11,4 @@ "use strict"; | ||
var __generator = (this && this.__generator) || function (thisArg, body) { | ||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t; | ||
return { next: verb(0), "throw": verb(1), "return": verb(2) }; | ||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; | ||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; | ||
function verb(n) { return function (v) { return step([n, v]); }; } | ||
@@ -65,3 +65,3 @@ function step(op) { | ||
var getFilteredLogs = function (getLogs, newBlock, filters) { return __awaiter(_this, void 0, void 0, function () { | ||
var logPromises; | ||
var logPromises, nestedLogs; | ||
return __generator(this, function (_a) { | ||
@@ -73,5 +73,6 @@ switch (_a.label) { | ||
.map(function (filter) { return getLogs(filter); }); | ||
return [4 /*yield*/, Promise.all(logPromises) | ||
.then(function (nestedLogs) { return nestedLogs.reduce(function (allLogs, logs) { return allLogs.concat(logs); }, []); })]; | ||
case 1: return [2 /*return*/, _a.sent()]; | ||
return [4 /*yield*/, Promise.all(logPromises)]; | ||
case 1: | ||
nestedLogs = _a.sent(); | ||
return [2 /*return*/, nestedLogs.reduce(function (allLogs, logs) { return allLogs.concat(logs); }, [])]; | ||
} | ||
@@ -81,3 +82,3 @@ }); | ||
var addNewLogsToHead = function (logHistory, newLogs, onLogAdded) { return __awaiter(_this, void 0, void 0, function () { | ||
var sortedLogs, _i, sortedLogs_1, log; | ||
var sortedLogs, _loop_1, _i, sortedLogs_1, logToAdd; | ||
return __generator(this, function (_a) { | ||
@@ -87,2 +88,17 @@ switch (_a.label) { | ||
sortedLogs = newLogs.sort(function (logA, logB) { return parseInt(logA.logIndex, 16) - parseInt(logB.logIndex, 16); }); | ||
_loop_1 = function (logToAdd) { | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
// we may already have this log because two filters can return the same log | ||
if (logHistory.some(function (logInHistory) { return logInHistory.blockHash === logToAdd.blockHash && logInHistory.logIndex === logToAdd.logIndex; })) | ||
return [2 /*return*/, "continue"]; | ||
ensureOrder(logHistory.last(), logToAdd); | ||
return [4 /*yield*/, addNewLogToHead(logHistory, logToAdd, onLogAdded)]; | ||
case 1: | ||
logHistory = _a.sent(); | ||
return [2 /*return*/]; | ||
} | ||
}); | ||
}; | ||
_i = 0, sortedLogs_1 = sortedLogs; | ||
@@ -92,7 +108,6 @@ _a.label = 1; | ||
if (!(_i < sortedLogs_1.length)) return [3 /*break*/, 4]; | ||
log = sortedLogs_1[_i]; | ||
ensureOrder(logHistory.last(), log); | ||
return [4 /*yield*/, addNewLogToHead(logHistory, log, onLogAdded)]; | ||
logToAdd = sortedLogs_1[_i]; | ||
return [5 /*yield**/, _loop_1(logToAdd)]; | ||
case 2: | ||
logHistory = _a.sent(); | ||
_a.sent(); | ||
_a.label = 3; | ||
@@ -132,3 +147,3 @@ case 3: | ||
if (headBlockNumber > newLogBlockNumber) | ||
throw new Error("received log for a block older than current head log's block"); | ||
throw new Error("received log for a block (" + newLogBlockNumber + ") older than current head log's block (" + headBlockNumber + ")"); | ||
if (headBlockNumber !== newLogBlockNumber) | ||
@@ -139,3 +154,3 @@ return; | ||
if (headLogIndex >= newLogIndex) | ||
throw new Error("received log with same block number but index newer than previous index"); | ||
throw new Error("received log with same block number (" + newLogBlockNumber + ") but index (" + newLogIndex + ") is the same or older than previous index (" + headLogIndex + ")"); | ||
}; | ||
@@ -142,0 +157,0 @@ exports.reconcileLogHistoryWithRemovedBlock = function (logHistory, removedBlock, onLogRemoved) { return __awaiter(_this, void 0, void 0, function () { |
{ | ||
"name": "ethereumjs-blockstream", | ||
"version": "3.1.0", | ||
"version": "4.0.0", | ||
"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", |
@@ -28,4 +28,4 @@ import { Block } from "./models/block"; | ||
.map(filter => getLogs(filter)); | ||
return await Promise.all(logPromises) | ||
.then(nestedLogs => nestedLogs.reduce((allLogs, logs) => allLogs.concat(logs), [])); | ||
const nestedLogs = await Promise.all(logPromises); | ||
return nestedLogs.reduce((allLogs, logs) => allLogs.concat(logs), []); | ||
} | ||
@@ -35,5 +35,7 @@ | ||
const sortedLogs = newLogs.sort((logA, logB) => parseInt(logA.logIndex, 16) - parseInt(logB.logIndex, 16)); | ||
for (const log of sortedLogs) { | ||
ensureOrder(logHistory.last(), log); | ||
logHistory = await addNewLogToHead(logHistory, log, onLogAdded); | ||
for (const logToAdd of sortedLogs) { | ||
// we may already have this log because two filters can return the same log | ||
if (logHistory.some(logInHistory => logInHistory!.blockHash === logToAdd.blockHash && logInHistory!.logIndex === logToAdd.logIndex)) continue; | ||
ensureOrder(logHistory.last(), logToAdd); | ||
logHistory = await addNewLogToHead(logHistory, logToAdd, onLogAdded); | ||
} | ||
@@ -59,7 +61,7 @@ return logHistory; | ||
const newLogBlockNumber = parseInt(newLog.blockNumber, 16); | ||
if (headBlockNumber > newLogBlockNumber) throw new Error("received log for a block older than current head log's block"); | ||
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); | ||
if (headLogIndex >= newLogIndex) throw new Error("received log with same block number but index newer than previous index"); | ||
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})`); | ||
} | ||
@@ -66,0 +68,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
82287
1036