ethereumjs-blockstream
Advanced tools
Comparing version 5.0.0 to 6.0.0
import { Block } from "./models/block"; | ||
import { Log } from "./models/log"; | ||
import { Filter, FilterOptions } from "./models/filters"; | ||
import { List as ImmutableList } from "immutable"; | ||
export declare const reconcileLogHistoryWithAddedBlock: <TBlock extends Block, TLog extends Log>(getLogs: (filterOptions: FilterOptions) => Promise<TLog[]>, logHistory: ImmutableList<TLog> | Promise<ImmutableList<TLog>>, newBlock: TBlock, onLogAdded: (log: TLog) => Promise<void>, filters?: Filter[], historyBlockLength?: number) => Promise<ImmutableList<TLog>>; | ||
export declare const reconcileLogHistoryWithRemovedBlock: <TBlock extends Block, TLog extends Log>(logHistory: ImmutableList<TLog> | Promise<ImmutableList<TLog>>, removedBlock: TBlock, onLogRemoved: (log: TLog) => Promise<void>) => Promise<ImmutableList<TLog>>; | ||
export declare const reconcileLogHistoryWithAddedBlock: <TBlock extends Block, TLog extends Log>(getLogs: (filterOptions: FilterOptions) => Promise<TLog[]>, logHistory: import("../../../../../Users/micah/Source/ethereumjs-blockstream/node_modules/immutable").List<TLog> | Promise<import("../../../../../Users/micah/Source/ethereumjs-blockstream/node_modules/immutable").List<TLog>>, newBlock: TBlock, onLogAdded: (log: TLog) => Promise<void>, filters?: Filter[], historyBlockLength?: number) => Promise<import("../../../../../Users/micah/Source/ethereumjs-blockstream/node_modules/immutable").List<TLog>>; | ||
export declare const reconcileLogHistoryWithRemovedBlock: <TBlock extends Block, TLog extends Log>(logHistory: import("../../../../../Users/micah/Source/ethereumjs-blockstream/node_modules/immutable").List<TLog> | Promise<import("../../../../../Users/micah/Source/ethereumjs-blockstream/node_modules/immutable").List<TLog>>, removedBlock: TBlock, onLogRemoved: (log: TLog) => Promise<void>) => Promise<import("../../../../../Users/micah/Source/ethereumjs-blockstream/node_modules/immutable").List<TLog>>; |
@@ -52,3 +52,2 @@ "use strict"; | ||
logs = _a.sent(); | ||
ensureBlockhash(newBlock, logs); | ||
return [4 /*yield*/, addNewLogsToHead(logHistory, logs, onLogAdded)]; | ||
@@ -71,3 +70,3 @@ case 3: | ||
logPromises = filters | ||
.map(function (filter) { return ({ fromBlock: newBlock.number, toBlock: newBlock.number, address: filter.address, topics: filter.topics, }); }) | ||
.map(function (filter) { return ({ blockHash: newBlock.hash, address: filter.address, topics: filter.topics, }); }) | ||
.map(function (filter) { return getLogs(filter); }); | ||
@@ -152,9 +151,2 @@ return [4 /*yield*/, Promise.all(logPromises)]; | ||
}; | ||
var ensureBlockhash = function (block, logs) { | ||
// FIXME: This technique for verifying we got the right logs will not work if there were no logs present in the block! This means it is possible to miss logs. Can be fixed once https://eips.ethereum.org/EIPS/eip-234 is implemented | ||
logs.forEach(function (log) { | ||
if (log.blockHash !== block.hash) | ||
throw new Error("Received log for block hash " + log.blockHash + " when asking for logs of block " + block.hash + "."); | ||
}); | ||
}; | ||
exports.reconcileLogHistoryWithRemovedBlock = function (logHistory, removedBlock, onLogRemoved) { return __awaiter(_this, void 0, void 0, function () { | ||
@@ -161,0 +153,0 @@ return __generator(this, function (_a) { |
@@ -6,4 +6,3 @@ export interface Filter { | ||
export interface FilterOptions extends Filter { | ||
readonly fromBlock?: string; | ||
readonly toBlock?: string; | ||
readonly blockHash: string; | ||
} |
{ | ||
"name": "ethereumjs-blockstream", | ||
"version": "5.0.0", | ||
"version": "6.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", |
@@ -61,5 +61,5 @@ [![Build Status](https://travis-ci.org/ethereumjs/ethereumjs-blockstream.svg?branch=master)](https://travis-ci.org/ethereumjs/ethereumjs-blockstream) [![Coverage Status](https://coveralls.io/repos/ethereumjs/ethereumjs-blockstream/badge.svg?branch=master&service=github)](https://coveralls.io/github/ethereumjs/ethereumjs-blockstream?branch=master) [![npm version](https://badge.fury.io/js/ethereumjs-blockstream.svg)](https://badge.fury.io/js/ethereumjs-blockstream) | ||
Note: if you have a TypeScript aware editor this will all be available in the tooltip | ||
* [Filter/FilterOptions](https://github.com/ethereumjs/ethereumjs-blockstream/blob/master/source/models/filters.ts#L1-L10) - More details at [Parity JSON-RPC Wiki](https://github.com/paritytech/parity/wiki/JSONRPC-eth-module#eth_newfilter) | ||
* [Block](https://github.com/ethereumjs/ethereumjs-blockstream/blob/master/source/models/block.ts#L3-L22) - More details at [Parity JSON-RPC Wiki](https://github.com/paritytech/parity/wiki/JSONRPC-eth-module#eth_getblockbyhash) | ||
* [Log](https://github.com/ethereumjs/ethereumjs-blockstream/blob/master/source/models/log.ts#L1-L10) - More details at [Parity JSON-RPC Wiki](https://github.com/paritytech/parity/wiki/JSONRPC-eth-module#eth_getfilterchanges) | ||
* [Filter/FilterOptions](https://github.com/ethereumjs/ethereumjs-blockstream/blob/master/source/models/filters.ts#L1-L10) - More details at [Parity JSON-RPC Wiki](https://wiki.parity.io/JSONRPC-eth-module#eth_newfilter) | ||
* [Block](https://github.com/ethereumjs/ethereumjs-blockstream/blob/master/source/models/block.ts#L3-L22) - More details at [Parity JSON-RPC Wiki](https://wiki.parity.io/JSONRPC-eth-module#eth_getblockbyhash) | ||
* [Log](https://github.com/ethereumjs/ethereumjs-blockstream/blob/master/source/models/log.ts#L1-L10) - More details at [Parity JSON-RPC Wiki](https://wiki.parity.io/JSONRPC-eth-module#eth_getfilterchanges) | ||
@@ -66,0 +66,0 @@ # Development |
@@ -5,3 +5,2 @@ import { Block } from "./models/block"; | ||
import { LogHistory } from "./models/log-history"; | ||
import { List as ImmutableList } from "immutable"; | ||
@@ -18,3 +17,2 @@ export const reconcileLogHistoryWithAddedBlock = async <TBlock extends Block, TLog extends Log>( | ||
const logs = await getFilteredLogs(getLogs, newBlock, filters); | ||
ensureBlockhash(newBlock, logs); | ||
logHistory = await addNewLogsToHead(logHistory, logs, onLogAdded); | ||
@@ -27,3 +25,3 @@ logHistory = await pruneOldLogs(logHistory, newBlock, historyBlockLength); | ||
const logPromises = filters | ||
.map(filter => ({ fromBlock: newBlock.number, toBlock: newBlock.number, address: filter.address, topics: filter.topics, })) | ||
.map(filter => ({ blockHash: newBlock.hash, address: filter.address, topics: filter.topics, })) | ||
.map(filter => getLogs(filter)); | ||
@@ -68,9 +66,2 @@ const nestedLogs = await Promise.all(logPromises); | ||
const ensureBlockhash = <TBlock extends Block, TLog extends Log>(block: TBlock, logs: Array<TLog>) => { | ||
// FIXME: This technique for verifying we got the right logs will not work if there were no logs present in the block! This means it is possible to miss logs. Can be fixed once https://eips.ethereum.org/EIPS/eip-234 is implemented | ||
logs.forEach(log => { | ||
if (log.blockHash !== block.hash) throw new Error(`Received log for block hash ${log.blockHash} when asking for logs of block ${block.hash}.`); | ||
}); | ||
} | ||
export const reconcileLogHistoryWithRemovedBlock = async <TBlock extends Block, TLog extends Log>( | ||
@@ -77,0 +68,0 @@ logHistory: LogHistory<TLog>|Promise<LogHistory<TLog>>, |
@@ -7,4 +7,3 @@ export interface Filter { | ||
export interface FilterOptions extends Filter { | ||
readonly fromBlock?: string; | ||
readonly toBlock?: string; | ||
readonly blockHash: string | ||
} |
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
198064
2348