@subql/node-ethereum 4.7.3 → 4.7.4-0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +3 -0
- package/dist/.tsbuildinfo +1 -1
- package/dist/configure/SubqueryProject.d.ts +3 -3
- package/dist/configure/SubqueryProject.js +1 -4
- package/dist/configure/SubqueryProject.js.map +1 -1
- package/dist/ethereum/api.ethereum.d.ts +4 -3
- package/dist/ethereum/api.ethereum.js +18 -5
- package/dist/ethereum/api.ethereum.js.map +1 -1
- package/dist/ethereum/api.ethereum.test.js.map +1 -1
- package/dist/ethereum/api.service.ethereum.d.ts +1 -1
- package/dist/ethereum/api.service.ethereum.js +11 -1
- package/dist/ethereum/api.service.ethereum.js.map +1 -1
- package/dist/ethereum/block.ethereum.d.ts +1 -1
- package/dist/ethereum/block.ethereum.js.map +1 -1
- package/dist/ethereum/ethers/celo/celo-provider.d.ts +54 -54
- package/dist/ethereum/ethers/celo/celo-ws-provider.spec.js.map +1 -1
- package/dist/ethereum/ethers/json-rpc-batch-provider.d.ts +2 -2
- package/dist/ethereum/ethers/json-rpc-batch-provider.js +4 -4
- package/dist/ethereum/ethers/json-rpc-batch-provider.js.map +1 -1
- package/dist/ethereum/ethers/json-rpc-batch-provider.spec.js.map +1 -1
- package/dist/ethereum/ethers/json-rpc-provider.js +3 -3
- package/dist/ethereum/ethers/json-rpc-provider.js.map +1 -1
- package/dist/ethereum/ethers/op/op-provider.d.ts +72 -72
- package/dist/ethereum/ethers/op/op-provider.spec.js +2 -2
- package/dist/ethereum/ethers/op/op-provider.spec.js.map +1 -1
- package/dist/ethereum/ethers/web/geturl.js +17 -14
- package/dist/ethereum/ethers/web/geturl.js.map +1 -1
- package/dist/ethereum/ethers/web/index.d.ts +1 -1
- package/dist/ethereum/ethers/web/index.js +18 -16
- package/dist/ethereum/ethers/web/index.js.map +1 -1
- package/dist/ethereum/ethers/web/types.d.ts +1 -1
- package/dist/ethereum/ethers/web/types.js.map +1 -1
- package/dist/ethereum/utils.ethereum.d.ts +3 -3
- package/dist/ethereum/utils.ethereum.js +1 -1
- package/dist/ethereum/utils.ethereum.js.map +1 -1
- package/dist/indexer/blockDispatcher/worker-block-dispatcher.service.js +1 -1
- package/dist/indexer/blockDispatcher/worker-block-dispatcher.service.js.map +1 -1
- package/dist/indexer/dictionary/v1/ethDictionaryV1.d.ts +2 -2
- package/dist/indexer/dictionary/v1/ethDictionaryV1.js +3 -1
- package/dist/indexer/dictionary/v1/ethDictionaryV1.js.map +1 -1
- package/dist/indexer/dictionary/v1/ethDictionaryV1.spec.js +1 -1
- package/dist/indexer/dictionary/v1/ethDictionaryV1.spec.js.map +1 -1
- package/dist/indexer/dictionary/v2/ethDictionaryV2.js +11 -6
- package/dist/indexer/dictionary/v2/ethDictionaryV2.js.map +1 -1
- package/dist/indexer/dictionary/v2/ethDictionaryV2.spec.js +2 -1
- package/dist/indexer/dictionary/v2/ethDictionaryV2.spec.js.map +1 -1
- package/dist/indexer/dictionary/v2/types.d.ts +1 -1
- package/dist/indexer/dictionary/v2/types.js.map +1 -1
- package/dist/indexer/dictionary/v2/utils.js +1 -3
- package/dist/indexer/dictionary/v2/utils.js.map +1 -1
- package/dist/indexer/dynamic-ds.service.js.map +1 -1
- package/dist/indexer/fetch.service.js +1 -1
- package/dist/indexer/fetch.service.js.map +1 -1
- package/dist/indexer/indexer.manager.js.map +1 -1
- package/dist/indexer/project.service.test.js.map +1 -1
- package/dist/indexer/unfinalizedBlocks.service.js +3 -0
- package/dist/indexer/unfinalizedBlocks.service.js.map +1 -1
- package/dist/indexer/worker/worker.js.map +1 -1
- package/dist/init.js +1 -9
- package/dist/init.js.map +1 -1
- package/dist/meta/meta.controller.d.ts +12 -12
- package/dist/meta/meta.service.d.ts +2 -2
- package/dist/meta/meta.service.js +2 -2
- package/dist/meta/meta.service.js.map +1 -1
- package/dist/utils/string.d.ts +1 -1
- package/dist/utils/string.js.map +1 -1
- package/package.json +6 -5
|
@@ -60,7 +60,7 @@ function _fetchData(connection, body, processFunc) {
|
|
|
60
60
|
logger.assertArgument(throttleSlotInterval > 0 && throttleSlotInterval % 1 === 0, 'invalid connection throttle slot interval', 'connection.throttleSlotInterval', throttleSlotInterval);
|
|
61
61
|
const errorPassThrough = typeof connection === 'object' ? !!connection.errorPassThrough : false;
|
|
62
62
|
const headers = {};
|
|
63
|
-
let url
|
|
63
|
+
let url;
|
|
64
64
|
// @TODO: Allow ConnectionInfo to override some of these values
|
|
65
65
|
const options = {
|
|
66
66
|
method: 'GET',
|
|
@@ -116,6 +116,9 @@ function _fetchData(connection, body, processFunc) {
|
|
|
116
116
|
options.agents = connection.agents;
|
|
117
117
|
}
|
|
118
118
|
}
|
|
119
|
+
else {
|
|
120
|
+
throw new Error('invalid connection');
|
|
121
|
+
}
|
|
119
122
|
const reData = new RegExp('^data:([^;:]*)?(;base64)?,(.*)$', 'i');
|
|
120
123
|
const dataMatch = url ? url.match(reData) : null;
|
|
121
124
|
if (dataMatch) {
|
|
@@ -238,15 +241,14 @@ function _fetchData(connection, body, processFunc) {
|
|
|
238
241
|
}
|
|
239
242
|
catch (error) {
|
|
240
243
|
response = error.response;
|
|
241
|
-
if (response == null)
|
|
244
|
+
if (response == null)
|
|
242
245
|
runningTimeout.cancel();
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
}
|
|
246
|
+
throw logger.throwError('missing response', logger_1.Logger.errors.SERVER_ERROR, {
|
|
247
|
+
requestBody: bodyify(options.body, flatHeaders['content-type']),
|
|
248
|
+
requestMethod: options.method,
|
|
249
|
+
serverError: error,
|
|
250
|
+
url: url,
|
|
251
|
+
});
|
|
250
252
|
}
|
|
251
253
|
let body = response.body;
|
|
252
254
|
if (allow304 && response.statusCode === 304) {
|
|
@@ -255,7 +257,7 @@ function _fetchData(connection, body, processFunc) {
|
|
|
255
257
|
else if (!errorPassThrough &&
|
|
256
258
|
(response.statusCode < 200 || response.statusCode >= 300)) {
|
|
257
259
|
runningTimeout.cancel();
|
|
258
|
-
logger.throwError('bad response', logger_1.Logger.errors.SERVER_ERROR, {
|
|
260
|
+
throw logger.throwError('bad response', logger_1.Logger.errors.SERVER_ERROR, {
|
|
259
261
|
status: response.statusCode,
|
|
260
262
|
headers: response.headers,
|
|
261
263
|
body: bodyify(body, response.headers ? response.headers['content-type'] : null),
|
|
@@ -286,7 +288,7 @@ function _fetchData(connection, body, processFunc) {
|
|
|
286
288
|
}
|
|
287
289
|
}
|
|
288
290
|
runningTimeout.cancel();
|
|
289
|
-
logger.throwError('processing response error', logger_1.Logger.errors.SERVER_ERROR, {
|
|
291
|
+
throw logger.throwError('processing response error', logger_1.Logger.errors.SERVER_ERROR, {
|
|
290
292
|
body: bodyify(body, response.headers ? response.headers['content-type'] : null),
|
|
291
293
|
error: error,
|
|
292
294
|
requestBody: bodyify(options.body, flatHeaders['content-type']),
|
|
@@ -331,7 +333,7 @@ function fetchJson(connection, json, processFunc) {
|
|
|
331
333
|
// If we have json to send, we must
|
|
332
334
|
// - add content-type of application/json (unless already overridden)
|
|
333
335
|
// - convert the json to bytes
|
|
334
|
-
let body
|
|
336
|
+
let body;
|
|
335
337
|
if (json != null) {
|
|
336
338
|
body = (0, strings_1.toUtf8Bytes)(json);
|
|
337
339
|
// Create a connection with the content-type set for JSON
|
|
@@ -381,14 +383,14 @@ function poll(func, options) {
|
|
|
381
383
|
}
|
|
382
384
|
return true;
|
|
383
385
|
};
|
|
384
|
-
if (options
|
|
386
|
+
if (options?.timeout) {
|
|
385
387
|
timer = setTimeout(() => {
|
|
386
388
|
if (cancel()) {
|
|
387
389
|
reject(new Error('timeout'));
|
|
388
390
|
}
|
|
389
391
|
}, options.timeout);
|
|
390
392
|
}
|
|
391
|
-
const retryLimit = options
|
|
393
|
+
const retryLimit = options?.retryLimit ?? 0;
|
|
392
394
|
let attempt = 0;
|
|
393
395
|
function check() {
|
|
394
396
|
return func().then(function (result) {
|
|
@@ -398,10 +400,10 @@ function poll(func, options) {
|
|
|
398
400
|
resolve(result);
|
|
399
401
|
}
|
|
400
402
|
}
|
|
401
|
-
else if (options
|
|
403
|
+
else if (options?.oncePoll) {
|
|
402
404
|
options.oncePoll.once('poll', check);
|
|
403
405
|
}
|
|
404
|
-
else if (options
|
|
406
|
+
else if (options?.onceBlock) {
|
|
405
407
|
options.onceBlock.once('block', check);
|
|
406
408
|
// Otherwise, exponential back-off (up to 10s) our next request
|
|
407
409
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/ethereum/ethers/web/index.ts"],"names":[],"mappings":"AAAA,oBAAoB;AACpB,YAAY,CAAC;;;AAIb,kDAG+B;AAC/B,gDAA4D;AAC5D,0DAAwD;AACxD,oDAAmE;AAEnE,kDAA+C;AAC/C,yCAAqC;AACrC,MAAM,MAAM,GAAG,IAAI,eAAM,CAAC,kBAAO,CAAC,CAAC;AAEnC,qCAA2D;AAE3D,SAAS,OAAO,CAAC,QAAgB;IAC/B,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;QAC7B,UAAU,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;IAChC,CAAC,CAAC,CAAC;AACL,CAAC;AAED,SAAS,OAAO,CAAC,KAAU,EAAE,IAAY;IACvC,IAAI,KAAK,IAAI,IAAI,EAAE;QACjB,OAAO,IAAI,CAAC;KACb;IAED,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE;QAC7B,OAAO,KAAK,CAAC;KACd;IAED,IAAI,IAAA,mBAAW,EAAC,KAAK,CAAC,EAAE;QACtB,IACE,IAAI;YACJ,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,MAAM;gBAC5B,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,KAAK,kBAAkB,CAAC,EACnD;YACA,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,IAAI,MAAM,EAAE,EAAE;oBACZ,MAAM,CAAC,KAAK,CAAC,CAAC;iBACf;YACH,CAAC,CACF,CAAC;QACJ,CAAC;QACD,KAAK,EAAE,CAAC;IACV,CAAC,CAAC,CAAC;AACL,CAAC;AA5FD,oBA4FC","sourcesContent":["/* eslint-disable */\n'use strict';\n\nimport http from 'http';\nimport https from 'https';\nimport {\n decode as base64Decode,\n encode as base64Encode,\n} from '@ethersproject/base64';\nimport { hexlify, isBytesLike } from '@ethersproject/bytes';\nimport { shallowCopy } from '@ethersproject/properties';\nimport { toUtf8Bytes, toUtf8String } from '@ethersproject/strings';\n\nimport { Logger } from '@ethersproject/logger';\nimport { version } from './_version';\nconst logger = new Logger(version);\n\nimport { getUrl, GetUrlResponse, Options } from './geturl';\n\nfunction staller(duration: number): Promise<void> {\n return new Promise((resolve) => {\n setTimeout(resolve, duration);\n });\n}\n\nfunction bodyify(value: any, type: string): string {\n if (value == null) {\n return null;\n }\n\n if (typeof value === 'string') {\n return value;\n }\n\n if (isBytesLike(value)) {\n if (\n type &&\n (type.split('/')[0] === 'text' ||\n type.split(';')[0].trim() === 'application/json')\n ) {\n try {\n return toUtf8String(value);\n } catch (error) {}\n }\n return hexlify(value);\n }\n\n return value;\n}\n\n// Exported Types\nexport type ConnectionInfo = {\n url: string;\n headers?: { [key: string]: string | number };\n\n user?: string;\n password?: string;\n\n allowInsecureAuthentication?: boolean;\n allowGzip?: boolean;\n\n throttleLimit?: number;\n throttleSlotInterval?: number;\n throttleCallback?: (attempt: number, url: string) => Promise<boolean>;\n\n skipFetchSetup?: boolean;\n fetchOptions?: Record<string, string>;\n errorPassThrough?: boolean;\n\n timeout?: number;\n\n agents?: {\n http?: http.Agent;\n https?: https.Agent;\n };\n};\n\nexport interface OnceBlockable {\n once(eventName: 'block', handler: () => void): void;\n}\n\nexport interface OncePollable {\n once(eventName: 'poll', handler: () => void): void;\n}\n\nexport type PollOptions = {\n timeout?: number;\n floor?: number;\n ceiling?: number;\n interval?: number;\n retryLimit?: number;\n onceBlock?: OnceBlockable;\n oncePoll?: OncePollable;\n};\n\nexport type FetchJsonResponse = {\n statusCode: number;\n headers: { [header: string]: string };\n};\n\ntype Header = { key: string; value: string };\n\nfunction unpercent(value: string): Uint8Array {\n return toUtf8Bytes(\n value.replace(/%([0-9a-f][0-9a-f])/gi, (all, code) => {\n return String.fromCharCode(parseInt(code, 16));\n }),\n );\n}\n\n// This API is still a work in progress; the future changes will likely be:\n// - ConnectionInfo => FetchDataRequest<T = any>\n// - FetchDataRequest.body? = string | Uint8Array | { contentType: string, data: string | Uint8Array }\n// - If string => text/plain, Uint8Array => application/octet-stream (if content-type unspecified)\n// - FetchDataRequest.processFunc = (body: Uint8Array, response: FetchDataResponse) => T\n// For this reason, it should be considered internal until the API is finalized\nexport function _fetchData<T = Uint8Array>(\n connection: string | ConnectionInfo,\n body?: Uint8Array,\n processFunc?: (value: Uint8Array, response: FetchJsonResponse) => T,\n): Promise<T> {\n // How many times to retry in the event of a throttle\n const attemptLimit =\n typeof connection === 'object' && connection.throttleLimit != null\n ? connection.throttleLimit\n : 12;\n logger.assertArgument(\n attemptLimit > 0 && attemptLimit % 1 === 0,\n 'invalid connection throttle limit',\n 'connection.throttleLimit',\n attemptLimit,\n );\n\n const throttleCallback =\n typeof connection === 'object' ? connection.throttleCallback : null;\n const throttleSlotInterval =\n typeof connection === 'object' &&\n typeof connection.throttleSlotInterval === 'number'\n ? connection.throttleSlotInterval\n : 100;\n logger.assertArgument(\n throttleSlotInterval > 0 && throttleSlotInterval % 1 === 0,\n 'invalid connection throttle slot interval',\n 'connection.throttleSlotInterval',\n throttleSlotInterval,\n );\n\n const errorPassThrough =\n typeof connection === 'object' ? !!connection.errorPassThrough : false;\n\n const headers: { [key: string]: Header } = {};\n\n let url: string = null;\n\n // @TODO: Allow ConnectionInfo to override some of these values\n const options: Options = {\n method: 'GET',\n };\n\n let allow304 = false;\n\n let timeout = 2 * 60 * 1000;\n\n if (typeof connection === 'string') {\n url = connection;\n } else if (typeof connection === 'object') {\n if (connection == null || connection.url == null) {\n logger.throwArgumentError('missing URL', 'connection.url', connection);\n }\n\n url = connection.url;\n\n if (typeof connection.timeout === 'number' && connection.timeout > 0) {\n timeout = connection.timeout;\n }\n\n if (connection.headers) {\n for (const key in connection.headers) {\n headers[key.toLowerCase()] = {\n key: key,\n value: String(connection.headers[key]),\n };\n if (\n ['if-none-match', 'if-modified-since'].indexOf(key.toLowerCase()) >= 0\n ) {\n allow304 = true;\n }\n }\n }\n\n options.allowGzip = !!connection.allowGzip;\n\n if (connection.user != null && connection.password != null) {\n if (\n url.substring(0, 6) !== 'https:' &&\n connection.allowInsecureAuthentication !== true\n ) {\n logger.throwError(\n 'basic authentication requires a secure https url',\n Logger.errors.INVALID_ARGUMENT,\n {\n argument: 'url',\n url: url,\n user: connection.user,\n password: '[REDACTED]',\n },\n );\n }\n\n const authorization = connection.user + ':' + connection.password;\n headers['authorization'] = {\n key: 'Authorization',\n value: 'Basic ' + base64Encode(toUtf8Bytes(authorization)),\n };\n }\n\n if (connection.skipFetchSetup != null) {\n options.skipFetchSetup = !!connection.skipFetchSetup;\n }\n\n if (connection.fetchOptions != null) {\n options.fetchOptions = shallowCopy(connection.fetchOptions);\n }\n\n if (connection.agents != null) {\n options.agents = connection.agents;\n }\n }\n\n const reData = new RegExp('^data:([^;:]*)?(;base64)?,(.*)$', 'i');\n const dataMatch = url ? url.match(reData) : null;\n if (dataMatch) {\n try {\n const response = {\n statusCode: 200,\n statusMessage: 'OK',\n headers: { 'content-type': dataMatch[1] || 'text/plain' },\n body: dataMatch[2]\n ? base64Decode(dataMatch[3])\n : unpercent(dataMatch[3]),\n };\n\n let result: T = <T>(<unknown>response.body);\n if (processFunc) {\n result = processFunc(response.body, response);\n }\n return Promise.resolve(<T>(<unknown>result));\n } catch (error) {\n logger.throwError(\n 'processing response error',\n Logger.errors.SERVER_ERROR,\n {\n body: bodyify(dataMatch[1], dataMatch[2]),\n error: error,\n requestBody: null,\n requestMethod: 'GET',\n url: url,\n },\n );\n }\n }\n\n if (body) {\n options.method = 'POST';\n options.body = body;\n if (headers['content-type'] == null) {\n headers['content-type'] = {\n key: 'Content-Type',\n value: 'application/octet-stream',\n };\n }\n if (headers['content-length'] == null) {\n headers['content-length'] = {\n key: 'Content-Length',\n value: String(body.length),\n };\n }\n }\n\n const flatHeaders: { [key: string]: string } = {};\n Object.keys(headers).forEach((key) => {\n const header = headers[key];\n flatHeaders[header.key] = header.value;\n });\n options.headers = flatHeaders;\n\n const runningTimeout = (function () {\n let timer: NodeJS.Timer = null;\n const promise: Promise<never> = new Promise(function (resolve, reject) {\n if (timeout) {\n timer = setTimeout(() => {\n if (timer == null) {\n return;\n }\n timer = null;\n\n reject(\n logger.makeError('timeout', Logger.errors.TIMEOUT, {\n requestBody: bodyify(options.body, flatHeaders['content-type']),\n requestMethod: options.method,\n timeout: timeout,\n url: url,\n }),\n );\n }, timeout);\n }\n });\n\n const cancel = function () {\n if (timer == null) {\n return;\n }\n clearTimeout(timer);\n timer = null;\n };\n\n return { promise, cancel };\n })();\n\n const runningFetch = (async function () {\n for (let attempt = 0; attempt < attemptLimit; attempt++) {\n let response: GetUrlResponse = null;\n\n try {\n response = await getUrl(url, options);\n\n if (response.statusCode === 301 || response.statusCode === 302) {\n // Redirection; for now we only support absolute locataions\n const location = response.headers.location || '';\n if (options.method === 'GET' && location.match(/^https:/)) {\n url = response.headers.location;\n continue;\n }\n } else if (response.statusCode === 429) {\n // If it's the last attempt we throw an error with the response\n if (attempt == attemptLimit - 1) {\n const err = new Error('rate limited');\n (err as any).response = response;\n throw err;\n }\n\n // Exponential back-off throttling\n let tryAgain = true;\n if (throttleCallback) {\n tryAgain = await throttleCallback(attempt, url);\n }\n\n if (tryAgain) {\n let stall = 0;\n\n const retryAfter = response.headers['retry-after'];\n if (\n typeof retryAfter === 'string' &&\n retryAfter.match(/^[1-9][0-9]*$/)\n ) {\n stall = parseInt(retryAfter) * 1000;\n } else {\n stall =\n throttleSlotInterval *\n parseInt(String(Math.random() * Math.pow(2, attempt)));\n }\n\n //console.log(\"Stalling 429\");\n await staller(stall);\n continue;\n }\n }\n } catch (error) {\n response = (<any>error).response;\n if (response == null) {\n runningTimeout.cancel();\n logger.throwError('missing response', Logger.errors.SERVER_ERROR, {\n requestBody: bodyify(options.body, flatHeaders['content-type']),\n requestMethod: options.method,\n serverError: error,\n url: url,\n });\n }\n }\n\n let body = response.body;\n\n if (allow304 && response.statusCode === 304) {\n body = null;\n } else if (\n !errorPassThrough &&\n (response.statusCode < 200 || response.statusCode >= 300)\n ) {\n runningTimeout.cancel();\n logger.throwError('bad response', Logger.errors.SERVER_ERROR, {\n status: response.statusCode,\n headers: response.headers,\n body: bodyify(\n body,\n response.headers ? response.headers['content-type'] : null,\n ),\n requestBody: bodyify(options.body, flatHeaders['content-type']),\n requestMethod: options.method,\n url: url,\n });\n }\n\n if (processFunc) {\n try {\n const result = await processFunc(body, response);\n runningTimeout.cancel();\n return result;\n } catch (error) {\n // Allow the processFunc to trigger a throttle\n if (error.throttleRetry && attempt < attemptLimit) {\n let tryAgain = true;\n if (throttleCallback) {\n tryAgain = await throttleCallback(attempt, url);\n }\n\n if (tryAgain) {\n const timeout =\n throttleSlotInterval *\n parseInt(String(Math.random() * Math.pow(2, attempt)));\n //console.log(\"Stalling callback\");\n await staller(timeout);\n continue;\n }\n }\n\n runningTimeout.cancel();\n logger.throwError(\n 'processing response error',\n Logger.errors.SERVER_ERROR,\n {\n body: bodyify(\n body,\n response.headers ? response.headers['content-type'] : null,\n ),\n error: error,\n requestBody: bodyify(options.body, flatHeaders['content-type']),\n requestMethod: options.method,\n url: url,\n },\n );\n }\n }\n\n runningTimeout.cancel();\n\n // If we had a processFunc, it either returned a T or threw above.\n // The \"body\" is now a Uint8Array.\n return <T>(<unknown>body);\n }\n\n return logger.throwError('failed response', Logger.errors.SERVER_ERROR, {\n requestBody: bodyify(options.body, flatHeaders['content-type']),\n requestMethod: options.method,\n url: url,\n });\n })();\n\n return Promise.race([runningTimeout.promise, runningFetch]);\n}\n\nexport function fetchJson(\n connection: string | ConnectionInfo,\n json?: string,\n processFunc?: (value: any, response: FetchJsonResponse) => any,\n): Promise<any> {\n let processJsonFunc = (value: Uint8Array, response: FetchJsonResponse) => {\n let result: any = null;\n if (value != null) {\n try {\n result = JSON.parse(toUtf8String(value));\n } catch (error) {\n logger.throwError('invalid JSON', Logger.errors.SERVER_ERROR, {\n body: value,\n error: error,\n });\n }\n }\n\n if (processFunc) {\n result = processFunc(result, response);\n }\n\n return result;\n };\n\n // If we have json to send, we must\n // - add content-type of application/json (unless already overridden)\n // - convert the json to bytes\n let body: Uint8Array = null;\n if (json != null) {\n body = toUtf8Bytes(json);\n\n // Create a connection with the content-type set for JSON\n const updated: ConnectionInfo =\n typeof connection === 'string'\n ? { url: connection }\n : shallowCopy(connection);\n if (updated.headers) {\n const hasContentType =\n Object.keys(updated.headers).filter(\n (k) => k.toLowerCase() === 'content-type',\n ).length !== 0;\n if (!hasContentType) {\n updated.headers = shallowCopy(updated.headers);\n updated.headers['content-type'] = 'application/json';\n }\n } else {\n updated.headers = { 'content-type': 'application/json' };\n }\n connection = updated;\n }\n\n return _fetchData<any>(connection, body, processJsonFunc);\n}\n\nexport function poll<T>(\n func: () => Promise<T>,\n options?: PollOptions,\n): Promise<T> {\n if (!options) {\n options = {};\n }\n options = shallowCopy(options);\n if (options.floor == null) {\n options.floor = 0;\n }\n if (options.ceiling == null) {\n options.ceiling = 10000;\n }\n if (options.interval == null) {\n options.interval = 250;\n }\n\n return new Promise(function (resolve, reject) {\n let timer: NodeJS.Timer = null;\n let done: boolean = false;\n\n // Returns true if cancel was successful. Unsuccessful cancel means we're already done.\n const cancel = (): boolean => {\n if (done) {\n return false;\n }\n done = true;\n if (timer) {\n clearTimeout(timer);\n }\n return true;\n };\n\n if (options.timeout) {\n timer = setTimeout(() => {\n if (cancel()) {\n reject(new Error('timeout'));\n }\n }, options.timeout);\n }\n\n const retryLimit = options.retryLimit;\n\n let attempt = 0;\n function check() {\n return func().then(\n function (result) {\n // If we have a result, or are allowed null then we're done\n if (result !== undefined) {\n if (cancel()) {\n resolve(result);\n }\n } else if (options.oncePoll) {\n options.oncePoll.once('poll', check);\n } else if (options.onceBlock) {\n options.onceBlock.once('block', check);\n\n // Otherwise, exponential back-off (up to 10s) our next request\n } else if (!done) {\n attempt++;\n if (attempt > retryLimit) {\n if (cancel()) {\n reject(new Error('retry limit reached'));\n }\n return;\n }\n\n let timeout =\n options.interval *\n parseInt(String(Math.random() * Math.pow(2, attempt)));\n if (timeout < options.floor) {\n timeout = options.floor;\n }\n if (timeout > options.ceiling) {\n timeout = options.ceiling;\n }\n\n setTimeout(check, timeout);\n }\n\n return null;\n },\n function (error) {\n if (cancel()) {\n reject(error);\n }\n },\n );\n }\n check();\n });\n}\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/ethereum/ethers/web/index.ts"],"names":[],"mappings":"AAAA,oBAAoB;AACpB,YAAY,CAAC;;;AAIb,kDAG+B;AAC/B,gDAA4D;AAC5D,0DAAwD;AACxD,oDAAmE;AAEnE,kDAA+C;AAC/C,yCAAqC;AACrC,MAAM,MAAM,GAAG,IAAI,eAAM,CAAC,kBAAO,CAAC,CAAC;AAEnC,qCAA2D;AAE3D,SAAS,OAAO,CAAC,QAAgB;IAC/B,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;QAC7B,UAAU,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;IAChC,CAAC,CAAC,CAAC;AACL,CAAC;AAED,SAAS,OAAO,CAAC,KAAU,EAAE,IAAmB;IAC9C,IAAI,KAAK,IAAI,IAAI,EAAE;QACjB,OAAO,IAAI,CAAC;KACb;IAED,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE;QAC7B,OAAO,KAAK,CAAC;KACd;IAED,IAAI,IAAA,mBAAW,EAAC,KAAK,CAAC,EAAE;QACtB,IACE,IAAI;YACJ,C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,CAAC,KAAM,CAAC;qBAC3B;oBACD,IAAI,OAAO,GAAG,OAAQ,CAAC,OAAQ,EAAE;wBAC/B,OAAO,GAAG,OAAQ,CAAC,OAAQ,CAAC;qBAC7B;oBAED,UAAU,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;iBAC5B;gBAED,OAAO,IAAI,CAAC;YACd,CAAC,EACD,UAAU,KAAK;gBACb,IAAI,MAAM,EAAE,EAAE;oBACZ,MAAM,CAAC,KAAK,CAAC,CAAC;iBACf;YACH,CAAC,CACF,CAAC;QACJ,CAAC;QACD,KAAK,EAAE,CAAC;IACV,CAAC,CAAC,CAAC;AACL,CAAC;AA5FD,oBA4FC","sourcesContent":["/* eslint-disable */\n'use strict';\n\nimport http from 'http';\nimport https from 'https';\nimport {\n decode as base64Decode,\n encode as base64Encode,\n} from '@ethersproject/base64';\nimport { hexlify, isBytesLike } from '@ethersproject/bytes';\nimport { shallowCopy } from '@ethersproject/properties';\nimport { toUtf8Bytes, toUtf8String } from '@ethersproject/strings';\n\nimport { Logger } from '@ethersproject/logger';\nimport { version } from './_version';\nconst logger = new Logger(version);\n\nimport { getUrl, GetUrlResponse, Options } from './geturl';\n\nfunction staller(duration: number): Promise<void> {\n return new Promise((resolve) => {\n setTimeout(resolve, duration);\n });\n}\n\nfunction bodyify(value: any, type: string | null): string | null {\n if (value == null) {\n return null;\n }\n\n if (typeof value === 'string') {\n return value;\n }\n\n if (isBytesLike(value)) {\n if (\n type &&\n (type.split('/')[0] === 'text' ||\n type.split(';')[0].trim() === 'application/json')\n ) {\n try {\n return toUtf8String(value);\n } catch (error) {}\n }\n return hexlify(value);\n }\n\n return value;\n}\n\n// Exported Types\nexport type ConnectionInfo = {\n url: string;\n headers?: { [key: string]: string | number };\n\n user?: string;\n password?: string;\n\n allowInsecureAuthentication?: boolean;\n allowGzip?: boolean;\n\n throttleLimit?: number;\n throttleSlotInterval?: number;\n throttleCallback?: (attempt: number, url: string) => Promise<boolean>;\n\n skipFetchSetup?: boolean;\n fetchOptions?: Record<string, string>;\n errorPassThrough?: boolean;\n\n timeout?: number;\n\n agents?: {\n http?: http.Agent;\n https?: https.Agent;\n };\n};\n\nexport interface OnceBlockable {\n once(eventName: 'block', handler: () => void): void;\n}\n\nexport interface OncePollable {\n once(eventName: 'poll', handler: () => void): void;\n}\n\nexport type PollOptions = {\n timeout?: number;\n floor?: number;\n ceiling?: number;\n interval?: number;\n retryLimit?: number;\n onceBlock?: OnceBlockable;\n oncePoll?: OncePollable;\n};\n\nexport type FetchJsonResponse = {\n statusCode: number;\n headers: { [header: string]: string };\n};\n\ntype Header = { key: string; value: string };\n\nfunction unpercent(value: string): Uint8Array {\n return toUtf8Bytes(\n value.replace(/%([0-9a-f][0-9a-f])/gi, (all, code) => {\n return String.fromCharCode(parseInt(code, 16));\n }),\n );\n}\n\n// This API is still a work in progress; the future changes will likely be:\n// - ConnectionInfo => FetchDataRequest<T = any>\n// - FetchDataRequest.body? = string | Uint8Array | { contentType: string, data: string | Uint8Array }\n// - If string => text/plain, Uint8Array => application/octet-stream (if content-type unspecified)\n// - FetchDataRequest.processFunc = (body: Uint8Array, response: FetchDataResponse) => T\n// For this reason, it should be considered internal until the API is finalized\nexport function _fetchData<T = Uint8Array>(\n connection: string | ConnectionInfo,\n body?: Uint8Array,\n processFunc?: (value: Uint8Array | null, response: FetchJsonResponse) => T,\n): Promise<T> {\n // How many times to retry in the event of a throttle\n const attemptLimit =\n typeof connection === 'object' && connection.throttleLimit != null\n ? connection.throttleLimit\n : 12;\n logger.assertArgument(\n attemptLimit > 0 && attemptLimit % 1 === 0,\n 'invalid connection throttle limit',\n 'connection.throttleLimit',\n attemptLimit,\n );\n\n const throttleCallback =\n typeof connection === 'object' ? connection.throttleCallback : null;\n const throttleSlotInterval =\n typeof connection === 'object' &&\n typeof connection.throttleSlotInterval === 'number'\n ? connection.throttleSlotInterval\n : 100;\n logger.assertArgument(\n throttleSlotInterval > 0 && throttleSlotInterval % 1 === 0,\n 'invalid connection throttle slot interval',\n 'connection.throttleSlotInterval',\n throttleSlotInterval,\n );\n\n const errorPassThrough =\n typeof connection === 'object' ? !!connection.errorPassThrough : false;\n\n const headers: { [key: string]: Header } = {};\n\n let url: string;\n\n // @TODO: Allow ConnectionInfo to override some of these values\n const options: Options = {\n method: 'GET',\n };\n\n let allow304 = false;\n\n let timeout = 2 * 60 * 1000;\n\n if (typeof connection === 'string') {\n url = connection;\n } else if (typeof connection === 'object') {\n if (connection == null || connection.url == null) {\n logger.throwArgumentError('missing URL', 'connection.url', connection);\n }\n\n url = connection.url;\n\n if (typeof connection.timeout === 'number' && connection.timeout > 0) {\n timeout = connection.timeout;\n }\n\n if (connection.headers) {\n for (const key in connection.headers) {\n headers[key.toLowerCase()] = {\n key: key,\n value: String(connection.headers[key]),\n };\n if (\n ['if-none-match', 'if-modified-since'].indexOf(key.toLowerCase()) >= 0\n ) {\n allow304 = true;\n }\n }\n }\n\n options.allowGzip = !!connection.allowGzip;\n\n if (connection.user != null && connection.password != null) {\n if (\n url.substring(0, 6) !== 'https:' &&\n connection.allowInsecureAuthentication !== true\n ) {\n logger.throwError(\n 'basic authentication requires a secure https url',\n Logger.errors.INVALID_ARGUMENT,\n {\n argument: 'url',\n url: url,\n user: connection.user,\n password: '[REDACTED]',\n },\n );\n }\n\n const authorization = connection.user + ':' + connection.password;\n headers['authorization'] = {\n key: 'Authorization',\n value: 'Basic ' + base64Encode(toUtf8Bytes(authorization)),\n };\n }\n\n if (connection.skipFetchSetup != null) {\n options.skipFetchSetup = !!connection.skipFetchSetup;\n }\n\n if (connection.fetchOptions != null) {\n options.fetchOptions = shallowCopy(connection.fetchOptions);\n }\n\n if (connection.agents != null) {\n options.agents = connection.agents;\n }\n } else {\n throw new Error('invalid connection');\n }\n\n const reData = new RegExp('^data:([^;:]*)?(;base64)?,(.*)$', 'i');\n const dataMatch = url ? url.match(reData) : null;\n if (dataMatch) {\n try {\n const response = {\n statusCode: 200,\n statusMessage: 'OK',\n headers: { 'content-type': dataMatch[1] || 'text/plain' },\n body: dataMatch[2]\n ? base64Decode(dataMatch[3])\n : unpercent(dataMatch[3]),\n };\n\n let result: T = <T>(<unknown>response.body);\n if (processFunc) {\n result = processFunc(response.body, response);\n }\n return Promise.resolve(<T>(<unknown>result));\n } catch (error) {\n logger.throwError(\n 'processing response error',\n Logger.errors.SERVER_ERROR,\n {\n body: bodyify(dataMatch[1], dataMatch[2]),\n error: error,\n requestBody: null,\n requestMethod: 'GET',\n url: url,\n },\n );\n }\n }\n\n if (body) {\n options.method = 'POST';\n options.body = body;\n if (headers['content-type'] == null) {\n headers['content-type'] = {\n key: 'Content-Type',\n value: 'application/octet-stream',\n };\n }\n if (headers['content-length'] == null) {\n headers['content-length'] = {\n key: 'Content-Length',\n value: String(body.length),\n };\n }\n }\n\n const flatHeaders: { [key: string]: string } = {};\n Object.keys(headers).forEach((key) => {\n const header = headers[key];\n flatHeaders[header.key] = header.value;\n });\n options.headers = flatHeaders;\n\n const runningTimeout = (function () {\n let timer: NodeJS.Timer | null = null;\n const promise: Promise<never> = new Promise(function (resolve, reject) {\n if (timeout) {\n timer = setTimeout(() => {\n if (timer == null) {\n return;\n }\n timer = null;\n\n reject(\n logger.makeError('timeout', Logger.errors.TIMEOUT, {\n requestBody: bodyify(options.body, flatHeaders['content-type']),\n requestMethod: options.method,\n timeout: timeout,\n url: url,\n }),\n );\n }, timeout);\n }\n });\n\n const cancel = function () {\n if (timer == null) {\n return;\n }\n clearTimeout(timer);\n timer = null;\n };\n\n return { promise, cancel };\n })();\n\n const runningFetch = (async function () {\n for (let attempt = 0; attempt < attemptLimit; attempt++) {\n let response: GetUrlResponse | null = null;\n\n try {\n response = await getUrl(url, options);\n\n if (response.statusCode === 301 || response.statusCode === 302) {\n // Redirection; for now we only support absolute locataions\n const location = response.headers.location || '';\n if (options.method === 'GET' && location.match(/^https:/)) {\n url = response.headers.location;\n continue;\n }\n } else if (response.statusCode === 429) {\n // If it's the last attempt we throw an error with the response\n if (attempt == attemptLimit - 1) {\n const err = new Error('rate limited');\n (err as any).response = response;\n throw err;\n }\n\n // Exponential back-off throttling\n let tryAgain = true;\n if (throttleCallback) {\n tryAgain = await throttleCallback(attempt, url);\n }\n\n if (tryAgain) {\n let stall = 0;\n\n const retryAfter = response.headers['retry-after'];\n if (\n typeof retryAfter === 'string' &&\n retryAfter.match(/^[1-9][0-9]*$/)\n ) {\n stall = parseInt(retryAfter) * 1000;\n } else {\n stall =\n throttleSlotInterval *\n parseInt(String(Math.random() * Math.pow(2, attempt)));\n }\n\n //console.log(\"Stalling 429\");\n await staller(stall);\n continue;\n }\n }\n } catch (error) {\n response = (<any>error).response;\n if (response == null) runningTimeout.cancel();\n throw logger.throwError(\n 'missing response',\n Logger.errors.SERVER_ERROR,\n {\n requestBody: bodyify(options.body, flatHeaders['content-type']),\n requestMethod: options.method,\n serverError: error,\n url: url,\n },\n );\n }\n\n let body: Uint8Array | null = response.body;\n\n if (allow304 && response.statusCode === 304) {\n body = null;\n } else if (\n !errorPassThrough &&\n (response.statusCode < 200 || response.statusCode >= 300)\n ) {\n runningTimeout.cancel();\n throw logger.throwError('bad response', Logger.errors.SERVER_ERROR, {\n status: response.statusCode,\n headers: response.headers,\n body: bodyify(\n body,\n response.headers ? response.headers['content-type'] : null,\n ),\n requestBody: bodyify(options.body, flatHeaders['content-type']),\n requestMethod: options.method,\n url: url,\n });\n }\n\n if (processFunc) {\n try {\n const result = await processFunc(body, response);\n runningTimeout.cancel();\n return result;\n } catch (error: any) {\n // Allow the processFunc to trigger a throttle\n if (error.throttleRetry && attempt < attemptLimit) {\n let tryAgain = true;\n if (throttleCallback) {\n tryAgain = await throttleCallback(attempt, url);\n }\n\n if (tryAgain) {\n const timeout =\n throttleSlotInterval *\n parseInt(String(Math.random() * Math.pow(2, attempt)));\n //console.log(\"Stalling callback\");\n await staller(timeout);\n continue;\n }\n }\n\n runningTimeout.cancel();\n throw logger.throwError(\n 'processing response error',\n Logger.errors.SERVER_ERROR,\n {\n body: bodyify(\n body,\n response.headers ? response.headers['content-type'] : null,\n ),\n error: error,\n requestBody: bodyify(options.body, flatHeaders['content-type']),\n requestMethod: options.method,\n url: url,\n },\n );\n }\n }\n\n runningTimeout.cancel();\n\n // If we had a processFunc, it either returned a T or threw above.\n // The \"body\" is now a Uint8Array.\n return <T>(<unknown>body);\n }\n\n return logger.throwError('failed response', Logger.errors.SERVER_ERROR, {\n requestBody: bodyify(options.body, flatHeaders['content-type']),\n requestMethod: options.method,\n url: url,\n });\n })();\n\n return Promise.race([runningTimeout.promise, runningFetch]);\n}\n\nexport function fetchJson(\n connection: string | ConnectionInfo,\n json?: string,\n processFunc?: (value: any, response: FetchJsonResponse) => any,\n): Promise<any> {\n let processJsonFunc = (\n value: Uint8Array | null,\n response: FetchJsonResponse,\n ) => {\n let result: any = null;\n if (value != null) {\n try {\n result = JSON.parse(toUtf8String(value));\n } catch (error) {\n logger.throwError('invalid JSON', Logger.errors.SERVER_ERROR, {\n body: value,\n error: error,\n });\n }\n }\n\n if (processFunc) {\n result = processFunc(result, response);\n }\n\n return result;\n };\n\n // If we have json to send, we must\n // - add content-type of application/json (unless already overridden)\n // - convert the json to bytes\n let body: Uint8Array | undefined;\n if (json != null) {\n body = toUtf8Bytes(json);\n\n // Create a connection with the content-type set for JSON\n const updated: ConnectionInfo =\n typeof connection === 'string'\n ? { url: connection }\n : shallowCopy(connection);\n if (updated.headers) {\n const hasContentType =\n Object.keys(updated.headers).filter(\n (k) => k.toLowerCase() === 'content-type',\n ).length !== 0;\n if (!hasContentType) {\n updated.headers = shallowCopy(updated.headers);\n updated.headers['content-type'] = 'application/json';\n }\n } else {\n updated.headers = { 'content-type': 'application/json' };\n }\n connection = updated;\n }\n\n return _fetchData<any>(connection, body, processJsonFunc);\n}\n\nexport function poll<T>(\n func: () => Promise<T>,\n options?: PollOptions,\n): Promise<T> {\n if (!options) {\n options = {};\n }\n options = shallowCopy(options);\n if (options.floor == null) {\n options.floor = 0;\n }\n if (options.ceiling == null) {\n options.ceiling = 10000;\n }\n if (options.interval == null) {\n options.interval = 250;\n }\n\n return new Promise(function (resolve, reject) {\n let timer: NodeJS.Timer | null = null;\n let done: boolean = false;\n\n // Returns true if cancel was successful. Unsuccessful cancel means we're already done.\n const cancel = (): boolean => {\n if (done) {\n return false;\n }\n done = true;\n if (timer) {\n clearTimeout(timer);\n }\n return true;\n };\n\n if (options?.timeout) {\n timer = setTimeout(() => {\n if (cancel()) {\n reject(new Error('timeout'));\n }\n }, options.timeout);\n }\n\n const retryLimit = options?.retryLimit ?? 0;\n\n let attempt = 0;\n function check() {\n return func().then(\n function (result) {\n // If we have a result, or are allowed null then we're done\n if (result !== undefined) {\n if (cancel()) {\n resolve(result);\n }\n } else if (options?.oncePoll) {\n options.oncePoll.once('poll', check);\n } else if (options?.onceBlock) {\n options.onceBlock.once('block', check);\n\n // Otherwise, exponential back-off (up to 10s) our next request\n } else if (!done) {\n attempt++;\n if (attempt > retryLimit) {\n if (cancel()) {\n reject(new Error('retry limit reached'));\n }\n return;\n }\n\n let timeout =\n options!.interval! *\n parseInt(String(Math.random() * Math.pow(2, attempt)));\n if (timeout < options!.floor!) {\n timeout = options!.floor!;\n }\n if (timeout > options!.ceiling!) {\n timeout = options!.ceiling!;\n }\n\n setTimeout(check, timeout);\n }\n\n return null;\n },\n function (error) {\n if (cancel()) {\n reject(error);\n }\n },\n );\n }\n check();\n });\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/ethereum/ethers/web/types.ts"],"names":[],"mappings":"AAAA,oBAAoB;AACpB,YAAY,CAAC","sourcesContent":["/* eslint-disable */\n'use strict';\nimport http from 'http';\nimport https from 'https';\n\nexport type GetUrlResponse = {\n statusCode: number;\n statusMessage: string;\n headers: { [key: string]: string };\n body: Uint8Array;\n};\n\nexport type Options = {\n method?: string;\n allowGzip?: boolean;\n body?: Uint8Array;\n headers?: { [key: string]: string };\n skipFetchSetup?: boolean;\n fetchOptions?: Record<string, string>;\n agents?: {\n http?: http.Agent;\n https?: https.Agent;\n };\n};\n"]}
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/ethereum/ethers/web/types.ts"],"names":[],"mappings":"AAAA,oBAAoB;AACpB,YAAY,CAAC","sourcesContent":["/* eslint-disable */\n'use strict';\nimport http from 'http';\nimport https from 'https';\n\nexport type GetUrlResponse = {\n statusCode: number;\n statusMessage: string;\n headers: { [key: string]: string };\n body: Uint8Array | null;\n};\n\nexport type Options = {\n method?: string;\n allowGzip?: boolean;\n body?: Uint8Array;\n headers?: { [key: string]: string };\n skipFetchSetup?: boolean;\n fetchOptions?: Record<string, string>;\n agents?: {\n http?: http.Agent;\n https?: https.Agent;\n };\n};\n"]}
|
|
@@ -5,9 +5,9 @@ import { ApiWrapper, EthereumBlock, EthereumLog, EthereumReceipt, EthereumResult
|
|
|
5
5
|
import { BlockContent } from '../indexer/types';
|
|
6
6
|
export declare function calcInterval(api: ApiWrapper): number;
|
|
7
7
|
export declare function handleNumber(value: string | number): BigNumber;
|
|
8
|
-
export declare function formatBlock(block:
|
|
8
|
+
export declare function formatBlock(block: any): EthereumBlock;
|
|
9
9
|
export declare function formatBlockUtil<B extends EthereumBlock | LightEthereumBlock = EthereumBlock>(block: B): IBlock<B>;
|
|
10
10
|
export declare function formatLog(log: Omit<EthereumLog<EthereumResult> | EthereumLog, 'blockTimestamp' | 'block' | 'transaction'>, block: EthereumBlock): EthereumLog<EthereumResult> | EthereumLog;
|
|
11
|
-
export declare function formatTransaction(tx: Record<string, any>, block: EthereumBlock): EthereumTransaction
|
|
12
|
-
export declare function formatReceipt<R extends EthereumReceipt = EthereumReceipt>(receipt: Record<string, any
|
|
11
|
+
export declare function formatTransaction(tx: Record<string, any>, block: EthereumBlock): Omit<EthereumTransaction, 'receipt'>;
|
|
12
|
+
export declare function formatReceipt<R extends EthereumReceipt = EthereumReceipt>(receipt: Record<string, any>): R;
|
|
13
13
|
export declare function ethereumBlockToHeader(block: BlockContent | Block): Header;
|
|
@@ -106,7 +106,7 @@ function formatTransaction(tx, block) {
|
|
|
106
106
|
};
|
|
107
107
|
}
|
|
108
108
|
exports.formatTransaction = formatTransaction;
|
|
109
|
-
function formatReceipt(receipt
|
|
109
|
+
function formatReceipt(receipt) {
|
|
110
110
|
return {
|
|
111
111
|
...receipt,
|
|
112
112
|
from: handleAddress(receipt.from),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.ethereum.js","sourceRoot":"","sources":["../../src/ethereum/utils.ethereum.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;;AAGnC,oDAAoD;AACpD,wDAAqD;AACrD,wDAAgD;AAWhD,mCAA8B;AAG9B,SAAgB,YAAY,CAAC,GAAe;IAC1C,kDAAkD;IAClD,OAAO,IAAI,CAAC;AACd,CAAC;AAHD,oCAGC;AAED,SAAS,aAAa,CAAC,KAAa;IAClC,IAAI,CAAC,KAAK,IAAI,KAAK,KAAK,IAAI,EAAE;QAC5B,OAAO,IAAI,CAAC;KACb;IACD,OAAO,IAAA,oBAAU,EAAC,KAAK,CAAC,CAAC;AAC3B,CAAC;AAED,SAAgB,YAAY,CAAC,KAAsB;IACjD,IAAI,KAAK,KAAK,SAAS,EAAE;QACvB,OAAO,gBAAI,CAAC;KACb;IACD,IAAI,KAAK,KAAK,IAAI,EAAE;QAClB,OAAO,gBAAI,CAAC;KACb;IACD,IAAI,KAAK,KAAK,IAAI,EAAE;QAClB,OAAO,gBAAI,CAAC;KACb;IACD,OAAO,qBAAS,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;AAC/B,CAAC;AAXD,oCAWC;AAED,SAAgB,WAAW,CAAC,
|
|
1
|
+
{"version":3,"file":"utils.ethereum.js","sourceRoot":"","sources":["../../src/ethereum/utils.ethereum.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;;AAGnC,oDAAoD;AACpD,wDAAqD;AACrD,wDAAgD;AAWhD,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: GPL-3.0\n\nimport { Block } from '@ethersproject/abstract-provider';\nimport { getAddress } from '@ethersproject/address';\nimport { BigNumber } from '@ethersproject/bignumber';\nimport { Zero } from '@ethersproject/constants';\nimport { Header, IBlock } from '@subql/node-core';\nimport {\n ApiWrapper,\n EthereumBlock,\n EthereumLog,\n EthereumReceipt,\n EthereumResult,\n EthereumTransaction,\n LightEthereumBlock,\n} from '@subql/types-ethereum';\nimport { omit } from 'lodash';\nimport { BlockContent } from '../indexer/types';\n\nexport function calcInterval(api: ApiWrapper): number {\n // TODO find a way to get this from the blockchain\n return 6000;\n}\n\nfunction handleAddress(value: string): string | null {\n if (!value || value === '0x') {\n return null;\n }\n return getAddress(value);\n}\n\nexport function handleNumber(value: string | number): BigNumber {\n if (value === undefined) {\n return Zero;\n }\n if (value === '0x') {\n return Zero;\n }\n if (value === null) {\n return Zero;\n }\n return BigNumber.from(value);\n}\n\nexport function formatBlock(block: any): EthereumBlock {\n return {\n ...block,\n difficulty: handleNumber(block.difficulty).toBigInt(),\n gasLimit: handleNumber(block.gasLimit).toBigInt(),\n gasUsed: handleNumber(block.gasUsed).toBigInt(),\n number: handleNumber(block.number).toNumber(),\n size: handleNumber(block.size).toBigInt(),\n timestamp: handleNumber(block.timestamp).toBigInt(),\n totalDifficulty: handleNumber(block.totalDifficulty).toBigInt(),\n baseFeePerGas: block.baseFeePerGas\n ? handleNumber(block.baseFeePerGas).toBigInt()\n : undefined,\n blockGasCost: block.blockGasCost\n ? handleNumber(block.blockGasCost).toBigInt()\n : undefined,\n logs: [], // Filled in at AvalancheBlockWrapped constructor\n } as EthereumBlock;\n}\n\nexport function formatBlockUtil<\n B extends EthereumBlock | LightEthereumBlock = EthereumBlock,\n>(block: B): IBlock<B> {\n return {\n block,\n getHeader: () => ethereumBlockToHeader(block),\n };\n}\n\nexport function formatLog(\n log: Omit<\n EthereumLog<EthereumResult> | EthereumLog,\n 'blockTimestamp' | 'block' | 'transaction'\n >,\n block: EthereumBlock,\n): EthereumLog<EthereumResult> | EthereumLog {\n const formattedLog = {\n ...log,\n address: handleAddress(log.address),\n blockNumber: handleNumber(log.blockNumber).toNumber(),\n transactionIndex: handleNumber(log.transactionIndex).toNumber(),\n logIndex: handleNumber(log.logIndex).toNumber(),\n block,\n toJSON(): string {\n return JSON.stringify(omit(this, ['transaction', 'block', 'toJSON']));\n },\n };\n\n // Define this afterwards as the spread on `...log` breaks defining a getter\n Object.defineProperty(formattedLog, 'transaction', {\n get: () => {\n const rawTransaction = block.transactions?.find(\n (tx) => tx.hash === log.transactionHash,\n );\n\n return rawTransaction;\n },\n });\n return formattedLog as unknown as EthereumLog<EthereumResult>;\n}\n\nexport function formatTransaction(\n tx: Record<string, any>,\n block: EthereumBlock,\n): Omit<EthereumTransaction, 'receipt'> {\n return {\n ...(tx as Partial<EthereumTransaction>),\n from: handleAddress(tx.from),\n to: handleAddress(tx.to),\n blockNumber: handleNumber(tx.blockNumber).toNumber(),\n blockTimestamp: block.timestamp,\n gas: handleNumber(tx.gas).toBigInt(),\n gasPrice: handleNumber(tx.gasPrice).toBigInt(),\n nonce: handleNumber(tx.nonce).toBigInt(),\n transactionIndex: handleNumber(tx.transactionIndex).toBigInt(),\n value: handleNumber(tx.value).toBigInt(),\n v: handleNumber(tx.v).toBigInt(),\n maxFeePerGas: tx.maxFeePerGas\n ? handleNumber(tx.maxFeePerGas).toBigInt()\n : undefined,\n maxPriorityFeePerGas: tx.maxPriorityFeePerGas\n ? handleNumber(tx.maxPriorityFeePerGas).toBigInt()\n : undefined,\n receipt: undefined, // Filled in at Etheruem.fetchBlocks\n toJSON(): string {\n return JSON.stringify(omit(this, ['block', 'receipt', 'toJSON']));\n },\n } as Omit<EthereumTransaction, 'receipt'>;\n}\n\nexport function formatReceipt<R extends EthereumReceipt = EthereumReceipt>(\n receipt: Record<string, any>,\n): R {\n return {\n ...receipt,\n from: handleAddress(receipt.from),\n to: handleAddress(receipt.to),\n blockNumber: handleNumber(receipt.blockNumber).toNumber(),\n cumulativeGasUsed: handleNumber(receipt.cumulativeGasUsed).toBigInt(),\n effectiveGasPrice: handleNumber(receipt.effectiveGasPrice).toBigInt(),\n gasUsed: handleNumber(receipt.gasUsed).toBigInt(),\n logs: receipt.logs.map(formatLog),\n status: Boolean(handleNumber(receipt.status).toNumber()),\n transactionIndex: handleNumber(receipt.transactionIndex).toNumber(),\n toJSON(): string {\n return JSON.stringify(omit(this, ['toJSON']));\n },\n } as unknown as R;\n}\n\nexport function ethereumBlockToHeader(block: BlockContent | Block): Header {\n return {\n blockHeight: block.number,\n blockHash: block.hash,\n parentHash: block.parentHash,\n };\n}\n"]}
|
|
@@ -30,7 +30,7 @@ let WorkerBlockDispatcherService = class WorkerBlockDispatcherService extends no
|
|
|
30
30
|
super(nodeConfig, eventEmitter, projectService, projectUpgadeService, storeService, storeCacheService, poiSyncService, project, () => (0, node_core_1.createIndexerWorker)(path_1.default.resolve(__dirname, '../../../dist/indexer/worker/worker.js'), [], storeService.getStore(), cacheService.getCache(), dynamicDsService, unfinalizedBlocksSevice, connectionPoolState, project.root, projectService.startHeight, monitorService), monitorService);
|
|
31
31
|
}
|
|
32
32
|
async fetchBlock(worker, height) {
|
|
33
|
-
await worker.fetchBlock(height,
|
|
33
|
+
await worker.fetchBlock(height, 0 /* Unused with ethereum*/);
|
|
34
34
|
}
|
|
35
35
|
};
|
|
36
36
|
WorkerBlockDispatcherService = __decorate([
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"worker-block-dispatcher.service.js","sourceRoot":"","sources":["../../../src/indexer/blockDispatcher/worker-block-dispatcher.service.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;;;;;;;;;;;;;;;;;AAEnC,gDAAwB;AACxB,2CAA2E;AAC3E,yDAAsD;AACtD,gDAY0B;AAE1B,qEAGyC;AAEzC,8DAAyD;AAEzD,4EAAwE;AAQjE,IAAM,4BAA4B,GAAlC,MAAM,4BACX,SAAQ,iCAAsE;IAG9E,YACE,UAAsB,EACtB,YAA2B,EAE3B,cAAkD,EAElD,oBAA4C,EAC5C,YAAkC,EAClC,YAA0B,EAC1B,iBAAoC,EACpC,cAA8B,EACF,OAAwB,EACpD,gBAAkC,EAClC,uBAAiD,EACjD,mBAAsE,EACtE,cAAwC;QAExC,KAAK,CACH,UAAU,EACV,YAAY,EACZ,cAAc,EACd,oBAAoB,EACpB,YAAY,EACZ,iBAAiB,EACjB,cAAc,EACd,OAAO,EACP,GAAG,EAAE,CACH,IAAA,+BAAmB,EAMjB,cAAI,CAAC,OAAO,CAAC,SAAS,EAAE,wCAAwC,CAAC,EACjE,EAAE,EACF,YAAY,CAAC,QAAQ,EAAE,EACvB,YAAY,CAAC,QAAQ,EAAE,EACvB,gBAAgB,EAChB,uBAAuB,EACvB,mBAAmB,EACnB,OAAO,CAAC,IAAI,EACZ,cAAc,CAAC,WAAW,EAC1B,cAAc,CACf,EACH,cAAc,CACf,CAAC;IACJ,CAAC;IAES,KAAK,CAAC,UAAU,CACxB,MAAqB,EACrB,MAAc;QAEd,MAAM,MAAM,CAAC,UAAU,CAAC,MAAM,EAAE,
|
|
1
|
+
{"version":3,"file":"worker-block-dispatcher.service.js","sourceRoot":"","sources":["../../../src/indexer/blockDispatcher/worker-block-dispatcher.service.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;;;;;;;;;;;;;;;;;AAEnC,gDAAwB;AACxB,2CAA2E;AAC3E,yDAAsD;AACtD,gDAY0B;AAE1B,qEAGyC;AAEzC,8DAAyD;AAEzD,4EAAwE;AAQjE,IAAM,4BAA4B,GAAlC,MAAM,4BACX,SAAQ,iCAAsE;IAG9E,YACE,UAAsB,EACtB,YAA2B,EAE3B,cAAkD,EAElD,oBAA4C,EAC5C,YAAkC,EAClC,YAA0B,EAC1B,iBAAoC,EACpC,cAA8B,EACF,OAAwB,EACpD,gBAAkC,EAClC,uBAAiD,EACjD,mBAAsE,EACtE,cAAwC;QAExC,KAAK,CACH,UAAU,EACV,YAAY,EACZ,cAAc,EACd,oBAAoB,EACpB,YAAY,EACZ,iBAAiB,EACjB,cAAc,EACd,OAAO,EACP,GAAG,EAAE,CACH,IAAA,+BAAmB,EAMjB,cAAI,CAAC,OAAO,CAAC,SAAS,EAAE,wCAAwC,CAAC,EACjE,EAAE,EACF,YAAY,CAAC,QAAQ,EAAE,EACvB,YAAY,CAAC,QAAQ,EAAE,EACvB,gBAAgB,EAChB,uBAAuB,EACvB,mBAAmB,EACnB,OAAO,CAAC,IAAI,EACZ,cAAc,CAAC,WAAW,EAC1B,cAAc,CACf,EACH,cAAc,CACf,CAAC;IACJ,CAAC;IAES,KAAK,CAAC,UAAU,CACxB,MAAqB,EACrB,MAAc;QAEd,MAAM,MAAM,CAAC,UAAU,CAAC,MAAM,EAAE,CAAC,CAAC,yBAAyB,CAAC,CAAC;IAC/D,CAAC;CACF,CAAA;AA1DY,4BAA4B;IADxC,IAAA,mBAAU,GAAE;IAQR,WAAA,IAAA,eAAM,EAAC,iBAAiB,CAAC,CAAA;IAEzB,WAAA,IAAA,eAAM,EAAC,wBAAwB,CAAC,CAAA;IAMhC,WAAA,IAAA,eAAM,EAAC,kBAAkB,CAAC,CAAA;qCAVf,sBAAU;QACR,6BAAa,kBAKb,gCAAoB;QACpB,wBAAY;QACP,6BAAiB;QACpB,0BAAc;QACO,iCAAe;QAClC,qCAAgB;QACT,oDAAwB;QAC5B,sCAA0B;GAlBtC,4BAA4B,CA0DxC;AA1DY,oEAA4B","sourcesContent":["// Copyright 2020-2024 SubQuery Pte Ltd authors & contributors\n// SPDX-License-Identifier: GPL-3.0\n\nimport path from 'path';\nimport { Inject, Injectable, OnApplicationShutdown } from '@nestjs/common';\nimport { EventEmitter2 } from '@nestjs/event-emitter';\nimport {\n NodeConfig,\n StoreService,\n StoreCacheService,\n IProjectService,\n WorkerBlockDispatcher,\n ConnectionPoolStateManager,\n IProjectUpgradeService,\n PoiSyncService,\n InMemoryCacheService,\n createIndexerWorker,\n MonitorServiceInterface,\n} from '@subql/node-core';\nimport { EthereumBlock } from '@subql/types-ethereum';\nimport {\n EthereumProjectDs,\n SubqueryProject,\n} from '../../configure/SubqueryProject';\nimport { EthereumApiConnection } from '../../ethereum/api.connection';\nimport { DynamicDsService } from '../dynamic-ds.service';\nimport { BlockContent } from '../types';\nimport { UnfinalizedBlocksService } from '../unfinalizedBlocks.service';\nimport { IIndexerWorker } from '../worker/worker';\n\ntype IndexerWorker = IIndexerWorker & {\n terminate: () => Promise<number>;\n};\n\n@Injectable()\nexport class WorkerBlockDispatcherService\n extends WorkerBlockDispatcher<EthereumProjectDs, IndexerWorker, EthereumBlock>\n implements OnApplicationShutdown\n{\n constructor(\n nodeConfig: NodeConfig,\n eventEmitter: EventEmitter2,\n @Inject('IProjectService')\n projectService: IProjectService<EthereumProjectDs>,\n @Inject('IProjectUpgradeService')\n projectUpgadeService: IProjectUpgradeService,\n cacheService: InMemoryCacheService,\n storeService: StoreService,\n storeCacheService: StoreCacheService,\n poiSyncService: PoiSyncService,\n @Inject('ISubqueryProject') project: SubqueryProject,\n dynamicDsService: DynamicDsService,\n unfinalizedBlocksSevice: UnfinalizedBlocksService,\n connectionPoolState: ConnectionPoolStateManager<EthereumApiConnection>,\n monitorService?: MonitorServiceInterface,\n ) {\n super(\n nodeConfig,\n eventEmitter,\n projectService,\n projectUpgadeService,\n storeService,\n storeCacheService,\n poiSyncService,\n project,\n () =>\n createIndexerWorker<\n IIndexerWorker,\n EthereumApiConnection,\n BlockContent,\n EthereumProjectDs\n >(\n path.resolve(__dirname, '../../../dist/indexer/worker/worker.js'),\n [],\n storeService.getStore(),\n cacheService.getCache(),\n dynamicDsService,\n unfinalizedBlocksSevice,\n connectionPoolState,\n project.root,\n projectService.startHeight,\n monitorService,\n ),\n monitorService,\n );\n }\n\n protected async fetchBlock(\n worker: IndexerWorker,\n height: number,\n ): Promise<void> {\n await worker.fetchBlock(height, 0 /* Unused with ethereum*/);\n }\n}\n"]}
|
|
@@ -2,14 +2,14 @@ import { NodeConfig, DictionaryV1 } from '@subql/node-core';
|
|
|
2
2
|
import { DictionaryQueryCondition, DictionaryQueryEntry as DictionaryV1QueryEntry } from '@subql/types-core';
|
|
3
3
|
import { SubqlDatasource, SubqlEthereumProcessorOptions } from '@subql/types-ethereum';
|
|
4
4
|
import { EthereumProjectDs, EthereumProjectDsTemplate, SubqueryProject } from '../../../configure/SubqueryProject';
|
|
5
|
-
export declare function appendDsOptions(dsOptions: SubqlEthereumProcessorOptions | SubqlEthereumProcessorOptions[], conditions: DictionaryQueryCondition[]): void;
|
|
5
|
+
export declare function appendDsOptions(dsOptions: SubqlEthereumProcessorOptions | SubqlEthereumProcessorOptions[] | undefined, conditions: DictionaryQueryCondition[]): void;
|
|
6
6
|
export type GroupedEthereumProjectDs = SubqlDatasource & {
|
|
7
7
|
groupedOptions?: SubqlEthereumProcessorOptions[];
|
|
8
8
|
};
|
|
9
9
|
export declare function buildDictionaryV1QueryEntries(dataSources: GroupedEthereumProjectDs[]): DictionaryV1QueryEntry[];
|
|
10
10
|
export declare class EthDictionaryV1 extends DictionaryV1<GroupedEthereumProjectDs> {
|
|
11
11
|
private constructor();
|
|
12
|
-
static create(project: SubqueryProject, nodeConfig: NodeConfig, dictionaryUrl
|
|
12
|
+
static create(project: SubqueryProject, nodeConfig: NodeConfig, dictionaryUrl: string): Promise<EthDictionaryV1>;
|
|
13
13
|
private static getEvmChainId;
|
|
14
14
|
buildDictionaryQueryEntries(dataSources: (EthereumProjectDs | EthereumProjectDsTemplate)[]): DictionaryV1QueryEntry[];
|
|
15
15
|
}
|
|
@@ -19,7 +19,9 @@ const logger = (0, node_core_1.getLogger)('dictionary-v1');
|
|
|
19
19
|
function appendDsOptions(dsOptions, conditions) {
|
|
20
20
|
const queryAddressLimit = yargs_1.yargsOptions.argv['query-address-limit'];
|
|
21
21
|
if (Array.isArray(dsOptions)) {
|
|
22
|
-
const addresses = dsOptions
|
|
22
|
+
const addresses = dsOptions
|
|
23
|
+
.map((option) => option.address)
|
|
24
|
+
.filter((v) => Boolean(v));
|
|
23
25
|
if (addresses.length > queryAddressLimit) {
|
|
24
26
|
logger.debug(`Addresses length: ${addresses.length} is exceeding limit: ${queryAddressLimit}. Consider increasing this value with the flag --query-address-limit `);
|
|
25
27
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ethDictionaryV1.js","sourceRoot":"","sources":["../../../../src/indexer/dictionary/v1/ethDictionaryV1.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;;;;;AAEnC,gDAAuE;AAKvE,0DAO+B;AAC/B,kDAA0B;AAC1B,mCAAwC;AACxC,4DAA+B;AAM/B,kDAAwE;AACxE,0CAA8C;AAC9C,oCAAuC;AAEvC,MAAM,iBAAiB,GACrB,8EAA8E,CAAC;AAEjF,MAAM,MAAM,GAAG,IAAA,qBAAS,EAAC,eAAe,CAAC,CAAC;AAE1C,SAAgB,eAAe,CAC7B,SAA0E,EAC1E,UAAsC;IAEtC,MAAM,iBAAiB,GAAG,oBAAY,CAAC,IAAI,CAAC,qBAAqB,CAAC,CAAC;IACnE,IAAI,KAAK,CAAC,OAAO,CAAC,SAAS,CAAC,EAAE;QAC5B,MAAM,SAAS,GAAG,SAAS,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;QAE5E,IAAI,SAAS,CAAC,MAAM,GAAG,iBAAiB,EAAE;YACxC,MAAM,CAAC,KAAK,CACV,qBAAqB,SAAS,CAAC,MAAM,wBAAwB,iBAAiB,wEAAwE,CACvJ,CAAC;SACH;QAED,IAAI,SAAS,CAAC,MAAM,KAAK,CAAC,IAAI,SAAS,CAAC,MAAM,IAAI,iBAAiB,EAAE;YACnE,UAAU,CAAC,IAAI,CAAC;gBACd,KAAK,EAAE,SAAS;gBAChB,KAAK,EAAE,SAAS;gBAChB,OAAO,EAAE,IAAI;aACd,CAAC,CAAC;SACJ;KACF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AAK,CAAC,aAAa;QAChC,MAAM,QAAQ,GAAG,MAAM,IAAA,oBAAK,EAAC,iBAAiB,CAAC,CAAC;QAEhD,MAAM,GAAG,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;QAClC,wDAAwD;QACxD,OAAO,eAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAC1B,CAAC;IAED,2BAA2B;IACzB,oDAAoD;IACpD,WAA8D;QAE9D,MAAM,UAAU,GAAG,IAAA,mBAAW,EAAC,WAAW,CAAC,CAAC;QAC5C,OAAO,6BAA6B,CAAC,UAAU,CAAC,CAAC;IACnD,CAAC;CACF;AA/CD,0CA+CC","sourcesContent":["// Copyright 2020-2024 SubQuery Pte Ltd authors & contributors\n// SPDX-License-Identifier: GPL-3.0\n\nimport { NodeConfig, DictionaryV1, getLogger } from '@subql/node-core';\nimport {\n DictionaryQueryCondition,\n DictionaryQueryEntry as DictionaryV1QueryEntry,\n} from '@subql/types-core';\nimport {\n EthereumBlockFilter,\n EthereumHandlerKind,\n EthereumLogFilter,\n EthereumTransactionFilter,\n SubqlDatasource,\n SubqlEthereumProcessorOptions,\n} from '@subql/types-ethereum';\nimport JSON5 from 'json5';\nimport { sortBy, uniqBy } from 'lodash';\nimport fetch from 'node-fetch';\nimport {\n EthereumProjectDs,\n EthereumProjectDsTemplate,\n SubqueryProject,\n} from '../../../configure/SubqueryProject';\nimport { eventToTopic, functionToSighash } from '../../../utils/string';\nimport { yargsOptions } from '../../../yargs';\nimport { ethFilterDs } from '../utils';\n\nconst CHAIN_ALIASES_URL =\n 'https://raw.githubusercontent.com/subquery/templates/main/chainAliases.json5';\n\nconst logger = getLogger('dictionary-v1');\n\nexport function appendDsOptions(\n dsOptions: SubqlEthereumProcessorOptions | SubqlEthereumProcessorOptions[],\n conditions: DictionaryQueryCondition[],\n): void {\n const queryAddressLimit = yargsOptions.argv['query-address-limit'];\n if (Array.isArray(dsOptions)) {\n const addresses = dsOptions.map((option) => option.address).filter(Boolean);\n\n if (addresses.length > queryAddressLimit) {\n logger.debug(\n `Addresses length: ${addresses.length} is exceeding limit: ${queryAddressLimit}. Consider increasing this value with the flag --query-address-limit `,\n );\n }\n\n if (addresses.length !== 0 && addresses.length <= queryAddressLimit) {\n conditions.push({\n field: 'address',\n value: addresses,\n matcher: 'in',\n });\n }\n } else {\n if (dsOptions?.address) {\n conditions.push({\n field: 'address',\n value: dsOptions.address.toLowerCase(),\n matcher: 'equalTo',\n });\n }\n }\n}\n\nfunction eventFilterToQueryEntry(\n filter: EthereumLogFilter,\n dsOptions: SubqlEthereumProcessorOptions | SubqlEthereumProcessorOptions[],\n): DictionaryV1QueryEntry {\n const conditions: DictionaryQueryCondition[] = [];\n appendDsOptions(dsOptions, conditions);\n if (filter.topics) {\n for (let i = 0; i < Math.min(filter.topics.length, 4); i++) {\n const topic = filter.topics[i];\n if (!topic) {\n continue;\n }\n const field = `topics${i}`;\n\n if (topic === '!null') {\n conditions.push({\n field,\n value: false as any, // TODO update types to allow boolean\n matcher: 'isNull',\n });\n } else {\n conditions.push({\n field,\n value: eventToTopic(topic),\n matcher: 'equalTo',\n });\n }\n }\n }\n return {\n entity: 'evmLogs',\n conditions,\n };\n}\n\nfunction callFilterToQueryEntry(\n filter: EthereumTransactionFilter,\n dsOptions: SubqlEthereumProcessorOptions | SubqlEthereumProcessorOptions[],\n): DictionaryV1QueryEntry {\n const conditions: DictionaryQueryCondition[] = [];\n appendDsOptions(dsOptions, conditions);\n\n for (const condition of conditions) {\n if (condition.field === 'address') {\n condition.field = 'to';\n }\n }\n if (filter.from) {\n conditions.push({\n field: 'from',\n value: filter.from.toLowerCase(),\n matcher: 'equalTo',\n });\n }\n const optionsAddresses = conditions.find((c) => c.field === 'to');\n if (!optionsAddresses) {\n if (filter.to) {\n conditions.push({\n field: 'to',\n value: filter.to.toLowerCase(),\n matcher: 'equalTo',\n });\n } else if (filter.to === null) {\n conditions.push({\n field: 'to',\n value: true as any, // TODO update types to allow boolean\n matcher: 'isNull',\n });\n }\n } else if (optionsAddresses && (filter.to || filter.to === null)) {\n logger.warn(\n `TransactionFilter 'to' conflict with 'address' in data source options`,\n );\n }\n\n if (filter.function === null || filter.function === '0x') {\n conditions.push({\n field: 'func',\n value: true,\n matcher: 'isNull',\n });\n } else if (filter.function) {\n conditions.push({\n field: 'func',\n value: functionToSighash(filter.function),\n matcher: 'equalTo',\n });\n }\n return {\n entity: 'evmTransactions',\n conditions,\n };\n}\n\nexport type GroupedEthereumProjectDs = SubqlDatasource & {\n groupedOptions?: SubqlEthereumProcessorOptions[];\n};\n\nexport function buildDictionaryV1QueryEntries(\n dataSources: GroupedEthereumProjectDs[],\n): DictionaryV1QueryEntry[] {\n const queryEntries: DictionaryV1QueryEntry[] = [];\n\n for (const ds of dataSources) {\n for (const handler of ds.mapping.handlers) {\n // No filters, cant use dictionary\n if (!handler.filter) return [];\n\n switch (handler.kind) {\n case EthereumHandlerKind.Block:\n if (handler.filter.modulo === undefined) {\n return [];\n }\n break;\n case EthereumHandlerKind.Call: {\n const filter = handler.filter as EthereumTransactionFilter;\n if (\n filter.from !== undefined ||\n filter.to !== undefined ||\n filter.function !== undefined\n ) {\n queryEntries.push(callFilterToQueryEntry(filter, ds.options));\n } else {\n return [];\n }\n break;\n }\n case EthereumHandlerKind.Event: {\n const filter = handler.filter as EthereumLogFilter;\n if (ds.groupedOptions) {\n queryEntries.push(\n eventFilterToQueryEntry(filter, ds.groupedOptions),\n );\n } else if (ds.options?.address || filter.topics) {\n queryEntries.push(eventFilterToQueryEntry(filter, ds.options));\n } else {\n return [];\n }\n break;\n }\n default:\n }\n }\n }\n\n return uniqBy(\n queryEntries,\n (item) =>\n `${item.entity}|${JSON.stringify(\n sortBy(item.conditions, (c) => c.field),\n )}`,\n );\n}\n\nexport class EthDictionaryV1 extends DictionaryV1<GroupedEthereumProjectDs> {\n private constructor(\n project: SubqueryProject,\n nodeConfig: NodeConfig,\n dictionaryUrl: string,\n chainId?: string,\n ) {\n super(dictionaryUrl, chainId ?? project.network.chainId, nodeConfig);\n }\n\n static async create(\n project: SubqueryProject,\n nodeConfig: NodeConfig,\n dictionaryUrl?: string,\n ): Promise<EthDictionaryV1> {\n /*Some dictionarys for EVM are built with other SDKs as they are chains with an EVM runtime\n * we maintain a list of aliases so we can map the evmChainId to the genesis hash of the other SDKs\n * e.g moonbeam is built with Substrate SDK but can be used as an EVM dictionary\n */\n const chainAliases = await this.getEvmChainId();\n const chainAlias = chainAliases[project.network.chainId];\n\n const dictionary = new EthDictionaryV1(\n project,\n nodeConfig,\n dictionaryUrl,\n chainAlias,\n );\n await dictionary.init();\n return dictionary;\n }\n\n private static async getEvmChainId(): Promise<Record<string, string>> {\n const response = await fetch(CHAIN_ALIASES_URL);\n\n const raw = await response.text();\n // We use JSON5 here because the file has comments in it\n return JSON5.parse(raw);\n }\n\n buildDictionaryQueryEntries(\n // Add name to datasource as templates have this set\n dataSources: (EthereumProjectDs | EthereumProjectDsTemplate)[],\n ): DictionaryV1QueryEntry[] {\n const filteredDs = ethFilterDs(dataSources);\n return buildDictionaryV1QueryEntries(filteredDs);\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"ethDictionaryV1.js","sourceRoot":"","sources":["../../../../src/indexer/dictionary/v1/ethDictionaryV1.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;;;;;AAEnC,gDAAuE;AAKvE,0DAM+B;AAC/B,kDAA0B;AAC1B,mCAAwC;AACxC,4DAA+B;AAM/B,kDAAwE;AACxE,0CAA8C;AAC9C,oCAAuC;AAEvC,MAAM,iBAAiB,GACrB,8EAA8E,CAAC;AAEjF,MAAM,MAAM,GAAG,IAAA,qBAAS,EAAC,eAAe,CAAC,CAAC;AAE1C,SAAgB,eAAe,CAC7B,SAGa,EACb,UAAsC;IAEtC,MAAM,iBAAiB,GAAG,oBAAY,CAAC,IAAI,CAAC,qBAAqB,CAAC,CAAC;IACnE,IAAI,KAAK,CAAC,OAAO,CAAC,SAAS,CAAC,EAAE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AsB,EACtB,aAAqB,EACrB,OAAgB;QAEhB,KAAK,CAAC,aAAa,EAAE,OAAO,IAAI,OAAO,CAAC,OAAO,CAAC,OAAO,EAAE,UAAU,CAAC,CAAC;IACvE,CAAC;IAED,MAAM,CAAC,KAAK,CAAC,MAAM,CACjB,OAAwB,EACxB,UAAsB,EACtB,aAAqB;QAErB;;;WAGG;QACH,MAAM,YAAY,GAAG,MAAM,IAAI,CAAC,aAAa,EAAE,CAAC;QAChD,MAAM,UAAU,GAAG,YAAY,CAAC,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;QAEzD,MAAM,UAAU,GAAG,IAAI,eAAe,CACpC,OAAO,EACP,UAAU,EACV,aAAa,EACb,UAAU,CACX,CAAC;QACF,MAAM,UAAU,CAAC,IAAI,EAAE,CAAC;QACxB,OAAO,UAAU,CAAC;IACpB,CAAC;IAEO,MAAM,CAAC,KAAK,CAAC,aAAa;QAChC,MAAM,QAAQ,GAAG,MAAM,IAAA,oBAAK,EAAC,iBAAiB,CAAC,CAAC;QAEhD,MAAM,GAAG,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;QAClC,wDAAwD;QACxD,OAAO,eAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAC1B,CAAC;IAED,2BAA2B;IACzB,oDAAoD;IACpD,WAA8D;QAE9D,MAAM,UAAU,GAAG,IAAA,mBAAW,EAAC,WAAW,CAAC,CAAC;QAC5C,OAAO,6BAA6B,CAAC,UAAU,CAAC,CAAC;IACnD,CAAC;CACF;AA/CD,0CA+CC","sourcesContent":["// Copyright 2020-2024 SubQuery Pte Ltd authors & contributors\n// SPDX-License-Identifier: GPL-3.0\n\nimport { NodeConfig, DictionaryV1, getLogger } from '@subql/node-core';\nimport {\n DictionaryQueryCondition,\n DictionaryQueryEntry as DictionaryV1QueryEntry,\n} from '@subql/types-core';\nimport {\n EthereumHandlerKind,\n EthereumLogFilter,\n EthereumTransactionFilter,\n SubqlDatasource,\n SubqlEthereumProcessorOptions,\n} from '@subql/types-ethereum';\nimport JSON5 from 'json5';\nimport { sortBy, uniqBy } from 'lodash';\nimport fetch from 'node-fetch';\nimport {\n EthereumProjectDs,\n EthereumProjectDsTemplate,\n SubqueryProject,\n} from '../../../configure/SubqueryProject';\nimport { eventToTopic, functionToSighash } from '../../../utils/string';\nimport { yargsOptions } from '../../../yargs';\nimport { ethFilterDs } from '../utils';\n\nconst CHAIN_ALIASES_URL =\n 'https://raw.githubusercontent.com/subquery/templates/main/chainAliases.json5';\n\nconst logger = getLogger('dictionary-v1');\n\nexport function appendDsOptions(\n dsOptions:\n | SubqlEthereumProcessorOptions\n | SubqlEthereumProcessorOptions[]\n | undefined,\n conditions: DictionaryQueryCondition[],\n): void {\n const queryAddressLimit = yargsOptions.argv['query-address-limit'];\n if (Array.isArray(dsOptions)) {\n const addresses = dsOptions\n .map((option) => option.address)\n .filter((v): v is string => Boolean(v));\n\n if (addresses.length > queryAddressLimit) {\n logger.debug(\n `Addresses length: ${addresses.length} is exceeding limit: ${queryAddressLimit}. Consider increasing this value with the flag --query-address-limit `,\n );\n }\n\n if (addresses.length !== 0 && addresses.length <= queryAddressLimit) {\n conditions.push({\n field: 'address',\n value: addresses,\n matcher: 'in',\n });\n }\n } else {\n if (dsOptions?.address) {\n conditions.push({\n field: 'address',\n value: dsOptions.address.toLowerCase(),\n matcher: 'equalTo',\n });\n }\n }\n}\n\nfunction eventFilterToQueryEntry(\n filter: EthereumLogFilter,\n dsOptions?: SubqlEthereumProcessorOptions | SubqlEthereumProcessorOptions[],\n): DictionaryV1QueryEntry {\n const conditions: DictionaryQueryCondition[] = [];\n appendDsOptions(dsOptions, conditions);\n if (filter.topics) {\n for (let i = 0; i < Math.min(filter.topics.length, 4); i++) {\n const topic = filter.topics[i];\n if (!topic) {\n continue;\n }\n const field = `topics${i}`;\n\n if (topic === '!null') {\n conditions.push({\n field,\n value: false as any, // TODO update types to allow boolean\n matcher: 'isNull',\n });\n } else {\n conditions.push({\n field,\n value: eventToTopic(topic),\n matcher: 'equalTo',\n });\n }\n }\n }\n return {\n entity: 'evmLogs',\n conditions,\n };\n}\n\nfunction callFilterToQueryEntry(\n filter: EthereumTransactionFilter,\n dsOptions?: SubqlEthereumProcessorOptions | SubqlEthereumProcessorOptions[],\n): DictionaryV1QueryEntry {\n const conditions: DictionaryQueryCondition[] = [];\n appendDsOptions(dsOptions, conditions);\n\n for (const condition of conditions) {\n if (condition.field === 'address') {\n condition.field = 'to';\n }\n }\n if (filter.from) {\n conditions.push({\n field: 'from',\n value: filter.from.toLowerCase(),\n matcher: 'equalTo',\n });\n }\n const optionsAddresses = conditions.find((c) => c.field === 'to');\n if (!optionsAddresses) {\n if (filter.to) {\n conditions.push({\n field: 'to',\n value: filter.to.toLowerCase(),\n matcher: 'equalTo',\n });\n } else if (filter.to === null) {\n conditions.push({\n field: 'to',\n value: true as any, // TODO update types to allow boolean\n matcher: 'isNull',\n });\n }\n } else if (optionsAddresses && (filter.to || filter.to === null)) {\n logger.warn(\n `TransactionFilter 'to' conflict with 'address' in data source options`,\n );\n }\n\n if (filter.function === null || filter.function === '0x') {\n conditions.push({\n field: 'func',\n value: true,\n matcher: 'isNull',\n });\n } else if (filter.function) {\n conditions.push({\n field: 'func',\n value: functionToSighash(filter.function),\n matcher: 'equalTo',\n });\n }\n return {\n entity: 'evmTransactions',\n conditions,\n };\n}\n\nexport type GroupedEthereumProjectDs = SubqlDatasource & {\n groupedOptions?: SubqlEthereumProcessorOptions[];\n};\n\nexport function buildDictionaryV1QueryEntries(\n dataSources: GroupedEthereumProjectDs[],\n): DictionaryV1QueryEntry[] {\n const queryEntries: DictionaryV1QueryEntry[] = [];\n\n for (const ds of dataSources) {\n for (const handler of ds.mapping.handlers) {\n // No filters, cant use dictionary\n if (!handler.filter) return [];\n\n switch (handler.kind) {\n case EthereumHandlerKind.Block:\n if (handler.filter.modulo === undefined) {\n return [];\n }\n break;\n case EthereumHandlerKind.Call: {\n const filter = handler.filter as EthereumTransactionFilter;\n if (\n filter.from !== undefined ||\n filter.to !== undefined ||\n filter.function !== undefined\n ) {\n queryEntries.push(callFilterToQueryEntry(filter, ds.options));\n } else {\n return [];\n }\n break;\n }\n case EthereumHandlerKind.Event: {\n const filter = handler.filter as EthereumLogFilter;\n if (ds.groupedOptions) {\n queryEntries.push(\n eventFilterToQueryEntry(filter, ds.groupedOptions),\n );\n } else if (ds.options?.address || filter.topics) {\n queryEntries.push(eventFilterToQueryEntry(filter, ds.options));\n } else {\n return [];\n }\n break;\n }\n default:\n }\n }\n }\n\n return uniqBy(\n queryEntries,\n (item) =>\n `${item.entity}|${JSON.stringify(\n sortBy(item.conditions, (c) => c.field),\n )}`,\n );\n}\n\nexport class EthDictionaryV1 extends DictionaryV1<GroupedEthereumProjectDs> {\n private constructor(\n project: SubqueryProject,\n nodeConfig: NodeConfig,\n dictionaryUrl: string,\n chainId?: string,\n ) {\n super(dictionaryUrl, chainId ?? project.network.chainId, nodeConfig);\n }\n\n static async create(\n project: SubqueryProject,\n nodeConfig: NodeConfig,\n dictionaryUrl: string,\n ): Promise<EthDictionaryV1> {\n /*Some dictionarys for EVM are built with other SDKs as they are chains with an EVM runtime\n * we maintain a list of aliases so we can map the evmChainId to the genesis hash of the other SDKs\n * e.g moonbeam is built with Substrate SDK but can be used as an EVM dictionary\n */\n const chainAliases = await this.getEvmChainId();\n const chainAlias = chainAliases[project.network.chainId];\n\n const dictionary = new EthDictionaryV1(\n project,\n nodeConfig,\n dictionaryUrl,\n chainAlias,\n );\n await dictionary.init();\n return dictionary;\n }\n\n private static async getEvmChainId(): Promise<Record<string, string>> {\n const response = await fetch(CHAIN_ALIASES_URL);\n\n const raw = await response.text();\n // We use JSON5 here because the file has comments in it\n return JSON5.parse(raw);\n }\n\n buildDictionaryQueryEntries(\n // Add name to datasource as templates have this set\n dataSources: (EthereumProjectDs | EthereumProjectDsTemplate)[],\n ): DictionaryV1QueryEntry[] {\n const filteredDs = ethFilterDs(dataSources);\n return buildDictionaryV1QueryEntries(filteredDs);\n }\n}\n"]}
|
|
@@ -62,7 +62,7 @@ describe('Eth Dictionary V1', () => {
|
|
|
62
62
|
ethDictionaryV1_1.EthDictionaryV1.prototype.init = jest.fn();
|
|
63
63
|
const dictionary = await ethDictionaryV1_1.EthDictionaryV1.create({
|
|
64
64
|
network: { chainId: '336', dictionary: 'https://foo.bar' },
|
|
65
|
-
}, new node_core_1.NodeConfig({}, true),
|
|
65
|
+
}, new node_core_1.NodeConfig({}, true), '');
|
|
66
66
|
expect(dictionary.chainId).toBe('0xf1cf9022c7ebb34b162d5b5e34e705a5a740b2d0ecc1009fb89023e62a488108');
|
|
67
67
|
jest.clearAllMocks();
|
|
68
68
|
});
|