diff --git a/package-lock.json b/package-lock.json index b034a2b..e14b71a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -17,7 +17,7 @@ "cross-fetch": "3.1.5", "debug": "4.3.4", "dotenv": "16.0.0", - "eth-fun": "github:il3ven/eth-fun#fork", + "eth-fun": "github:il3ven/eth-fun#1a57ff48ed7cfa05367bfa4497c51542b345c52b", "fastq": "1.13.0", "limiter": "2.0.1", "multiformats": "9.9.0" @@ -1479,11 +1479,12 @@ }, "node_modules/eth-fun": { "version": "0.9.2", - "resolved": "git+ssh://git@github.com/il3ven/eth-fun.git#bc475c50285de91325e4d94c02610ae77894bdd8", + "resolved": "git+ssh://git@github.com/il3ven/eth-fun.git#1a57ff48ed7cfa05367bfa4497c51542b345c52b", + "integrity": "sha512-Dl51GzWYH5iaaxmrwYDFHyK6qRyvudHWDvJjJpg2kRSrVaw9MFln08bXSLber+F9Z8xXMnNd07IRtlmSqWJZyg==", "license": "GPL-3.0-only", "dependencies": { "async-retry": "1.3.3", - "cross-fetch": "3.1.4", + "cross-fetch": "4.0.0", "web3-eth-abi": "1.4.0" }, "engines": { @@ -1491,19 +1492,30 @@ } }, "node_modules/eth-fun/node_modules/cross-fetch": { - "version": "3.1.4", - "resolved": "https://registry.npmjs.org/cross-fetch/-/cross-fetch-3.1.4.tgz", - "integrity": "sha512-1eAtFWdIubi6T4XPy6ei9iUFoKpUkIF971QLN8lIvvvwueI65+Nw5haMNKUwfJxabqlIIDODJKGrQ66gxC0PbQ==", + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/cross-fetch/-/cross-fetch-4.0.0.tgz", + "integrity": "sha512-e4a5N8lVvuLgAWgnCrLr2PP0YyDOTHa9H/Rj54dirp61qXnNq46m82bRhNqIA5VccJtWBvPTFRV3TtvHUKPB1g==", "dependencies": { - "node-fetch": "2.6.1" + "node-fetch": "^2.6.12" } }, "node_modules/eth-fun/node_modules/node-fetch": { - "version": "2.6.1", - "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.1.tgz", - "integrity": "sha512-V4aYg89jEoVRxRb2fJdAg8FHvI7cEyYdVAh94HH0UIK8oJxUfkjlDQN9RbMx+bEjP7+ggMiFRprSti032Oipxw==", + "version": "2.6.12", + "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.12.tgz", + "integrity": "sha512-C/fGU2E8ToujUivIO0H+tpQ6HWo4eEmchoPIoXtxCrVghxdKq+QOHqEZW7tuP3KlV3bC8FRMO5nMCC7Zm1VP6g==", + "dependencies": { + "whatwg-url": "^5.0.0" + }, "engines": { "node": "4.x || >=6.0.0" + }, + "peerDependencies": { + "encoding": "^0.1.0" + }, + "peerDependenciesMeta": { + "encoding": { + "optional": true + } } }, "node_modules/eth-lib": { @@ -5190,26 +5202,30 @@ "dev": true }, "eth-fun": { - "version": "git+ssh://git@github.com/il3ven/eth-fun.git#bc475c50285de91325e4d94c02610ae77894bdd8", - "from": "eth-fun@github:il3ven/eth-fun#fork", + "version": "git+ssh://git@github.com/il3ven/eth-fun.git#1a57ff48ed7cfa05367bfa4497c51542b345c52b", + "integrity": "sha512-Dl51GzWYH5iaaxmrwYDFHyK6qRyvudHWDvJjJpg2kRSrVaw9MFln08bXSLber+F9Z8xXMnNd07IRtlmSqWJZyg==", + "from": "eth-fun@https://github.com/il3ven/eth-fun#1a57ff48ed7cfa05367bfa4497c51542b345c52b", "requires": { "async-retry": "1.3.3", - "cross-fetch": "3.1.4", + "cross-fetch": "4.0.0", "web3-eth-abi": "1.4.0" }, "dependencies": { "cross-fetch": { - "version": "3.1.4", - "resolved": "https://registry.npmjs.org/cross-fetch/-/cross-fetch-3.1.4.tgz", - "integrity": "sha512-1eAtFWdIubi6T4XPy6ei9iUFoKpUkIF971QLN8lIvvvwueI65+Nw5haMNKUwfJxabqlIIDODJKGrQ66gxC0PbQ==", + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/cross-fetch/-/cross-fetch-4.0.0.tgz", + "integrity": "sha512-e4a5N8lVvuLgAWgnCrLr2PP0YyDOTHa9H/Rj54dirp61qXnNq46m82bRhNqIA5VccJtWBvPTFRV3TtvHUKPB1g==", "requires": { - "node-fetch": "2.6.1" + "node-fetch": "^2.6.12" } }, "node-fetch": { - "version": "2.6.1", - "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.1.tgz", - "integrity": "sha512-V4aYg89jEoVRxRb2fJdAg8FHvI7cEyYdVAh94HH0UIK8oJxUfkjlDQN9RbMx+bEjP7+ggMiFRprSti032Oipxw==" + "version": "2.6.12", + "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.12.tgz", + "integrity": "sha512-C/fGU2E8ToujUivIO0H+tpQ6HWo4eEmchoPIoXtxCrVghxdKq+QOHqEZW7tuP3KlV3bC8FRMO5nMCC7Zm1VP6g==", + "requires": { + "whatwg-url": "^5.0.0" + } } } }, diff --git a/package.json b/package.json index 51a13c6..ba2c3a5 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "description": "The purpose of the neume-network/core Extraction Worker (short: \"EW\") is to parallelize retrieving distributed information from various data sources by abstracting away the complexity of scaling processes accross a distributed system such as e.g. multiple node.js Worker threads.", "main": "./src/worker.mjs", "exports": "./src/worker.mjs", - "types": "./src/worker.d.ts", + "types": "./src/worker.d.mts", "ava": { "files": [ "!test/start.mjs" @@ -68,7 +68,7 @@ "cross-fetch": "3.1.5", "debug": "4.3.4", "dotenv": "16.0.0", - "eth-fun": "github:il3ven/eth-fun#fork", + "eth-fun": "github:il3ven/eth-fun#1a57ff48ed7cfa05367bfa4497c51542b345c52b", "fastq": "1.13.0", "limiter": "2.0.1", "multiformats": "9.9.0" diff --git a/src/eth.mjs b/src/eth.mjs index f10cdc5..34b8164 100644 --- a/src/eth.mjs +++ b/src/eth.mjs @@ -6,51 +6,31 @@ import { getTransactionReceipt, getLogs, } from "eth-fun"; -import retry from "async-retry"; import { NotImplementedError } from "./errors.mjs"; -// NOTE: `AbortSignal.timeout` isn't yet supported: -// https://github.com/mysticatea/abort-controller/issues/35 -export const AbortSignal = { - timeout: function (value) { - const controller = new AbortController(); - setTimeout(() => controller.abort(), value); - return controller.signal; - }, -}; - export async function translate(options, method, params) { - return retry(async (bail) => { - if (options.timeout) { - options.signal = AbortSignal.timeout( - options.timeout ?? timeoutFromConfig - ); - delete options.timeout; - } - - if (method === "eth_getTransactionReceipt") { - return await getTransactionReceipt(options, params[0]); - } else if (method === "eth_getBlockByNumber") { - // NOTE: `getBlockByNumber` expects the `blockNumber` input to be an - // hexadecimal (`0x...`) value. - return await getBlockByNumber(options, ...params); - } else if (method === "eth_blockNumber") { - return await blockNumber(options); - } else if (method === "eth_call") { - const { from, to, data } = params[0]; - return await call(options, from, to, data, params[1]); - } else if (method === "eth_getLogs") { - const { fromBlock, toBlock, address, topics, limit } = params[0]; - return await getLogs(options, { - fromBlock, - toBlock, - address, - topics, - limit, - }); - } else { - bail(new NotImplementedError()); - } - }); + if (method === "eth_getTransactionReceipt") { + return await getTransactionReceipt(options, params[0]); + } else if (method === "eth_getBlockByNumber") { + // NOTE: `getBlockByNumber` expects the `blockNumber` input to be an + // hexadecimal (`0x...`) value. + return await getBlockByNumber(options, ...params); + } else if (method === "eth_blockNumber") { + return await blockNumber(options); + } else if (method === "eth_call") { + const { from, to, data } = params[0]; + return await call(options, from, to, data, params[1]); + } else if (method === "eth_getLogs") { + const { fromBlock, toBlock, address, topics, limit } = params[0]; + return await getLogs(options, { + fromBlock, + toBlock, + address, + topics, + limit, + }); + } else { + new NotImplementedError(); + } }