ethereumjs-blockstream
Advanced tools
Comparing version
@@ -16,6 +16,6 @@ import { Block } from "./models/block"; | ||
private readonly onLogRemovedSubscribers; | ||
constructor(getBlockByHash: (hash: string) => Promise<Block | null>, getLogs: (filterOptions: FilterOptions[]) => Promise<Log[]>, configuration?: { | ||
constructor(getBlockByHash: (hash: string) => Promise<Block | null>, getLogs: (filterOptions: FilterOptions) => Promise<Log[]>, configuration?: { | ||
blockRetention?: number; | ||
}); | ||
static createCallbackStyle: (getBlockByHash: (hash: string, callback: (error?: Error | undefined, block?: Block | null | undefined) => void) => void, getLogs: (filterOptions: FilterOptions[], callback: (error?: Error | undefined, logs?: Log[] | undefined) => void) => void, configuration?: { | ||
static createCallbackStyle: (getBlockByHash: (hash: string, callback: (error?: Error | undefined, block?: Block | null | undefined) => void) => void, getLogs: (filterOptions: FilterOptions, callback: (error?: Error | undefined, logs?: Log[] | undefined) => void) => void, configuration?: { | ||
blockRetention?: number | undefined; | ||
@@ -22,0 +22,0 @@ } | undefined) => BlockAndLogStreamer; |
@@ -5,3 +5,3 @@ import { Block } from "./models/block"; | ||
import { LogHistory } from "./models/log-history"; | ||
export declare function reconcileLogHistoryWithAddedBlock(getLogs: (filterOptions: FilterOptions[]) => Promise<Log[]>, logHistory: LogHistory | Promise<LogHistory>, newBlock: Block, onLogAdded: (log: Log) => Promise<void>, filters?: Filter[], historyBlockLength?: number): Promise<LogHistory>; | ||
export declare function reconcileLogHistoryWithAddedBlock(getLogs: (filterOptions: FilterOptions) => Promise<Log[]>, logHistory: LogHistory | Promise<LogHistory>, newBlock: Block, onLogAdded: (log: Log) => Promise<void>, filters?: Filter[], historyBlockLength?: number): Promise<LogHistory>; | ||
export declare function reconcileLogHistoryWithRemovedBlock(logHistory: LogHistory | Promise<LogHistory>, removedBlock: Block, onLogRemoved: (log: Log) => Promise<void>): Promise<LogHistory>; |
@@ -65,10 +65,11 @@ "use strict"; | ||
return __awaiter(this, void 0, void 0, function () { | ||
var filterOptions; | ||
var logPromises; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
if (filters.length === 0) | ||
filters = [{}]; | ||
filterOptions = filters.map(function (filter) { return ({ fromBlock: newBlock.number, toBlock: newBlock.number, address: filter.address, topics: filter.topics, }); }); | ||
return [4 /*yield*/, getLogs(filterOptions)]; | ||
logPromises = filters | ||
.map(function (filter) { return ({ fromBlock: newBlock.number, toBlock: newBlock.number, address: filter.address, topics: filter.topics, }); }) | ||
.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()]; | ||
@@ -75,0 +76,0 @@ } |
{ | ||
"name": "ethereumjs-blockstream", | ||
"version": "2.0.3", | ||
"version": "2.0.4", | ||
"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.", | ||
@@ -29,3 +29,5 @@ "main": "output/source/index.js", | ||
"chai-immutable": "1.6.0", | ||
"copyfiles": "^1.2.0", | ||
"copyfiles": "1.2.0", | ||
"coveralls": "2.13.0", | ||
"istanbul": "0.4.5", | ||
"mocha": "3.2.0", | ||
@@ -32,0 +34,0 @@ "typescript": "2.2.1" |
@@ -20,3 +20,3 @@ import { Block } from "./models/block"; | ||
private readonly getBlockByHash: (hash: string) => Promise<Block | null>; | ||
private readonly getLogs: (filterOptions: FilterOptions[]) => Promise<Log[]>; | ||
private readonly getLogs: (filterOptions: FilterOptions) => Promise<Log[]>; | ||
@@ -31,3 +31,3 @@ private readonly logFilters: { [propName: string]: Filter } = {} | ||
getBlockByHash: (hash: string) => Promise<Block | null>, | ||
getLogs: (filterOptions: FilterOptions[]) => Promise<Log[]>, | ||
getLogs: (filterOptions: FilterOptions) => Promise<Log[]>, | ||
configuration?: { blockRetention?: number }, | ||
@@ -42,3 +42,3 @@ ) { | ||
getBlockByHash: (hash: string, callback: (error?: Error, block?: Block | null) => void) => void, | ||
getLogs: (filterOptions: FilterOptions[], callback: (error?: Error, logs?: Log[]) => void) => void, | ||
getLogs: (filterOptions: FilterOptions, callback: (error?: Error, logs?: Log[]) => void) => void, | ||
configuration?: { blockRetention?: number }, | ||
@@ -52,3 +52,3 @@ ): BlockAndLogStreamer => { | ||
}); | ||
const wrappedGetLogs = (filterOptions: FilterOptions[]): Promise<Log[]> => new Promise<Log[]>((resolve, reject) => { | ||
const wrappedGetLogs = (filterOptions: FilterOptions): Promise<Log[]> => new Promise<Log[]>((resolve, reject) => { | ||
getLogs(filterOptions, (error, logs) => { | ||
@@ -55,0 +55,0 @@ if (error) throw error; |
@@ -9,3 +9,3 @@ import { Block } from "./models/block"; | ||
export async function reconcileLogHistoryWithAddedBlock( | ||
getLogs: (filterOptions: FilterOptions[]) => Promise<Log[]>, | ||
getLogs: (filterOptions: FilterOptions) => Promise<Log[]>, | ||
logHistory: LogHistory | Promise<LogHistory>, | ||
@@ -25,6 +25,8 @@ newBlock: Block, | ||
async function getFilteredLogs(getLogs: (filterOptions: FilterOptions[]) => Promise<Log[]>, newBlock: Block, filters: Filter[]): Promise<Log[]> { | ||
if (filters.length === 0) filters = [{}]; | ||
const filterOptions = filters.map((filter) => ({ fromBlock: newBlock.number, toBlock: newBlock.number, address: filter.address, topics: filter.topics, })); | ||
return await getLogs(filterOptions); | ||
async function getFilteredLogs(getLogs: (filterOptions: FilterOptions) => Promise<Log[]>, newBlock: Block, filters: Filter[]): Promise<Log[]> { | ||
const logPromises = filters | ||
.map(filter => ({ fromBlock: newBlock.number, toBlock: newBlock.number, address: filter.address, topics: filter.topics, })) | ||
.map(filter => getLogs(filter)); | ||
return await Promise.all(logPromises) | ||
.then(nestedLogs => nestedLogs.reduce((allLogs, logs) => allLogs.concat(logs), [])); | ||
} | ||
@@ -31,0 +33,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
106911
4.99%1372
0.22%102
436.84%11
22.22%