@subql/node-ethereum 0.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.
Files changed (118) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/LICENSE +201 -0
  3. package/README.md +76 -0
  4. package/bin/run +4 -0
  5. package/bin/run.cmd +3 -0
  6. package/dist/.tsbuildinfo +1 -0
  7. package/dist/app.module.d.ts +2 -0
  8. package/dist/app.module.js +35 -0
  9. package/dist/app.module.js.map +1 -0
  10. package/dist/configure/SubqueryProject.d.ts +38 -0
  11. package/dist/configure/SubqueryProject.js +133 -0
  12. package/dist/configure/SubqueryProject.js.map +1 -0
  13. package/dist/configure/configure.module.d.ts +7 -0
  14. package/dist/configure/configure.module.js +172 -0
  15. package/dist/configure/configure.module.js.map +1 -0
  16. package/dist/configure/configure.module.spec.d.ts +1 -0
  17. package/dist/configure/configure.module.spec.js +26 -0
  18. package/dist/configure/configure.module.spec.js.map +1 -0
  19. package/dist/ethereum/api.ethereum.d.ts +24 -0
  20. package/dist/ethereum/api.ethereum.js +177 -0
  21. package/dist/ethereum/api.ethereum.js.map +1 -0
  22. package/dist/ethereum/api.service.ethereum.d.ts +8 -0
  23. package/dist/ethereum/api.service.ethereum.js +57 -0
  24. package/dist/ethereum/api.service.ethereum.js.map +1 -0
  25. package/dist/ethereum/block.ethereum.d.ts +15 -0
  26. package/dist/ethereum/block.ethereum.js +87 -0
  27. package/dist/ethereum/block.ethereum.js.map +1 -0
  28. package/dist/ethereum/index.d.ts +2 -0
  29. package/dist/ethereum/index.js +21 -0
  30. package/dist/ethereum/index.js.map +1 -0
  31. package/dist/ethereum/utils.ethereum.d.ts +6 -0
  32. package/dist/ethereum/utils.ethereum.js +131 -0
  33. package/dist/ethereum/utils.ethereum.js.map +1 -0
  34. package/dist/indexer/dictionary.service.d.ts +7 -0
  35. package/dist/indexer/dictionary.service.js +29 -0
  36. package/dist/indexer/dictionary.service.js.map +1 -0
  37. package/dist/indexer/ds-processor.service.d.ts +26 -0
  38. package/dist/indexer/ds-processor.service.js +133 -0
  39. package/dist/indexer/ds-processor.service.js.map +1 -0
  40. package/dist/indexer/dynamic-ds.service.d.ts +25 -0
  41. package/dist/indexer/dynamic-ds.service.js +124 -0
  42. package/dist/indexer/dynamic-ds.service.js.map +1 -0
  43. package/dist/indexer/fetch.module.d.ts +2 -0
  44. package/dist/indexer/fetch.module.js +68 -0
  45. package/dist/indexer/fetch.module.js.map +1 -0
  46. package/dist/indexer/fetch.service.d.ts +44 -0
  47. package/dist/indexer/fetch.service.js +369 -0
  48. package/dist/indexer/fetch.service.js.map +1 -0
  49. package/dist/indexer/indexer.manager.d.ts +36 -0
  50. package/dist/indexer/indexer.manager.js +266 -0
  51. package/dist/indexer/indexer.manager.js.map +1 -0
  52. package/dist/indexer/indexer.module.d.ts +2 -0
  53. package/dist/indexer/indexer.module.js +52 -0
  54. package/dist/indexer/indexer.module.js.map +1 -0
  55. package/dist/indexer/project.service.d.ts +40 -0
  56. package/dist/indexer/project.service.js +259 -0
  57. package/dist/indexer/project.service.js.map +1 -0
  58. package/dist/indexer/sandbox.service.d.ts +12 -0
  59. package/dist/indexer/sandbox.service.js +58 -0
  60. package/dist/indexer/sandbox.service.js.map +1 -0
  61. package/dist/indexer/types.d.ts +10 -0
  62. package/dist/indexer/types.js +11 -0
  63. package/dist/indexer/types.js.map +1 -0
  64. package/dist/indexer/worker/block-dispatcher.service.d.ts +69 -0
  65. package/dist/indexer/worker/block-dispatcher.service.js +356 -0
  66. package/dist/indexer/worker/block-dispatcher.service.js.map +1 -0
  67. package/dist/indexer/worker/worker.d.ts +14 -0
  68. package/dist/indexer/worker/worker.js +85 -0
  69. package/dist/indexer/worker/worker.js.map +1 -0
  70. package/dist/indexer/worker/worker.module.d.ts +2 -0
  71. package/dist/indexer/worker/worker.module.js +33 -0
  72. package/dist/indexer/worker/worker.module.js.map +1 -0
  73. package/dist/indexer/worker/worker.service.d.ts +28 -0
  74. package/dist/indexer/worker/worker.service.js +79 -0
  75. package/dist/indexer/worker/worker.service.js.map +1 -0
  76. package/dist/init.d.ts +1 -0
  77. package/dist/init.js +54 -0
  78. package/dist/init.js.map +1 -0
  79. package/dist/main.d.ts +1 -0
  80. package/dist/main.js +14 -0
  81. package/dist/main.js.map +1 -0
  82. package/dist/meta/meta.controller.d.ts +23 -0
  83. package/dist/meta/meta.controller.js +36 -0
  84. package/dist/meta/meta.controller.js.map +1 -0
  85. package/dist/meta/meta.module.d.ts +2 -0
  86. package/dist/meta/meta.module.js +77 -0
  87. package/dist/meta/meta.module.js.map +1 -0
  88. package/dist/meta/meta.service.d.ts +42 -0
  89. package/dist/meta/meta.service.js +110 -0
  90. package/dist/meta/meta.service.js.map +1 -0
  91. package/dist/subcommands/forceClean.init.d.ts +1 -0
  92. package/dist/subcommands/forceClean.init.js +25 -0
  93. package/dist/subcommands/forceClean.init.js.map +1 -0
  94. package/dist/subcommands/forceClean.module.d.ts +4 -0
  95. package/dist/subcommands/forceClean.module.js +38 -0
  96. package/dist/subcommands/forceClean.module.js.map +1 -0
  97. package/dist/subcommands/forceClean.service.d.ts +8 -0
  98. package/dist/subcommands/forceClean.service.js +65 -0
  99. package/dist/subcommands/forceClean.service.js.map +1 -0
  100. package/dist/subcommands/reindex.init.d.ts +1 -0
  101. package/dist/subcommands/reindex.init.js +25 -0
  102. package/dist/subcommands/reindex.init.js.map +1 -0
  103. package/dist/subcommands/reindex.module.d.ts +4 -0
  104. package/dist/subcommands/reindex.module.js +39 -0
  105. package/dist/subcommands/reindex.module.js.map +1 -0
  106. package/dist/subcommands/reindex.service.d.ts +24 -0
  107. package/dist/subcommands/reindex.service.js +114 -0
  108. package/dist/subcommands/reindex.service.js.map +1 -0
  109. package/dist/utils/project.d.ts +13 -0
  110. package/dist/utils/project.js +191 -0
  111. package/dist/utils/project.js.map +1 -0
  112. package/dist/utils/string.d.ts +4 -0
  113. package/dist/utils/string.js +32 -0
  114. package/dist/utils/string.js.map +1 -0
  115. package/dist/yargs.d.ts +154 -0
  116. package/dist/yargs.js +193 -0
  117. package/dist/yargs.js.map +1 -0
  118. package/package.json +77 -0
@@ -0,0 +1,177 @@
1
+ "use strict";
2
+ // Copyright 2020-2022 OnFinality Limited authors & contributors
3
+ // SPDX-License-Identifier: Apache-2.0
4
+ var __importDefault = (this && this.__importDefault) || function (mod) {
5
+ return (mod && mod.__esModule) ? mod : { "default": mod };
6
+ };
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.EthereumApi = void 0;
9
+ const fs_1 = __importDefault(require("fs"));
10
+ const abi_1 = require("@ethersproject/abi");
11
+ const providers_1 = require("@ethersproject/providers");
12
+ const node_core_1 = require("@subql/node-core");
13
+ const utils_1 = require("ethers/lib/utils");
14
+ const block_ethereum_1 = require("./block.ethereum");
15
+ const utils_ethereum_1 = require("./utils.ethereum");
16
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
17
+ const { version: packageVersion } = require('../../package.json');
18
+ const logger = (0, node_core_1.getLogger)('api.ethereum');
19
+ async function loadAssets(ds) {
20
+ if (!ds.assets) {
21
+ return {};
22
+ }
23
+ const res = {};
24
+ for (const [name, { file }] of Object.entries(ds.assets)) {
25
+ try {
26
+ res[name] = await fs_1.default.promises.readFile(file, { encoding: 'utf8' });
27
+ }
28
+ catch (e) {
29
+ throw new Error(`Failed to load datasource asset ${file}`);
30
+ }
31
+ }
32
+ return res;
33
+ }
34
+ class EthereumApi {
35
+ constructor(endpoint) {
36
+ this.endpoint = endpoint;
37
+ this.contractInterfaces = {};
38
+ const { hostname, pathname, port, protocol, searchParams } = new URL(endpoint);
39
+ const protocolStr = protocol.replace(':', '');
40
+ if (protocolStr === 'https' || protocolStr === 'http') {
41
+ const connection = {
42
+ url: this.endpoint,
43
+ headers: {
44
+ 'User-Agent': `Subquery-Node ${packageVersion}`,
45
+ },
46
+ };
47
+ if (searchParams.apiKey) {
48
+ connection.headers.apiKey = searchParams.get('apiKey');
49
+ }
50
+ this.client = new providers_1.JsonRpcProvider(connection);
51
+ }
52
+ else if (protocolStr === 'ws' || protocolStr === 'wss') {
53
+ this.client = new providers_1.WebSocketProvider(this.endpoint);
54
+ }
55
+ else {
56
+ throw new Error(`Unsupported protocol: ${protocol}`);
57
+ }
58
+ }
59
+ async init() {
60
+ this.genesisBlock = await this.client.getBlock(0);
61
+ this.chainId = (await this.client.getNetwork()).chainId;
62
+ }
63
+ async getLastHeight() {
64
+ return this.client.getBlockNumber();
65
+ }
66
+ getRuntimeChain() {
67
+ return 'ethereum';
68
+ }
69
+ getChainId() {
70
+ return this.chainId;
71
+ }
72
+ getGenesisHash() {
73
+ return this.genesisBlock.hash;
74
+ }
75
+ getSpecName() {
76
+ return 'ethereum';
77
+ }
78
+ async getFinalizedBlockHeight() {
79
+ // Doesn't seem to be a difference between finalized and latest
80
+ return this.client.getBlockNumber();
81
+ }
82
+ async getBlockByHeight(height) {
83
+ return this.client.getBlock(height);
84
+ }
85
+ async fetchBlocks(bufferBlocks) {
86
+ return Promise.all(bufferBlocks.map(async (num) => {
87
+ try {
88
+ // Fetch Block
89
+ const block_promise = await this.client.send('eth_getBlockByNumber', [
90
+ (0, utils_1.hexValue)(num),
91
+ true,
92
+ ]);
93
+ const block = (0, utils_ethereum_1.formatBlock)(block_promise);
94
+ //const block = this.client.formatter.blockWithTransactions(rawBlock);
95
+ block.stateRoot = this.client.formatter.hash(block.stateRoot);
96
+ // Get transaction receipts
97
+ const transactions = await Promise.all(block.transactions.map(async (tx) => {
98
+ //logger.info(JSON.stringify(tx))
99
+ const transaction = (0, utils_ethereum_1.formatTransaction)(tx);
100
+ const receipt = await this.client.getTransactionReceipt(tx.hash);
101
+ transaction.receipt = (0, utils_ethereum_1.formatReceipt)(receipt, block);
102
+ return transaction;
103
+ }));
104
+ return new block_ethereum_1.EthereumBlockWrapped(block, transactions);
105
+ }
106
+ catch (e) {
107
+ // Wrap error from an axios error to fix issue with error being undefined
108
+ const error = new Error(e.message);
109
+ logger.error(error, `Failed to fetch block at height ${num}`);
110
+ throw error;
111
+ }
112
+ }));
113
+ }
114
+ freezeApi(processor, blockContent) {
115
+ processor.freeze(this.client, 'api');
116
+ }
117
+ buildInterface(abiName, assets) {
118
+ if (!assets[abiName]) {
119
+ throw new Error(`ABI named "${abiName}" not referenced in assets`);
120
+ }
121
+ // This assumes that all datasources have a different abi name or they are the same abi
122
+ if (!this.contractInterfaces[abiName]) {
123
+ // Constructing the interface validates the ABI
124
+ try {
125
+ let abiObj = JSON.parse(assets[abiName]);
126
+ /*
127
+ * Allows parsing JSON artifacts as well as ABIs
128
+ * https://trufflesuite.github.io/artifact-updates/background.html#what-are-artifacts
129
+ */
130
+ if (!Array.isArray(abiObj) && abiObj.abi) {
131
+ abiObj = abiObj.abi;
132
+ }
133
+ this.contractInterfaces[abiName] = new abi_1.Interface(abiObj);
134
+ }
135
+ catch (e) {
136
+ logger.error(`Unable to parse ABI: ${e.message}`);
137
+ throw new Error('ABI is invalid');
138
+ }
139
+ }
140
+ return this.contractInterfaces[abiName];
141
+ }
142
+ async parseLog(log, ds) {
143
+ var _a;
144
+ try {
145
+ if (!((_a = ds === null || ds === void 0 ? void 0 : ds.options) === null || _a === void 0 ? void 0 : _a.abi)) {
146
+ logger.warn('No ABI provided for datasource');
147
+ return log;
148
+ }
149
+ const iface = this.buildInterface(ds.options.abi, await loadAssets(ds));
150
+ return Object.assign(Object.assign({}, log), { args: iface === null || iface === void 0 ? void 0 : iface.parseLog(log).args });
151
+ }
152
+ catch (e) {
153
+ logger.warn(`Failed to parse log data: ${e.message}`);
154
+ return log;
155
+ }
156
+ }
157
+ async parseTransaction(transaction, ds) {
158
+ var _a;
159
+ try {
160
+ if (!((_a = ds === null || ds === void 0 ? void 0 : ds.options) === null || _a === void 0 ? void 0 : _a.abi)) {
161
+ logger.warn('No ABI provided for datasource');
162
+ return transaction;
163
+ }
164
+ const assets = await loadAssets(ds);
165
+ const iface = this.buildInterface(ds.options.abi, assets);
166
+ const func = iface.getFunction((0, utils_1.hexDataSlice)(transaction.input, 0, 4));
167
+ const args = iface.decodeFunctionData(func, transaction.input);
168
+ return Object.assign(Object.assign({}, transaction), { args });
169
+ }
170
+ catch (e) {
171
+ logger.warn(`Failed to parse transaction data: ${e.message}`);
172
+ return transaction;
173
+ }
174
+ }
175
+ }
176
+ exports.EthereumApi = EthereumApi;
177
+ //# sourceMappingURL=api.ethereum.js.map
@@ -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;AAGpB,4CAA+C;AAE/C,wDAA8E;AAE9E,gDAA6C;AAS7C,4CAA0E;AAC1E,qDAAwD;AACxD,qDAI0B;AAE1B,8DAA8D;AAC9D,MAAM,EAAE,OAAO,EAAE,cAAc,EAAE,GAAG,OAAO,CAAC,oBAAoB,CAAC,CAAC;AAElE,MAAM,MAAM,GAAG,IAAA,qBAAS,EAAC,cAAc,CAAC,CAAC;AAEzC,KAAK,UAAU,UAAU,CACvB,EAA2B;IAE3B,IAAI,CAAC,EAAE,CAAC,MAAM,EAAE;QACd,OAAO,EAAE,CAAC;KACX;IACD,MAAM,GAAG,GAA2B,EAAE,CAAC;IAEvC,KAAK,MAAM,CAAC,IAAI,EAAE,EAAE,IAAI,EAAE,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC,MAAM,CAAC,EAAE;QACxD,IAAI;YACF,GAAG,CAAC,IAAI,CAAC,GAAG,MAAM,YAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,IAAI,EAAE,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC,CAAC;SACpE;QAAC,OAAO,CAAC,EAAE;YACV,MAAM,IAAI,KAAK,CAAC,mCAAmC,IAAI,EAAE,CAAC,CAAC;SAC5D;KACF;IAED,OAAO,GAAG,CAAC;AACb,CAAC;AAED,MAAa,WAAW;IAMtB,YAAoB,QAAgB;QAAhB,aA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AI,GAAG,KAAK,CAAC,WAAW,CAAC,IAAA,oBAAY,EAAC,WAAW,CAAC,KAAK,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;YACtE,MAAM,IAAI,GAAG,KAAK,CAAC,kBAAkB,CAAC,IAAI,EAAE,WAAW,CAAC,KAAK,CAAM,CAAC;YACpE,uCACK,WAAW,KACd,IAAI,IACJ;SACH;QAAC,OAAO,CAAC,EAAE;YACV,MAAM,CAAC,IAAI,CAAC,qCAAqC,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC;YAC9D,OAAO,WAAW,CAAC;SACpB;IACH,CAAC;CACF;AApLD,kCAoLC","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 { Block } from '@ethersproject/abstract-provider';\nimport { JsonRpcProvider, WebSocketProvider } 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 { ConnectionInfo, hexDataSlice, hexValue } from 'ethers/lib/utils';\nimport { EthereumBlockWrapped } from './block.ethereum';\nimport {\n formatBlock,\n formatReceipt,\n formatTransaction,\n} from './utils.ethereum';\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: JsonRpcProvider;\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\n const protocolStr = protocol.replace(':', '');\n\n if (protocolStr === 'https' || protocolStr === 'http') {\n const connection: ConnectionInfo = {\n url: this.endpoint,\n headers: {\n 'User-Agent': `Subquery-Node ${packageVersion}`,\n },\n };\n if ((searchParams as any).apiKey) {\n (connection.headers as any).apiKey = searchParams.get('apiKey');\n }\n this.client = new JsonRpcProvider(connection);\n } else if (protocolStr === 'ws' || protocolStr === 'wss') {\n this.client = new WebSocketProvider(this.endpoint);\n } else {\n throw new Error(`Unsupported protocol: ${protocol}`);\n }\n }\n\n async init(): Promise<void> {\n this.genesisBlock = await this.client.getBlock(0);\n\n this.chainId = (await this.client.getNetwork()).chainId;\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 getBlockByHeight(height: number): Promise<Block> {\n return this.client.getBlock(height);\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\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.getTransactionReceipt(tx.hash);\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 logger.warn('No ABI provided for datasource');\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 async parseTransaction<T extends EthereumResult = EthereumResult>(\n transaction: EthereumTransaction,\n ds: RuntimeDataSourceV0_2_0,\n ): Promise<EthereumTransaction<T> | EthereumTransaction> {\n try {\n if (!ds?.options?.abi) {\n logger.warn('No ABI provided for datasource');\n return transaction;\n }\n const assets = await loadAssets(ds);\n const iface = this.buildInterface(ds.options.abi, assets);\n const func = iface.getFunction(hexDataSlice(transaction.input, 0, 4));\n const args = iface.decodeFunctionData(func, transaction.input) as T;\n return {\n ...transaction,\n args,\n };\n } catch (e) {\n logger.warn(`Failed to parse transaction data: ${e.message}`);\n return transaction;\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,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;gBAC7B,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;aACjB;YAED,IAAI,CAAC,GAAG,GAAG,IAAI,0BAAW,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;YAE7C,MAAM,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC;YACtB,IAAI,CAAC,WAAW,GAAG;gBACjB,KAAK,EAAE,IAAI,CAAC,GAAG,CAAC,eAAe,EAAE;gBACjC,QAAQ,EAAE,IAAI,CAAC,GAAG,CAAC,WAAW,EAAE;gBAChC,WAAW,EAAE,IAAI,CAAC,GAAG,CAAC,cAAc,EAAE;aACvC,CAAC;YAEF,IAAI,OAAO,CAAC,OAAO,KAAK,IAAI,CAAC,GAAG,CAAC,UAAU,EAAE,CAAC,QAAQ,EAAE,EAAE;gBACxD,MAAM,GAAG,GAAG,IAAI,KAAK,CACnB,6DACE,OAAO,CAAC,OACV,aAAa,IAAI,CAAC,GAAG,CAAC,UAAU,EAAE,EAAE,CACrC,CAAC;gBACF,MAAM,CAAC,KAAK,CAAC,GAAG,EAAE,GAAG,CAAC,OAAO,CAAC,CAAC;gBAC/B,MAAM,GAAG,CAAC;aACX;YAED,OAAO,IAAI,CAAC;SACb;QAAC,OAAO,CAAC,EAAE;YACV,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,4BAA4B,CAAC,CAAC;YAC9C,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;SACjB;IACH,CAAC;IAED,IAAI,GAAG;QACL,OAAO,IAAI,CAAC,IAAI,CAAC;IACnB,CAAC;IAED,IAAY,GAAG,CAAC,KAAkB;QAChC,IAAI,CAAC,IAAI,GAAG,KAAK,CAAC;IACpB,CAAC;CACF,CAAA;AA9CY,kBAAkB;IAD9B,IAAA,mBAAU,GAAE;GACA,kBAAkB,CA8C9B;AA9CY,gDAAkB","sourcesContent":["// Copyright 2020-2022 OnFinality Limited authors & contributors\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, address?: string): 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, address) {
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 @@
1
+ {"version":3,"file":"block.ethereum.js","sourceRoot":"","sources":["../../src/ethereum/block.ethereum.ts"],"names":[],"mappings":";AAAA,gEAAgE;AAChE,sCAAsC;;;AAYtC,mCAAiC;AACjC,4CAKyB;AACzB,qDAA6C;AAE7C,MAAa,oBAAoB;IAE/B,YACU,MAAqB,EACrB,IAA2B;QAD3B,WAAM,GAAN,MAAM,CAAe;QACrB,SAAI,GAAJ,IAAI,CAAuB;QAEnC,IAAI,CAAC,KAAK,GAAG,IAAA,gBAAO,EAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAClE,IAAA,0BAAS,EAAC,GAAG,EAAE,MAAM,CAAC,CACN,CAAC;QACnB,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE;YACrB,GAAG,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC;YACvB,OAAO,GAAG,CAAC;QACb,CAAC,CAAC,CAAC;QACH,IAAI,CAAC,KAAK,CAAC,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE;YACvC,MAAM,OAAO,qBAAQ,GAAG,CAAE,CAAC;YAC3B,OAAO,CAAC,KAAK,GAAG,SAAS,CAAC;YAC1B,OAAO,OAAO,CAAC;QACjB,CAAC,CAAC,CAAC;IACL,CAAC;IAED,IAAI,KAAK;QACP,OA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AAC,QAAQ,CAAC,CAAC,KAAK,CAAC,EACnE;YACA,OAAO,KAAK,CAAC;SACd;QACD,OAAO,IAAI,CAAC;IACd,CAAC;IAED,MAAM,CAAC,mBAAmB,CACxB,GAAgB,EAChB,MAAyB,EACzB,OAAgB;QAEhB,IAAI,OAAO,IAAI,CAAC,IAAA,2BAAkB,EAAC,OAAO,EAAE,GAAG,CAAC,OAAO,CAAC,EAAE;YACxD,OAAO,KAAK,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;AAvGD,oDAuGC","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 address?: string,\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,2 @@
1
+ export * from './api.ethereum';
2
+ export * from './api.service.ethereum';
@@ -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;KAC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,WAAW,EAAE,YAAY,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC,QAAQ,EAAE;QACzD,eAAe,EAAE,OAAO,CAAC,eAAe;QACxC,iBAAiB,EAAE,YAAY,CAAC,OAAO,CAAC,iBAAiB,CAAC,CAAC,QAAQ,EAAE;QACrE,iBAAiB,EAAE,YAAY,CAAC,OAAO,CAAC,iBAAiB,CAAC,CAAC,QAAQ,EAAE;QACrE,IAAI,EAAE,OAAO,CAAC,IAAI;QAClB,OAAO,EAAE,YAAY,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,QAAQ,EAAE;QACjD,IAAI,EAAE,OAAO,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"]}