@subql/node-ethereum 1.10.1-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 +7 -0
- package/LICENSE +201 -0
- package/README.md +76 -0
- package/bin/run +4 -0
- package/bin/run.cmd +3 -0
- package/dist/.tsbuildinfo +1 -0
- package/dist/app.module.d.ts +2 -0
- package/dist/app.module.js +35 -0
- package/dist/app.module.js.map +1 -0
- package/dist/configure/SubqueryProject.d.ts +29 -0
- package/dist/configure/SubqueryProject.js +82 -0
- package/dist/configure/SubqueryProject.js.map +1 -0
- package/dist/configure/configure.module.d.ts +7 -0
- package/dist/configure/configure.module.js +172 -0
- package/dist/configure/configure.module.js.map +1 -0
- package/dist/configure/configure.module.spec.d.ts +1 -0
- package/dist/configure/configure.module.spec.js +26 -0
- package/dist/configure/configure.module.spec.js.map +1 -0
- package/dist/ethereum/api.ethereum.d.ts +21 -0
- package/dist/ethereum/api.ethereum.js +190 -0
- package/dist/ethereum/api.ethereum.js.map +1 -0
- package/dist/ethereum/api.service.ethereum.d.ts +8 -0
- package/dist/ethereum/api.service.ethereum.js +57 -0
- package/dist/ethereum/api.service.ethereum.js.map +1 -0
- package/dist/ethereum/block.ethereum.d.ts +15 -0
- package/dist/ethereum/block.ethereum.js +87 -0
- package/dist/ethereum/block.ethereum.js.map +1 -0
- package/dist/ethereum/index.d.ts +2 -0
- package/dist/ethereum/index.js +21 -0
- package/dist/ethereum/index.js.map +1 -0
- package/dist/ethereum/utils.ethereum.d.ts +6 -0
- package/dist/ethereum/utils.ethereum.js +131 -0
- package/dist/ethereum/utils.ethereum.js.map +1 -0
- package/dist/indexer/dictionary.service.d.ts +7 -0
- package/dist/indexer/dictionary.service.js +29 -0
- package/dist/indexer/dictionary.service.js.map +1 -0
- package/dist/indexer/ds-processor.service.d.ts +26 -0
- package/dist/indexer/ds-processor.service.js +133 -0
- package/dist/indexer/ds-processor.service.js.map +1 -0
- package/dist/indexer/dynamic-ds.service.d.ts +23 -0
- package/dist/indexer/dynamic-ds.service.js +105 -0
- package/dist/indexer/dynamic-ds.service.js.map +1 -0
- package/dist/indexer/fetch.module.d.ts +2 -0
- package/dist/indexer/fetch.module.js +68 -0
- package/dist/indexer/fetch.module.js.map +1 -0
- package/dist/indexer/fetch.service.d.ts +43 -0
- package/dist/indexer/fetch.service.js +359 -0
- package/dist/indexer/fetch.service.js.map +1 -0
- package/dist/indexer/indexer.manager.d.ts +36 -0
- package/dist/indexer/indexer.manager.js +256 -0
- package/dist/indexer/indexer.manager.js.map +1 -0
- package/dist/indexer/indexer.module.d.ts +2 -0
- package/dist/indexer/indexer.module.js +52 -0
- package/dist/indexer/indexer.module.js.map +1 -0
- package/dist/indexer/project.service.d.ts +39 -0
- package/dist/indexer/project.service.js +255 -0
- package/dist/indexer/project.service.js.map +1 -0
- package/dist/indexer/sandbox.service.d.ts +12 -0
- package/dist/indexer/sandbox.service.js +58 -0
- package/dist/indexer/sandbox.service.js.map +1 -0
- package/dist/indexer/types.d.ts +10 -0
- package/dist/indexer/types.js +11 -0
- package/dist/indexer/types.js.map +1 -0
- package/dist/indexer/worker/block-dispatcher.service.d.ts +69 -0
- package/dist/indexer/worker/block-dispatcher.service.js +356 -0
- package/dist/indexer/worker/block-dispatcher.service.js.map +1 -0
- package/dist/indexer/worker/worker.d.ts +14 -0
- package/dist/indexer/worker/worker.js +85 -0
- package/dist/indexer/worker/worker.js.map +1 -0
- package/dist/indexer/worker/worker.module.d.ts +2 -0
- package/dist/indexer/worker/worker.module.js +33 -0
- package/dist/indexer/worker/worker.module.js.map +1 -0
- package/dist/indexer/worker/worker.service.d.ts +28 -0
- package/dist/indexer/worker/worker.service.js +79 -0
- package/dist/indexer/worker/worker.service.js.map +1 -0
- package/dist/init.d.ts +1 -0
- package/dist/init.js +54 -0
- package/dist/init.js.map +1 -0
- package/dist/main.d.ts +1 -0
- package/dist/main.js +14 -0
- package/dist/main.js.map +1 -0
- package/dist/meta/meta.controller.d.ts +23 -0
- package/dist/meta/meta.controller.js +36 -0
- package/dist/meta/meta.controller.js.map +1 -0
- package/dist/meta/meta.module.d.ts +2 -0
- package/dist/meta/meta.module.js +77 -0
- package/dist/meta/meta.module.js.map +1 -0
- package/dist/meta/meta.service.d.ts +42 -0
- package/dist/meta/meta.service.js +110 -0
- package/dist/meta/meta.service.js.map +1 -0
- package/dist/subcommands/forceClean.init.d.ts +1 -0
- package/dist/subcommands/forceClean.init.js +25 -0
- package/dist/subcommands/forceClean.init.js.map +1 -0
- package/dist/subcommands/forceClean.module.d.ts +4 -0
- package/dist/subcommands/forceClean.module.js +38 -0
- package/dist/subcommands/forceClean.module.js.map +1 -0
- package/dist/subcommands/forceClean.service.d.ts +8 -0
- package/dist/subcommands/forceClean.service.js +65 -0
- package/dist/subcommands/forceClean.service.js.map +1 -0
- package/dist/subcommands/reindex.init.d.ts +1 -0
- package/dist/subcommands/reindex.init.js +25 -0
- package/dist/subcommands/reindex.init.js.map +1 -0
- package/dist/subcommands/reindex.module.d.ts +4 -0
- package/dist/subcommands/reindex.module.js +39 -0
- package/dist/subcommands/reindex.module.js.map +1 -0
- package/dist/subcommands/reindex.service.d.ts +24 -0
- package/dist/subcommands/reindex.service.js +114 -0
- package/dist/subcommands/reindex.service.js.map +1 -0
- package/dist/utils/project.d.ts +13 -0
- package/dist/utils/project.js +191 -0
- package/dist/utils/project.js.map +1 -0
- package/dist/utils/string.d.ts +4 -0
- package/dist/utils/string.js +32 -0
- package/dist/utils/string.js.map +1 -0
- package/dist/yargs.d.ts +154 -0
- package/dist/yargs.js +193 -0
- package/dist/yargs.js.map +1 -0
- package/package.json +77 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api.ethereum.js","sourceRoot":"","sources":["../../src/ethereum/api.ethereum.ts"],"names":[],"mappings":";AAAA,gEAAgE;AAChE,sCAAsC;;;;;;AAEtC,4CAAoB;AACpB,gDAAwB;AACxB,kDAA0B;AAC1B,4CAA+C;AAC/C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ACpC;SACH;QAAC,OAAO,CAAC,EAAE;YACV,MAAM,CAAC,IAAI,CAAC,6BAA6B,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC;YACtD,OAAO,GAAG,CAAC;SACZ;IACH,CAAC;CACF;AA3LD,kCA2LC","sourcesContent":["// Copyright 2020-2022 OnFinality Limited authors & contributors\n// SPDX-License-Identifier: Apache-2.0\n\nimport fs from 'fs';\nimport http from 'http';\nimport https from 'https';\nimport { Interface } from '@ethersproject/abi';\nimport { Web3Provider } from '@ethersproject/providers';\nimport { RuntimeDataSourceV0_2_0 } from '@subql/common-ethereum';\nimport { getLogger } from '@subql/node-core';\nimport {\n ApiWrapper,\n BlockWrapper,\n EthereumBlockWrapper,\n EthereumTransaction,\n EthereumResult,\n EthereumLog,\n} from '@subql/types-ethereum';\nimport { hexValue } from 'ethers/lib/utils';\nimport { EthereumBlockWrapped } from './block.ethereum';\nimport {\n formatBlock,\n formatReceipt,\n formatTransaction,\n} from './utils.ethereum';\nconst Web3HttpProvider = require('web3-providers-http');\nconst Web3WsProvider = require('web3-providers-ws');\n\n// eslint-disable-next-line @typescript-eslint/no-var-requires\nconst { version: packageVersion } = require('../../package.json');\n\nconst logger = getLogger('api.ethereum');\n\nasync function loadAssets(\n ds: RuntimeDataSourceV0_2_0,\n): Promise<Record<string, string>> {\n if (!ds.assets) {\n return {};\n }\n const res: Record<string, string> = {};\n\n for (const [name, { file }] of Object.entries(ds.assets)) {\n try {\n res[name] = await fs.promises.readFile(file, { encoding: 'utf8' });\n } catch (e) {\n throw new Error(`Failed to load datasource asset ${file}`);\n }\n }\n\n return res;\n}\n\nexport class EthereumApi implements ApiWrapper<EthereumBlockWrapper> {\n private client: Web3Provider;\n private genesisBlock: Record<string, any>;\n private contractInterfaces: Record<string, Interface> = {};\n private chainId: number;\n\n constructor(private endpoint: string) {\n const { hostname, pathname, port, protocol, searchParams } = new URL(\n endpoint,\n );\n const httpAgent = new http.Agent({ keepAlive: true, maxSockets: 10 });\n const httpsAgent = new https.Agent({ keepAlive: true, maxSockets: 10 });\n\n const protocolStr = protocol.replace(':', '');\n const portNum = port\n ? parseInt(port, 10)\n : protocolStr === 'https'\n ? undefined\n : 80;\n\n let provider;\n if (protocolStr === 'https' || protocolStr === 'http') {\n const options = {\n keepAlive: true,\n headers: [\n {\n name: 'User-Agent',\n value: `Subquery-Node ${packageVersion}`,\n },\n ],\n agent: {\n http: httpAgent,\n https: httpsAgent,\n },\n };\n if ((searchParams as any).apiKey) {\n (options.headers as any).apiKey = searchParams.get('apiKey');\n }\n provider = new Web3HttpProvider(this.endpoint, options);\n } else if (protocolStr === 'ws' || protocolStr === 'wss') {\n const options = {\n headers: {\n 'User-Agent': `Subquery-Node ${packageVersion}`,\n },\n clientConfig: {\n keepAlive: true,\n },\n };\n if ((searchParams as any).apiKey) {\n (options.headers as any).apiKey = searchParams.get('apiKey');\n }\n\n provider = new Web3WsProvider(endpoint, options);\n } else {\n throw new Error(`Unsupported protocol: ${protocol}`);\n }\n\n this.client = new Web3Provider(provider);\n }\n\n async init(): Promise<void> {\n this.genesisBlock = await this.client.send('eth_getBlockByNumber', [\n hexValue(0),\n true,\n ]);\n logger.info(this.endpoint);\n\n this.chainId = await this.client.send('net_version', []);\n }\n\n async getLastHeight(): Promise<number> {\n return this.client.getBlockNumber();\n }\n\n getRuntimeChain(): string {\n return 'ethereum';\n }\n\n getChainId(): number {\n return this.chainId;\n }\n\n getGenesisHash(): string {\n return this.genesisBlock.hash;\n }\n\n getSpecName(): string {\n return 'ethereum';\n }\n\n async getFinalizedBlockHeight(): Promise<number> {\n // Doesn't seem to be a difference between finalized and latest\n return this.client.getBlockNumber();\n }\n\n async fetchBlocks(bufferBlocks: number[]): Promise<EthereumBlockWrapper[]> {\n return Promise.all(\n bufferBlocks.map(async (num) => {\n try {\n // Fetch Block\n const block_promise = await this.client.send('eth_getBlockByNumber', [\n hexValue(num),\n true,\n ]);\n\n const block = formatBlock(block_promise);\n //const block = this.client.formatter.blockWithTransactions(rawBlock);\n block.stateRoot = this.client.formatter.hash(block.stateRoot);\n // Get transaction receipts\n const transactions = await Promise.all(\n block.transactions.map(async (tx) => {\n //logger.info(JSON.stringify(tx))\n const transaction = formatTransaction(tx);\n const receipt = await this.client.send(\n 'eth_getTransactionReceipt',\n [tx.hash],\n );\n\n transaction.receipt = formatReceipt(receipt, block);\n return transaction;\n }),\n );\n return new EthereumBlockWrapped(block, transactions);\n } catch (e) {\n // Wrap error from an axios error to fix issue with error being undefined\n const error = new Error(e.message);\n logger.error(error, `Failed to fetch block at height ${num}`);\n throw error;\n }\n }),\n );\n }\n\n freezeApi(processor: any, blockContent: BlockWrapper): void {\n processor.freeze(this.client, 'api');\n }\n\n private buildInterface(\n abiName: string,\n assets: Record<string, string>,\n ): Interface | undefined {\n if (!assets[abiName]) {\n throw new Error(`ABI named \"${abiName}\" not referenced in assets`);\n }\n\n // This assumes that all datasources have a different abi name or they are the same abi\n if (!this.contractInterfaces[abiName]) {\n // Constructing the interface validates the ABI\n try {\n let abiObj = JSON.parse(assets[abiName]);\n\n /*\n * Allows parsing JSON artifacts as well as ABIs\n * https://trufflesuite.github.io/artifact-updates/background.html#what-are-artifacts\n */\n if (!Array.isArray(abiObj) && abiObj.abi) {\n abiObj = abiObj.abi;\n }\n\n this.contractInterfaces[abiName] = new Interface(abiObj);\n } catch (e) {\n logger.error(`Unable to parse ABI: ${e.message}`);\n throw new Error('ABI is invalid');\n }\n }\n\n return this.contractInterfaces[abiName];\n }\n\n async parseLog<T extends EthereumResult = EthereumResult>(\n log: EthereumLog,\n ds: RuntimeDataSourceV0_2_0,\n ): Promise<EthereumLog<T> | EthereumLog> {\n try {\n if (!ds?.options?.abi) {\n return log;\n }\n const iface = this.buildInterface(ds.options.abi, await loadAssets(ds));\n return {\n ...log,\n args: iface?.parseLog(log).args as T,\n };\n } catch (e) {\n logger.warn(`Failed to parse log data: ${e.message}`);\n return log;\n }\n }\n}\n"]}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ApiService } from '@subql/node-core';
|
|
2
|
+
import { EthereumApi } from './api.ethereum';
|
|
3
|
+
export declare class EthereumApiService extends ApiService {
|
|
4
|
+
private _api;
|
|
5
|
+
init(): Promise<EthereumApiService>;
|
|
6
|
+
get api(): EthereumApi;
|
|
7
|
+
private set api(value);
|
|
8
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright 2020-2022 OnFinality Limited authors & contributors
|
|
3
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
5
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
6
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
7
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
8
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
9
|
+
};
|
|
10
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
+
exports.EthereumApiService = void 0;
|
|
12
|
+
const common_1 = require("@nestjs/common");
|
|
13
|
+
const node_core_1 = require("@subql/node-core");
|
|
14
|
+
const api_ethereum_1 = require("./api.ethereum");
|
|
15
|
+
const logger = (0, node_core_1.getLogger)('api');
|
|
16
|
+
let EthereumApiService = class EthereumApiService extends node_core_1.ApiService {
|
|
17
|
+
async init() {
|
|
18
|
+
try {
|
|
19
|
+
let network;
|
|
20
|
+
try {
|
|
21
|
+
network = this.project.network;
|
|
22
|
+
}
|
|
23
|
+
catch (e) {
|
|
24
|
+
logger.error(Object.keys(e));
|
|
25
|
+
process.exit(1);
|
|
26
|
+
}
|
|
27
|
+
this.api = new api_ethereum_1.EthereumApi(network.endpoint);
|
|
28
|
+
await this.api.init();
|
|
29
|
+
this.networkMeta = {
|
|
30
|
+
chain: this.api.getRuntimeChain(),
|
|
31
|
+
specName: this.api.getSpecName(),
|
|
32
|
+
genesisHash: this.api.getGenesisHash(),
|
|
33
|
+
};
|
|
34
|
+
if (network.chainId !== this.api.getChainId().toString()) {
|
|
35
|
+
const err = new Error(`Network chainId doesn't match expected chainId. expected="${network.chainId}" actual="${this.api.getChainId()}`);
|
|
36
|
+
logger.error(err, err.message);
|
|
37
|
+
throw err;
|
|
38
|
+
}
|
|
39
|
+
return this;
|
|
40
|
+
}
|
|
41
|
+
catch (e) {
|
|
42
|
+
logger.error(e, 'Failed to init api service');
|
|
43
|
+
process.exit(1);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
get api() {
|
|
47
|
+
return this._api;
|
|
48
|
+
}
|
|
49
|
+
set api(value) {
|
|
50
|
+
this._api = value;
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
EthereumApiService = __decorate([
|
|
54
|
+
(0, common_1.Injectable)()
|
|
55
|
+
], EthereumApiService);
|
|
56
|
+
exports.EthereumApiService = EthereumApiService;
|
|
57
|
+
//# sourceMappingURL=api.service.ethereum.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api.service.ethereum.js","sourceRoot":"","sources":["../../src/ethereum/api.service.ethereum.ts"],"names":[],"mappings":";AAAA,gEAAgE;AAChE,sCAAsC;;;;;;;;;AAEtC,2CAA4C;AAE5C,gDAAyD;AACzD,iDAA6C;AAE7C,MAAM,MAAM,GAAG,IAAA,qBAAS,EAAC,KAAK,CAAC,CAAC;AAGzB,IAAM,kBAAkB,GAAxB,MAAM,kBAAmB,SAAQ,sBAAU;IAGhD,KAAK,CAAC,IAAI;QACR,IAAI;YACF,IAAI,OAA6B,CAAC;YAClC,IAAI;gBACF,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC;aAChC;YAAC,OAAO,CAAC,EAAE;gBACV,MAAM,CAAC,KAAK,CAAC,M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ors\n// SPDX-License-Identifier: Apache-2.0\n\nimport { Injectable } from '@nestjs/common';\nimport { ProjectNetworkV1_0_0 } from '@subql/common-ethereum';\nimport { ApiService, getLogger } from '@subql/node-core';\nimport { EthereumApi } from './api.ethereum';\n\nconst logger = getLogger('api');\n\n@Injectable()\nexport class EthereumApiService extends ApiService {\n private _api: EthereumApi;\n\n async init(): Promise<EthereumApiService> {\n try {\n let network: ProjectNetworkV1_0_0;\n try {\n network = this.project.network;\n } catch (e) {\n logger.error(Object.keys(e));\n process.exit(1);\n }\n\n this.api = new EthereumApi(network.endpoint);\n\n await this.api.init();\n this.networkMeta = {\n chain: this.api.getRuntimeChain(),\n specName: this.api.getSpecName(),\n genesisHash: this.api.getGenesisHash(),\n };\n\n if (network.chainId !== this.api.getChainId().toString()) {\n const err = new Error(\n `Network chainId doesn't match expected chainId. expected=\"${\n network.chainId\n }\" actual=\"${this.api.getChainId()}`,\n );\n logger.error(err, err.message);\n throw err;\n }\n\n return this;\n } catch (e) {\n logger.error(e, 'Failed to init api service');\n process.exit(1);\n }\n }\n\n get api(): EthereumApi {\n return this._api;\n }\n\n private set api(value: EthereumApi) {\n this._api = value;\n }\n}\n"]}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { EthereumBlock, EthereumTransactionFilter, EthereumLog, EthereumLogFilter, EthereumBlockFilter, EthereumBlockWrapper, EthereumTransaction } from '@subql/types-ethereum';
|
|
2
|
+
export declare class EthereumBlockWrapped implements EthereumBlockWrapper {
|
|
3
|
+
private _block;
|
|
4
|
+
private _txs;
|
|
5
|
+
private _logs;
|
|
6
|
+
constructor(_block: EthereumBlock, _txs: EthereumTransaction[]);
|
|
7
|
+
get block(): EthereumBlock;
|
|
8
|
+
get blockHeight(): number;
|
|
9
|
+
get hash(): string;
|
|
10
|
+
get transactions(): EthereumTransaction[];
|
|
11
|
+
get logs(): EthereumLog[];
|
|
12
|
+
static filterBlocksProcessor(block: EthereumBlock, filter: EthereumBlockFilter): boolean;
|
|
13
|
+
static filterTransactionsProcessor(transaction: EthereumTransaction, filter: EthereumTransactionFilter, address?: string): boolean;
|
|
14
|
+
static filterLogsProcessor(log: EthereumLog, filter: EthereumLogFilter, address?: string): boolean;
|
|
15
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright 2020-2022 OnFinality Limited authors & contributors
|
|
3
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
+
exports.EthereumBlockWrapped = void 0;
|
|
6
|
+
const lodash_1 = require("lodash");
|
|
7
|
+
const string_1 = require("../utils/string");
|
|
8
|
+
const utils_ethereum_1 = require("./utils.ethereum");
|
|
9
|
+
class EthereumBlockWrapped {
|
|
10
|
+
constructor(_block, _txs) {
|
|
11
|
+
this._block = _block;
|
|
12
|
+
this._txs = _txs;
|
|
13
|
+
this._logs = (0, lodash_1.flatten)(_txs.map((tx) => tx.receipt.logs)).map((log) => (0, utils_ethereum_1.formatLog)(log, _block));
|
|
14
|
+
this._logs.map((log) => {
|
|
15
|
+
log.block = this.block;
|
|
16
|
+
return log;
|
|
17
|
+
});
|
|
18
|
+
this.block.logs = this._logs.map((log) => {
|
|
19
|
+
const logCopy = Object.assign({}, log);
|
|
20
|
+
logCopy.block = undefined;
|
|
21
|
+
return logCopy;
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
get block() {
|
|
25
|
+
return this._block;
|
|
26
|
+
}
|
|
27
|
+
get blockHeight() {
|
|
28
|
+
return this.block.number;
|
|
29
|
+
}
|
|
30
|
+
get hash() {
|
|
31
|
+
return this.block.hash;
|
|
32
|
+
}
|
|
33
|
+
get transactions() {
|
|
34
|
+
return this._txs;
|
|
35
|
+
}
|
|
36
|
+
get logs() {
|
|
37
|
+
return this._logs;
|
|
38
|
+
}
|
|
39
|
+
static filterBlocksProcessor(block, filter) {
|
|
40
|
+
if ((filter === null || filter === void 0 ? void 0 : filter.modulo) && block.number % filter.modulo !== 0) {
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
return true;
|
|
44
|
+
}
|
|
45
|
+
static filterTransactionsProcessor(transaction, filter, address) {
|
|
46
|
+
if (!filter)
|
|
47
|
+
return true;
|
|
48
|
+
if (filter.to && !(0, string_1.stringNormalizedEq)(filter.to, transaction.to)) {
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
if (filter.from && !(0, string_1.stringNormalizedEq)(filter.from, transaction.from)) {
|
|
52
|
+
return false;
|
|
53
|
+
}
|
|
54
|
+
if (address && !filter.to && !(0, string_1.stringNormalizedEq)(address, transaction.to)) {
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
57
|
+
if (filter.function &&
|
|
58
|
+
transaction.input.indexOf((0, string_1.functionToSighash)(filter.function)) !== 0) {
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
return true;
|
|
62
|
+
}
|
|
63
|
+
static filterLogsProcessor(log, filter, address) {
|
|
64
|
+
if (address && !(0, string_1.stringNormalizedEq)(address, log.address)) {
|
|
65
|
+
return false;
|
|
66
|
+
}
|
|
67
|
+
if (!filter)
|
|
68
|
+
return true;
|
|
69
|
+
if (filter.topics) {
|
|
70
|
+
for (let i = 0; i < Math.min(filter.topics.length, 4); i++) {
|
|
71
|
+
const topic = filter.topics[i];
|
|
72
|
+
if (!topic) {
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
if (!log.topics[i]) {
|
|
76
|
+
return false;
|
|
77
|
+
}
|
|
78
|
+
if (!(0, string_1.hexStringEq)((0, string_1.eventToTopic)(topic), log.topics[i])) {
|
|
79
|
+
return false;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
return true;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
exports.EthereumBlockWrapped = EthereumBlockWrapped;
|
|
87
|
+
//# sourceMappingURL=block.ethereum.js.map
|
|
@@ -0,0 +1 @@
|
|
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K,CAAC;SACd;QAED,IAAI,CAAC,MAAM;YAAE,OAAO,IAAI,CAAC;QAEzB,IAAI,MAAM,CAAC,MAAM,EAAE;YACjB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE;gBAC1D,MAAM,KAAK,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;gBAC/B,IAAI,CAAC,KAAK,EAAE;oBACV,SAAS;iBACV;gBAED,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE;oBAClB,OAAO,KAAK,CAAC;iBACd;gBACD,IAAI,CAAC,IAAA,oBAAW,EAAC,IAAA,qBAAY,EAAC,KAAK,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,EAAE;oBACpD,OAAO,KAAK,CAAC;iBACd;aACF;SACF;QACD,OAAO,IAAI,CAAC;IACd,CAAC;CACF;AAtGD,oDAsGC","sourcesContent":["// Copyright 2020-2022 OnFinality Limited authors & contributors\n// SPDX-License-Identifier: Apache-2.0\n\nimport {\n EthereumBlock,\n EthereumTransactionFilter,\n EthereumLog,\n EthereumLogFilter,\n EthereumResult,\n EthereumBlockFilter,\n EthereumBlockWrapper,\n EthereumTransaction,\n} from '@subql/types-ethereum';\nimport { flatten } from 'lodash';\nimport {\n eventToTopic,\n functionToSighash,\n hexStringEq,\n stringNormalizedEq,\n} from '../utils/string';\nimport { formatLog } from './utils.ethereum';\n\nexport class EthereumBlockWrapped implements EthereumBlockWrapper {\n private _logs: EthereumLog[];\n constructor(\n private _block: EthereumBlock,\n private _txs: EthereumTransaction[],\n ) {\n this._logs = flatten(_txs.map((tx) => tx.receipt.logs)).map((log) =>\n formatLog(log, _block),\n ) as EthereumLog[];\n this._logs.map((log) => {\n log.block = this.block;\n return log;\n });\n this.block.logs = this._logs.map((log) => {\n const logCopy = { ...log };\n logCopy.block = undefined;\n return logCopy;\n });\n }\n\n get block(): EthereumBlock {\n return this._block;\n }\n\n get blockHeight(): number {\n return this.block.number;\n }\n\n get hash(): string {\n return this.block.hash;\n }\n\n get transactions(): EthereumTransaction[] {\n return this._txs;\n }\n\n get logs(): EthereumLog[] {\n return this._logs;\n }\n\n static filterBlocksProcessor(\n block: EthereumBlock,\n filter: EthereumBlockFilter,\n ): boolean {\n if (filter?.modulo && block.number % filter.modulo !== 0) {\n return false;\n }\n return true;\n }\n\n static filterTransactionsProcessor(\n transaction: EthereumTransaction,\n filter: EthereumTransactionFilter,\n address?: string,\n ): boolean {\n if (!filter) return true;\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 (address && !filter.to && !stringNormalizedEq(address, transaction.to)) {\n return false;\n }\n if (\n filter.function &&\n transaction.input.indexOf(functionToSighash(filter.function)) !== 0\n ) {\n return false;\n }\n return true;\n }\n\n static filterLogsProcessor(\n log: EthereumLog,\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 if (!hexStringEq(eventToTopic(topic), log.topics[i])) {\n return false;\n }\n }\n }\n return true;\n }\n}\n"]}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright 2020-2022 OnFinality Limited authors & contributors
|
|
3
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
5
|
+
if (k2 === undefined) k2 = k;
|
|
6
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
7
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
8
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
9
|
+
}
|
|
10
|
+
Object.defineProperty(o, k2, desc);
|
|
11
|
+
}) : (function(o, m, k, k2) {
|
|
12
|
+
if (k2 === undefined) k2 = k;
|
|
13
|
+
o[k2] = m[k];
|
|
14
|
+
}));
|
|
15
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
16
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
17
|
+
};
|
|
18
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
+
__exportStar(require("./api.ethereum"), exports);
|
|
20
|
+
__exportStar(require("./api.service.ethereum"), exports);
|
|
21
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/ethereum/index.ts"],"names":[],"mappings":";AAAA,gEAAgE;AAChE,sCAAsC;;;;;;;;;;;;;;;;AAEtC,iDAA+B;AAC/B,yDAAuC","sourcesContent":["// Copyright 2020-2022 OnFinality Limited authors & contributors\n// SPDX-License-Identifier: Apache-2.0\n\nexport * from './api.ethereum';\nexport * from './api.service.ethereum';\n"]}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { ApiWrapper, EthereumBlock, EthereumLog, EthereumReceipt, EthereumResult, EthereumTransaction } from '@subql/types-ethereum';
|
|
2
|
+
export declare function calcInterval(api: ApiWrapper): number;
|
|
3
|
+
export declare function formatBlock(block: Record<string, any>): EthereumBlock;
|
|
4
|
+
export declare function formatLog(log: EthereumLog<EthereumResult> | EthereumLog, block: EthereumBlock): EthereumLog<EthereumResult> | EthereumLog;
|
|
5
|
+
export declare function formatTransaction(tx: Record<string, any>): EthereumTransaction;
|
|
6
|
+
export declare function formatReceipt(receipt: Record<string, any>, block: EthereumBlock): EthereumReceipt;
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright 2020-2022 OnFinality Limited authors & contributors
|
|
3
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
+
exports.formatReceipt = exports.formatTransaction = exports.formatLog = exports.formatBlock = exports.calcInterval = void 0;
|
|
6
|
+
const address_1 = require("@ethersproject/address");
|
|
7
|
+
const bignumber_1 = require("@ethersproject/bignumber");
|
|
8
|
+
const constants_1 = require("@ethersproject/constants");
|
|
9
|
+
function calcInterval(api) {
|
|
10
|
+
// TODO find a way to get this from the blockchain
|
|
11
|
+
return 6000;
|
|
12
|
+
}
|
|
13
|
+
exports.calcInterval = calcInterval;
|
|
14
|
+
function handleAddress(value) {
|
|
15
|
+
if (value === '0x') {
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
return (0, address_1.getAddress)(value);
|
|
19
|
+
}
|
|
20
|
+
function handleNumber(value) {
|
|
21
|
+
if (value === undefined) {
|
|
22
|
+
return constants_1.Zero;
|
|
23
|
+
}
|
|
24
|
+
if (value === '0x') {
|
|
25
|
+
return constants_1.Zero;
|
|
26
|
+
}
|
|
27
|
+
return bignumber_1.BigNumber.from(value);
|
|
28
|
+
}
|
|
29
|
+
function formatBlock(block) {
|
|
30
|
+
const newBlock = {
|
|
31
|
+
difficulty: handleNumber(block.difficulty).toBigInt(),
|
|
32
|
+
extDataGasUsed: block.extDataGasUsed,
|
|
33
|
+
extDataHash: block.extDataHash,
|
|
34
|
+
gasLimit: handleNumber(block.gasLimit).toBigInt(),
|
|
35
|
+
gasUsed: handleNumber(block.gasUsed).toBigInt(),
|
|
36
|
+
hash: block.hash,
|
|
37
|
+
logsBloom: block.logsBloom,
|
|
38
|
+
miner: block.miner,
|
|
39
|
+
mixHash: block.mixHash,
|
|
40
|
+
nonce: block.nonce,
|
|
41
|
+
number: handleNumber(block.number).toNumber(),
|
|
42
|
+
parentHash: block.parentHash,
|
|
43
|
+
receiptsRoot: block.receiptsRoot,
|
|
44
|
+
sha3Uncles: block.sha3Uncles,
|
|
45
|
+
size: handleNumber(block.size).toBigInt(),
|
|
46
|
+
stateRoot: block.stateRoot,
|
|
47
|
+
timestamp: handleNumber(block.timestamp).toBigInt(),
|
|
48
|
+
totalDifficulty: handleNumber(block.totalDifficulty).toBigInt(),
|
|
49
|
+
transactions: block.transactions,
|
|
50
|
+
transactionsRoot: block.transactionsRoot,
|
|
51
|
+
uncles: block.uncles,
|
|
52
|
+
baseFeePerGas: block.baseFeePerGas
|
|
53
|
+
? handleNumber(block.baseFeePerGas).toBigInt()
|
|
54
|
+
: undefined,
|
|
55
|
+
blockGasCost: block.blockGasCost
|
|
56
|
+
? handleNumber(block.blockGasCost).toBigInt()
|
|
57
|
+
: undefined,
|
|
58
|
+
blockExtraData: block.blockExtraData,
|
|
59
|
+
logs: [], // Filled in at AvalancheBlockWrapped constructor
|
|
60
|
+
};
|
|
61
|
+
return newBlock;
|
|
62
|
+
}
|
|
63
|
+
exports.formatBlock = formatBlock;
|
|
64
|
+
function formatLog(log, block) {
|
|
65
|
+
const newLog = {
|
|
66
|
+
address: log.address,
|
|
67
|
+
topics: log.topics,
|
|
68
|
+
data: log.data,
|
|
69
|
+
blockNumber: handleNumber(log.blockNumber).toNumber(),
|
|
70
|
+
transactionHash: log.transactionHash,
|
|
71
|
+
transactionIndex: handleNumber(log.transactionIndex).toNumber(),
|
|
72
|
+
blockHash: log.blockHash,
|
|
73
|
+
logIndex: handleNumber(log.logIndex).toNumber(),
|
|
74
|
+
removed: log.removed,
|
|
75
|
+
args: log.args,
|
|
76
|
+
block,
|
|
77
|
+
};
|
|
78
|
+
return newLog;
|
|
79
|
+
}
|
|
80
|
+
exports.formatLog = formatLog;
|
|
81
|
+
function formatTransaction(tx) {
|
|
82
|
+
const transaction = {
|
|
83
|
+
blockHash: tx.blockHash,
|
|
84
|
+
blockNumber: handleNumber(tx.blockNumber).toNumber(),
|
|
85
|
+
from: tx.from,
|
|
86
|
+
gas: handleNumber(tx.gas).toBigInt(),
|
|
87
|
+
gasPrice: handleNumber(tx.gasPrice).toBigInt(),
|
|
88
|
+
hash: tx.hash,
|
|
89
|
+
input: tx.input,
|
|
90
|
+
nonce: handleNumber(tx.nonce).toBigInt(),
|
|
91
|
+
to: tx.to,
|
|
92
|
+
transactionIndex: handleNumber(tx.transactionIndex).toBigInt(),
|
|
93
|
+
value: handleNumber(tx.value).toBigInt(),
|
|
94
|
+
type: tx.type,
|
|
95
|
+
v: handleNumber(tx.v).toBigInt(),
|
|
96
|
+
r: tx.r,
|
|
97
|
+
s: tx.s,
|
|
98
|
+
accessList: tx.accessList,
|
|
99
|
+
chainId: tx.chainId,
|
|
100
|
+
maxFeePerGas: tx.maxFeePerGas
|
|
101
|
+
? handleNumber(tx.maxFeePerGas).toBigInt()
|
|
102
|
+
: undefined,
|
|
103
|
+
maxPriorityFeePerGas: tx.maxPriorityFeePerGas
|
|
104
|
+
? handleNumber(tx.maxPriorityFeePerGas).toBigInt()
|
|
105
|
+
: undefined,
|
|
106
|
+
receipt: undefined, // Filled in at AvalancheApi.fetchBlocks
|
|
107
|
+
};
|
|
108
|
+
return transaction;
|
|
109
|
+
}
|
|
110
|
+
exports.formatTransaction = formatTransaction;
|
|
111
|
+
function formatReceipt(receipt, block) {
|
|
112
|
+
const newReceipt = {
|
|
113
|
+
blockHash: receipt.blockHash,
|
|
114
|
+
blockNumber: handleNumber(receipt.blockNumber).toNumber(),
|
|
115
|
+
contractAddress: receipt.contractAddress,
|
|
116
|
+
cumulativeGasUsed: handleNumber(receipt.cumulativeGasUsed).toBigInt(),
|
|
117
|
+
effectiveGasPrice: handleNumber(receipt.effectiveGasPrice).toBigInt(),
|
|
118
|
+
from: receipt.from,
|
|
119
|
+
gasUsed: handleNumber(receipt.gasUsed).toBigInt(),
|
|
120
|
+
logs: receipt.logs.map((log) => formatLog(log, block)),
|
|
121
|
+
logsBloom: receipt.logsBloom,
|
|
122
|
+
status: Boolean(handleNumber(receipt.status).toNumber()),
|
|
123
|
+
to: receipt.to,
|
|
124
|
+
transactionHash: receipt.transactionHash,
|
|
125
|
+
transactionIndex: handleNumber(receipt.transactionIndex).toNumber(),
|
|
126
|
+
type: receipt.type,
|
|
127
|
+
};
|
|
128
|
+
return newReceipt;
|
|
129
|
+
}
|
|
130
|
+
exports.formatReceipt = formatReceipt;
|
|
131
|
+
//# sourceMappingURL=utils.ethereum.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.ethereum.js","sourceRoot":"","sources":["../../src/ethereum/utils.ethereum.ts"],"names":[],"mappings":";AAAA,gEAAgE;AAChE,sCAAsC;;;AAEtC,oDAAoD;AACpD,wDAAqD;AACrD,wDAAgD;AAUhD,SAAgB,YAAY,CAAC,GAAe;IAC1C,kDAAkD;IAClD,OAAO,IAAI,CAAC;AACd,CAAC;AAHD,oCAGC;AAED,SAAS,aAAa,CAAC,KAAa;IAClC,IAAI,KAAK,KAAK,IAAI,EAAE;QAClB,OAAO,IAAI,CAAC;KACb;IACD,OAAO,IAAA,oBAAU,EAAC,KAAK,CAAC,CAAC;AAC3B,CAAC;AAED,SAAS,YAAY,CAAC,KAAsB;IAC1C,IAAI,KAAK,KAAK,SAAS,EAAE;QACvB,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;AAED,SAAgB,WAAW,CAAC,KAA0B;IACpD,MAAM,QAAQ,GAAkB;QAC9B,UAAU,EAAE,YAAY,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,QAAQ,EAAE;QACrD,cAAc,EAAE,KAAK,CAAC,cAAc;QACpC,WAAW,EAAE,KAAK,CAAC,WAAW;QAC9B,QAAQ,EAAE,YAAY,CAAC,KAAK,CAAC,QAAQ,C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O,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,SAAS,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;QACtD,SAAS,EAAE,OAAO,CAAC,SAAS;QAC5B,MAAM,EAAE,OAAO,CAAC,YAAY,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,QAAQ,EAAE,CAAC;QACxD,EAAE,EAAE,OAAO,CAAC,EAAE;QACd,eAAe,EAAE,OAAO,CAAC,eAAe;QACxC,gBAAgB,EAAE,YAAY,CAAC,OAAO,CAAC,gBAAgB,CAAC,CAAC,QAAQ,EAAE;QACnE,IAAI,EAAE,OAAO,CAAC,IAAI;KACnB,CAAC;IACF,OAAO,UAAU,CAAC;AACpB,CAAC;AArBD,sCAqBC","sourcesContent":["// Copyright 2020-2022 OnFinality Limited authors & contributors\n// SPDX-License-Identifier: Apache-2.0\n\nimport { getAddress } from '@ethersproject/address';\nimport { BigNumber } from '@ethersproject/bignumber';\nimport { Zero } from '@ethersproject/constants';\nimport {\n ApiWrapper,\n EthereumBlock,\n EthereumLog,\n EthereumReceipt,\n EthereumResult,\n EthereumTransaction,\n} from '@subql/types-ethereum';\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 {\n if (value === '0x') {\n return null;\n }\n return getAddress(value);\n}\n\nfunction handleNumber(value: string | number): BigNumber {\n if (value === undefined) {\n return Zero;\n }\n if (value === '0x') {\n return Zero;\n }\n return BigNumber.from(value);\n}\n\nexport function formatBlock(block: Record<string, any>): EthereumBlock {\n const newBlock: EthereumBlock = {\n difficulty: handleNumber(block.difficulty).toBigInt(),\n extDataGasUsed: block.extDataGasUsed,\n extDataHash: block.extDataHash,\n gasLimit: handleNumber(block.gasLimit).toBigInt(),\n gasUsed: handleNumber(block.gasUsed).toBigInt(),\n hash: block.hash,\n logsBloom: block.logsBloom,\n miner: block.miner,\n mixHash: block.mixHash,\n nonce: block.nonce,\n number: handleNumber(block.number).toNumber(),\n parentHash: block.parentHash,\n receiptsRoot: block.receiptsRoot,\n sha3Uncles: block.sha3Uncles,\n size: handleNumber(block.size).toBigInt(),\n stateRoot: block.stateRoot,\n timestamp: handleNumber(block.timestamp).toBigInt(),\n totalDifficulty: handleNumber(block.totalDifficulty).toBigInt(),\n transactions: block.transactions,\n transactionsRoot: block.transactionsRoot,\n uncles: block.uncles,\n baseFeePerGas: block.baseFeePerGas\n ? handleNumber(block.baseFeePerGas).toBigInt()\n : undefined,\n blockGasCost: block.blockGasCost\n ? handleNumber(block.blockGasCost).toBigInt()\n : undefined,\n blockExtraData: block.blockExtraData,\n logs: [], // Filled in at AvalancheBlockWrapped constructor\n };\n\n return newBlock;\n}\nexport function formatLog(\n log: EthereumLog<EthereumResult> | EthereumLog,\n block: EthereumBlock,\n): EthereumLog<EthereumResult> | EthereumLog {\n const newLog: EthereumLog<EthereumResult> = {\n address: log.address,\n topics: log.topics,\n data: log.data,\n blockNumber: handleNumber(log.blockNumber).toNumber(),\n transactionHash: log.transactionHash,\n transactionIndex: handleNumber(log.transactionIndex).toNumber(),\n blockHash: log.blockHash,\n logIndex: handleNumber(log.logIndex).toNumber(),\n removed: log.removed,\n args: log.args,\n block,\n };\n return newLog;\n}\n\nexport function formatTransaction(\n tx: Record<string, any>,\n): EthereumTransaction {\n const transaction: EthereumTransaction = {\n blockHash: tx.blockHash,\n blockNumber: handleNumber(tx.blockNumber).toNumber(),\n from: tx.from,\n gas: handleNumber(tx.gas).toBigInt(),\n gasPrice: handleNumber(tx.gasPrice).toBigInt(),\n hash: tx.hash,\n input: tx.input,\n nonce: handleNumber(tx.nonce).toBigInt(),\n to: tx.to,\n transactionIndex: handleNumber(tx.transactionIndex).toBigInt(),\n value: handleNumber(tx.value).toBigInt(),\n type: tx.type,\n v: handleNumber(tx.v).toBigInt(),\n r: tx.r,\n s: tx.s,\n accessList: tx.accessList,\n chainId: tx.chainId,\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 AvalancheApi.fetchBlocks\n };\n return transaction;\n}\n\nexport function formatReceipt(\n receipt: Record<string, any>,\n block: EthereumBlock,\n): EthereumReceipt {\n const newReceipt: EthereumReceipt = {\n blockHash: receipt.blockHash,\n blockNumber: handleNumber(receipt.blockNumber).toNumber(),\n contractAddress: receipt.contractAddress,\n cumulativeGasUsed: handleNumber(receipt.cumulativeGasUsed).toBigInt(),\n effectiveGasPrice: handleNumber(receipt.effectiveGasPrice).toBigInt(),\n from: receipt.from,\n gasUsed: handleNumber(receipt.gasUsed).toBigInt(),\n logs: receipt.logs.map((log) => formatLog(log, block)),\n logsBloom: receipt.logsBloom,\n status: Boolean(handleNumber(receipt.status).toNumber()),\n to: receipt.to,\n transactionHash: receipt.transactionHash,\n transactionIndex: handleNumber(receipt.transactionIndex).toNumber(),\n type: receipt.type,\n };\n return newReceipt;\n}\n"]}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { OnApplicationShutdown } from '@nestjs/common';
|
|
2
|
+
import { NodeConfig, DictionaryService as CoreDictionaryService } from '@subql/node-core';
|
|
3
|
+
import { SubqueryProject } from '../configure/SubqueryProject';
|
|
4
|
+
export declare class DictionaryService extends CoreDictionaryService implements OnApplicationShutdown {
|
|
5
|
+
protected project: SubqueryProject;
|
|
6
|
+
constructor(project: SubqueryProject, nodeConfig: NodeConfig);
|
|
7
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright 2020-2022 OnFinality Limited authors & contributors
|
|
3
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
5
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
6
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
7
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
8
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
9
|
+
};
|
|
10
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
11
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
12
|
+
};
|
|
13
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
exports.DictionaryService = void 0;
|
|
15
|
+
const common_1 = require("@nestjs/common");
|
|
16
|
+
const node_core_1 = require("@subql/node-core");
|
|
17
|
+
const SubqueryProject_1 = require("../configure/SubqueryProject");
|
|
18
|
+
let DictionaryService = class DictionaryService extends node_core_1.DictionaryService {
|
|
19
|
+
constructor(project, nodeConfig) {
|
|
20
|
+
super(project.network.dictionary, nodeConfig);
|
|
21
|
+
this.project = project;
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
DictionaryService = __decorate([
|
|
25
|
+
(0, common_1.Injectable)(),
|
|
26
|
+
__metadata("design:paramtypes", [SubqueryProject_1.SubqueryProject, node_core_1.NodeConfig])
|
|
27
|
+
], DictionaryService);
|
|
28
|
+
exports.DictionaryService = DictionaryService;
|
|
29
|
+
//# sourceMappingURL=dictionary.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dictionary.service.js","sourceRoot":"","sources":["../../src/indexer/dictionary.service.ts"],"names":[],"mappings":";AAAA,gEAAgE;AAChE,sCAAsC;;;;;;;;;;;;AAEtC,2CAAmE;AACnE,gDAG0B;AAC1B,kEAA+D;AAGxD,IAAM,iBAAiB,GAAvB,MAAM,iBACX,SAAQ,6BAAqB;IAG7B,YAAsB,OAAwB,EAAE,UAAsB;QACpE,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,UAAU,EAAE,UAAU,CAAC,CAAC;QAD1B,YAAO,GAAP,OAAO,CAAiB;IAE9C,CAAC;CACF,CAAA;AAPY,iBAAiB;IAD7B,IAAA,mBAAU,GAAE;qCAKoB,iCAAe,EAAc,sBAAU;GAJ3D,iBAAiB,CAO7B;AAPY,8CAAiB","sourcesContent":["// Copyright 2020-2022 OnFinality Limited authors & contributors\n// SPDX-License-Identifier: Apache-2.0\n\nimport { Injectable, OnApplicationShutdown } from '@nestjs/common';\nimport {\n NodeConfig,\n DictionaryService as CoreDictionaryService,\n} from '@subql/node-core';\nimport { SubqueryProject } from '../configure/SubqueryProject';\n\n@Injectable()\nexport class DictionaryService\n extends CoreDictionaryService\n implements OnApplicationShutdown\n{\n constructor(protected project: SubqueryProject, nodeConfig: NodeConfig) {\n super(project.network.dictionary, nodeConfig);\n }\n}\n"]}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { EthereumHandlerKind, SubqlEthereumCustomDataSource, SubqlDatasourceProcessor } from '@subql/common-ethereum';
|
|
2
|
+
import { NodeConfig, Sandbox } from '@subql/node-core';
|
|
3
|
+
import { SecondLayerHandlerProcessor_0_0_0, SecondLayerHandlerProcessor_1_0_0, SubqlCustomDatasource } from '@subql/types-ethereum';
|
|
4
|
+
import { SubqueryProject } from '../configure/SubqueryProject';
|
|
5
|
+
export interface DsPluginSandboxOption {
|
|
6
|
+
root: string;
|
|
7
|
+
entry: string;
|
|
8
|
+
script: string;
|
|
9
|
+
}
|
|
10
|
+
export declare function isSecondLayerHandlerProcessor_0_0_0<K extends EthereumHandlerKind, F, E, DS extends SubqlCustomDatasource = SubqlEthereumCustomDataSource>(processor: SecondLayerHandlerProcessor_0_0_0<K, F, E, DS> | SecondLayerHandlerProcessor_1_0_0<K, F, E, DS>): processor is SecondLayerHandlerProcessor_0_0_0<K, F, E, DS>;
|
|
11
|
+
export declare function isSecondLayerHandlerProcessor_1_0_0<K extends EthereumHandlerKind, F, E, DS extends SubqlEthereumCustomDataSource = SubqlEthereumCustomDataSource>(processor: SecondLayerHandlerProcessor_0_0_0<K, F, E, DS> | SecondLayerHandlerProcessor_1_0_0<K, F, E, DS>): processor is SecondLayerHandlerProcessor_1_0_0<K, F, E, DS>;
|
|
12
|
+
export declare function asSecondLayerHandlerProcessor_1_0_0<K extends EthereumHandlerKind, F, E, DS extends SubqlEthereumCustomDataSource = SubqlEthereumCustomDataSource>(processor: SecondLayerHandlerProcessor_0_0_0<K, F, E, DS> | SecondLayerHandlerProcessor_1_0_0<K, F, E, DS>): SecondLayerHandlerProcessor_1_0_0<K, F, E, DS>;
|
|
13
|
+
export declare class DsPluginSandbox extends Sandbox {
|
|
14
|
+
constructor(option: DsPluginSandboxOption, nodeConfig: NodeConfig);
|
|
15
|
+
getDsPlugin<D extends string>(): SubqlDatasourceProcessor<D, unknown>;
|
|
16
|
+
}
|
|
17
|
+
export declare class DsProcessorService {
|
|
18
|
+
private project;
|
|
19
|
+
private readonly nodeConfig;
|
|
20
|
+
private processorCache;
|
|
21
|
+
constructor(project: SubqueryProject, nodeConfig: NodeConfig);
|
|
22
|
+
validateCustomDs(datasources: SubqlEthereumCustomDataSource[]): Promise<void>;
|
|
23
|
+
validateProjectCustomDatasources(): Promise<void>;
|
|
24
|
+
getDsProcessor<D extends string>(ds: SubqlEthereumCustomDataSource<string>): SubqlDatasourceProcessor<D, unknown>;
|
|
25
|
+
getAssets(ds: SubqlEthereumCustomDataSource): Promise<Record<string, string>>;
|
|
26
|
+
}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright 2020-2022 OnFinality Limited authors & contributors
|
|
3
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
5
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
6
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
7
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
8
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
9
|
+
};
|
|
10
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
11
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
12
|
+
};
|
|
13
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.DsProcessorService = exports.DsPluginSandbox = exports.asSecondLayerHandlerProcessor_1_0_0 = exports.isSecondLayerHandlerProcessor_1_0_0 = exports.isSecondLayerHandlerProcessor_0_0_0 = void 0;
|
|
18
|
+
const fs_1 = __importDefault(require("fs"));
|
|
19
|
+
const path_1 = __importDefault(require("path"));
|
|
20
|
+
const common_1 = require("@nestjs/common");
|
|
21
|
+
const common_ethereum_1 = require("@subql/common-ethereum");
|
|
22
|
+
const node_core_1 = require("@subql/node-core");
|
|
23
|
+
const vm2_1 = require("vm2");
|
|
24
|
+
const SubqueryProject_1 = require("../configure/SubqueryProject");
|
|
25
|
+
const logger = (0, node_core_1.getLogger)('ds-sandbox');
|
|
26
|
+
function isSecondLayerHandlerProcessor_0_0_0(processor) {
|
|
27
|
+
// Exisiting datasource processors had no concept of specVersion, therefore undefined is equivalent to 0.0.0
|
|
28
|
+
return processor.specVersion === undefined;
|
|
29
|
+
}
|
|
30
|
+
exports.isSecondLayerHandlerProcessor_0_0_0 = isSecondLayerHandlerProcessor_0_0_0;
|
|
31
|
+
function isSecondLayerHandlerProcessor_1_0_0(processor) {
|
|
32
|
+
return processor.specVersion === '1.0.0';
|
|
33
|
+
}
|
|
34
|
+
exports.isSecondLayerHandlerProcessor_1_0_0 = isSecondLayerHandlerProcessor_1_0_0;
|
|
35
|
+
function asSecondLayerHandlerProcessor_1_0_0(processor) {
|
|
36
|
+
if (isSecondLayerHandlerProcessor_1_0_0(processor)) {
|
|
37
|
+
return processor;
|
|
38
|
+
}
|
|
39
|
+
if (!isSecondLayerHandlerProcessor_0_0_0(processor)) {
|
|
40
|
+
throw new Error('Unsupported ds processor version');
|
|
41
|
+
}
|
|
42
|
+
return Object.assign(Object.assign({}, processor), { specVersion: '1.0.0', filterProcessor: (params) => processor.filterProcessor(params.filter, params.input, params.ds), transformer: (params) => processor
|
|
43
|
+
.transformer(params.input, params.ds, params.api, params.assets)
|
|
44
|
+
.then((res) => [res]) });
|
|
45
|
+
}
|
|
46
|
+
exports.asSecondLayerHandlerProcessor_1_0_0 = asSecondLayerHandlerProcessor_1_0_0;
|
|
47
|
+
class DsPluginSandbox extends node_core_1.Sandbox {
|
|
48
|
+
constructor(option, nodeConfig) {
|
|
49
|
+
super(option, new vm2_1.VMScript(`module.exports = require('${option.entry}').default;`, path_1.default.join(option.root, 'ds_sandbox')), nodeConfig);
|
|
50
|
+
this.freeze(logger, 'logger');
|
|
51
|
+
}
|
|
52
|
+
getDsPlugin() {
|
|
53
|
+
return this.run(this.script);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
exports.DsPluginSandbox = DsPluginSandbox;
|
|
57
|
+
let DsProcessorService = class DsProcessorService {
|
|
58
|
+
constructor(project, nodeConfig) {
|
|
59
|
+
this.project = project;
|
|
60
|
+
this.nodeConfig = nodeConfig;
|
|
61
|
+
this.processorCache = {};
|
|
62
|
+
}
|
|
63
|
+
async validateCustomDs(datasources) {
|
|
64
|
+
for (const ds of datasources) {
|
|
65
|
+
const processor = this.getDsProcessor(ds);
|
|
66
|
+
/* Standard validation applicable to all custom ds and processors */
|
|
67
|
+
if (ds.kind !== processor.kind) {
|
|
68
|
+
throw new Error(`ds kind (${ds.kind}) doesnt match processor (${processor.kind})`);
|
|
69
|
+
}
|
|
70
|
+
for (const handler of ds.mapping.handlers) {
|
|
71
|
+
if (!(handler.kind in processor.handlerProcessors)) {
|
|
72
|
+
throw new Error(`ds kind ${handler.kind} not one of ${Object.keys(processor.handlerProcessors).join(', ')}`);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
ds.mapping.handlers.map((handler) => processor.handlerProcessors[handler.kind].filterValidator(handler.filter));
|
|
76
|
+
/* Additional processor specific validation */
|
|
77
|
+
processor.validate(ds, await this.getAssets(ds));
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
async validateProjectCustomDatasources() {
|
|
81
|
+
await this.validateCustomDs(this.project.dataSources.filter(common_ethereum_1.isCustomDs));
|
|
82
|
+
}
|
|
83
|
+
getDsProcessor(ds) {
|
|
84
|
+
if (!(0, common_ethereum_1.isCustomDs)(ds)) {
|
|
85
|
+
throw new Error(`data source is not a custom data source`);
|
|
86
|
+
}
|
|
87
|
+
if (!this.processorCache[ds.processor.file]) {
|
|
88
|
+
const sandbox = new DsPluginSandbox({
|
|
89
|
+
root: this.project.root,
|
|
90
|
+
entry: ds.processor.file,
|
|
91
|
+
script: null /* TODO get working with Readers, same as with sandbox */,
|
|
92
|
+
}, this.nodeConfig);
|
|
93
|
+
try {
|
|
94
|
+
this.processorCache[ds.processor.file] = sandbox.getDsPlugin();
|
|
95
|
+
}
|
|
96
|
+
catch (e) {
|
|
97
|
+
logger.error(`not supported ds @${ds.kind}`);
|
|
98
|
+
throw e;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
return this.processorCache[ds.processor.file];
|
|
102
|
+
}
|
|
103
|
+
// eslint-disable-next-line @typescript-eslint/require-await
|
|
104
|
+
async getAssets(ds) {
|
|
105
|
+
if (!(0, common_ethereum_1.isCustomDs)(ds)) {
|
|
106
|
+
throw new Error(`data source is not a custom data source`);
|
|
107
|
+
}
|
|
108
|
+
if (!ds.assets) {
|
|
109
|
+
return {};
|
|
110
|
+
}
|
|
111
|
+
const res = {};
|
|
112
|
+
for (const [name, { file }] of ds.assets) {
|
|
113
|
+
// TODO update with https://github.com/subquery/subql/pull/511
|
|
114
|
+
try {
|
|
115
|
+
res[name] = fs_1.default.readFileSync(file, {
|
|
116
|
+
encoding: 'utf8',
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
catch (e) {
|
|
120
|
+
logger.error(`Failed to load datasource asset ${file}`);
|
|
121
|
+
throw e;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
return res;
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
DsProcessorService = __decorate([
|
|
128
|
+
(0, common_1.Injectable)(),
|
|
129
|
+
__metadata("design:paramtypes", [SubqueryProject_1.SubqueryProject,
|
|
130
|
+
node_core_1.NodeConfig])
|
|
131
|
+
], DsProcessorService);
|
|
132
|
+
exports.DsProcessorService = DsProcessorService;
|
|
133
|
+
//# sourceMappingURL=ds-processor.service.js.map
|