@subql/node-ethereum 4.3.2 → 4.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 +6 -1
- package/dist/.tsbuildinfo +1 -1
- package/dist/admin/admin.module.d.ts +2 -0
- package/dist/admin/admin.module.js +25 -0
- package/dist/admin/admin.module.js.map +1 -0
- package/dist/app.module.js +2 -0
- package/dist/app.module.js.map +1 -1
- package/dist/configure/SubqueryProject.js +15 -18
- package/dist/configure/SubqueryProject.js.map +1 -1
- package/dist/ethereum/api.connection.js +4 -1
- package/dist/ethereum/api.connection.js.map +1 -1
- package/dist/ethereum/api.ethereum.js +26 -11
- package/dist/ethereum/api.ethereum.js.map +1 -1
- package/dist/ethereum/api.service.ethereum.js +7 -6
- package/dist/ethereum/api.service.ethereum.js.map +1 -1
- package/dist/ethereum/api.service.ethereum.test.js +1 -1
- package/dist/ethereum/api.service.ethereum.test.js.map +1 -1
- package/dist/ethereum/block.ethereum.js +1 -1
- package/dist/ethereum/block.ethereum.js.map +1 -1
- package/dist/ethereum/ethers/celo/celo-provider.js +15 -20
- package/dist/ethereum/ethers/celo/celo-provider.js.map +1 -1
- package/dist/ethereum/ethers/celo/celo-ws-provider.spec.js +1 -1
- package/dist/ethereum/ethers/celo/celo-ws-provider.spec.js.map +1 -1
- package/dist/ethereum/ethers/json-rpc-batch-provider.js +9 -9
- package/dist/ethereum/ethers/json-rpc-batch-provider.js.map +1 -1
- package/dist/ethereum/ethers/json-rpc-batch-provider.spec.js +1 -1
- package/dist/ethereum/ethers/json-rpc-batch-provider.spec.js.map +1 -1
- package/dist/ethereum/ethers/op/op-provider.js +7 -1
- package/dist/ethereum/ethers/op/op-provider.js.map +1 -1
- package/dist/ethereum/ethers/web/geturl.js +2 -3
- package/dist/ethereum/ethers/web/geturl.js.map +1 -1
- package/dist/ethereum/safe-api.js +3 -0
- package/dist/ethereum/safe-api.js.map +1 -1
- package/dist/ethereum/utils.ethereum.js +58 -13
- package/dist/ethereum/utils.ethereum.js.map +1 -1
- package/dist/indexer/blockDispatcher/block-dispatcher.service.js +1 -0
- package/dist/indexer/blockDispatcher/block-dispatcher.service.js.map +1 -1
- package/dist/indexer/blockDispatcher/worker-block-dispatcher.service.d.ts +2 -2
- package/dist/indexer/blockDispatcher/worker-block-dispatcher.service.js +3 -3
- package/dist/indexer/blockDispatcher/worker-block-dispatcher.service.js.map +1 -1
- package/dist/indexer/dictionary/ethDictionary.service.js +2 -0
- package/dist/indexer/dictionary/ethDictionary.service.js.map +1 -1
- package/dist/indexer/dictionary/utils.js +5 -2
- package/dist/indexer/dictionary/utils.js.map +1 -1
- package/dist/indexer/dictionary/utils.spec.js +3 -3
- package/dist/indexer/dictionary/utils.spec.js.map +1 -1
- package/dist/indexer/dictionary/v1/ethDictionaryV1.js +3 -4
- package/dist/indexer/dictionary/v1/ethDictionaryV1.js.map +1 -1
- package/dist/indexer/dictionary/v1/ethDictionaryV1.spec.js +3 -3
- package/dist/indexer/dictionary/v1/ethDictionaryV1.spec.js.map +1 -1
- package/dist/indexer/dictionary/v2/ethDictionaryV2.js +7 -20
- package/dist/indexer/dictionary/v2/ethDictionaryV2.js.map +1 -1
- package/dist/indexer/dictionary/v2/utils.js +12 -6
- package/dist/indexer/dictionary/v2/utils.js.map +1 -1
- package/dist/indexer/dictionary/v2/utils.spec.js +4 -15
- package/dist/indexer/dictionary/v2/utils.spec.js.map +1 -1
- package/dist/indexer/ds-processor.service.js +1 -4
- package/dist/indexer/ds-processor.service.js.map +1 -1
- package/dist/indexer/dynamic-ds.service.js +9 -2
- package/dist/indexer/dynamic-ds.service.js.map +1 -1
- package/dist/indexer/fetch.module.js +5 -3
- package/dist/indexer/fetch.module.js.map +1 -1
- package/dist/indexer/fetch.service.js +2 -0
- package/dist/indexer/fetch.service.js.map +1 -1
- package/dist/indexer/indexer.manager.js +7 -8
- package/dist/indexer/indexer.manager.js.map +1 -1
- package/dist/indexer/project.service.js +1 -1
- package/dist/indexer/project.service.js.map +1 -1
- package/dist/indexer/unfinalizedBlocks.service.js +3 -1
- package/dist/indexer/unfinalizedBlocks.service.js.map +1 -1
- package/dist/indexer/worker/worker-fetch.module.js +4 -0
- package/dist/indexer/worker/worker-fetch.module.js.map +1 -1
- package/dist/indexer/worker/worker.service.js +2 -0
- package/dist/indexer/worker/worker.service.js.map +1 -1
- package/dist/init.js +3 -6
- package/dist/init.js.map +1 -1
- package/dist/meta/meta.controller.js +1 -0
- package/dist/meta/meta.controller.js.map +1 -1
- package/dist/meta/meta.service.js +11 -9
- package/dist/meta/meta.service.js.map +1 -1
- package/dist/subcommands/testing.init.js +1 -2
- package/dist/subcommands/testing.init.js.map +1 -1
- package/dist/utils/project.js +1 -1
- package/dist/utils/project.js.map +1 -1
- package/dist/utils/string.js +1 -1
- package/dist/utils/string.js.map +1 -1
- package/package.json +3 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"block.ethereum.js","sourceRoot":"","sources":["../../src/ethereum/block.ethereum.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;;AAEnC,gDAAmE;AAYnE,4CAKyB;AAEzB,MAAM,MAAM,GAAG,IAAA,qBAAS,EAAC,gBAAgB,CAAC,CAAC;AAE3C,SAAgB,qBAAqB,CACnC,KAAoB,EACpB,MAA2B,EAC3B,OAAgB;IAEhB,IAAI,
|
|
1
|
+
{"version":3,"file":"block.ethereum.js","sourceRoot":"","sources":["../../src/ethereum/block.ethereum.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;;AAEnC,gDAAmE;AAYnE,4CAKyB;AAEzB,MAAM,MAAM,GAAG,IAAA,qBAAS,EAAC,gBAAgB,CAAC,CAAC;AAE3C,SAAgB,qBAAqB,CACnC,KAAoB,EACpB,MAA2B,EAC3B,OAAgB;IAEhB,IAAI,MAAM,EAAE,MAAM,IAAI,KAAK,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,KAAK,CAAC,EA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Q,CAAC;KACrE;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AARD,kCAQC","sourcesContent":["// Copyright 2020-2024 SubQuery Pte Ltd authors & contributors\n// SPDX-License-Identifier: GPL-3.0\n\nimport { filterBlockTimestamp, getLogger } from '@subql/node-core';\nimport {\n EthereumBlock,\n EthereumTransactionFilter,\n EthereumLog,\n EthereumLogFilter,\n EthereumBlockFilter,\n EthereumTransaction,\n LightEthereumLog,\n} from '@subql/types-ethereum';\nimport { SubqlProjectBlockFilter } from '../configure/SubqueryProject';\nimport { BlockContent } from '../indexer/types';\nimport {\n eventToTopic,\n functionToSighash,\n hexStringEq,\n stringNormalizedEq,\n} from '../utils/string';\n\nconst logger = getLogger('block.ethereum');\n\nexport function filterBlocksProcessor(\n block: EthereumBlock,\n filter: EthereumBlockFilter,\n address?: string,\n): boolean {\n if (filter?.modulo && block.number % filter.modulo !== 0) {\n return false;\n }\n // Multiply to add MS\n if (\n !filterBlockTimestamp(\n Number(block.timestamp) * 1000,\n filter as SubqlProjectBlockFilter,\n )\n ) {\n return false;\n }\n return true;\n}\n\nexport function filterTransactionsProcessor(\n transaction: EthereumTransaction,\n filter: EthereumTransactionFilter,\n address?: string,\n): boolean {\n if (!filter) return true;\n\n if (\n filter.to === null &&\n !(transaction.to === null || transaction.to === undefined)\n ) {\n return false;\n }\n\n if (filter.to && !stringNormalizedEq(filter.to, transaction.to)) {\n return false;\n }\n if (filter.from && !stringNormalizedEq(filter.from, transaction.from)) {\n return false;\n }\n if (\n address &&\n filter.to === undefined &&\n !stringNormalizedEq(address, transaction.to)\n ) {\n return false;\n }\n if (filter.function === null || filter.function === '0x') {\n if (transaction.input !== '0x') {\n return false;\n }\n } else if (\n filter.function !== undefined &&\n transaction.input.indexOf(functionToSighash(filter.function)) !== 0\n ) {\n return false;\n }\n\n return true;\n}\n\nexport function filterLogsProcessor(\n log: EthereumLog | LightEthereumLog,\n filter: EthereumLogFilter,\n address?: string,\n): boolean {\n if (address && !stringNormalizedEq(address, log.address)) {\n return false;\n }\n\n if (!filter) return true;\n\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\n if (!log.topics[i]) {\n return false;\n }\n\n if (topic === '!null') {\n return true;\n }\n\n if (!hexStringEq(eventToTopic(topic), log.topics[i])) {\n return false;\n }\n }\n }\n return true;\n}\n\nexport function isFullBlock(block: BlockContent): block is EthereumBlock {\n // Light etherum block just contains transaction hashes for transactions.\n // If the block has no transactions then both types would be the same\n\n if (block.transactions.length && block.logs.length) {\n return typeof (block as EthereumBlock).transactions[0] !== 'string';\n }\n return false;\n}\n"]}
|
|
@@ -1,11 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
// Copyright 2020-2024 SubQuery Pte Ltd authors & contributors
|
|
3
3
|
// SPDX-License-Identifier: GPL-3.0
|
|
4
|
-
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
5
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
6
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
7
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
8
|
-
};
|
|
9
4
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
5
|
exports.CeloJsonRpcBatchProvider = exports.CeloJsonRpcProvider = exports.CeloWsProvider = void 0;
|
|
11
6
|
const providers_1 = require("@ethersproject/providers");
|
|
@@ -13,21 +8,21 @@ const ethers_1 = require("ethers");
|
|
|
13
8
|
const json_rpc_batch_provider_1 = require("../json-rpc-batch-provider");
|
|
14
9
|
const json_rpc_provider_1 = require("../json-rpc-provider");
|
|
15
10
|
function CeloBlockFormatterMixin(Base) {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
11
|
+
return class CeloProvider extends Base {
|
|
12
|
+
#flanHardForkBlock = ethers_1.BigNumber.from('16068685');
|
|
13
|
+
constructor(...args) {
|
|
14
|
+
super(...args);
|
|
15
|
+
const originalBlockFormatter = this.formatter._block;
|
|
16
|
+
this.formatter._block = (value, format) => {
|
|
17
|
+
return originalBlockFormatter({
|
|
18
|
+
gasLimit: ethers_1.BigNumber.from(value.number) < this.#flanHardForkBlock
|
|
19
|
+
? ethers_1.constants.Zero
|
|
20
|
+
: value.gasLimit,
|
|
21
|
+
...value,
|
|
22
|
+
}, format);
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
};
|
|
31
26
|
}
|
|
32
27
|
exports.CeloWsProvider = CeloBlockFormatterMixin(providers_1.WebSocketProvider);
|
|
33
28
|
exports.CeloJsonRpcProvider = CeloBlockFormatterMixin(json_rpc_provider_1.JsonRpcProvider);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"celo-provider.js","sourceRoot":"","sources":["../../../../src/ethereum/ethers/celo/celo-provider.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC
|
|
1
|
+
{"version":3,"file":"celo-provider.js","sourceRoot":"","sources":["../../../../src/ethereum/ethers/celo/celo-provider.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;;AAEnC,wDAA2E;AAC3E,mCAA8C;AAC9C,wEAAkE;AAClE,4DAAuD;AAIvD,SAAS,uBAAuB,CAAwB,IAAO;IAC7D,OAAO,MAAM,YAAa,SAAQ,IAAI;QACpC,kBAAkB,GAAG,kBAAS,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;QAEhD,YAAY,GAAG,IAAW;YACxB,KAAK,CAAC,GAAG,IAAI,CAAC,CAAC;YAEf,MAAM,sBAAsB,GAAG,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC;YACrD,IAAI,CAAC,SAAS,CAAC,MAAM,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE;gBACxC,OAAO,sBAAsB,CAC3B;oBACE,QAAQ,EACN,kBAAS,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,GAAG,IAAI,CAAC,kBAAkB;wBACpD,CAAC,CAAC,kBAAS,CAAC,IAAI;wBAChB,CAAC,CAAC,KAAK,CAAC,QAAQ;oBACpB,GAAG,KAAK;iBACT,EACD,MAAM,CACP,CAAC;YACJ,CAAC,CAAC;QACJ,CAAC;KACF,CAAC;AACJ,CAAC;AAEY,QAAA,cAAc,GAAG,uBAAuB,CAAC,6BAAiB,CAAC,CAAC;AAC5D,QAAA,mBAAmB,GAAG,uBAAuB,CAAC,mCAAe,CAAC,CAAC;AAC/D,QAAA,wBAAwB,GACnC,uBAAuB,CAAC,8CAAoB,CAAC,CAAC","sourcesContent":["// Copyright 2020-2024 SubQuery Pte Ltd authors & contributors\n// SPDX-License-Identifier: GPL-3.0\n\nimport { WebSocketProvider, BaseProvider } from '@ethersproject/providers';\nimport { BigNumber, constants } from 'ethers';\nimport { JsonRpcBatchProvider } from '../json-rpc-batch-provider';\nimport { JsonRpcProvider } from '../json-rpc-provider';\n\n/* This mixin replaces the block formatter on any provider with specific celo changes */\ntype Constructor = new (...args: any[]) => BaseProvider;\nfunction CeloBlockFormatterMixin<B extends Constructor>(Base: B) {\n return class CeloProvider extends Base {\n #flanHardForkBlock = BigNumber.from('16068685');\n\n constructor(...args: any[]) {\n super(...args);\n\n const originalBlockFormatter = this.formatter._block;\n this.formatter._block = (value, format) => {\n return originalBlockFormatter(\n {\n gasLimit:\n BigNumber.from(value.number) < this.#flanHardForkBlock\n ? constants.Zero\n : value.gasLimit,\n ...value,\n },\n format,\n );\n };\n }\n };\n}\n\nexport const CeloWsProvider = CeloBlockFormatterMixin(WebSocketProvider);\nexport const CeloJsonRpcProvider = CeloBlockFormatterMixin(JsonRpcProvider);\nexport const CeloJsonRpcBatchProvider =\n CeloBlockFormatterMixin(JsonRpcBatchProvider);\n"]}
|
|
@@ -15,7 +15,7 @@ describe('CeloRPCProviders', () => {
|
|
|
15
15
|
new celo_provider_1.CeloJsonRpcBatchProvider(HTTP_ENDPOINT),
|
|
16
16
|
];
|
|
17
17
|
afterAll(async () => {
|
|
18
|
-
await Promise.all(providers.map((p) =>
|
|
18
|
+
await Promise.all(providers.map((p) => p?.destroy?.()));
|
|
19
19
|
});
|
|
20
20
|
// This returns a value now, needs further investigation
|
|
21
21
|
it.skip.each(providers)('should set gasLimit to zero for blocks before the hard fork', async (provider) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"celo-ws-provider.spec.js","sourceRoot":"","sources":["../../../../src/ethereum/ethers/celo/celo-ws-provider.spec.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;AAGnC,mCAAqD;AACrD,yDAAmD;AACnD,mDAIyB;AAEzB,MAAM,aAAa,GAAG,wBAAwB,CAAC;AAC/C,MAAM,UAAU,GAAG,QAAQ,CAAC;AAE5B,QAAQ,CAAC,kBAAkB,EAAE,GAAG,EAAE;IAChC,oDAAoD;IACpD,MAAM,SAAS,GAAG;QAChB,IAAI,8BAAc,CAAC,yBAAyB,CAAC;QAC7C,IAAI,mCAAmB,CAAC,aAAa,CAAC;QACtC,IAAI,wCAAwB,CAAC,aAAa,CAAC;KAC5C,CAAC;IACF,QAAQ,CAAC,KAAK,IAAI,EAAE;QAClB,MAAM,OAAO,CAAC,GAAG,CACf,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,
|
|
1
|
+
{"version":3,"file":"celo-ws-provider.spec.js","sourceRoot":"","sources":["../../../../src/ethereum/ethers/celo/celo-ws-provider.spec.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;AAGnC,mCAAqD;AACrD,yDAAmD;AACnD,mDAIyB;AAEz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GAAG,CAAC,kBAAS,CAAC,IAAI,CAAC,CAAC,CAAC,UAAU,EAAE,CAAC;IAC1E,CAAC,CACF,CAAC;AACJ,CAAC,CAAC,CAAC","sourcesContent":["// Copyright 2020-2024 SubQuery Pte Ltd authors & contributors\n// SPDX-License-Identifier: GPL-3.0\n\nimport { WebSocketProvider } from '@ethersproject/providers';\nimport { BigNumber, constants, utils } from 'ethers';\nimport { formatBlock } from '../../utils.ethereum';\nimport {\n CeloJsonRpcBatchProvider,\n CeloJsonRpcProvider,\n CeloWsProvider,\n} from './celo-provider';\n\nconst HTTP_ENDPOINT = 'https://forno.celo.org';\nconst TEST_BLOCK = 16068684;\n\ndescribe('CeloRPCProviders', () => {\n // For some reason defining this in before all fails\n const providers = [\n new CeloWsProvider('wss://forno.celo.org/ws'),\n new CeloJsonRpcProvider(HTTP_ENDPOINT),\n new CeloJsonRpcBatchProvider(HTTP_ENDPOINT),\n ];\n afterAll(async () => {\n await Promise.all(\n providers.map((p) => (p as WebSocketProvider)?.destroy?.()),\n );\n });\n\n // This returns a value now, needs further investigation\n it.skip.each(providers)(\n 'should set gasLimit to zero for blocks before the hard fork',\n async (provider) => {\n const block = formatBlock(\n await provider.send('eth_getBlockByNumber', [\n utils.hexValue(TEST_BLOCK),\n true,\n ]),\n );\n expect(BigNumber.from(block.gasLimit)).toEqual(constants.Zero);\n },\n );\n\n it.each(providers)(\n 'should not set gasLimit to zero for blocks after the hard fork',\n async (provider) => {\n const block = formatBlock(\n await provider.send('eth_getBlockByNumber', ['latest', true]),\n );\n expect(BigNumber.from(block.gasLimit).gte(constants.Zero)).toBeTruthy();\n },\n );\n});\n"]}
|
|
@@ -9,13 +9,15 @@ const node_core_1 = require("@subql/node-core");
|
|
|
9
9
|
const logger = (0, node_core_1.getLogger)('JsonRpcBatchProvider');
|
|
10
10
|
// Experimental
|
|
11
11
|
class JsonRpcBatchProvider extends providers_1.JsonRpcProvider {
|
|
12
|
+
batchSize = 1;
|
|
13
|
+
successfulBatchCount = 0;
|
|
14
|
+
failedBatchCount = 0;
|
|
15
|
+
batchSizeAdjustmentInterval = 10; // Adjust batch size after every 10 batches
|
|
16
|
+
_pendingBatchAggregator;
|
|
17
|
+
_pendingBatch;
|
|
18
|
+
_chainIdCache = null;
|
|
12
19
|
constructor(url, network) {
|
|
13
20
|
super(url, network);
|
|
14
|
-
this.batchSize = 1;
|
|
15
|
-
this.successfulBatchCount = 0;
|
|
16
|
-
this.failedBatchCount = 0;
|
|
17
|
-
this.batchSizeAdjustmentInterval = 10; // Adjust batch size after every 10 batches
|
|
18
|
-
this._chainIdCache = null;
|
|
19
21
|
}
|
|
20
22
|
setBatchSize(batchSize) {
|
|
21
23
|
this.batchSize = batchSize;
|
|
@@ -71,7 +73,6 @@ class JsonRpcBatchProvider extends providers_1.JsonRpcProvider {
|
|
|
71
73
|
});
|
|
72
74
|
return (0, web_1.fetchJson)(this.connection, JSON.stringify(request))
|
|
73
75
|
.then((result) => {
|
|
74
|
-
var _a;
|
|
75
76
|
this.emit('debug', {
|
|
76
77
|
action: 'response',
|
|
77
78
|
request: request,
|
|
@@ -87,7 +88,7 @@ class JsonRpcBatchProvider extends providers_1.JsonRpcProvider {
|
|
|
87
88
|
batch.forEach((inflightRequest) => {
|
|
88
89
|
inflightRequest.reject(error);
|
|
89
90
|
});
|
|
90
|
-
if (
|
|
91
|
+
if (result.error?.message === 'Batch size is too large') {
|
|
91
92
|
this.adjustBatchSize(false);
|
|
92
93
|
}
|
|
93
94
|
return;
|
|
@@ -107,8 +108,7 @@ class JsonRpcBatchProvider extends providers_1.JsonRpcProvider {
|
|
|
107
108
|
*/
|
|
108
109
|
if (result.length === 1 && result[0].id === null) {
|
|
109
110
|
batch.forEach((inflightRequest) => {
|
|
110
|
-
|
|
111
|
-
inflightRequest.reject(new Error((_a = result[0].error) === null || _a === void 0 ? void 0 : _a.message));
|
|
111
|
+
inflightRequest.reject(new Error(result[0].error?.message));
|
|
112
112
|
});
|
|
113
113
|
this.adjustBatchSize(false);
|
|
114
114
|
return;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"json-rpc-batch-provider.js","sourceRoot":"","sources":["../../../src/ethereum/ethers/json-rpc-batch-provider.ts"],"names":[],"mappings":";;;AAAA,oBAAoB;AACpB,0DAAqD;AAErD,wDAA2D;AAE3D,+BAAkD;AAClD,gDAA6C;AAE7C,MAAM,MAAM,GAAG,IAAA,qBAAS,EAAC,sBAAsB,CAAC,CAAC;AAajD,eAAe;AAEf,MAAa,oBAAqB,SAAQ,2BAAe;IAevD,YAAY,GAA4B,EAAE,OAAoB;QAC5D,KAAK,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;QAfd,cAAS,GAAG,CAAC,CAAC;QACd,yBAAoB,GAAG,CAAC,CAAC;QACzB,qBAAgB,GAAG,CAAC,CAAC;QACrB,gCAA2B,GAAG,EAAE,CAAC,CAAC,2CAA2C;QASrF,kBAAa,GAAkB,IAAI,CAAC;IAIpC,CAAC;IAED,YAAY,CAAC,SAAiB;QAC5B,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;IAC7B,CAAC;IAED,IAAI,CAAC,MAAc,EAAE,MAAkB;QACrC,IAAI,MAAM,KAAK,aAAa,IAAI,IAAI,CAAC,aAAa,KAAK,IAAI,EAAE;YAC3D,OAAO,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;SAC5C;QAED,MAAM,OAAO,GAAG;YACd,MAAM,EAAE,MAAM;YACd,MAAM,EAAE,MAAM;YACd,EAAE,EAAE,IAAI,CAAC,OAAO,EAAE;YAClB,OAAO,EAAE,KAAK;SACf,CAAC;QAEF,IAAI,IAAI,CAAC,aAAa,IAAI,IAAI,EAAE;YAC9B,IAAI,CAAC,aAAa,GAAG,EAAE,CAAC;SACzB;QAED,MAAM,eAAe,GAAQ,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC;QAEtE,MAAM,OAAO,GAAG,IA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B,IAAI,CAAC,oBAAoB,GAAG,CAAC,CAAC;YAC9B,IAAI,CAAC,gBAAgB,GAAG,CAAC,CAAC;SAC3B;IACH,CAAC;CACF;AArND,oDAqNC","sourcesContent":["/* eslint-disable */\nimport { deepCopy } from '@ethersproject/properties';\n\nimport { JsonRpcProvider } from '@ethersproject/providers';\nimport { Networkish } from '@ethersproject/networks';\nimport { ConnectionInfo, fetchJson } from './web';\nimport { getLogger } from '@subql/node-core';\n\nconst logger = getLogger('JsonRpcBatchProvider');\n\ninterface RpcResult {\n jsonrpc: '2.0';\n id: number;\n result?: string;\n error?: {\n code: number;\n message: string;\n data?: any;\n };\n}\n\n// Experimental\n\nexport class JsonRpcBatchProvider extends JsonRpcProvider {\n private batchSize = 1;\n private successfulBatchCount = 0;\n private failedBatchCount = 0;\n private batchSizeAdjustmentInterval = 10; // Adjust batch size after every 10 batches\n\n _pendingBatchAggregator: NodeJS.Timer;\n _pendingBatch: Array<{\n request: { method: string; params: Array<any>; id: number; jsonrpc: '2.0' };\n resolve: (result: any) => void;\n reject: (error: Error) => void;\n }>;\n\n _chainIdCache: string | null = null;\n\n constructor(url: string | ConnectionInfo, network?: Networkish) {\n super(url, network);\n }\n\n setBatchSize(batchSize: number) {\n this.batchSize = batchSize;\n }\n\n send(method: string, params: Array<any>): Promise<any> {\n if (method === 'eth_chainId' && this._chainIdCache !== null) {\n return Promise.resolve(this._chainIdCache);\n }\n\n const request = {\n method: method,\n params: params,\n id: this._nextId++,\n jsonrpc: '2.0',\n };\n\n if (this._pendingBatch == null) {\n this._pendingBatch = [];\n }\n\n const inflightRequest: any = { request, resolve: null, reject: null };\n\n const promise = new Promise((resolve, reject) => {\n inflightRequest.resolve = resolve;\n inflightRequest.reject = reject;\n });\n\n this._pendingBatch.push(inflightRequest);\n\n if (!this._pendingBatchAggregator) {\n // Schedule batch for next event loop + short duration\n this._pendingBatchAggregator = setTimeout(() => {\n this.runRequests();\n }, 1);\n }\n\n if (this._pendingBatch.length > this.batchSize) {\n this.flush();\n }\n\n return promise;\n }\n\n flush(): void {\n if (this._pendingBatchAggregator) {\n clearTimeout(this._pendingBatchAggregator);\n this.runRequests();\n }\n }\n\n private runRequests() {\n // Get teh current batch and clear it, so new requests\n // go into the next batch\n const batch = this._pendingBatch;\n this._pendingBatch = null;\n this._pendingBatchAggregator = null;\n\n // Get the request as an array of requests\n const request = batch.map((inflight) => inflight.request);\n\n this.emit('debug', {\n action: 'requestBatch',\n request: deepCopy(request),\n provider: this,\n });\n\n return fetchJson(this.connection, JSON.stringify(request))\n .then((result: RpcResult[]) => {\n this.emit('debug', {\n action: 'response',\n request: request,\n response: result,\n provider: this,\n });\n\n // if (!Array.isArray(result)) {\n // result = [result];\n // }\n\n // https://github.com/ethers-io/ethers.js/pull/2657\n if (!Array.isArray(result)) {\n const error = new Error(\n 'Invalid response \\n' + JSON.stringify(result),\n );\n batch.forEach((inflightRequest) => {\n inflightRequest.reject(error);\n });\n if (\n (result as RpcResult).error?.message === 'Batch size is too large'\n ) {\n this.adjustBatchSize(false);\n }\n return;\n }\n\n // BSC returns a 200 response with this when being rate limited, we need a special case for it\n /*\n [\n {\n jsonrpc: '2.0',\n id: null,\n error: {\n code: -32005,\n message: 'method eth_getLogs in batch triggered rate limit'\n }\n }\n ]\n */\n if (result.length === 1 && result[0].id === null) {\n batch.forEach((inflightRequest) => {\n inflightRequest.reject(new Error(result[0].error?.message));\n });\n this.adjustBatchSize(false);\n return;\n }\n\n const resultMap = result.reduce((resultMap, payload) => {\n resultMap[payload.id] = payload;\n return resultMap;\n }, {} as Record<number, RpcResult>);\n\n // For each result, feed it to the correct Promise, depending\n // on whether it was a success or error\n batch.forEach((inflightRequest) => {\n const payload = resultMap[inflightRequest.request.id];\n if (!payload) {\n inflightRequest.reject(\n new Error(\n `Missing payload in response for request ${inflightRequest.request.id}`,\n ),\n );\n } else if (payload.error) {\n const error = new Error(payload.error.message);\n (<any>error).code = payload.error.code;\n (<any>error).data = payload.error.data;\n if (\n payload.error.message === 'Batch size limit exceeded' || // onfinality\n payload.error.message === 'exceeded project rate limit' || // infura\n payload.error.message.includes(\n 'Failed to buffer the request body',\n ) ||\n payload.error.message.includes('Too Many Requests') ||\n payload.error.message.includes('Request Entity Too Large')\n ) {\n this.adjustBatchSize(false);\n }\n inflightRequest.reject(error);\n } else {\n if (inflightRequest.request.method === 'eth_chainId') {\n this._chainIdCache = payload.result;\n }\n inflightRequest.resolve(payload.result);\n }\n });\n\n this.adjustBatchSize(true);\n })\n .catch((error) => {\n this.emit('debug', {\n action: 'response',\n error: error,\n request: request,\n provider: this,\n });\n\n //logger.error(error);\n\n batch.forEach((inflightRequest) => {\n inflightRequest.reject(error);\n });\n\n //this.adjustBatchSize(false);\n });\n }\n\n private adjustBatchSize(success: boolean) {\n success ? this.successfulBatchCount++ : this.failedBatchCount++;\n const totalBatches = this.successfulBatchCount + this.failedBatchCount;\n\n if (totalBatches % this.batchSizeAdjustmentInterval === 0) {\n const successRate = this.successfulBatchCount / totalBatches;\n\n // Adjust the batch size based on the success rate.\n if (successRate < 0.9 && this.batchSize > 1) {\n this.batchSize--;\n } else if (successRate > 0.95 && this.batchSize < 10) {\n this.batchSize++;\n }\n\n // Reset the counters\n this.successfulBatchCount = 0;\n this.failedBatchCount = 0;\n }\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"json-rpc-batch-provider.js","sourceRoot":"","sources":["../../../src/ethereum/ethers/json-rpc-batch-provider.ts"],"names":[],"mappings":";;;AAAA,oBAAoB;AACpB,0DAAqD;AAErD,wDAA2D;AAE3D,+BAAkD;AAClD,gDAA6C;AAE7C,MAAM,MAAM,GAAG,IAAA,qBAAS,EAAC,sBAAsB,CAAC,CAAC;AAajD,eAAe;AAEf,MAAa,oBAAqB,SAAQ,2BAAe;IAC/C,SAAS,GAAG,CAAC,CAAC;IACd,oBAAoB,GAAG,CAAC,CAAC;IACzB,gBAAgB,GAAG,CAAC,CAAC;IACrB,2BAA2B,GAAG,EAAE,CAAC,CAAC,2CAA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B,KAAK,CAAC,OAAO,CAAC,CAAC,eAAe,EAAE,EAAE;gBAChC,eAAe,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;YAChC,CAAC,CAAC,CAAC;YAEH,8BAA8B;QAChC,CAAC,CAAC,CAAC;IACP,CAAC;IAEO,eAAe,CAAC,OAAgB;QACtC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,oBAAoB,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,gBAAgB,EAAE,CAAC;QAChE,MAAM,YAAY,GAAG,IAAI,CAAC,oBAAoB,GAAG,IAAI,CAAC,gBAAgB,CAAC;QAEvE,IAAI,YAAY,GAAG,IAAI,CAAC,2BAA2B,KAAK,CAAC,EAAE;YACzD,MAAM,WAAW,GAAG,IAAI,CAAC,oBAAoB,GAAG,YAAY,CAAC;YAE7D,mDAAmD;YACnD,IAAI,WAAW,GAAG,GAAG,IAAI,IAAI,CAAC,SAAS,GAAG,CAAC,EAAE;gBAC3C,IAAI,CAAC,SAAS,EAAE,CAAC;aAClB;iBAAM,IAAI,WAAW,GAAG,IAAI,IAAI,IAAI,CAAC,SAAS,GAAG,EAAE,EAAE;gBACpD,IAAI,CAAC,SAAS,EAAE,CAAC;aAClB;YAED,qBAAqB;YACrB,IAAI,CAAC,oBAAoB,GAAG,CAAC,CAAC;YAC9B,IAAI,CAAC,gBAAgB,GAAG,CAAC,CAAC;SAC3B;IACH,CAAC;CACF;AArND,oDAqNC","sourcesContent":["/* eslint-disable */\nimport { deepCopy } from '@ethersproject/properties';\n\nimport { JsonRpcProvider } from '@ethersproject/providers';\nimport { Networkish } from '@ethersproject/networks';\nimport { ConnectionInfo, fetchJson } from './web';\nimport { getLogger } from '@subql/node-core';\n\nconst logger = getLogger('JsonRpcBatchProvider');\n\ninterface RpcResult {\n jsonrpc: '2.0';\n id: number;\n result?: string;\n error?: {\n code: number;\n message: string;\n data?: any;\n };\n}\n\n// Experimental\n\nexport class JsonRpcBatchProvider extends JsonRpcProvider {\n private batchSize = 1;\n private successfulBatchCount = 0;\n private failedBatchCount = 0;\n private batchSizeAdjustmentInterval = 10; // Adjust batch size after every 10 batches\n\n _pendingBatchAggregator: NodeJS.Timer;\n _pendingBatch: Array<{\n request: { method: string; params: Array<any>; id: number; jsonrpc: '2.0' };\n resolve: (result: any) => void;\n reject: (error: Error) => void;\n }>;\n\n _chainIdCache: string | null = null;\n\n constructor(url: string | ConnectionInfo, network?: Networkish) {\n super(url, network);\n }\n\n setBatchSize(batchSize: number) {\n this.batchSize = batchSize;\n }\n\n send(method: string, params: Array<any>): Promise<any> {\n if (method === 'eth_chainId' && this._chainIdCache !== null) {\n return Promise.resolve(this._chainIdCache);\n }\n\n const request = {\n method: method,\n params: params,\n id: this._nextId++,\n jsonrpc: '2.0',\n };\n\n if (this._pendingBatch == null) {\n this._pendingBatch = [];\n }\n\n const inflightRequest: any = { request, resolve: null, reject: null };\n\n const promise = new Promise((resolve, reject) => {\n inflightRequest.resolve = resolve;\n inflightRequest.reject = reject;\n });\n\n this._pendingBatch.push(inflightRequest);\n\n if (!this._pendingBatchAggregator) {\n // Schedule batch for next event loop + short duration\n this._pendingBatchAggregator = setTimeout(() => {\n this.runRequests();\n }, 1);\n }\n\n if (this._pendingBatch.length > this.batchSize) {\n this.flush();\n }\n\n return promise;\n }\n\n flush(): void {\n if (this._pendingBatchAggregator) {\n clearTimeout(this._pendingBatchAggregator);\n this.runRequests();\n }\n }\n\n private runRequests() {\n // Get teh current batch and clear it, so new requests\n // go into the next batch\n const batch = this._pendingBatch;\n this._pendingBatch = null;\n this._pendingBatchAggregator = null;\n\n // Get the request as an array of requests\n const request = batch.map((inflight) => inflight.request);\n\n this.emit('debug', {\n action: 'requestBatch',\n request: deepCopy(request),\n provider: this,\n });\n\n return fetchJson(this.connection, JSON.stringify(request))\n .then((result: RpcResult[]) => {\n this.emit('debug', {\n action: 'response',\n request: request,\n response: result,\n provider: this,\n });\n\n // if (!Array.isArray(result)) {\n // result = [result];\n // }\n\n // https://github.com/ethers-io/ethers.js/pull/2657\n if (!Array.isArray(result)) {\n const error = new Error(\n 'Invalid response \\n' + JSON.stringify(result),\n );\n batch.forEach((inflightRequest) => {\n inflightRequest.reject(error);\n });\n if (\n (result as RpcResult).error?.message === 'Batch size is too large'\n ) {\n this.adjustBatchSize(false);\n }\n return;\n }\n\n // BSC returns a 200 response with this when being rate limited, we need a special case for it\n /*\n [\n {\n jsonrpc: '2.0',\n id: null,\n error: {\n code: -32005,\n message: 'method eth_getLogs in batch triggered rate limit'\n }\n }\n ]\n */\n if (result.length === 1 && result[0].id === null) {\n batch.forEach((inflightRequest) => {\n inflightRequest.reject(new Error(result[0].error?.message));\n });\n this.adjustBatchSize(false);\n return;\n }\n\n const resultMap = result.reduce((resultMap, payload) => {\n resultMap[payload.id] = payload;\n return resultMap;\n }, {} as Record<number, RpcResult>);\n\n // For each result, feed it to the correct Promise, depending\n // on whether it was a success or error\n batch.forEach((inflightRequest) => {\n const payload = resultMap[inflightRequest.request.id];\n if (!payload) {\n inflightRequest.reject(\n new Error(\n `Missing payload in response for request ${inflightRequest.request.id}`,\n ),\n );\n } else if (payload.error) {\n const error = new Error(payload.error.message);\n (<any>error).code = payload.error.code;\n (<any>error).data = payload.error.data;\n if (\n payload.error.message === 'Batch size limit exceeded' || // onfinality\n payload.error.message === 'exceeded project rate limit' || // infura\n payload.error.message.includes(\n 'Failed to buffer the request body',\n ) ||\n payload.error.message.includes('Too Many Requests') ||\n payload.error.message.includes('Request Entity Too Large')\n ) {\n this.adjustBatchSize(false);\n }\n inflightRequest.reject(error);\n } else {\n if (inflightRequest.request.method === 'eth_chainId') {\n this._chainIdCache = payload.result;\n }\n inflightRequest.resolve(payload.result);\n }\n });\n\n this.adjustBatchSize(true);\n })\n .catch((error) => {\n this.emit('debug', {\n action: 'response',\n error: error,\n request: request,\n provider: this,\n });\n\n //logger.error(error);\n\n batch.forEach((inflightRequest) => {\n inflightRequest.reject(error);\n });\n\n //this.adjustBatchSize(false);\n });\n }\n\n private adjustBatchSize(success: boolean) {\n success ? this.successfulBatchCount++ : this.failedBatchCount++;\n const totalBatches = this.successfulBatchCount + this.failedBatchCount;\n\n if (totalBatches % this.batchSizeAdjustmentInterval === 0) {\n const successRate = this.successfulBatchCount / totalBatches;\n\n // Adjust the batch size based on the success rate.\n if (successRate < 0.9 && this.batchSize > 1) {\n this.batchSize--;\n } else if (successRate > 0.95 && this.batchSize < 10) {\n this.batchSize++;\n }\n\n // Reset the counters\n this.successfulBatchCount = 0;\n this.failedBatchCount = 0;\n }\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"json-rpc-batch-provider.spec.js","sourceRoot":"","sources":["../../../src/ethereum/ethers/json-rpc-batch-provider.spec.ts"],"names":[],"mappings":";;AAAA,oBAAoB;AACpB,uEAAiE;AAGjE,QAAQ,CAAC,sBAAsB,EAAE,GAAG,EAAE;IACpC,IAAI,aAAmC,CAAC;IACxC,IAAI,aAA+B,CAAC;IAEpC,UAAU,CAAC,GAAG,EAAE;QACd,qEAAqE;QACrE,aAAa,GAAG,IAAI,8CAAoB,CAAC,uBAAuB,CAAC,CAAC;QAElE,mFAAmF;QACnF,aAAa,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,WAAW,CAAC,CAAC;IAC5D,CAAC,CAAC,CAAC;IAEH,SAAS,CAAC,GAAG,EAAE;QACb,2CAA2C;QAC3C,aAAa,CAAC,WAAW,EAAE,CAAC;IAC9B,CAAC,CAAC,CAAC;IAEH,IAAI,CAAC,mEAAmE,EAAE,KAAK,IAAI,EAAE;QACnF,iDAAiD;QACjD,aAAa,CAAC,kBAAkB,CAC9B,KAAK,EAAE,UAA0B,EAAE,OAAe,EAAE,EAAE;YACpD,MAAM,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;YACrC,OAAO,QAAQ,CAAC,GAAG,CAAC,CAAC,OAAY,EAAE,EAAE,CAAC,CAAC;gBACr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C;YACzD,cAAc,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;SACpC;QAED,IAAI;YACF,MAAM,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC;SACnC;QAAC,
|
|
1
|
+
{"version":3,"file":"json-rpc-batch-provider.spec.js","sourceRoot":"","sources":["../../../src/ethereum/ethers/json-rpc-batch-provider.spec.ts"],"names":[],"mappings":";;AAAA,oBAAoB;AACpB,uEAAiE;AAGjE,QAAQ,CAAC,sBAAsB,EAAE,GAAG,EAAE;IACpC,IAAI,aAAmC,CAAC;IACxC,IAAI,aAA+B,CAAC;IAEpC,UAAU,CAAC,GAAG,EAAE;QACd,qEAAqE;QACrE,aAAa,GAAG,IAAI,8CAAoB,CAAC,uBAAuB,CAAC,CAAC;QAElE,mFAAmF;QACnF,aAAa,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,WAAW,CAAC,CAAC;IAC5D,CAAC,CAAC,CAAC;IAEH,SAAS,CAAC,GAAG,EAAE;QACb,2CAA2C;QAC3C,aAAa,CAAC,WAAW,EAAE,CAAC;IAC9B,CAAC,CAAC,CAAC;IAEH,IAAI,CAAC,mEAAmE,EAAE,KAAK,IAAI,EAAE;QACnF,iDAAiD;QACjD,aAAa,CAAC,kBAAkB,CAC9B,KAAK,EAAE,UAA0B,EAAE,OAAe,EAAE,EAAE;YACpD,MAAM,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;YACrC,OAAO,QAAQ,CAAC,GAAG,CAAC,CAAC,OAAY,EAAE,EAAE,CAAC,CAAC;gBACrC,EAAE,EAAE,OAAO,CAAC,EAAE;gBACd,OAAO,EAAE,KAAK;gBACd,MAAM,EAAE,KAAK;aACd,CAAC,CAAC,CAAC;QACN,CAAC,CACF,CAAC;QAEF,yEAAyE;QACzE,MAAM,YAAY,GAAG,EAAE,CAAC;QACxB,MAAM,QAAQ,GAAG,EAAE,CAAC;QACpB,KAAK,IAAI,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AC,CAAC,CAAC,CAAC;IACrD,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["/* eslint-disable */\nimport { JsonRpcBatchProvider } from './json-rpc-batch-provider';\nimport { ConnectionInfo } from './web';\n\ndescribe('JsonRpcBatchProvider', () => {\n let batchProvider: JsonRpcBatchProvider;\n let fetchJsonMock: jest.SpyInstance;\n\n beforeEach(() => {\n // Create a new instance of the JsonRpcBatchProvider before each test\n batchProvider = new JsonRpcBatchProvider('http://localhost:8545');\n\n // Mock the fetchJson function from the ethers package to simulate server responses\n fetchJsonMock = jest.spyOn(require('./web'), 'fetchJson');\n });\n\n afterEach(() => {\n // Reset the fetchJson mock after each test\n fetchJsonMock.mockRestore();\n });\n\n test('adjustBatchSize properly adjusts batch size based on success rate', async () => {\n // Mock fetchJson to return a successful response\n fetchJsonMock.mockImplementation(\n async (connection: ConnectionInfo, payload: string) => {\n const requests = JSON.parse(payload);\n return requests.map((request: any) => ({\n id: request.id,\n jsonrpc: '2.0',\n result: '0x1',\n }));\n },\n );\n\n // Execute the send method multiple times to simulate successful requests\n const requestCount = 20;\n const promises = [];\n for (let i = 0; i < requestCount; i++) {\n const promise = batchProvider.send('eth_call', []);\n promises.push(promise);\n }\n await Promise.all(promises);\n\n // Check if the batch size has increased due to the success rate\n expect(batchProvider['batchSize']).toBeGreaterThan(1);\n\n // Now, mock fetchJson to return an error response\n fetchJsonMock.mockImplementation(\n async (connection: ConnectionInfo, payload: string) => {\n const requests = JSON.parse(payload);\n return requests.map((request: any) => ({\n id: request.id,\n jsonrpc: '2.0',\n error: { code: -32603, message: 'Batch size limit exceeded' },\n }));\n },\n );\n\n // Execute the send method multiple times to simulate failed requests\n const failedPromises = [];\n for (let i = 0; i < requestCount + 10; i++) {\n const failedPromise = batchProvider.send('eth_call', []);\n failedPromises.push(failedPromise);\n }\n\n try {\n await Promise.all(failedPromises);\n } catch {\n // ignore error\n }\n\n // Check if the batch size has decreased due to the failure rate\n expect(batchProvider['batchSize']).toBeLessThan(2);\n });\n});\n"]}
|
|
@@ -10,7 +10,13 @@ function OPFormatterMixin(Base) {
|
|
|
10
10
|
return class OPProvider extends Base {
|
|
11
11
|
constructor(...args) {
|
|
12
12
|
super(...args);
|
|
13
|
-
this.formatter.formats.receipt =
|
|
13
|
+
this.formatter.formats.receipt = {
|
|
14
|
+
...this.formatter.formats.receipt,
|
|
15
|
+
l1Fee: providers_1.Formatter.allowNull(this.formatter.bigNumber.bind(this.formatter)),
|
|
16
|
+
l1FeeScalar: providers_1.Formatter.allowNull((v) => Number(v)),
|
|
17
|
+
l1GasPrice: providers_1.Formatter.allowNull(this.formatter.bigNumber.bind(this.formatter)),
|
|
18
|
+
l1GasUsed: providers_1.Formatter.allowNull(this.formatter.bigNumber.bind(this.formatter)),
|
|
19
|
+
};
|
|
14
20
|
}
|
|
15
21
|
};
|
|
16
22
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"op-provider.js","sourceRoot":"","sources":["../../../../src/ethereum/ethers/op/op-provider.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;;AAEnC,wDAIkC;AAClC,wEAAkE;AAClE,4DAAuD;AAIvD,SAAgB,gBAAgB,CAAwB,IAAO;IAC7D,OAAO,MAAM,UAAW,SAAQ,IAAI;QAClC,YAAY,GAAG,IAAW;YACxB,KAAK,CAAC,GAAG,IAAI,CAAC,CAAC;YAEf,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,OAAO,
|
|
1
|
+
{"version":3,"file":"op-provider.js","sourceRoot":"","sources":["../../../../src/ethereum/ethers/op/op-provider.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;;AAEnC,wDAIkC;AAClC,wEAAkE;AAClE,4DAAuD;AAIvD,SAAgB,gBAAgB,CAAwB,IAAO;IAC7D,OAAO,MAAM,UAAW,SAAQ,IAAI;QAClC,YAAY,GAAG,IAAW;YACxB,KAAK,CAAC,GAAG,IAAI,CAAC,CAAC;YAEf,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,OAAO,GAAG;gBAC/B,GAAG,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,OAAO;gBACjC,KAAK,EAAE,qBAAS,CAAC,SAAS,CACxB,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,CAC9C;gBACD,WAAW,EAAE,qBAAS,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;gBAClD,UAAU,EAAE,qBAAS,CAAC,SAAS,CAC7B,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,CAC9C;gBACD,SAAS,EAAE,qBAAS,CAAC,SAAS,CAC5B,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,CAC9C;aACF,CAAC;QACJ,CAAC;KACF,CAAC;AACJ,CAAC;AApBD,4CAoBC;AAEY,QAAA,YAAY,GAAG,gBAAgB,CAAC,6BAAiB,CAAC,CAAC;AACnD,QAAA,iBAAiB,GAAG,gBAAgB,CAAC,mCAAe,CAAC,CAAC;AACtD,QAAA,sBAAsB,GAAG,gBAAgB,CAAC,8CAAoB,CAAC,CAAC","sourcesContent":["// Copyright 2020-2024 SubQuery Pte Ltd authors & contributors\n// SPDX-License-Identifier: GPL-3.0\n\nimport {\n WebSocketProvider,\n BaseProvider,\n Formatter,\n} from '@ethersproject/providers';\nimport { JsonRpcBatchProvider } from '../json-rpc-batch-provider';\nimport { JsonRpcProvider } from '../json-rpc-provider';\n\n/* This mixin replaces the block formatter on any provider with specific OP changes */\ntype Constructor = new (...args: any[]) => BaseProvider;\nexport function OPFormatterMixin<B extends Constructor>(Base: B) {\n return class OPProvider extends Base {\n constructor(...args: any[]) {\n super(...args);\n\n this.formatter.formats.receipt = {\n ...this.formatter.formats.receipt,\n l1Fee: Formatter.allowNull(\n this.formatter.bigNumber.bind(this.formatter),\n ),\n l1FeeScalar: Formatter.allowNull((v) => Number(v)),\n l1GasPrice: Formatter.allowNull(\n this.formatter.bigNumber.bind(this.formatter),\n ),\n l1GasUsed: Formatter.allowNull(\n this.formatter.bigNumber.bind(this.formatter),\n ),\n };\n }\n };\n}\n\nexport const OPWsProvider = OPFormatterMixin(WebSocketProvider);\nexport const OPJsonRpcProvider = OPFormatterMixin(JsonRpcProvider);\nexport const OPJsonRpcBatchProvider = OPFormatterMixin(JsonRpcBatchProvider);\n"]}
|
|
@@ -64,7 +64,6 @@ function nonnull(value) {
|
|
|
64
64
|
return value;
|
|
65
65
|
}
|
|
66
66
|
async function getUrl(href, options) {
|
|
67
|
-
var _a, _b;
|
|
68
67
|
if (options == null) {
|
|
69
68
|
options = {};
|
|
70
69
|
}
|
|
@@ -87,13 +86,13 @@ async function getUrl(href, options) {
|
|
|
87
86
|
let req = null;
|
|
88
87
|
switch (nonnull(url.protocol)) {
|
|
89
88
|
case 'http:':
|
|
90
|
-
if (
|
|
89
|
+
if (options?.agents?.http) {
|
|
91
90
|
request.agent = options.agents.http;
|
|
92
91
|
}
|
|
93
92
|
req = http_1.default.request(request);
|
|
94
93
|
break;
|
|
95
94
|
case 'https:':
|
|
96
|
-
if (
|
|
95
|
+
if (options?.agents?.https) {
|
|
97
96
|
request.agent = options.agents.https;
|
|
98
97
|
}
|
|
99
98
|
req = https_1.default.request(request);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"geturl.js","sourceRoot":"","sources":["../../../../src/ethereum/ethers/web/geturl.ts"],"names":[],"mappings":"AAAA,oBAAoB;AACpB,YAAY,CAAC;;;;;;AAEb,gDAAwB;AACxB,kDAA0B;AAC1B,+BAAkC;AAClC,6BAA4B;AAE5B,gDAAwD;AACxD,0DAAwD;AAIxD,kDAA+C;AAC/C,yCAAqC;AACrC,MAAM,MAAM,GAAG,IAAI,eAAM,CAAC,kBAAO,CAAC,CA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AO,CAAC,iBAAiB,CAAC,GAAG,MAAM,CAAC;KAC7C;IAED,IAAI,GAAG,GAAuB,IAAI,CAAC;IACnC,QAAQ,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE;QAC7B,KAAK,OAAO;YACV,IAAI,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE;gBACzB,OAAO,CAAC,KAAK,GAAG,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC;aACrC;YACD,GAAG,GAAG,cAAI,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;YAC5B,MAAM;QACR,KAAK,QAAQ;YACX,IAAI,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE;gBAC1B,OAAO,CAAC,KAAK,GAAG,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC;aACtC;YACD,GAAG,GAAG,eAAK,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;YAC7B,MAAM;QACR;YACE,0BAA0B;YAC1B,MAAM,CAAC,UAAU,CACf,wBAAwB,GAAG,CAAC,QAAQ,EAAE,EACtC,eAAM,CAAC,MAAM,CAAC,qBAAqB,EACnC;gBACE,QAAQ,EAAE,GAAG,CAAC,QAAQ;gBACtB,SAAS,EAAE,SAAS;aACrB,CACF,CAAC;KACL;IAED,IAAI,OAAO,CAAC,IAAI,EAAE;QAChB,GAAG,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC;KACtC;IACD,GAAG,CAAC,GAAG,EAAE,CAAC;IAEV,MAAM,QAAQ,GAAG,MAAM,WAAW,CAAC,GAAG,CAAC,CAAC;IACxC,OAAO,QAAQ,CAAC;AAClB,CAAC;AA7DD,wBA6DC","sourcesContent":["/* eslint-disable */\n'use strict';\n\nimport http from 'http';\nimport https from 'https';\nimport { gunzipSync } from 'zlib';\nimport { parse } from 'url';\n\nimport { arrayify, concat } from '@ethersproject/bytes';\nimport { shallowCopy } from '@ethersproject/properties';\n\nimport type { GetUrlResponse, Options } from './types';\n\nimport { Logger } from '@ethersproject/logger';\nimport { version } from './_version';\nconst logger = new Logger(version);\n\nexport { GetUrlResponse, Options };\n\nfunction getResponse(request: http.ClientRequest): Promise<GetUrlResponse> {\n return new Promise((resolve, reject) => {\n request.once('response', (resp: http.IncomingMessage) => {\n const response: GetUrlResponse = {\n statusCode: resp.statusCode,\n statusMessage: resp.statusMessage,\n headers: Object.keys(resp.headers).reduce((accum, name) => {\n let value = resp.headers[name];\n if (Array.isArray(value)) {\n value = value.join(', ');\n }\n accum[name] = value;\n return accum;\n }, <{ [name: string]: string }>{}),\n body: null,\n };\n //resp.setEncoding(\"utf8\");\n\n resp.on('data', (chunk: Uint8Array) => {\n if (response.body == null) {\n response.body = new Uint8Array(0);\n }\n response.body = concat([response.body, chunk]);\n });\n\n resp.on('end', () => {\n if (response.headers['content-encoding'] === 'gzip') {\n //const size = response.body.length;\n response.body = arrayify(gunzipSync(response.body));\n //console.log(\"Delta:\", response.body.length - size, Buffer.from(response.body).toString());\n }\n resolve(response);\n });\n\n resp.on('error', (error) => {\n /* istanbul ignore next */\n (<any>error).response = response;\n reject(error);\n });\n });\n\n request.on('error', (error) => {\n reject(error);\n });\n });\n}\n\n// The URL.parse uses null instead of the empty string\nfunction nonnull(value: string): string {\n if (value == null) {\n return '';\n }\n return value;\n}\n\nexport async function getUrl(\n href: string,\n options?: Options,\n): Promise<GetUrlResponse> {\n if (options == null) {\n options = {};\n }\n\n // @TODO: Once we drop support for node 8, we can pass the href\n // directly into request and skip adding the components\n // to this request object\n const url = parse(href);\n\n const request = {\n protocol: nonnull(url.protocol),\n hostname: nonnull(url.hostname),\n port: nonnull(url.port),\n path: nonnull(url.pathname) + nonnull(url.search),\n\n method: options.method || 'GET',\n headers: shallowCopy(options.headers || {}),\n agent: null,\n };\n\n if (options.allowGzip) {\n request.headers['accept-encoding'] = 'gzip';\n }\n\n let req: http.ClientRequest = null;\n switch (nonnull(url.protocol)) {\n case 'http:':\n if (options?.agents?.http) {\n request.agent = options.agents.http;\n }\n req = http.request(request);\n break;\n case 'https:':\n if (options?.agents?.https) {\n request.agent = options.agents.https;\n }\n req = https.request(request);\n break;\n default:\n /* istanbul ignore next */\n logger.throwError(\n `unsupported protocol ${url.protocol}`,\n Logger.errors.UNSUPPORTED_OPERATION,\n {\n protocol: url.protocol,\n operation: 'request',\n },\n );\n }\n\n if (options.body) {\n req.write(Buffer.from(options.body));\n }\n req.end();\n\n const response = await getResponse(req);\n return response;\n}\n"]}
|
|
@@ -6,6 +6,9 @@ const abstract_provider_1 = require("@ethersproject/abstract-provider");
|
|
|
6
6
|
const node_core_1 = require("@subql/node-core");
|
|
7
7
|
const logger = (0, node_core_1.getLogger)('safe.api.ethereum');
|
|
8
8
|
class SafeEthProvider extends abstract_provider_1.Provider {
|
|
9
|
+
baseApi;
|
|
10
|
+
blockHeight;
|
|
11
|
+
network;
|
|
9
12
|
constructor(baseApi, blockHeight) {
|
|
10
13
|
super();
|
|
11
14
|
this.baseApi = baseApi;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"safe-api.js","sourceRoot":"","sources":["../../src/ethereum/safe-api.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;AAEnC,wEAY0C;AAI1C,gDAA6C;AAE7C,MAAM,MAAM,GAAG,IAAA,qBAAS,EAAC,mBAAmB,CAAC,CAAC;AAE9C,MAAqB,eAAgB,SAAQ,4BAAQ;
|
|
1
|
+
{"version":3,"file":"safe-api.js","sourceRoot":"","sources":["../../src/ethereum/safe-api.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;AAEnC,wEAY0C;AAI1C,gDAA6C;AAE7C,MAAM,MAAM,GAAG,IAAA,qBAAS,EAAC,mBAAmB,CAAC,CAAC;AAE9C,MAAqB,eAAgB,SAAQ,4BAAQ;IAGzC;IACA;IAHF,OAAO,CAAW;IAC1B,YACU,OAAiB,EACjB,WAAyC;QAEjD,KAAK,EAAE,CAAC;QAH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MAAM,IAAI,KAAK,CAAC,uCAAuC,CAAC,CAAC;IAC3D,CAAC;IACD,EAAE,CAAC,SAAoB,EAAE,QAAkB;QACzC,MAAM,IAAI,KAAK,CAAC,4BAA4B,CAAC,CAAC;IAChD,CAAC;IACD,IAAI,CAAC,SAAoB,EAAE,QAAkB;QAC3C,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAC;IAClD,CAAC;IACD,IAAI,CAAC,SAAoB,EAAE,GAAG,IAAW;QACvC,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAC;IAClD,CAAC;IACD,aAAa,CAAC,SAAqB;QACjC,MAAM,IAAI,KAAK,CAAC,uCAAuC,CAAC,CAAC;IAC3D,CAAC;IACD,SAAS,CAAC,SAAqB;QAC7B,MAAM,IAAI,KAAK,CAAC,mCAAmC,CAAC,CAAC;IACvD,CAAC;IACD,GAAG,CAAC,SAAoB,EAAE,QAAmB;QAC3C,MAAM,IAAI,KAAK,CAAC,6BAA6B,CAAC,CAAC;IACjD,CAAC;IACD,kBAAkB,CAAC,SAAqB;QACtC,MAAM,IAAI,KAAK,CAAC,4CAA4C,CAAC,CAAC;IAChE,CAAC;IACD,qEAAqE;IACrE,kBAAkB,CAChB,eAAuB,EACvB,aAAsB,EACtB,OAAgB;QAEhB,MAAM,IAAI,KAAK,CAAC,4CAA4C,CAAC,CAAC;IAChE,CAAC;CACF;AAxID,kCAwIC","sourcesContent":["// Copyright 2020-2024 SubQuery Pte Ltd authors & contributors\n// SPDX-License-Identifier: GPL-3.0\n\nimport {\n Block,\n BlockTag,\n BlockWithTransactions,\n EventType,\n Filter,\n Listener,\n Log,\n TransactionReceipt,\n TransactionRequest,\n TransactionResponse,\n Provider,\n} from '@ethersproject/abstract-provider';\nimport { BigNumber, BigNumberish } from '@ethersproject/bignumber';\nimport type { Network } from '@ethersproject/networks';\nimport type { Deferrable } from '@ethersproject/properties';\nimport { getLogger } from '@subql/node-core';\n\nconst logger = getLogger('safe.api.ethereum');\n\nexport default class SafeEthProvider extends Provider {\n private network?: Network;\n constructor(\n private baseApi: Provider,\n private blockHeight: BlockTag | Promise<BlockTag>,\n ) {\n super();\n }\n\n async getBalance(\n addressOrName: string | Promise<string>,\n blockTag?: BlockTag | Promise<BlockTag>,\n ): Promise<BigNumber> {\n if (blockTag) logger.warn(`Provided parameter 'blockTag' will not be used`);\n return this.baseApi.getBalance(addressOrName, this.blockHeight);\n }\n\n async getTransactionCount(\n addressOrName: string | Promise<string>,\n blockTag?: BlockTag | Promise<BlockTag>,\n ): Promise<number> {\n if (blockTag) logger.warn(`Provided parameter 'blockTag' will not be used`);\n return this.baseApi.getTransactionCount(addressOrName, this.blockHeight);\n }\n\n async getCode(\n addressOrName: string | Promise<string>,\n blockTag?: BlockTag | Promise<BlockTag>,\n ): Promise<string> {\n if (blockTag) logger.warn(`Provided parameter 'blockTag' will not be used`);\n return this.baseApi.getCode(addressOrName, this.blockHeight);\n }\n\n async getStorageAt(\n addressOrName: string | Promise<string>,\n position: BigNumberish | Promise<BigNumberish>,\n blockTag?: BlockTag | Promise<BlockTag>,\n ): Promise<string> {\n if (blockTag) logger.warn(`Provided parameter 'blockTag' will not be used`);\n return this.baseApi.getStorageAt(addressOrName, position, this.blockHeight);\n }\n\n async call(\n transaction: Deferrable<TransactionRequest>,\n blockTag?: BlockTag | Promise<BlockTag>,\n ): Promise<string> {\n if (blockTag) logger.warn(`Provided parameter 'blockTag' will not be used`);\n\n return this.baseApi.call(transaction, this.blockHeight);\n }\n\n async getNetwork(): Promise<Network> {\n if (!this.network) {\n this.network = await this.baseApi.getNetwork();\n }\n return this.network;\n }\n\n // eslint-disable-next-line @typescript-eslint/promise-function-async\n getBlockWithTransactions(\n blockHashOrBlockTag: BlockTag | Promise<BlockTag>,\n ): Promise<BlockWithTransactions> {\n throw new Error('Method `getBlockWithTransactions` not supported.');\n }\n\n // eslint-disable-next-line @typescript-eslint/promise-function-async\n getBlock(blockHashOrBlockTag: BlockTag | Promise<BlockTag>): Promise<Block> {\n throw new Error('Method `getBlock` not supported.');\n }\n // eslint-disable-next-line @typescript-eslint/promise-function-async\n getTransaction(transactionHash: string): Promise<TransactionResponse> {\n throw new Error('Method `getTransaction` not supported.');\n }\n // eslint-disable-next-line @typescript-eslint/promise-function-async\n getTransactionReceipt(transactionHash: string): Promise<TransactionReceipt> {\n throw new Error('Method `getTransactionReceipt` not supported.');\n }\n // eslint-disable-next-line @typescript-eslint/promise-function-async\n getLogs(filter: Filter): Promise<Log[]> {\n throw new Error('Method `getLogs` not supported.');\n }\n // eslint-disable-next-line @typescript-eslint/promise-function-async\n getBlockNumber(): Promise<number> {\n throw new Error('Method `getBlockNumber` not supported.');\n }\n // eslint-disable-next-line @typescript-eslint/promise-function-async\n getGasPrice(): Promise<BigNumber> {\n throw new Error('Method `getGasPrice` not supported.');\n }\n // eslint-disable-next-line @typescript-eslint/promise-function-async\n estimateGas(transaction: Deferrable<TransactionRequest>): Promise<BigNumber> {\n throw new Error('Method `estimateGas` not supported.');\n }\n // eslint-disable-next-line @typescript-eslint/promise-function-async\n sendTransaction(\n signedTransaction: string | Promise<string>,\n ): Promise<TransactionResponse> {\n throw new Error('Method `sendTransaction` not supported.');\n }\n // eslint-disable-next-line @typescript-eslint/promise-function-async\n resolveName(name: string | Promise<string>): Promise<string | null> {\n throw new Error('Method `resolveName` not supported.');\n }\n // eslint-disable-next-line @typescript-eslint/promise-function-async\n lookupAddress(address: string | Promise<string>): Promise<string | null> {\n throw new Error('Method `lookupAddress` not supported.');\n }\n on(eventName: EventType, listener: Listener): Provider {\n throw new Error('Method `on` not supported.');\n }\n once(eventName: EventType, listener: Listener): Provider {\n throw new Error('Method `once` not supported.');\n }\n emit(eventName: EventType, ...args: any[]): boolean {\n throw new Error('Method `emit` not supported.');\n }\n listenerCount(eventName?: EventType): number {\n throw new Error('Method `listenerCount` not supported.');\n }\n listeners(eventName?: EventType): Listener[] {\n throw new Error('Method `listeners` not supported.');\n }\n off(eventName: EventType, listener?: Listener): Provider {\n throw new Error('Method `off` not supported.');\n }\n removeAllListeners(eventName?: EventType): Provider {\n throw new Error('Method `removeAllListeners` not supported.');\n }\n // eslint-disable-next-line @typescript-eslint/promise-function-async\n waitForTransaction(\n transactionHash: string,\n confirmations?: number,\n timeout?: number,\n ): Promise<TransactionReceipt> {\n throw new Error('Method `waitForTransaction` not supported.');\n }\n}\n"]}
|
|
@@ -32,11 +32,23 @@ function handleNumber(value) {
|
|
|
32
32
|
}
|
|
33
33
|
exports.handleNumber = handleNumber;
|
|
34
34
|
function formatBlock(block) {
|
|
35
|
-
return
|
|
35
|
+
return {
|
|
36
|
+
...block,
|
|
37
|
+
difficulty: handleNumber(block.difficulty).toBigInt(),
|
|
38
|
+
gasLimit: handleNumber(block.gasLimit).toBigInt(),
|
|
39
|
+
gasUsed: handleNumber(block.gasUsed).toBigInt(),
|
|
40
|
+
number: handleNumber(block.number).toNumber(),
|
|
41
|
+
size: handleNumber(block.size).toBigInt(),
|
|
42
|
+
timestamp: handleNumber(block.timestamp).toBigInt(),
|
|
43
|
+
totalDifficulty: handleNumber(block.totalDifficulty).toBigInt(),
|
|
44
|
+
baseFeePerGas: block.baseFeePerGas
|
|
36
45
|
? handleNumber(block.baseFeePerGas).toBigInt()
|
|
37
|
-
: undefined,
|
|
46
|
+
: undefined,
|
|
47
|
+
blockGasCost: block.blockGasCost
|
|
38
48
|
? handleNumber(block.blockGasCost).toBigInt()
|
|
39
|
-
: undefined,
|
|
49
|
+
: undefined,
|
|
50
|
+
logs: [], // Filled in at AvalancheBlockWrapped constructor
|
|
51
|
+
};
|
|
40
52
|
}
|
|
41
53
|
exports.formatBlock = formatBlock;
|
|
42
54
|
function formatBlockUtil(block) {
|
|
@@ -47,15 +59,21 @@ function formatBlockUtil(block) {
|
|
|
47
59
|
}
|
|
48
60
|
exports.formatBlockUtil = formatBlockUtil;
|
|
49
61
|
function formatLog(log, block) {
|
|
50
|
-
const formattedLog =
|
|
62
|
+
const formattedLog = {
|
|
63
|
+
...log,
|
|
64
|
+
address: handleAddress(log.address),
|
|
65
|
+
blockNumber: handleNumber(log.blockNumber).toNumber(),
|
|
66
|
+
transactionIndex: handleNumber(log.transactionIndex).toNumber(),
|
|
67
|
+
logIndex: handleNumber(log.logIndex).toNumber(),
|
|
68
|
+
block,
|
|
51
69
|
toJSON() {
|
|
52
70
|
return JSON.stringify((0, lodash_1.omit)(this, ['transaction', 'block', 'toJSON']));
|
|
53
|
-
}
|
|
71
|
+
},
|
|
72
|
+
};
|
|
54
73
|
// Define this afterwards as the spread on `...log` breaks defining a getter
|
|
55
74
|
Object.defineProperty(formattedLog, 'transaction', {
|
|
56
75
|
get: () => {
|
|
57
|
-
|
|
58
|
-
const rawTransaction = (_a = block.transactions) === null || _a === void 0 ? void 0 : _a.find((tx) => tx.hash === log.transactionHash);
|
|
76
|
+
const rawTransaction = block.transactions?.find((tx) => tx.hash === log.transactionHash);
|
|
59
77
|
return rawTransaction;
|
|
60
78
|
},
|
|
61
79
|
});
|
|
@@ -63,20 +81,47 @@ function formatLog(log, block) {
|
|
|
63
81
|
}
|
|
64
82
|
exports.formatLog = formatLog;
|
|
65
83
|
function formatTransaction(tx, block) {
|
|
66
|
-
return
|
|
84
|
+
return {
|
|
85
|
+
...tx,
|
|
86
|
+
from: handleAddress(tx.from),
|
|
87
|
+
to: handleAddress(tx.to),
|
|
88
|
+
blockNumber: handleNumber(tx.blockNumber).toNumber(),
|
|
89
|
+
blockTimestamp: block.timestamp,
|
|
90
|
+
gas: handleNumber(tx.gas).toBigInt(),
|
|
91
|
+
gasPrice: handleNumber(tx.gasPrice).toBigInt(),
|
|
92
|
+
nonce: handleNumber(tx.nonce).toBigInt(),
|
|
93
|
+
transactionIndex: handleNumber(tx.transactionIndex).toBigInt(),
|
|
94
|
+
value: handleNumber(tx.value).toBigInt(),
|
|
95
|
+
v: handleNumber(tx.v).toBigInt(),
|
|
96
|
+
maxFeePerGas: tx.maxFeePerGas
|
|
67
97
|
? handleNumber(tx.maxFeePerGas).toBigInt()
|
|
68
|
-
: undefined,
|
|
98
|
+
: undefined,
|
|
99
|
+
maxPriorityFeePerGas: tx.maxPriorityFeePerGas
|
|
69
100
|
? handleNumber(tx.maxPriorityFeePerGas).toBigInt()
|
|
70
|
-
: undefined,
|
|
101
|
+
: undefined,
|
|
102
|
+
receipt: undefined,
|
|
71
103
|
toJSON() {
|
|
72
104
|
return JSON.stringify((0, lodash_1.omit)(this, ['block', 'receipt', 'toJSON']));
|
|
73
|
-
}
|
|
105
|
+
},
|
|
106
|
+
};
|
|
74
107
|
}
|
|
75
108
|
exports.formatTransaction = formatTransaction;
|
|
76
109
|
function formatReceipt(receipt, block) {
|
|
77
|
-
return
|
|
110
|
+
return {
|
|
111
|
+
...receipt,
|
|
112
|
+
from: handleAddress(receipt.from),
|
|
113
|
+
to: handleAddress(receipt.to),
|
|
114
|
+
blockNumber: handleNumber(receipt.blockNumber).toNumber(),
|
|
115
|
+
cumulativeGasUsed: handleNumber(receipt.cumulativeGasUsed).toBigInt(),
|
|
116
|
+
effectiveGasPrice: handleNumber(receipt.effectiveGasPrice).toBigInt(),
|
|
117
|
+
gasUsed: handleNumber(receipt.gasUsed).toBigInt(),
|
|
118
|
+
logs: receipt.logs.map(formatLog),
|
|
119
|
+
status: Boolean(handleNumber(receipt.status).toNumber()),
|
|
120
|
+
transactionIndex: handleNumber(receipt.transactionIndex).toNumber(),
|
|
121
|
+
toJSON() {
|
|
78
122
|
return JSON.stringify((0, lodash_1.omit)(this, ['toJSON']));
|
|
79
|
-
}
|
|
123
|
+
},
|
|
124
|
+
};
|
|
80
125
|
}
|
|
81
126
|
exports.formatReceipt = formatReceipt;
|
|
82
127
|
function ethereumBlockToHeader(block) {
|
|
@@ -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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AAiB,CAAC,CAAC,QAAQ,EAAE;QACrE,iBAAiB,EAAE,YAAY,CAAC,OAAO,CAAC,iBAAiB,CAAC,CAAC,QAAQ,EAAE;QACrE,OAAO,EAAE,YAAY,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,QAAQ,EAAE;QACjD,IAAI,EAAE,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,SAAS,CAAC;QACjC,MAAM,EAAE,OAAO,CAAC,YAAY,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,QAAQ,EAAE,CAAC;QACxD,gBAAgB,EAAE,YAAY,CAAC,OAAO,CAAC,gBAAgB,CAAC,CAAC,QAAQ,EAAE;QACnE,MAAM;YACJ,OAAO,IAAI,CAAC,SAAS,CAAC,IAAA,aAAI,EAAC,IAAI,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;QAChD,CAAC;KACc,CAAC;AACpB,CAAC;AAnBD,sCAmBC;AAED,SAAgB,qBAAqB,CAAC,KAA2B;IAC/D,OAAO;QACL,WAAW,EAAE,KAAK,CAAC,MAAM;QACzB,SAAS,EAAE,KAAK,CAAC,IAAI;QACrB,UAAU,EAAE,KAAK,CAAC,UAAU;KAC7B,CAAC;AACJ,CAAC;AAND,sDAMC","sourcesContent":["// Copyright 2020-2024 SubQuery Pte Ltd authors & contributors\n// SPDX-License-Identifier: 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: Record<string, 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): EthereumTransaction {\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 EthereumTransaction;\n}\n\nexport function formatReceipt<R extends EthereumReceipt = EthereumReceipt>(\n receipt: Record<string, any>,\n block: EthereumBlock,\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"]}
|
|
@@ -24,6 +24,7 @@ const indexer_manager_1 = require("../indexer.manager");
|
|
|
24
24
|
* @description Intended to behave the same as WorkerBlockDispatcherService but doesn't use worker threads or any parallel processing
|
|
25
25
|
*/
|
|
26
26
|
let BlockDispatcherService = class BlockDispatcherService extends node_core_1.BlockDispatcher {
|
|
27
|
+
indexerManager;
|
|
27
28
|
constructor(apiService, nodeConfig, indexerManager, eventEmitter, projectService, projectUpgradeService, storeService, storeCacheService, poiSyncService, project) {
|
|
28
29
|
super(nodeConfig, eventEmitter, projectService, projectUpgradeService, storeService, storeCacheService, poiSyncService, project, apiService.fetchBlocks.bind(apiService));
|
|
29
30
|
this.indexerManager = indexerManager;
|