@subql/node-ethereum 4.1.2-2 → 4.2.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 +5 -1
- package/dist/.tsbuildinfo +1 -1
- package/dist/indexer/dictionary/v1/ethDictionaryV1.js +4 -1
- package/dist/indexer/dictionary/v1/ethDictionaryV1.js.map +1 -1
- package/dist/indexer/dictionary/v1/ethDictionaryV1.spec.js +44 -0
- package/dist/indexer/dictionary/v1/ethDictionaryV1.spec.js.map +1 -1
- package/dist/indexer/dictionary/v2/ethDictionaryV2.js +21 -15
- package/dist/indexer/dictionary/v2/ethDictionaryV2.js.map +1 -1
- package/dist/indexer/dictionary/v2/ethDictionaryV2.spec.js +39 -0
- package/dist/indexer/dictionary/v2/ethDictionaryV2.spec.js.map +1 -1
- package/dist/indexer/dictionary/v2/types.d.ts +2 -2
- package/dist/indexer/dictionary/v2/types.js.map +1 -1
- package/package.json +4 -5
|
@@ -137,7 +137,10 @@ function buildDictionaryV1QueryEntries(dataSources) {
|
|
|
137
137
|
return [];
|
|
138
138
|
switch (handler.kind) {
|
|
139
139
|
case types_ethereum_1.EthereumHandlerKind.Block:
|
|
140
|
-
|
|
140
|
+
if (handler.filter.modulo === undefined) {
|
|
141
|
+
return [];
|
|
142
|
+
}
|
|
143
|
+
break;
|
|
141
144
|
case types_ethereum_1.EthereumHandlerKind.Call: {
|
|
142
145
|
const filter = handler.filter;
|
|
143
146
|
if (filter.from !== undefined ||
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ethDictionaryV1.js","sourceRoot":"","sources":["../../../../src/indexer/dictionary/v1/ethDictionaryV1.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;;;;;AAEnC,gDAAuE;AAKvE,0DAM+B;AAC/B,kDAA0B;AAC1B,mCAAwC;AACxC,4DAA+B;AAM/B,kDAAwE;AACxE,0CAA8C;AAC9C,oCAAuC;AAEvC,MA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-License-Identifier: GPL-3.0\n\nimport { NodeConfig, DictionaryV1, getLogger } from '@subql/node-core';\nimport {\n DictionaryQueryCondition,\n DictionaryQueryEntry as DictionaryV1QueryEntry,\n} from '@subql/types-core';\nimport {\n EthereumHandlerKind,\n EthereumLogFilter,\n EthereumTransactionFilter,\n SubqlDatasource,\n SubqlEthereumProcessorOptions,\n} from '@subql/types-ethereum';\nimport JSON5 from 'json5';\nimport { sortBy, uniqBy } from 'lodash';\nimport fetch from 'node-fetch';\nimport {\n EthereumProjectDs,\n EthereumProjectDsTemplate,\n SubqueryProject,\n} from '../../../configure/SubqueryProject';\nimport { eventToTopic, functionToSighash } from '../../../utils/string';\nimport { yargsOptions } from '../../../yargs';\nimport { ethFilterDs } from '../utils';\n\nconst CHAIN_ALIASES_URL =\n 'https://raw.githubusercontent.com/subquery/templates/main/chainAliases.json5';\n\nconst logger = getLogger('dictionary-v1');\n\nexport function appendDsOptions(\n dsOptions: SubqlEthereumProcessorOptions | SubqlEthereumProcessorOptions[],\n conditions: DictionaryQueryCondition[],\n): void {\n const queryAddressLimit = yargsOptions.argv['query-address-limit'];\n if (Array.isArray(dsOptions)) {\n const addresses = dsOptions.map((option) => option.address).filter(Boolean);\n\n if (addresses.length > queryAddressLimit) {\n logger.debug(\n `Addresses length: ${addresses.length} is exceeding limit: ${queryAddressLimit}. Consider increasing this value with the flag --query-address-limit `,\n );\n }\n\n if (addresses.length !== 0 && addresses.length <= queryAddressLimit) {\n conditions.push({\n field: 'address',\n value: addresses,\n matcher: 'in',\n });\n }\n } else {\n if (dsOptions?.address) {\n conditions.push({\n field: 'address',\n value: dsOptions.address.toLowerCase(),\n matcher: 'equalTo',\n });\n }\n }\n}\n\nfunction eventFilterToQueryEntry(\n filter: EthereumLogFilter,\n dsOptions: SubqlEthereumProcessorOptions | SubqlEthereumProcessorOptions[],\n): DictionaryV1QueryEntry {\n const conditions: DictionaryQueryCondition[] = [];\n appendDsOptions(dsOptions, conditions);\n if (filter.topics) {\n for (let i = 0; i < Math.min(filter.topics.length, 4); i++) {\n const topic = filter.topics[i];\n if (!topic) {\n continue;\n }\n const field = `topics${i}`;\n\n if (topic === '!null') {\n conditions.push({\n field,\n value: false as any, // TODO update types to allow boolean\n matcher: 'isNull',\n });\n } else {\n conditions.push({\n field,\n value: eventToTopic(topic),\n matcher: 'equalTo',\n });\n }\n }\n }\n return {\n entity: 'evmLogs',\n conditions,\n };\n}\n\nfunction callFilterToQueryEntry(\n filter: EthereumTransactionFilter,\n dsOptions: SubqlEthereumProcessorOptions | SubqlEthereumProcessorOptions[],\n): DictionaryV1QueryEntry {\n const conditions: DictionaryQueryCondition[] = [];\n appendDsOptions(dsOptions, conditions);\n\n for (const condition of conditions) {\n if (condition.field === 'address') {\n condition.field = 'to';\n }\n }\n if (filter.from) {\n conditions.push({\n field: 'from',\n value: filter.from.toLowerCase(),\n matcher: 'equalTo',\n });\n }\n const optionsAddresses = conditions.find((c) => c.field === 'to');\n if (!optionsAddresses) {\n if (filter.to) {\n conditions.push({\n field: 'to',\n value: filter.to.toLowerCase(),\n matcher: 'equalTo',\n });\n } else if (filter.to === null) {\n conditions.push({\n field: 'to',\n value: true as any, // TODO update types to allow boolean\n matcher: 'isNull',\n });\n }\n } else if (optionsAddresses && (filter.to || filter.to === null)) {\n logger.warn(\n `TransactionFilter 'to' conflict with 'address' in data source options`,\n );\n }\n\n if (filter.function === null || filter.function === '0x') {\n conditions.push({\n field: 'func',\n value: true,\n matcher: 'isNull',\n });\n } else if (filter.function) {\n conditions.push({\n field: 'func',\n value: functionToSighash(filter.function),\n matcher: 'equalTo',\n });\n }\n return {\n entity: 'evmTransactions',\n conditions,\n };\n}\n\nexport type GroupedEthereumProjectDs = SubqlDatasource & {\n groupedOptions?: SubqlEthereumProcessorOptions[];\n};\n\nexport function buildDictionaryV1QueryEntries(\n dataSources: GroupedEthereumProjectDs[],\n): DictionaryV1QueryEntry[] {\n const queryEntries: DictionaryV1QueryEntry[] = [];\n\n for (const ds of dataSources) {\n for (const handler of ds.mapping.handlers) {\n // No filters, cant use dictionary\n if (!handler.filter) return [];\n\n switch (handler.kind) {\n case EthereumHandlerKind.Block:\n return [];\n case EthereumHandlerKind.Call: {\n const filter = handler.filter as EthereumTransactionFilter;\n if (\n filter.from !== undefined ||\n filter.to !== undefined ||\n filter.function !== undefined\n ) {\n queryEntries.push(callFilterToQueryEntry(filter, ds.options));\n } else {\n return [];\n }\n break;\n }\n case EthereumHandlerKind.Event: {\n const filter = handler.filter as EthereumLogFilter;\n if (ds.groupedOptions) {\n queryEntries.push(\n eventFilterToQueryEntry(filter, ds.groupedOptions),\n );\n } else if (ds.options?.address || filter.topics) {\n queryEntries.push(eventFilterToQueryEntry(filter, ds.options));\n } else {\n return [];\n }\n break;\n }\n default:\n }\n }\n }\n\n return uniqBy(\n queryEntries,\n (item) =>\n `${item.entity}|${JSON.stringify(\n sortBy(item.conditions, (c) => c.field),\n )}`,\n );\n}\n\nexport class EthDictionaryV1 extends DictionaryV1<GroupedEthereumProjectDs> {\n private constructor(\n project: SubqueryProject,\n nodeConfig: NodeConfig,\n dictionaryUrl: string,\n chainId?: string,\n ) {\n super(dictionaryUrl, chainId ?? project.network.chainId, nodeConfig);\n }\n\n static async create(\n project: SubqueryProject,\n nodeConfig: NodeConfig,\n dictionaryUrl?: string,\n ): Promise<EthDictionaryV1> {\n /*Some dictionarys for EVM are built with other SDKs as they are chains with an EVM runtime\n * we maintain a list of aliases so we can map the evmChainId to the genesis hash of the other SDKs\n * e.g moonbeam is built with Substrate SDK but can be used as an EVM dictionary\n */\n const chainAliases = await this.getEvmChainId();\n const chainAlias = chainAliases[project.network.chainId];\n\n const dictionary = new EthDictionaryV1(\n project,\n nodeConfig,\n dictionaryUrl,\n chainAlias,\n );\n await dictionary.init();\n return dictionary;\n }\n\n private static async getEvmChainId(): Promise<Record<string, string>> {\n const response = await fetch(CHAIN_ALIASES_URL);\n\n const raw = await response.text();\n // We use JSON5 here because the file has comments in it\n return JSON5.parse(raw);\n }\n\n buildDictionaryQueryEntries(\n // Add name to datasource as templates have this set\n dataSources: (EthereumProjectDs | EthereumProjectDsTemplate)[],\n ): DictionaryV1QueryEntry[] {\n const filteredDs = ethFilterDs(dataSources);\n return buildDictionaryV1QueryEntries(filteredDs);\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"ethDictionaryV1.js","sourceRoot":"","sources":["../../../../src/indexer/dictionary/v1/ethDictionaryV1.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;;;;;AAEnC,gDAAuE;AAKvE,0DAO+B;AAC/B,kDAA0B;AAC1B,mCAAwC;AACxC,4DAA+B;AAM/B,kDAAwE;AACxE,0CAA8C;AAC9C,oCAAuC;AAEvC,MAAM,iBAAiB,GACrB,8EAA8E,CAAC;AAEjF,MAAM,MAAM,GAAG,IAAA,qBAAS,EAAC,eAAe,CAAC,CAAC;AAE1C,SAAgB,eAAe,CAC7B,SAA0E,EAC1E,UAAsC;IAEtC,MAAM,iBAAiB,GAAG,oBAAY,CAAC,IAAI,CAAC,qBAAqB,CAAC,CAAC;IACnE,IAAI,KAAK,CAAC,OAAO,CAAC,SAAS,CAAC,EAAE;QAC5B,MAAM,SAAS,GAAG,SAAS,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;QAE5E,IAAI,SAAS,CAAC,MAAM,GAAG,iBAAiB,EAAE;YACxC,MAAM,CAAC,KAAK,CACV,qBAAqB,SAAS,CAAC,MAAM,wBAAwB,iBAAiB,wEAAwE,CACvJ,CAAC;SACH;QAED,IAAI,SAAS,CAAC,MAAM,KAAK,CAAC,IAAI,SAAS,CAAC,MAAM,IAAI,iBAAiB,EAAE;YACnE,UAAU,CAAC,IAAI,CAAC;gBACd,KAAK,EAAE,SAAS;gBAChB,KAAK,EAAE,SAAS;gBAChB,OAAO,EAAE,IAAI;aACd,CAAC,CAAC;SACJ;KACF;SA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AAC;QACxB,OAAO,UAAU,CAAC;IACpB,CAAC;IAEO,MAAM,CAAC,KAAK,CAAC,aAAa;QAChC,MAAM,QAAQ,GAAG,MAAM,IAAA,oBAAK,EAAC,iBAAiB,CAAC,CAAC;QAEhD,MAAM,GAAG,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;QAClC,wDAAwD;QACxD,OAAO,eAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAC1B,CAAC;IAED,2BAA2B;IACzB,oDAAoD;IACpD,WAA8D;QAE9D,MAAM,UAAU,GAAG,IAAA,mBAAW,EAAC,WAAW,CAAC,CAAC;QAC5C,OAAO,6BAA6B,CAAC,UAAU,CAAC,CAAC;IACnD,CAAC;CACF;AA/CD,0CA+CC","sourcesContent":["// Copyright 2020-2024 SubQuery Pte Ltd authors & contributors\n// SPDX-License-Identifier: GPL-3.0\n\nimport { NodeConfig, DictionaryV1, getLogger } from '@subql/node-core';\nimport {\n DictionaryQueryCondition,\n DictionaryQueryEntry as DictionaryV1QueryEntry,\n} from '@subql/types-core';\nimport {\n EthereumBlockFilter,\n EthereumHandlerKind,\n EthereumLogFilter,\n EthereumTransactionFilter,\n SubqlDatasource,\n SubqlEthereumProcessorOptions,\n} from '@subql/types-ethereum';\nimport JSON5 from 'json5';\nimport { sortBy, uniqBy } from 'lodash';\nimport fetch from 'node-fetch';\nimport {\n EthereumProjectDs,\n EthereumProjectDsTemplate,\n SubqueryProject,\n} from '../../../configure/SubqueryProject';\nimport { eventToTopic, functionToSighash } from '../../../utils/string';\nimport { yargsOptions } from '../../../yargs';\nimport { ethFilterDs } from '../utils';\n\nconst CHAIN_ALIASES_URL =\n 'https://raw.githubusercontent.com/subquery/templates/main/chainAliases.json5';\n\nconst logger = getLogger('dictionary-v1');\n\nexport function appendDsOptions(\n dsOptions: SubqlEthereumProcessorOptions | SubqlEthereumProcessorOptions[],\n conditions: DictionaryQueryCondition[],\n): void {\n const queryAddressLimit = yargsOptions.argv['query-address-limit'];\n if (Array.isArray(dsOptions)) {\n const addresses = dsOptions.map((option) => option.address).filter(Boolean);\n\n if (addresses.length > queryAddressLimit) {\n logger.debug(\n `Addresses length: ${addresses.length} is exceeding limit: ${queryAddressLimit}. Consider increasing this value with the flag --query-address-limit `,\n );\n }\n\n if (addresses.length !== 0 && addresses.length <= queryAddressLimit) {\n conditions.push({\n field: 'address',\n value: addresses,\n matcher: 'in',\n });\n }\n } else {\n if (dsOptions?.address) {\n conditions.push({\n field: 'address',\n value: dsOptions.address.toLowerCase(),\n matcher: 'equalTo',\n });\n }\n }\n}\n\nfunction eventFilterToQueryEntry(\n filter: EthereumLogFilter,\n dsOptions: SubqlEthereumProcessorOptions | SubqlEthereumProcessorOptions[],\n): DictionaryV1QueryEntry {\n const conditions: DictionaryQueryCondition[] = [];\n appendDsOptions(dsOptions, conditions);\n if (filter.topics) {\n for (let i = 0; i < Math.min(filter.topics.length, 4); i++) {\n const topic = filter.topics[i];\n if (!topic) {\n continue;\n }\n const field = `topics${i}`;\n\n if (topic === '!null') {\n conditions.push({\n field,\n value: false as any, // TODO update types to allow boolean\n matcher: 'isNull',\n });\n } else {\n conditions.push({\n field,\n value: eventToTopic(topic),\n matcher: 'equalTo',\n });\n }\n }\n }\n return {\n entity: 'evmLogs',\n conditions,\n };\n}\n\nfunction callFilterToQueryEntry(\n filter: EthereumTransactionFilter,\n dsOptions: SubqlEthereumProcessorOptions | SubqlEthereumProcessorOptions[],\n): DictionaryV1QueryEntry {\n const conditions: DictionaryQueryCondition[] = [];\n appendDsOptions(dsOptions, conditions);\n\n for (const condition of conditions) {\n if (condition.field === 'address') {\n condition.field = 'to';\n }\n }\n if (filter.from) {\n conditions.push({\n field: 'from',\n value: filter.from.toLowerCase(),\n matcher: 'equalTo',\n });\n }\n const optionsAddresses = conditions.find((c) => c.field === 'to');\n if (!optionsAddresses) {\n if (filter.to) {\n conditions.push({\n field: 'to',\n value: filter.to.toLowerCase(),\n matcher: 'equalTo',\n });\n } else if (filter.to === null) {\n conditions.push({\n field: 'to',\n value: true as any, // TODO update types to allow boolean\n matcher: 'isNull',\n });\n }\n } else if (optionsAddresses && (filter.to || filter.to === null)) {\n logger.warn(\n `TransactionFilter 'to' conflict with 'address' in data source options`,\n );\n }\n\n if (filter.function === null || filter.function === '0x') {\n conditions.push({\n field: 'func',\n value: true,\n matcher: 'isNull',\n });\n } else if (filter.function) {\n conditions.push({\n field: 'func',\n value: functionToSighash(filter.function),\n matcher: 'equalTo',\n });\n }\n return {\n entity: 'evmTransactions',\n conditions,\n };\n}\n\nexport type GroupedEthereumProjectDs = SubqlDatasource & {\n groupedOptions?: SubqlEthereumProcessorOptions[];\n};\n\nexport function buildDictionaryV1QueryEntries(\n dataSources: GroupedEthereumProjectDs[],\n): DictionaryV1QueryEntry[] {\n const queryEntries: DictionaryV1QueryEntry[] = [];\n\n for (const ds of dataSources) {\n for (const handler of ds.mapping.handlers) {\n // No filters, cant use dictionary\n if (!handler.filter) return [];\n\n switch (handler.kind) {\n case EthereumHandlerKind.Block:\n if (handler.filter.modulo === undefined) {\n return [];\n }\n break;\n case EthereumHandlerKind.Call: {\n const filter = handler.filter as EthereumTransactionFilter;\n if (\n filter.from !== undefined ||\n filter.to !== undefined ||\n filter.function !== undefined\n ) {\n queryEntries.push(callFilterToQueryEntry(filter, ds.options));\n } else {\n return [];\n }\n break;\n }\n case EthereumHandlerKind.Event: {\n const filter = handler.filter as EthereumLogFilter;\n if (ds.groupedOptions) {\n queryEntries.push(\n eventFilterToQueryEntry(filter, ds.groupedOptions),\n );\n } else if (ds.options?.address || filter.topics) {\n queryEntries.push(eventFilterToQueryEntry(filter, ds.options));\n } else {\n return [];\n }\n break;\n }\n default:\n }\n }\n }\n\n return uniqBy(\n queryEntries,\n (item) =>\n `${item.entity}|${JSON.stringify(\n sortBy(item.conditions, (c) => c.field),\n )}`,\n );\n}\n\nexport class EthDictionaryV1 extends DictionaryV1<GroupedEthereumProjectDs> {\n private constructor(\n project: SubqueryProject,\n nodeConfig: NodeConfig,\n dictionaryUrl: string,\n chainId?: string,\n ) {\n super(dictionaryUrl, chainId ?? project.network.chainId, nodeConfig);\n }\n\n static async create(\n project: SubqueryProject,\n nodeConfig: NodeConfig,\n dictionaryUrl?: string,\n ): Promise<EthDictionaryV1> {\n /*Some dictionarys for EVM are built with other SDKs as they are chains with an EVM runtime\n * we maintain a list of aliases so we can map the evmChainId to the genesis hash of the other SDKs\n * e.g moonbeam is built with Substrate SDK but can be used as an EVM dictionary\n */\n const chainAliases = await this.getEvmChainId();\n const chainAlias = chainAliases[project.network.chainId];\n\n const dictionary = new EthDictionaryV1(\n project,\n nodeConfig,\n dictionaryUrl,\n chainAlias,\n );\n await dictionary.init();\n return dictionary;\n }\n\n private static async getEvmChainId(): Promise<Record<string, string>> {\n const response = await fetch(CHAIN_ALIASES_URL);\n\n const raw = await response.text();\n // We use JSON5 here because the file has comments in it\n return JSON5.parse(raw);\n }\n\n buildDictionaryQueryEntries(\n // Add name to datasource as templates have this set\n dataSources: (EthereumProjectDs | EthereumProjectDsTemplate)[],\n ): DictionaryV1QueryEntry[] {\n const filteredDs = ethFilterDs(dataSources);\n return buildDictionaryV1QueryEntries(filteredDs);\n }\n}\n"]}
|
|
@@ -299,6 +299,50 @@ describe('buildDictionaryV1QueryEntries', () => {
|
|
|
299
299
|
},
|
|
300
300
|
]);
|
|
301
301
|
});
|
|
302
|
+
it('builds a filter when theres a block handler with modulo filter', () => {
|
|
303
|
+
const ds = {
|
|
304
|
+
kind: types_ethereum_1.EthereumDatasourceKind.Runtime,
|
|
305
|
+
assets: new Map(),
|
|
306
|
+
options: {
|
|
307
|
+
abi: 'erc20',
|
|
308
|
+
},
|
|
309
|
+
startBlock: 1,
|
|
310
|
+
mapping: {
|
|
311
|
+
file: '',
|
|
312
|
+
handlers: [
|
|
313
|
+
{
|
|
314
|
+
handler: 'handleTransfer',
|
|
315
|
+
kind: types_ethereum_1.EthereumHandlerKind.Call,
|
|
316
|
+
filter: {
|
|
317
|
+
to: '0xabcde',
|
|
318
|
+
function: 'approve(address spender, uint256 rawAmount)',
|
|
319
|
+
},
|
|
320
|
+
},
|
|
321
|
+
{
|
|
322
|
+
handler: 'handleBlock',
|
|
323
|
+
kind: types_ethereum_1.EthereumHandlerKind.Block,
|
|
324
|
+
filter: {
|
|
325
|
+
modulo: 200,
|
|
326
|
+
},
|
|
327
|
+
},
|
|
328
|
+
],
|
|
329
|
+
},
|
|
330
|
+
};
|
|
331
|
+
const result = (0, ethDictionaryV1_1.buildDictionaryV1QueryEntries)([ds]);
|
|
332
|
+
expect(result).toEqual([
|
|
333
|
+
{
|
|
334
|
+
entity: 'evmTransactions',
|
|
335
|
+
conditions: [
|
|
336
|
+
{
|
|
337
|
+
field: 'to',
|
|
338
|
+
matcher: 'equalTo',
|
|
339
|
+
value: '0xabcde',
|
|
340
|
+
},
|
|
341
|
+
{ field: 'func', matcher: 'equalTo', value: '0x095ea7b3' },
|
|
342
|
+
],
|
|
343
|
+
},
|
|
344
|
+
]);
|
|
345
|
+
});
|
|
302
346
|
});
|
|
303
347
|
describe('Correct dictionary query with dynamic ds', () => {
|
|
304
348
|
it('Build correct erc1155 transfer single query', () => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ethDictionaryV1.spec.js","sourceRoot":"","sources":["../../../../src/indexer/dictionary/v1/ethDictionaryV1.spec.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;AAEnC,gDAA8C;AAC9C,0DAI+B;AAC/B,qCAAwC;AAKxC,uDAG2B;AAE3B,gEAAgE;AAChE,MAAM,aAAa,GAAG,0BAA0B,CAAC;AACjD,MAAM,UAAU,GAAgC;IAC9C;QACE,IAAI,EAAE,QAAQ;QACd,IAAI,EAAE,uCAAsB,CAAC,OAAO;QACpC,MAAM,EAAE,IAAI,GAAG,EAAE;QACjB,OAAO,EAAE;YACP,IAAI,EAAE,EAAE;YACR,QAAQ,EAAE;gBACR;oBACE,OAAO,EAAE,cAAc;oB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B,KAAK,EACH,oEAAoE;yBACvE;qBACF;oBACD,MAAM,EAAE,SAAS;iBAClB;gBACD;oBACE,UAAU,EAAE;wBACV;4BACE,KAAK,EAAE,SAAS;4BAChB,OAAO,EAAE,SAAS;4BAClB,KAAK,EAAE,UAAU;yBAClB;wBACD;4BACE,KAAK,EAAE,SAAS;4BAChB,OAAO,EAAE,SAAS;4BAClB,KAAK,EACH,oEAAoE;yBACvE;qBACF;oBACD,MAAM,EAAE,SAAS;iBAClB;gBACD;oBACE,UAAU,EAAE;wBACV;4BACE,KAAK,EAAE,SAAS;4BAChB,OAAO,EAAE,SAAS;4BAClB,KAAK,EAAE,UAAU;yBAClB;wBACD;4BACE,KAAK,EAAE,SAAS;4BAChB,OAAO,EAAE,SAAS;4BAClB,KAAK,EACH,oEAAoE;yBACvE;qBACF;oBACD,MAAM,EAAE,SAAS;iBAClB;aACF,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["// Copyright 2020-2024 SubQuery Pte Ltd authors & contributors\n// SPDX-License-Identifier: GPL-3.0\n\nimport { NodeConfig } from '@subql/node-core';\nimport {\n EthereumDatasourceKind,\n EthereumHandlerKind,\n SubqlRuntimeDatasource,\n} from '@subql/types-ethereum';\nimport { GraphQLSchema } from 'graphql';\nimport {\n EthereumProjectDsTemplate,\n SubqueryProject,\n} from '../../../configure/SubqueryProject';\nimport {\n buildDictionaryV1QueryEntries,\n EthDictionaryV1,\n} from './ethDictionaryV1';\n\n// const HTTP_ENDPOINT = 'https://eth.api.onfinality.io/public';\nconst HTTP_ENDPOINT = 'https://eth.llamarpc.com';\nconst mockTempDs: EthereumProjectDsTemplate[] = [\n {\n name: 'ERC721',\n kind: EthereumDatasourceKind.Runtime,\n assets: new Map(),\n mapping: {\n file: '',\n handlers: [\n {\n handler: 'handleERC721',\n kind: EthereumHandlerKind.Event,\n filter: {\n topics: ['Transfer(address, address, uint256)'],\n },\n },\n ],\n },\n },\n {\n name: 'ERC1155',\n kind: EthereumDatasourceKind.Runtime,\n assets: new Map(),\n mapping: {\n file: '',\n handlers: [\n {\n handler: 'handleERC1155',\n kind: EthereumHandlerKind.Event,\n filter: {\n topics: [\n 'TransferSingle(address, address, address, uint256, uint256)',\n ],\n },\n },\n ],\n },\n },\n];\nfunction testSubqueryProject(\n endpoint: string,\n ds: any,\n mockTempDs,\n): SubqueryProject {\n return {\n network: {\n endpoint,\n chainId: '1',\n },\n dataSources: ds as any,\n id: 'test',\n root: './',\n schema: new GraphQLSchema({}),\n templates: mockTempDs as any,\n } as any;\n}\n\ndescribe('Eth Dictionary V1', () => {\n it('Can resovle chain aliases', async () => {\n (EthDictionaryV1.prototype as any).init = jest.fn();\n const dictionary = await EthDictionaryV1.create(\n {\n network: { chainId: '336', dictionary: 'https://foo.bar' } as any,\n } as any,\n new NodeConfig({} as any, true),\n null,\n );\n\n expect((dictionary as any).chainId).toBe(\n '0xf1cf9022c7ebb34b162d5b5e34e705a5a740b2d0ecc1009fb89023e62a488108',\n );\n\n jest.clearAllMocks();\n });\n});\n\ndescribe('buildDictionaryV1QueryEntries', () => {\n describe('Log filters', () => {\n it('Build filter for !null', () => {\n const ds: SubqlRuntimeDatasource = {\n kind: EthereumDatasourceKind.Runtime,\n assets: new Map(),\n options: {\n abi: 'erc20',\n address: '0x7ceB23fD6bC0adD59E62ac25578270cFf1b9f619',\n },\n startBlock: 1,\n mapping: {\n file: '',\n handlers: [\n {\n handler: 'handleLog',\n kind: EthereumHandlerKind.Event,\n filter: {\n topics: [\n 'Transfer(address, address, uint256)',\n undefined,\n undefined,\n '!null',\n ],\n },\n },\n ],\n },\n };\n const result = buildDictionaryV1QueryEntries([ds]);\n\n expect(result).toEqual([\n {\n entity: 'evmLogs',\n conditions: [\n {\n field: 'address',\n matcher: 'equalTo',\n value: '0x7ceb23fd6bc0add59e62ac25578270cff1b9f619',\n },\n {\n field: 'topics0',\n value:\n '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef',\n matcher: 'equalTo',\n },\n {\n field: 'topics3',\n value: false,\n matcher: 'isNull',\n },\n ],\n },\n ]);\n });\n });\n\n describe('Transaction filters', () => {\n it('Build a filter for contract creation transactions', () => {\n const ds: SubqlRuntimeDatasource = {\n kind: EthereumDatasourceKind.Runtime,\n assets: new Map(),\n startBlock: 1,\n mapping: {\n file: '',\n handlers: [\n {\n handler: 'handleTransaction',\n kind: EthereumHandlerKind.Call,\n filter: {\n to: null,\n },\n },\n ],\n },\n };\n\n const result = buildDictionaryV1QueryEntries([ds]);\n\n expect(result).toEqual([\n {\n entity: 'evmTransactions',\n conditions: [{ field: 'to', matcher: 'isNull', value: true }],\n },\n ]);\n });\n\n it('Build a filter with include ds option and contract address', () => {\n const ds: SubqlRuntimeDatasource = {\n kind: EthereumDatasourceKind.Runtime,\n assets: new Map(),\n options: {\n abi: 'erc20',\n address: '0x7ceB23fD6bC0adD59E62ac25578270cFf1b9f619',\n },\n startBlock: 1,\n mapping: {\n file: '',\n handlers: [\n {\n handler: 'handleTransfer',\n kind: EthereumHandlerKind.Call,\n filter: {\n function: 'approve(address spender, uint256 rawAmount)',\n },\n },\n ],\n },\n };\n\n const result = buildDictionaryV1QueryEntries([ds]);\n expect(result).toEqual([\n {\n entity: 'evmTransactions',\n conditions: [\n {\n field: 'to',\n matcher: 'equalTo',\n value: '0x7ceb23fd6bc0add59e62ac25578270cff1b9f619',\n },\n { field: 'func', matcher: 'equalTo', value: '0x095ea7b3' },\n ],\n },\n ]);\n });\n\n it('If ds option and filter both provide contract address, it should use ds options one', () => {\n const ds: SubqlRuntimeDatasource = {\n kind: EthereumDatasourceKind.Runtime,\n assets: new Map(),\n options: {\n abi: 'erc20',\n address: '0x7ceB23fD6bC0adD59E62ac25578270cFf1b9f619',\n },\n startBlock: 1,\n mapping: {\n file: '',\n handlers: [\n {\n handler: 'handleTransfer',\n kind: EthereumHandlerKind.Call,\n filter: {\n to: '0xabcde',\n function: 'approve(address spender, uint256 rawAmount)',\n },\n },\n ],\n },\n };\n\n const result = buildDictionaryV1QueryEntries([ds]);\n expect(result).toEqual([\n {\n entity: 'evmTransactions',\n conditions: [\n {\n field: 'to',\n matcher: 'equalTo',\n value: '0x7ceb23fd6bc0add59e62ac25578270cff1b9f619',\n },\n { field: 'func', matcher: 'equalTo', value: '0x095ea7b3' },\n ],\n },\n ]);\n });\n\n it('If ds option provide contract address, it should use ds options \"address\"', () => {\n const ds: SubqlRuntimeDatasource = {\n kind: EthereumDatasourceKind.Runtime,\n assets: new Map(),\n options: {\n abi: 'erc20',\n address: '0x7ceB23fD6bC0adD59E62ac25578270cFf1b9f619',\n },\n startBlock: 1,\n mapping: {\n file: '',\n handlers: [\n {\n handler: 'handleTransfer',\n kind: EthereumHandlerKind.Call,\n filter: {\n function: 'approve(address spender, uint256 rawAmount)',\n },\n },\n ],\n },\n };\n\n const result = buildDictionaryV1QueryEntries([ds]);\n expect(result).toEqual([\n {\n entity: 'evmTransactions',\n conditions: [\n {\n field: 'to',\n matcher: 'equalTo',\n value: '0x7ceb23fd6bc0add59e62ac25578270cff1b9f619',\n },\n { field: 'func', matcher: 'equalTo', value: '0x095ea7b3' },\n ],\n },\n ]);\n });\n\n it('If filter provide contract address, it should use filter \"to\"', () => {\n const ds: SubqlRuntimeDatasource = {\n kind: EthereumDatasourceKind.Runtime,\n assets: new Map(),\n options: {\n abi: 'erc20',\n },\n startBlock: 1,\n mapping: {\n file: '',\n handlers: [\n {\n handler: 'handleTransfer',\n kind: EthereumHandlerKind.Call,\n filter: {\n to: '0xabcde',\n function: 'approve(address spender, uint256 rawAmount)',\n },\n },\n ],\n },\n };\n\n const result = buildDictionaryV1QueryEntries([ds]);\n expect(result).toEqual([\n {\n entity: 'evmTransactions',\n conditions: [\n {\n field: 'to',\n matcher: 'equalTo',\n value: '0xabcde',\n },\n { field: 'func', matcher: 'equalTo', value: '0x095ea7b3' },\n ],\n },\n ]);\n });\n });\n describe('Correct dictionary query with dynamic ds', () => {\n it('Build correct erc1155 transfer single query', () => {\n const ds: SubqlRuntimeDatasource = {\n kind: EthereumDatasourceKind.Runtime,\n assets: new Map(),\n startBlock: 1,\n mapping: {\n file: '',\n handlers: [\n {\n handler: 'handleDyanmicDs',\n kind: EthereumHandlerKind.Event,\n filter: {\n topics: [\n 'TransferSingle(address, address, address, uint256, uint256)',\n ],\n },\n },\n ],\n },\n };\n const result = buildDictionaryV1QueryEntries([ds]);\n expect(result).toEqual([\n {\n entity: 'evmLogs',\n conditions: [\n {\n field: 'topics0',\n value:\n '0xc3d58168c5ae7397731d063d5bbf3d657854427343f4c083240f7aacaa2d0f62',\n matcher: 'equalTo',\n },\n ],\n },\n ]);\n });\n\n it('Builds a groupded query for multiple dynamic ds', () => {\n const ds: SubqlRuntimeDatasource = {\n kind: EthereumDatasourceKind.Runtime,\n assets: new Map(),\n startBlock: 1,\n mapping: {\n file: '',\n handlers: [\n {\n handler: 'handleDyanmicDs',\n kind: EthereumHandlerKind.Event,\n filter: {\n topics: [\n 'TransferSingle(address, address, address, uint256, uint256)',\n ],\n },\n },\n ],\n },\n };\n\n const duplicateDataSources = [\n { ...mockTempDs[0], options: { address: 'address1' } },\n { ...mockTempDs[0], options: { address: 'address2' } },\n { ...mockTempDs[1], options: { address: 'address3' } },\n ];\n\n const dataSources = [ds, ...duplicateDataSources];\n\n const queryEntry = buildDictionaryV1QueryEntries(dataSources);\n\n expect(queryEntry).toEqual([\n {\n conditions: [\n {\n field: 'topics0',\n matcher: 'equalTo',\n value:\n '0xc3d58168c5ae7397731d063d5bbf3d657854427343f4c083240f7aacaa2d0f62',\n },\n ],\n entity: 'evmLogs',\n },\n {\n conditions: [\n {\n field: 'address',\n matcher: 'equalTo',\n value: 'address1',\n },\n {\n field: 'topics0',\n matcher: 'equalTo',\n value:\n '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef',\n },\n ],\n entity: 'evmLogs',\n },\n {\n conditions: [\n {\n field: 'address',\n matcher: 'equalTo',\n value: 'address2',\n },\n {\n field: 'topics0',\n matcher: 'equalTo',\n value:\n '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef',\n },\n ],\n entity: 'evmLogs',\n },\n {\n conditions: [\n {\n field: 'address',\n matcher: 'equalTo',\n value: 'address3',\n },\n {\n field: 'topics0',\n matcher: 'equalTo',\n value:\n '0xc3d58168c5ae7397731d063d5bbf3d657854427343f4c083240f7aacaa2d0f62',\n },\n ],\n entity: 'evmLogs',\n },\n ]);\n });\n });\n});\n"]}
|
|
1
|
+
{"version":3,"file":"ethDictionaryV1.spec.js","sourceRoot":"","sources":["../../../../src/indexer/dictionary/v1/ethDictionaryV1.spec.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;AAEnC,gDAA8C;AAC9C,0DAI+B;AAC/B,qCAAwC;AAKxC,uDAG2B;AAE3B,gEAAgE;AAChE,MAAM,aAAa,GAAG,0BAA0B,CAAC;AACjD,MAAM,UAAU,GAAgC;IAC9C;QACE,IAAI,EAAE,QAAQ;QACd,IAAI,EAAE,uCAAsB,CAAC,OAAO;QACpC,MAAM,EAAE,IAAI,GAAG,EAAE;QACjB,OAAO,EAAE;YACP,IAAI,EAAE,EAAE;YACR,QAAQ,EAAE;gBACR;oBACE,OAAO,EAAE,cAAc;oBACvB,IAAI,EAAE,oCAAmB,CAAC,KAAK;oBAC/B,MAAM,EAAE;wBACN,MAAM,EAAE,CAAC,qCAAqC,CAAC;qBAChD;iBACF;aACF;SACF;KACF;IACD;QACE,IAAI,EAAE,SAAS;QACf,IAAI,EAAE,uCAAsB,CAAC,OAAO;QACpC,MAAM,EAAE,IAAI,GAAG,EAAE;QACjB,OAAO,EAAE;YACP,IAAI,EAAE,EAAE;YACR,QAAQ,EAAE;gBACR;oBACE,OAAO,EAAE,eAAe;oBACxB,IAAI,EAAE,oCAAmB,CAAC,KAAK;oBAC/B,MAAM,EAAE;wBACN,MAAM,EAAE;4BAC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["// Copyright 2020-2024 SubQuery Pte Ltd authors & contributors\n// SPDX-License-Identifier: GPL-3.0\n\nimport { NodeConfig } from '@subql/node-core';\nimport {\n EthereumDatasourceKind,\n EthereumHandlerKind,\n SubqlRuntimeDatasource,\n} from '@subql/types-ethereum';\nimport { GraphQLSchema } from 'graphql';\nimport {\n EthereumProjectDsTemplate,\n SubqueryProject,\n} from '../../../configure/SubqueryProject';\nimport {\n buildDictionaryV1QueryEntries,\n EthDictionaryV1,\n} from './ethDictionaryV1';\n\n// const HTTP_ENDPOINT = 'https://eth.api.onfinality.io/public';\nconst HTTP_ENDPOINT = 'https://eth.llamarpc.com';\nconst mockTempDs: EthereumProjectDsTemplate[] = [\n {\n name: 'ERC721',\n kind: EthereumDatasourceKind.Runtime,\n assets: new Map(),\n mapping: {\n file: '',\n handlers: [\n {\n handler: 'handleERC721',\n kind: EthereumHandlerKind.Event,\n filter: {\n topics: ['Transfer(address, address, uint256)'],\n },\n },\n ],\n },\n },\n {\n name: 'ERC1155',\n kind: EthereumDatasourceKind.Runtime,\n assets: new Map(),\n mapping: {\n file: '',\n handlers: [\n {\n handler: 'handleERC1155',\n kind: EthereumHandlerKind.Event,\n filter: {\n topics: [\n 'TransferSingle(address, address, address, uint256, uint256)',\n ],\n },\n },\n ],\n },\n },\n];\nfunction testSubqueryProject(\n endpoint: string,\n ds: any,\n mockTempDs,\n): SubqueryProject {\n return {\n network: {\n endpoint,\n chainId: '1',\n },\n dataSources: ds as any,\n id: 'test',\n root: './',\n schema: new GraphQLSchema({}),\n templates: mockTempDs as any,\n } as any;\n}\n\ndescribe('Eth Dictionary V1', () => {\n it('Can resovle chain aliases', async () => {\n (EthDictionaryV1.prototype as any).init = jest.fn();\n const dictionary = await EthDictionaryV1.create(\n {\n network: { chainId: '336', dictionary: 'https://foo.bar' } as any,\n } as any,\n new NodeConfig({} as any, true),\n null,\n );\n\n expect((dictionary as any).chainId).toBe(\n '0xf1cf9022c7ebb34b162d5b5e34e705a5a740b2d0ecc1009fb89023e62a488108',\n );\n\n jest.clearAllMocks();\n });\n});\n\ndescribe('buildDictionaryV1QueryEntries', () => {\n describe('Log filters', () => {\n it('Build filter for !null', () => {\n const ds: SubqlRuntimeDatasource = {\n kind: EthereumDatasourceKind.Runtime,\n assets: new Map(),\n options: {\n abi: 'erc20',\n address: '0x7ceB23fD6bC0adD59E62ac25578270cFf1b9f619',\n },\n startBlock: 1,\n mapping: {\n file: '',\n handlers: [\n {\n handler: 'handleLog',\n kind: EthereumHandlerKind.Event,\n filter: {\n topics: [\n 'Transfer(address, address, uint256)',\n undefined,\n undefined,\n '!null',\n ],\n },\n },\n ],\n },\n };\n const result = buildDictionaryV1QueryEntries([ds]);\n\n expect(result).toEqual([\n {\n entity: 'evmLogs',\n conditions: [\n {\n field: 'address',\n matcher: 'equalTo',\n value: '0x7ceb23fd6bc0add59e62ac25578270cff1b9f619',\n },\n {\n field: 'topics0',\n value:\n '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef',\n matcher: 'equalTo',\n },\n {\n field: 'topics3',\n value: false,\n matcher: 'isNull',\n },\n ],\n },\n ]);\n });\n });\n\n describe('Transaction filters', () => {\n it('Build a filter for contract creation transactions', () => {\n const ds: SubqlRuntimeDatasource = {\n kind: EthereumDatasourceKind.Runtime,\n assets: new Map(),\n startBlock: 1,\n mapping: {\n file: '',\n handlers: [\n {\n handler: 'handleTransaction',\n kind: EthereumHandlerKind.Call,\n filter: {\n to: null,\n },\n },\n ],\n },\n };\n\n const result = buildDictionaryV1QueryEntries([ds]);\n\n expect(result).toEqual([\n {\n entity: 'evmTransactions',\n conditions: [{ field: 'to', matcher: 'isNull', value: true }],\n },\n ]);\n });\n\n it('Build a filter with include ds option and contract address', () => {\n const ds: SubqlRuntimeDatasource = {\n kind: EthereumDatasourceKind.Runtime,\n assets: new Map(),\n options: {\n abi: 'erc20',\n address: '0x7ceB23fD6bC0adD59E62ac25578270cFf1b9f619',\n },\n startBlock: 1,\n mapping: {\n file: '',\n handlers: [\n {\n handler: 'handleTransfer',\n kind: EthereumHandlerKind.Call,\n filter: {\n function: 'approve(address spender, uint256 rawAmount)',\n },\n },\n ],\n },\n };\n\n const result = buildDictionaryV1QueryEntries([ds]);\n expect(result).toEqual([\n {\n entity: 'evmTransactions',\n conditions: [\n {\n field: 'to',\n matcher: 'equalTo',\n value: '0x7ceb23fd6bc0add59e62ac25578270cff1b9f619',\n },\n { field: 'func', matcher: 'equalTo', value: '0x095ea7b3' },\n ],\n },\n ]);\n });\n\n it('If ds option and filter both provide contract address, it should use ds options one', () => {\n const ds: SubqlRuntimeDatasource = {\n kind: EthereumDatasourceKind.Runtime,\n assets: new Map(),\n options: {\n abi: 'erc20',\n address: '0x7ceB23fD6bC0adD59E62ac25578270cFf1b9f619',\n },\n startBlock: 1,\n mapping: {\n file: '',\n handlers: [\n {\n handler: 'handleTransfer',\n kind: EthereumHandlerKind.Call,\n filter: {\n to: '0xabcde',\n function: 'approve(address spender, uint256 rawAmount)',\n },\n },\n ],\n },\n };\n\n const result = buildDictionaryV1QueryEntries([ds]);\n expect(result).toEqual([\n {\n entity: 'evmTransactions',\n conditions: [\n {\n field: 'to',\n matcher: 'equalTo',\n value: '0x7ceb23fd6bc0add59e62ac25578270cff1b9f619',\n },\n { field: 'func', matcher: 'equalTo', value: '0x095ea7b3' },\n ],\n },\n ]);\n });\n\n it('If ds option provide contract address, it should use ds options \"address\"', () => {\n const ds: SubqlRuntimeDatasource = {\n kind: EthereumDatasourceKind.Runtime,\n assets: new Map(),\n options: {\n abi: 'erc20',\n address: '0x7ceB23fD6bC0adD59E62ac25578270cFf1b9f619',\n },\n startBlock: 1,\n mapping: {\n file: '',\n handlers: [\n {\n handler: 'handleTransfer',\n kind: EthereumHandlerKind.Call,\n filter: {\n function: 'approve(address spender, uint256 rawAmount)',\n },\n },\n ],\n },\n };\n\n const result = buildDictionaryV1QueryEntries([ds]);\n expect(result).toEqual([\n {\n entity: 'evmTransactions',\n conditions: [\n {\n field: 'to',\n matcher: 'equalTo',\n value: '0x7ceb23fd6bc0add59e62ac25578270cff1b9f619',\n },\n { field: 'func', matcher: 'equalTo', value: '0x095ea7b3' },\n ],\n },\n ]);\n });\n\n it('If filter provide contract address, it should use filter \"to\"', () => {\n const ds: SubqlRuntimeDatasource = {\n kind: EthereumDatasourceKind.Runtime,\n assets: new Map(),\n options: {\n abi: 'erc20',\n },\n startBlock: 1,\n mapping: {\n file: '',\n handlers: [\n {\n handler: 'handleTransfer',\n kind: EthereumHandlerKind.Call,\n filter: {\n to: '0xabcde',\n function: 'approve(address spender, uint256 rawAmount)',\n },\n },\n ],\n },\n };\n\n const result = buildDictionaryV1QueryEntries([ds]);\n expect(result).toEqual([\n {\n entity: 'evmTransactions',\n conditions: [\n {\n field: 'to',\n matcher: 'equalTo',\n value: '0xabcde',\n },\n { field: 'func', matcher: 'equalTo', value: '0x095ea7b3' },\n ],\n },\n ]);\n });\n\n it('builds a filter when theres a block handler with modulo filter', () => {\n const ds: SubqlRuntimeDatasource = {\n kind: EthereumDatasourceKind.Runtime,\n assets: new Map(),\n options: {\n abi: 'erc20',\n },\n startBlock: 1,\n mapping: {\n file: '',\n handlers: [\n {\n handler: 'handleTransfer',\n kind: EthereumHandlerKind.Call,\n filter: {\n to: '0xabcde',\n function: 'approve(address spender, uint256 rawAmount)',\n },\n },\n {\n handler: 'handleBlock',\n kind: EthereumHandlerKind.Block,\n filter: {\n modulo: 200,\n },\n },\n ],\n },\n };\n\n const result = buildDictionaryV1QueryEntries([ds]);\n expect(result).toEqual([\n {\n entity: 'evmTransactions',\n conditions: [\n {\n field: 'to',\n matcher: 'equalTo',\n value: '0xabcde',\n },\n { field: 'func', matcher: 'equalTo', value: '0x095ea7b3' },\n ],\n },\n ]);\n });\n });\n\n describe('Correct dictionary query with dynamic ds', () => {\n it('Build correct erc1155 transfer single query', () => {\n const ds: SubqlRuntimeDatasource = {\n kind: EthereumDatasourceKind.Runtime,\n assets: new Map(),\n startBlock: 1,\n mapping: {\n file: '',\n handlers: [\n {\n handler: 'handleDyanmicDs',\n kind: EthereumHandlerKind.Event,\n filter: {\n topics: [\n 'TransferSingle(address, address, address, uint256, uint256)',\n ],\n },\n },\n ],\n },\n };\n const result = buildDictionaryV1QueryEntries([ds]);\n expect(result).toEqual([\n {\n entity: 'evmLogs',\n conditions: [\n {\n field: 'topics0',\n value:\n '0xc3d58168c5ae7397731d063d5bbf3d657854427343f4c083240f7aacaa2d0f62',\n matcher: 'equalTo',\n },\n ],\n },\n ]);\n });\n\n it('Builds a groupded query for multiple dynamic ds', () => {\n const ds: SubqlRuntimeDatasource = {\n kind: EthereumDatasourceKind.Runtime,\n assets: new Map(),\n startBlock: 1,\n mapping: {\n file: '',\n handlers: [\n {\n handler: 'handleDyanmicDs',\n kind: EthereumHandlerKind.Event,\n filter: {\n topics: [\n 'TransferSingle(address, address, address, uint256, uint256)',\n ],\n },\n },\n ],\n },\n };\n\n const duplicateDataSources = [\n { ...mockTempDs[0], options: { address: 'address1' } },\n { ...mockTempDs[0], options: { address: 'address2' } },\n { ...mockTempDs[1], options: { address: 'address3' } },\n ];\n\n const dataSources = [ds, ...duplicateDataSources];\n\n const queryEntry = buildDictionaryV1QueryEntries(dataSources);\n\n expect(queryEntry).toEqual([\n {\n conditions: [\n {\n field: 'topics0',\n matcher: 'equalTo',\n value:\n '0xc3d58168c5ae7397731d063d5bbf3d657854427343f4c083240f7aacaa2d0f62',\n },\n ],\n entity: 'evmLogs',\n },\n {\n conditions: [\n {\n field: 'address',\n matcher: 'equalTo',\n value: 'address1',\n },\n {\n field: 'topics0',\n matcher: 'equalTo',\n value:\n '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef',\n },\n ],\n entity: 'evmLogs',\n },\n {\n conditions: [\n {\n field: 'address',\n matcher: 'equalTo',\n value: 'address2',\n },\n {\n field: 'topics0',\n matcher: 'equalTo',\n value:\n '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef',\n },\n ],\n entity: 'evmLogs',\n },\n {\n conditions: [\n {\n field: 'address',\n matcher: 'equalTo',\n value: 'address3',\n },\n {\n field: 'topics0',\n matcher: 'equalTo',\n value:\n '0xc3d58168c5ae7397731d063d5bbf3d657854427343f4c083240f7aacaa2d0f62',\n },\n ],\n entity: 'evmLogs',\n },\n ]);\n });\n });\n});\n"]}
|
|
@@ -108,6 +108,21 @@ function eventFilterToDictionaryCondition(filter, dsOptions) {
|
|
|
108
108
|
}
|
|
109
109
|
return logConditions;
|
|
110
110
|
}
|
|
111
|
+
function sanitiseDictionaryConditions(dictionaryConditions) {
|
|
112
|
+
if (!dictionaryConditions.logs.length) {
|
|
113
|
+
delete dictionaryConditions.logs;
|
|
114
|
+
}
|
|
115
|
+
else {
|
|
116
|
+
dictionaryConditions.logs = (0, lodash_1.uniqBy)(dictionaryConditions.logs, (log) => JSON.stringify(log));
|
|
117
|
+
}
|
|
118
|
+
if (!dictionaryConditions.transactions.length) {
|
|
119
|
+
delete dictionaryConditions.transactions;
|
|
120
|
+
}
|
|
121
|
+
else {
|
|
122
|
+
dictionaryConditions.transactions = (0, lodash_1.uniqBy)(dictionaryConditions.transactions, (tx) => JSON.stringify(tx));
|
|
123
|
+
}
|
|
124
|
+
return dictionaryConditions;
|
|
125
|
+
}
|
|
111
126
|
function buildDictionaryV2QueryEntry(dataSources) {
|
|
112
127
|
var _a;
|
|
113
128
|
const dictionaryConditions = {
|
|
@@ -118,10 +133,13 @@ function buildDictionaryV2QueryEntry(dataSources) {
|
|
|
118
133
|
for (const handler of ds.mapping.handlers) {
|
|
119
134
|
// No filters, cant use dictionary
|
|
120
135
|
if (!handler.filter)
|
|
121
|
-
return
|
|
136
|
+
return {};
|
|
122
137
|
switch (handler.kind) {
|
|
123
138
|
case types_ethereum_1.EthereumHandlerKind.Block:
|
|
124
|
-
|
|
139
|
+
if (handler.filter.modulo === undefined) {
|
|
140
|
+
return {};
|
|
141
|
+
}
|
|
142
|
+
break;
|
|
125
143
|
case types_ethereum_1.EthereumHandlerKind.Call: {
|
|
126
144
|
const filter = handler.filter;
|
|
127
145
|
if (filter.from !== undefined ||
|
|
@@ -151,19 +169,7 @@ function buildDictionaryV2QueryEntry(dataSources) {
|
|
|
151
169
|
}
|
|
152
170
|
}
|
|
153
171
|
}
|
|
154
|
-
|
|
155
|
-
delete dictionaryConditions.logs;
|
|
156
|
-
}
|
|
157
|
-
else {
|
|
158
|
-
dictionaryConditions.logs = (0, lodash_1.uniqBy)(dictionaryConditions.logs, (log) => JSON.stringify(log));
|
|
159
|
-
}
|
|
160
|
-
if (!dictionaryConditions.transactions.length) {
|
|
161
|
-
delete dictionaryConditions.transactions;
|
|
162
|
-
}
|
|
163
|
-
else {
|
|
164
|
-
dictionaryConditions.transactions = (0, lodash_1.uniqBy)(dictionaryConditions.transactions, (tx) => JSON.stringify(tx));
|
|
165
|
-
}
|
|
166
|
-
return dictionaryConditions;
|
|
172
|
+
return sanitiseDictionaryConditions(dictionaryConditions);
|
|
167
173
|
}
|
|
168
174
|
exports.buildDictionaryV2QueryEntry = buildDictionaryV2QueryEntry;
|
|
169
175
|
class EthDictionaryV2 extends node_core_1.DictionaryV2 {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ethDictionaryV2.js","sourceRoot":"","sources":["../../../../src/indexer/dictionary/v2/ethDictionaryV2.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;;;;;;;;;;;;;;AAEnC,gDAO0B;AAC1B,0DAO+B;AAC/B,mCAAgC;AAChC,8DAAmE;AAOnE,kDAAwE;AACxE,0CAA8C;AAC9C,oCAAuC;AAQvC,mCAA6C;AAE7C,MAAM,eAAe,GAAG,GAAG,CAAC;AAE5B,MAAM,MAAM,GAAG,IAAA,qBAAS,EAAC,eAAe,CAAC,CAAC;AAE1C,SAAS,sBAAsB,CAC7B,SAA0E;IAE1E,MAAM,iBAAiB,GAAG,oBAAY,CAAC,IAAI,CAAC,qBAAqB,CA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C,GAAG,CAAC,CAAC,CAAC;YAC9C,OAAO;gBACL,WAAW,EAAE,MAAM;gBACnB,kBAAkB,EAAE,MAAM,CAAC,MAAM;oBAC/B,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM;oBACxC,CAAC,CAAC,SAAS;aACd,CAAC;SACH;QAAC,OAAO,CAAC,EAAE;YACV,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,kCAAkC,CAAC,CAAC;YACpD,MAAM,CAAC,CAAC;SACT;IACH,CAAC;CACF;AAnED,0CAmEC","sourcesContent":["// Copyright 2020-2024 SubQuery Pte Ltd authors & contributors\n// SPDX-License-Identifier: GPL-3.0\n\nimport {\n NodeConfig,\n DictionaryV2,\n RawDictionaryResponseData,\n DictionaryResponse,\n getLogger,\n IBlock,\n} from '@subql/node-core';\nimport {\n EthereumBlock,\n EthereumHandlerKind,\n EthereumLogFilter,\n EthereumTransactionFilter,\n SubqlDatasource,\n SubqlEthereumProcessorOptions,\n} from '@subql/types-ethereum';\nimport { uniqBy } from 'lodash';\nimport { EthereumNodeConfig } from '../../../configure/NodeConfig';\nimport {\n EthereumProjectDs,\n EthereumProjectDsTemplate,\n SubqueryProject,\n} from '../../../configure/SubqueryProject';\nimport { EthereumApi } from '../../../ethereum';\nimport { eventToTopic, functionToSighash } from '../../../utils/string';\nimport { yargsOptions } from '../../../yargs';\nimport { ethFilterDs } from '../utils';\nimport { GroupedEthereumProjectDs } from '../v1';\nimport {\n RawEthBlock,\n EthDictionaryV2QueryEntry,\n EthDictionaryTxConditions,\n EthDictionaryLogConditions,\n} from './types';\nimport { rawBlockToEthBlock } from './utils';\n\nconst MIN_FETCH_LIMIT = 200;\n\nconst logger = getLogger('dictionary-v2');\n\nfunction extractOptionAddresses(\n dsOptions: SubqlEthereumProcessorOptions | SubqlEthereumProcessorOptions[],\n): string[] {\n const queryAddressLimit = yargsOptions.argv['query-address-limit'];\n const addressArray: string[] = [];\n if (Array.isArray(dsOptions)) {\n const addresses = dsOptions.map((option) => option.address).filter(Boolean);\n\n if (addresses.length > queryAddressLimit) {\n logger.debug(\n `Addresses length: ${addresses.length} is exceeding limit: ${queryAddressLimit}. Consider increasing this value with the flag --query-address-limit `,\n );\n }\n if (addresses.length !== 0 && addresses.length <= queryAddressLimit) {\n addressArray.push(...addresses);\n }\n } else {\n if (dsOptions?.address) {\n addressArray.push(dsOptions.address.toLowerCase());\n }\n }\n return addressArray;\n}\n\nfunction callFilterToDictionaryCondition(\n filter: EthereumTransactionFilter,\n dsOptions: SubqlEthereumProcessorOptions,\n): EthDictionaryTxConditions {\n const txConditions: EthDictionaryTxConditions = {};\n const toArray = [];\n const fromArray = [];\n const funcArray = [];\n\n if (filter.from) {\n fromArray.push(filter.from.toLowerCase());\n }\n\n const assignTo = (value: string | null | undefined) => {\n if (value === null) {\n toArray.push(null);\n } else if (value !== undefined) {\n toArray.push(value.toLowerCase());\n }\n };\n\n const optionsAddresses = extractOptionAddresses(dsOptions);\n if (!optionsAddresses.length) {\n assignTo(filter.to);\n } else {\n if (filter.to || filter.to === null) {\n logger.warn(\n `TransactionFilter 'to' conflicts with 'address' in data source options, using data source option`,\n );\n }\n optionsAddresses.forEach(assignTo);\n }\n\n if (filter.function) {\n funcArray.push(functionToSighash(filter.function));\n }\n\n if (toArray.length !== 0) {\n txConditions.to = toArray;\n }\n if (fromArray.length !== 0) {\n txConditions.from = fromArray;\n }\n\n if (funcArray.length !== 0) {\n txConditions.data = funcArray;\n }\n\n return txConditions;\n}\n\nfunction eventFilterToDictionaryCondition(\n filter: EthereumLogFilter,\n dsOptions: SubqlEthereumProcessorOptions | SubqlEthereumProcessorOptions[],\n): EthDictionaryLogConditions {\n const logConditions: EthDictionaryLogConditions = {};\n logConditions.address = extractOptionAddresses(dsOptions);\n if (filter.topics) {\n for (let i = 0; i < Math.min(filter.topics.length, 4); i++) {\n const topic = filter.topics[i];\n if (!topic) {\n continue;\n }\n const field = `topics${i}`;\n // Initialized\n if (!logConditions[field]) {\n logConditions[field] = [];\n }\n if (topic === '!null') {\n logConditions[field] = []; // TODO, check if !null\n } else {\n logConditions[field].push(eventToTopic(topic));\n }\n }\n }\n return logConditions;\n}\n\nexport function buildDictionaryV2QueryEntry(\n dataSources: GroupedEthereumProjectDs[],\n): EthDictionaryV2QueryEntry {\n const dictionaryConditions: EthDictionaryV2QueryEntry = {\n logs: [],\n transactions: [],\n };\n\n for (const ds of dataSources) {\n for (const handler of ds.mapping.handlers) {\n // No filters, cant use dictionary\n if (!handler.filter) return dictionaryConditions;\n\n switch (handler.kind) {\n case EthereumHandlerKind.Block:\n return dictionaryConditions;\n case EthereumHandlerKind.Call: {\n const filter = handler.filter as EthereumTransactionFilter;\n if (\n filter.from !== undefined ||\n filter.to !== undefined ||\n filter.function !== undefined\n ) {\n dictionaryConditions.transactions.push(\n callFilterToDictionaryCondition(filter, ds.options),\n );\n } else {\n // do nothing;\n }\n break;\n }\n case EthereumHandlerKind.Event: {\n const filter = handler.filter as EthereumLogFilter;\n if (ds.groupedOptions) {\n dictionaryConditions.logs.push(\n eventFilterToDictionaryCondition(filter, ds.groupedOptions),\n );\n } else if (ds.options?.address || filter.topics) {\n dictionaryConditions.logs.push(\n eventFilterToDictionaryCondition(filter, ds.options),\n );\n } else {\n // do nothing;\n }\n break;\n }\n default:\n }\n }\n }\n\n if (!dictionaryConditions.logs.length) {\n delete dictionaryConditions.logs;\n } else {\n dictionaryConditions.logs = uniqBy(dictionaryConditions.logs, (log) =>\n JSON.stringify(log),\n );\n }\n\n if (!dictionaryConditions.transactions.length) {\n delete dictionaryConditions.transactions;\n } else {\n dictionaryConditions.transactions = uniqBy(\n dictionaryConditions.transactions,\n (tx) => JSON.stringify(tx),\n );\n }\n return dictionaryConditions;\n}\n\nexport class EthDictionaryV2 extends DictionaryV2<\n EthereumBlock,\n SubqlDatasource,\n EthDictionaryV2QueryEntry\n> {\n #skipTransactions: boolean;\n\n constructor(\n endpoint: string,\n nodeConfig: NodeConfig,\n project: SubqueryProject,\n private api: EthereumApi,\n ) {\n super(endpoint, project.network.chainId, nodeConfig);\n this.#skipTransactions = !!new EthereumNodeConfig(nodeConfig)\n .skipTransactions;\n }\n\n static async create(\n endpoint: string,\n nodeConfig: NodeConfig,\n project: SubqueryProject,\n api: EthereumApi,\n ): Promise<EthDictionaryV2> {\n const dictionary = new EthDictionaryV2(endpoint, nodeConfig, project, api);\n await dictionary.init();\n return dictionary;\n }\n\n buildDictionaryQueryEntries(\n dataSources: (EthereumProjectDs | EthereumProjectDsTemplate)[],\n ): EthDictionaryV2QueryEntry {\n const filteredDs = ethFilterDs(dataSources);\n return buildDictionaryV2QueryEntry(filteredDs);\n }\n\n // eslint-disable-next-line @typescript-eslint/require-await\n async getData(\n startBlock: number,\n endBlock: number,\n limit: number = MIN_FETCH_LIMIT,\n ): Promise<DictionaryResponse<IBlock<EthereumBlock> | number> | undefined> {\n return super.getData(startBlock, endBlock, limit, {\n blockHeader: true,\n logs: { transaction: !this.#skipTransactions },\n transactions: { log: true },\n });\n }\n\n convertResponseBlocks<RFB = RawEthBlock>(\n data: RawDictionaryResponseData<RFB>,\n ): DictionaryResponse<IBlock<EthereumBlock>> | undefined {\n try {\n const blocks: IBlock<EthereumBlock>[] = (\n (data.blocks as RawEthBlock[]) || []\n ).map((b) => rawBlockToEthBlock(b, this.api));\n return {\n batchBlocks: blocks,\n lastBufferedHeight: blocks.length\n ? blocks[blocks.length - 1].block.number\n : undefined,\n };\n } catch (e) {\n logger.error(e, `Failed to handle block response}`);\n throw e;\n }\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"ethDictionaryV2.js","sourceRoot":"","sources":["../../../../src/indexer/dictionary/v2/ethDictionaryV2.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;;;;;;;;;;;;;;AAEnC,gDAO0B;AAC1B,0DAO+B;AAC/B,mCAAgC;AAChC,8DAAmE;AAOnE,kDAAwE;AACxE,0CAA8C;A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AE,QAAQ,EAAE,KAAK,EAAE;YAChD,WAAW,EAAE,IAAI;YACjB,IAAI,EAAE,EAAE,WAAW,EAAE,CAAC,uBAAA,IAAI,yCAAkB,EAAE;YAC9C,YAAY,EAAE,EAAE,GAAG,EAAE,IAAI,EAAE;SAC5B,CAAC,CAAC;IACL,CAAC;IAED,qBAAqB,CACnB,IAAoC;QAEpC,IAAI;YACF,MAAM,MAAM,GAA4B,CACrC,IAAI,CAAC,MAAwB,IAAI,EAAE,CACrC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAA,0BAAkB,EAAC,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;YAC9C,OAAO;gBACL,WAAW,EAAE,MAAM;gBACnB,kBAAkB,EAAE,MAAM,CAAC,MAAM;oBAC/B,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM;oBACxC,CAAC,CAAC,SAAS;aACd,CAAC;SACH;QAAC,OAAO,CAAC,EAAE;YACV,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,kCAAkC,CAAC,CAAC;YACpD,MAAM,CAAC,CAAC;SACT;IACH,CAAC;CACF;AAnED,0CAmEC","sourcesContent":["// Copyright 2020-2024 SubQuery Pte Ltd authors & contributors\n// SPDX-License-Identifier: GPL-3.0\n\nimport {\n NodeConfig,\n DictionaryV2,\n RawDictionaryResponseData,\n DictionaryResponse,\n getLogger,\n IBlock,\n} from '@subql/node-core';\nimport {\n EthereumBlock,\n EthereumHandlerKind,\n EthereumLogFilter,\n EthereumTransactionFilter,\n SubqlDatasource,\n SubqlEthereumProcessorOptions,\n} from '@subql/types-ethereum';\nimport { uniqBy } from 'lodash';\nimport { EthereumNodeConfig } from '../../../configure/NodeConfig';\nimport {\n EthereumProjectDs,\n EthereumProjectDsTemplate,\n SubqueryProject,\n} from '../../../configure/SubqueryProject';\nimport { EthereumApi } from '../../../ethereum';\nimport { eventToTopic, functionToSighash } from '../../../utils/string';\nimport { yargsOptions } from '../../../yargs';\nimport { ethFilterDs } from '../utils';\nimport { GroupedEthereumProjectDs } from '../v1';\nimport {\n RawEthBlock,\n EthDictionaryV2QueryEntry,\n EthDictionaryTxConditions,\n EthDictionaryLogConditions,\n} from './types';\nimport { rawBlockToEthBlock } from './utils';\n\nconst MIN_FETCH_LIMIT = 200;\n\nconst logger = getLogger('dictionary-v2');\n\nfunction extractOptionAddresses(\n dsOptions: SubqlEthereumProcessorOptions | SubqlEthereumProcessorOptions[],\n): string[] {\n const queryAddressLimit = yargsOptions.argv['query-address-limit'];\n const addressArray: string[] = [];\n if (Array.isArray(dsOptions)) {\n const addresses = dsOptions.map((option) => option.address).filter(Boolean);\n\n if (addresses.length > queryAddressLimit) {\n logger.debug(\n `Addresses length: ${addresses.length} is exceeding limit: ${queryAddressLimit}. Consider increasing this value with the flag --query-address-limit `,\n );\n }\n if (addresses.length !== 0 && addresses.length <= queryAddressLimit) {\n addressArray.push(...addresses);\n }\n } else {\n if (dsOptions?.address) {\n addressArray.push(dsOptions.address.toLowerCase());\n }\n }\n return addressArray;\n}\n\nfunction callFilterToDictionaryCondition(\n filter: EthereumTransactionFilter,\n dsOptions: SubqlEthereumProcessorOptions,\n): EthDictionaryTxConditions {\n const txConditions: EthDictionaryTxConditions = {};\n const toArray = [];\n const fromArray = [];\n const funcArray = [];\n\n if (filter.from) {\n fromArray.push(filter.from.toLowerCase());\n }\n\n const assignTo = (value: string | null | undefined) => {\n if (value === null) {\n toArray.push(null);\n } else if (value !== undefined) {\n toArray.push(value.toLowerCase());\n }\n };\n\n const optionsAddresses = extractOptionAddresses(dsOptions);\n if (!optionsAddresses.length) {\n assignTo(filter.to);\n } else {\n if (filter.to || filter.to === null) {\n logger.warn(\n `TransactionFilter 'to' conflicts with 'address' in data source options, using data source option`,\n );\n }\n optionsAddresses.forEach(assignTo);\n }\n\n if (filter.function) {\n funcArray.push(functionToSighash(filter.function));\n }\n\n if (toArray.length !== 0) {\n txConditions.to = toArray;\n }\n if (fromArray.length !== 0) {\n txConditions.from = fromArray;\n }\n\n if (funcArray.length !== 0) {\n txConditions.data = funcArray;\n }\n\n return txConditions;\n}\n\nfunction eventFilterToDictionaryCondition(\n filter: EthereumLogFilter,\n dsOptions: SubqlEthereumProcessorOptions | SubqlEthereumProcessorOptions[],\n): EthDictionaryLogConditions {\n const logConditions: EthDictionaryLogConditions = {};\n logConditions.address = extractOptionAddresses(dsOptions);\n if (filter.topics) {\n for (let i = 0; i < Math.min(filter.topics.length, 4); i++) {\n const topic = filter.topics[i];\n if (!topic) {\n continue;\n }\n const field = `topics${i}`;\n // Initialized\n if (!logConditions[field]) {\n logConditions[field] = [];\n }\n if (topic === '!null') {\n logConditions[field] = []; // TODO, check if !null\n } else {\n logConditions[field].push(eventToTopic(topic));\n }\n }\n }\n return logConditions;\n}\n\nfunction sanitiseDictionaryConditions(\n dictionaryConditions: EthDictionaryV2QueryEntry,\n): EthDictionaryV2QueryEntry {\n if (!dictionaryConditions.logs.length) {\n delete dictionaryConditions.logs;\n } else {\n dictionaryConditions.logs = uniqBy(dictionaryConditions.logs, (log) =>\n JSON.stringify(log),\n );\n }\n\n if (!dictionaryConditions.transactions.length) {\n delete dictionaryConditions.transactions;\n } else {\n dictionaryConditions.transactions = uniqBy(\n dictionaryConditions.transactions,\n (tx) => JSON.stringify(tx),\n );\n }\n\n return dictionaryConditions;\n}\n\nexport function buildDictionaryV2QueryEntry(\n dataSources: GroupedEthereumProjectDs[],\n): EthDictionaryV2QueryEntry {\n const dictionaryConditions: EthDictionaryV2QueryEntry = {\n logs: [],\n transactions: [],\n };\n\n for (const ds of dataSources) {\n for (const handler of ds.mapping.handlers) {\n // No filters, cant use dictionary\n if (!handler.filter) return {};\n\n switch (handler.kind) {\n case EthereumHandlerKind.Block:\n if (handler.filter.modulo === undefined) {\n return {};\n }\n break;\n case EthereumHandlerKind.Call: {\n const filter = handler.filter as EthereumTransactionFilter;\n if (\n filter.from !== undefined ||\n filter.to !== undefined ||\n filter.function !== undefined\n ) {\n dictionaryConditions.transactions.push(\n callFilterToDictionaryCondition(filter, ds.options),\n );\n } else {\n // do nothing;\n }\n break;\n }\n case EthereumHandlerKind.Event: {\n const filter = handler.filter as EthereumLogFilter;\n if (ds.groupedOptions) {\n dictionaryConditions.logs.push(\n eventFilterToDictionaryCondition(filter, ds.groupedOptions),\n );\n } else if (ds.options?.address || filter.topics) {\n dictionaryConditions.logs.push(\n eventFilterToDictionaryCondition(filter, ds.options),\n );\n } else {\n // do nothing;\n }\n break;\n }\n default:\n }\n }\n }\n\n return sanitiseDictionaryConditions(dictionaryConditions);\n}\n\nexport class EthDictionaryV2 extends DictionaryV2<\n EthereumBlock,\n SubqlDatasource,\n EthDictionaryV2QueryEntry\n> {\n #skipTransactions: boolean;\n\n constructor(\n endpoint: string,\n nodeConfig: NodeConfig,\n project: SubqueryProject,\n private api: EthereumApi,\n ) {\n super(endpoint, project.network.chainId, nodeConfig);\n this.#skipTransactions = !!new EthereumNodeConfig(nodeConfig)\n .skipTransactions;\n }\n\n static async create(\n endpoint: string,\n nodeConfig: NodeConfig,\n project: SubqueryProject,\n api: EthereumApi,\n ): Promise<EthDictionaryV2> {\n const dictionary = new EthDictionaryV2(endpoint, nodeConfig, project, api);\n await dictionary.init();\n return dictionary;\n }\n\n buildDictionaryQueryEntries(\n dataSources: (EthereumProjectDs | EthereumProjectDsTemplate)[],\n ): EthDictionaryV2QueryEntry {\n const filteredDs = ethFilterDs(dataSources);\n return buildDictionaryV2QueryEntry(filteredDs);\n }\n\n // eslint-disable-next-line @typescript-eslint/require-await\n async getData(\n startBlock: number,\n endBlock: number,\n limit: number = MIN_FETCH_LIMIT,\n ): Promise<DictionaryResponse<IBlock<EthereumBlock> | number> | undefined> {\n return super.getData(startBlock, endBlock, limit, {\n blockHeader: true,\n logs: { transaction: !this.#skipTransactions },\n transactions: { log: true },\n });\n }\n\n convertResponseBlocks<RFB = RawEthBlock>(\n data: RawDictionaryResponseData<RFB>,\n ): DictionaryResponse<IBlock<EthereumBlock>> | undefined {\n try {\n const blocks: IBlock<EthereumBlock>[] = (\n (data.blocks as RawEthBlock[]) || []\n ).map((b) => rawBlockToEthBlock(b, this.api));\n return {\n batchBlocks: blocks,\n lastBufferedHeight: blocks.length\n ? blocks[blocks.length - 1].block.number\n : undefined,\n };\n } catch (e) {\n logger.error(e, `Failed to handle block response}`);\n throw e;\n }\n }\n}\n"]}
|
|
@@ -465,5 +465,44 @@ describe('buildDictionaryV2QueryEntry', () => {
|
|
|
465
465
|
],
|
|
466
466
|
});
|
|
467
467
|
});
|
|
468
|
+
it('builds a filter when theres a block handler with modulo filter', () => {
|
|
469
|
+
const ds = {
|
|
470
|
+
kind: types_ethereum_1.EthereumDatasourceKind.Runtime,
|
|
471
|
+
assets: new Map(),
|
|
472
|
+
options: {
|
|
473
|
+
abi: 'erc20',
|
|
474
|
+
address: '0x7ceB23fD6bC0adD59E62ac25578270cFf1b9f619',
|
|
475
|
+
},
|
|
476
|
+
startBlock: 1,
|
|
477
|
+
mapping: {
|
|
478
|
+
file: '',
|
|
479
|
+
handlers: [
|
|
480
|
+
{
|
|
481
|
+
handler: 'handleBlock',
|
|
482
|
+
kind: types_ethereum_1.EthereumHandlerKind.Block,
|
|
483
|
+
filter: {
|
|
484
|
+
modulo: 100,
|
|
485
|
+
},
|
|
486
|
+
},
|
|
487
|
+
{
|
|
488
|
+
handler: 'handleTx',
|
|
489
|
+
kind: types_ethereum_1.EthereumHandlerKind.Call,
|
|
490
|
+
filter: {
|
|
491
|
+
function: 'setminimumStakingAmount(uint256 amount)',
|
|
492
|
+
},
|
|
493
|
+
},
|
|
494
|
+
],
|
|
495
|
+
},
|
|
496
|
+
};
|
|
497
|
+
const result = (0, ethDictionaryV2_1.buildDictionaryV2QueryEntry)([ds]);
|
|
498
|
+
expect(result).toEqual({
|
|
499
|
+
transactions: [
|
|
500
|
+
{
|
|
501
|
+
to: ['0x7ceb23fd6bc0add59e62ac25578270cff1b9f619'],
|
|
502
|
+
data: ['0x7ef9ea98'],
|
|
503
|
+
},
|
|
504
|
+
],
|
|
505
|
+
});
|
|
506
|
+
});
|
|
468
507
|
});
|
|
469
508
|
//# sourceMappingURL=ethDictionaryV2.spec.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ethDictionaryV2.spec.js","sourceRoot":"","sources":["../../../../src/indexer/dictionary/v2/ethDictionaryV2.spec.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;;;;AAEnC,gDAK0B;AAC1B,0DAM+B;AAC/B,kEAA0C;AAM1C,gDAAgD;AAChD,oCAAuC;AACvC,uDAG2B;AAE3B,MAAM,kBAAkB,GAAG,+CAA+C,CAAC;AAC3E,MAAM,aAAa,GAAG,0BAA0B,CAAC;AACjD,MAAM,MAAM,GAAwB;IAClC;QACE,IAAI,EAAE,uCAAsB,CAAC,OAAO;QACpC,MAAM,EAAE,IAAI,GAAG,EAAE;QACjB,UAAU,EAAE,QAAQ;QACpB,OAAO,EAAE;YACP,IAAI,EAAE,iBAAiB;YACvB,QAAQ,EAAE;gBACR;oBACE,OAAO,EAAE,mBAAmB;oBAC5B,IAAI,EAAE,oCAAmB,CAAC,IAAI;oBAC9B,MAAM,EAAE;wBACN,QAAQ,EAAE,6CAA6C;qBACxD;iBACF;gBACD;oBACE,OAAO,EAAE,WAAW;oBACpB,IAAI,EAAE,oCAAmB,CAAC,KAAK;oBAC/B,MAAM,EAAE;wBACN,MAAM,EAAE;4BACN,oEAAoE;yBACrE;qBACF;iBACF;aACF;SACF;KACF;CACF,CAAC;AAEF,MAAM,UAAU,GAA8B;IAC5C,IAAI,EAAE,UAAU;IAChB,IAAI,EAAE,uCAAsB,CAAC,OAAO;IACpC,MAAM,EAAE,IAAI,GAAG,EAAE;IACjB,OAAO,EAAE;QACP,GAAG,EAAE,OAAO;QACZ,yDAAyD;KAC1D;IACD,iBAAiB;IACjB,OAAO,EAAE;QACP,IAA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,KAAK;wBACL,KAAK;wBACL,KAAK;qBACN;oBACD,OAAO,EAAE;wBACP,oEAAoE;qBACrE;iBACF;aACF;SACF,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,8DAA8D,EAAE,GAAG,EAAE;QACtE,MAAM,EAAE,GAA6B,EAAE,CAAC;QAExC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,GAAG,EAAE,CAAC,EAAE,EAAE;YAC5B,mBAAmB;YACnB,MAAM,GAAG,GAAI,MAAc,CAAC,eAAe,CAAC,UAAU,CAAC,CAAC;YACxD,CAAC,GAAG,CAAC,OAAO,CAAC,OAAO,GAAG,KAAK,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;SAChD;QAED,MAAM,MAAM,GAAG,IAAA,6CAA2B,EAAC,IAAA,mBAAW,EAAC,EAAE,CAAC,CAAC,CAAC;QAE5D,MAAM,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC;YACrB,IAAI,EAAE;gBACJ;oBACE,OAAO,EAAE,EAAE;oBACX,OAAO,EAAE;wBACP,oEAAoE;qBACrE;iBACF;aACF;SACF,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["// Copyright 2020-2024 SubQuery Pte Ltd authors & contributors\n// SPDX-License-Identifier: GPL-3.0\n\nimport {\n BlockHeightMap,\n DictionaryResponse,\n IBlock,\n NodeConfig,\n} from '@subql/node-core';\nimport {\n EthereumBlock,\n EthereumDatasourceKind,\n EthereumHandlerKind,\n SubqlDatasource,\n SubqlRuntimeDatasource,\n} from '@subql/types-ethereum';\nimport EventEmitter2 from 'eventemitter2';\nimport {\n EthereumProjectDs,\n EthereumProjectDsTemplate,\n SubqueryProject,\n} from '../../../configure/SubqueryProject';\nimport { EthereumApi } from '../../../ethereum';\nimport { ethFilterDs } from '../utils';\nimport {\n buildDictionaryV2QueryEntry,\n EthDictionaryV2,\n} from './ethDictionaryV2';\n\nconst DEFAULT_DICTIONARY = 'https://ethereum.node.subquery.network/public';\nconst HTTP_ENDPOINT = 'https://eth.llamarpc.com';\nconst mockDs: EthereumProjectDs[] = [\n {\n kind: EthereumDatasourceKind.Runtime,\n assets: new Map(),\n startBlock: 19217803,\n mapping: {\n file: './dist/index.js',\n handlers: [\n {\n handler: 'handleTransaction',\n kind: EthereumHandlerKind.Call,\n filter: {\n function: 'approve(address spender, uint256 rawAmount)',\n },\n },\n {\n handler: 'handleLog',\n kind: EthereumHandlerKind.Event,\n filter: {\n topics: [\n 'Transfer(address indexed from, address indexed to, uint256 amount)',\n ],\n },\n },\n ],\n },\n },\n];\n\nconst templateTs: EthereumProjectDsTemplate = {\n name: 'template',\n kind: EthereumDatasourceKind.Runtime,\n assets: new Map(),\n options: {\n abi: 'erc20',\n // address: '0x7ceB23fD6bC0adD59E62ac25578270cFf1b9f619',\n },\n // startBlock: 1,\n mapping: {\n file: '',\n handlers: [\n {\n handler: 'handleLog',\n kind: EthereumHandlerKind.Event,\n filter: {\n topics: ['Transfer(address, address, uint256)'],\n },\n },\n ],\n },\n};\n\n// tx to is null\nconst mockDs2: EthereumProjectDs[] = [\n {\n kind: EthereumDatasourceKind.Runtime,\n assets: new Map(),\n startBlock: 19217803,\n mapping: {\n file: './dist/index.js',\n handlers: [\n {\n handler: 'handleTransaction',\n kind: EthereumHandlerKind.Call,\n filter: {\n to: null,\n },\n },\n ],\n },\n },\n];\n\nconst nodeConfig = new NodeConfig({\n subquery: 'eth-starter',\n subqueryName: 'eth-starter',\n dictionaryTimeout: 10,\n networkEndpoint: [HTTP_ENDPOINT],\n networkDictionary: [DEFAULT_DICTIONARY],\n});\n\nfunction makeBlockHeightMap(mockDs: SubqlDatasource[]): BlockHeightMap<any> {\n const m = new Map<number, any>();\n mockDs.forEach((ds, index, dataSources) => {\n m.set(ds.startBlock, dataSources.slice(0, index + 1));\n });\n return new BlockHeightMap(m);\n}\n\n// enable this once dictionary v2 is online\ndescribe('eth dictionary v2', () => {\n let ethDictionaryV2: EthDictionaryV2;\n\n const dsMap = makeBlockHeightMap(mockDs);\n\n beforeAll(async () => {\n ethDictionaryV2 = await EthDictionaryV2.create(\n DEFAULT_DICTIONARY,\n nodeConfig,\n { network: { chainId: '1' } } as SubqueryProject,\n new EthereumApi(HTTP_ENDPOINT, 1, new EventEmitter2()),\n );\n }, 10000);\n\n beforeEach(() => {\n ethDictionaryV2.updateQueriesMap(dsMap);\n });\n\n it('converts ds to v2 dictionary queries', () => {\n const query = (ethDictionaryV2 as any).queriesMap.get(19217803);\n expect(query.logs.length).toBe(1);\n expect(query.transactions.length).toBe(1);\n });\n\n it('query response match with entries', async () => {\n const ethBlocks = (await ethDictionaryV2.getData(\n 19217803,\n (ethDictionaryV2 as any)._metadata.end,\n 2,\n )) as DictionaryResponse<IBlock<EthereumBlock>>;\n\n expect(ethBlocks.batchBlocks.map((b) => b.block.number)).toStrictEqual([\n 19217803, 19217804,\n ]);\n\n const ethBlock19217803 = ethBlocks.batchBlocks[0].block;\n const ethBlock19217804 = ethBlocks.batchBlocks[1].block;\n\n expect(ethBlock19217803.number).toBe(19217803);\n expect(ethBlock19217804.number).toBe(19217804);\n\n // Sighash of approval tx\n expect(\n ethBlock19217803.transactions.filter(\n (tx) => tx.input.indexOf('0x095ea7b3') === 0,\n ).length,\n ).toBe(4);\n\n expect(ethBlock19217804.logs.length).toBe(233);\n\n // This matches with dictionaryQueryEntries[0].topics\n expect(ethBlock19217804.logs[0].topics).toContain(\n '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef',\n );\n }, 10000);\n\n // Geth currently throwing errors with this request\n it.skip('is able to get transaction with field to is null', async () => {\n const dsMap = makeBlockHeightMap(mockDs2);\n ethDictionaryV2.updateQueriesMap(dsMap);\n\n const { conditions } = (ethDictionaryV2 as any).getQueryConditions(\n 19217803,\n (ethDictionaryV2 as any)._metadata.end,\n );\n\n expect(conditions).toEqual({ transactions: [{ to: [null] }] });\n\n const ethBlocks = (await ethDictionaryV2.getData(\n 19217803,\n (ethDictionaryV2 as any)._metadata.end,\n 1,\n )) as DictionaryResponse<IBlock<EthereumBlock>>;\n\n const { hash, transactions } = ethBlocks.batchBlocks[0].block;\n\n expect(hash).toBe(\n '0xa9ba70126240a8418739a103527860948a2be32de2eb9a8f590591faa174c08b',\n );\n\n // https://etherscan.io/tx/0x57e8cd9483cb5d308151372b0cf33fdc615999283c80ee3c28e94f074dda61f1\n expect(\n transactions.find(\n (tx) =>\n tx.hash ===\n '0x57e8cd9483cb5d308151372b0cf33fdc615999283c80ee3c28e94f074dda61f1',\n ),\n ).toBeDefined();\n });\n\n it('is able to query with not null topics', async () => {\n /**\n * Dictionary v1 supported filtering logs where a topic was null or not null.\n * V2 doesn't yet support this but we should still be able to make a dictionary query that gets relevant logs.\n * It will just include events that will be filtered out later.\n * */\n\n const ds: SubqlRuntimeDatasource = {\n kind: EthereumDatasourceKind.Runtime,\n assets: new Map(),\n options: {\n abi: 'erc20',\n },\n startBlock: 19476187,\n mapping: {\n file: '',\n handlers: [\n {\n handler: 'handleLog',\n kind: EthereumHandlerKind.Event,\n filter: {\n topics: [\n 'Transfer(address, address, uint256)',\n undefined,\n undefined,\n '!null',\n ],\n },\n },\n ],\n },\n };\n\n const dsMap = makeBlockHeightMap([ds]);\n ethDictionaryV2.updateQueriesMap(dsMap);\n\n const { conditions } = (ethDictionaryV2 as any).getQueryConditions(\n 19476187,\n (ethDictionaryV2 as any)._metadata.end,\n );\n\n expect(conditions).toEqual({\n logs: [\n {\n address: [],\n topics0: [\n '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef',\n ],\n topics3: [],\n },\n ],\n });\n\n const ethBlocks = (await ethDictionaryV2.getData(\n 19476187,\n (ethDictionaryV2 as any)._metadata.end,\n 2,\n )) as DictionaryResponse<IBlock<EthereumBlock>>;\n\n const { hash, logs } = ethBlocks.batchBlocks[0].block;\n\n expect(hash).toEqual(\n '0xa798861151ed58ad67d80d1cf61dc30e65d003bc958e99a7969a05a67e69e0b2',\n );\n\n const log = logs.find((l) => l.logIndex === 184);\n expect(log).toBeDefined();\n expect(log.transactionHash).toEqual(\n '0x5491f3f4b7ca6cc81f992a17e19bc9bafff408518c643c5a254de44b5a7b6d72',\n );\n\n // Uncomment this when not null filter supported\n // expect(logs.filter(l => !l.topics[3]).length).toEqual(6) // There are 6 events with no topic3\n }, 100000);\n});\n\ndescribe('buildDictionaryV2QueryEntry', () => {\n it('Build filter for !null', () => {\n const ds: SubqlRuntimeDatasource = {\n kind: EthereumDatasourceKind.Runtime,\n assets: new Map(),\n options: {\n abi: 'erc20',\n address: '0x7ceB23fD6bC0adD59E62ac25578270cFf1b9f619',\n },\n startBlock: 1,\n mapping: {\n file: '',\n handlers: [\n {\n handler: 'handleLog',\n kind: EthereumHandlerKind.Event,\n filter: {\n topics: [\n 'Transfer(address, address, uint256)',\n undefined,\n undefined,\n '!null',\n ],\n },\n },\n ],\n },\n };\n const result = buildDictionaryV2QueryEntry([ds]);\n\n expect(result).toEqual({\n logs: [\n {\n address: ['0x7ceb23fd6bc0add59e62ac25578270cff1b9f619'],\n topics0: [\n '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef',\n ],\n topics3: [],\n },\n ],\n });\n });\n\n it('Build filter tx filter', () => {\n const ds: SubqlRuntimeDatasource = {\n kind: EthereumDatasourceKind.Runtime,\n assets: new Map(),\n options: {\n abi: 'erc20',\n address: '0x7ceB23fD6bC0adD59E62ac25578270cFf1b9f619',\n },\n startBlock: 1,\n mapping: {\n file: '',\n handlers: [\n {\n handler: 'handleTx',\n kind: EthereumHandlerKind.Call,\n filter: {\n function: 'setminimumStakingAmount(uint256 amount)',\n },\n },\n ],\n },\n };\n const result = buildDictionaryV2QueryEntry([ds]);\n\n expect(result).toEqual({\n transactions: [\n {\n to: ['0x7ceb23fd6bc0add59e62ac25578270cff1b9f619'],\n data: ['0x7ef9ea98'],\n },\n ],\n });\n });\n\n it('build query entries for multiple ds', () => {\n const ds: SubqlRuntimeDatasource[] = [\n {\n kind: EthereumDatasourceKind.Runtime,\n startBlock: 3327417,\n options: {\n abi: 'EnsRegistry',\n address: '0x314159265dd8dbb310642f98f50c066173c1259b',\n },\n assets: new Map(),\n mapping: {\n file: './dist/index.js',\n handlers: [\n // one duplicate one\n {\n kind: EthereumHandlerKind.Event,\n handler: 'handleTransferOldRegistry',\n filter: {\n topics: ['Transfer(bytes32,address)'],\n },\n },\n {\n kind: EthereumHandlerKind.Event,\n handler: 'handleTransferOldRegistry',\n filter: {\n topics: ['Transfer(bytes32,address)'],\n },\n },\n {\n kind: EthereumHandlerKind.Event,\n handler: 'handleNewOwnerOldRegistry',\n filter: {\n topics: ['NewOwner(bytes32,bytes32,address)'],\n },\n },\n ],\n },\n },\n {\n kind: EthereumDatasourceKind.Runtime,\n startBlock: 3327417,\n options: {\n abi: 'Resolver',\n },\n assets: new Map(),\n mapping: {\n file: './dist/index.js',\n handlers: [\n {\n kind: EthereumHandlerKind.Event,\n handler: 'handleABIChanged',\n filter: {\n topics: ['ABIChanged(bytes32,uint256)'],\n },\n },\n {\n kind: EthereumHandlerKind.Event,\n handler: 'handleAddrChanged',\n filter: {\n topics: ['AddrChanged(bytes32,address)'],\n },\n },\n {\n kind: EthereumHandlerKind.Event,\n handler: 'handleMulticoinAddrChanged',\n filter: {\n topics: ['AddressChanged(bytes32,uint256,bytes)'],\n },\n },\n {\n kind: EthereumHandlerKind.Event,\n handler: 'handleAuthorisationChanged',\n filter: {\n topics: ['AuthorisationChanged(bytes32,address,address,bool)'],\n },\n },\n ],\n },\n },\n ];\n\n const queryEntry = buildDictionaryV2QueryEntry(ds);\n // Total 7 handlers were given, 1 is duplicate\n expect(queryEntry.logs.length).toBe(6);\n });\n\n it('should unique QueryEntry for duplicate dataSources', () => {\n const ds: SubqlRuntimeDatasource = {\n kind: EthereumDatasourceKind.Runtime,\n assets: new Map(),\n options: {\n abi: 'erc20',\n address: '0x7ceB23fD6bC0adD59E62ac25578270cFf1b9f619',\n },\n startBlock: 1,\n mapping: {\n file: '',\n handlers: [\n {\n handler: 'handleLog',\n kind: EthereumHandlerKind.Event,\n filter: {\n topics: ['Transfer(address, address, uint256)'],\n },\n },\n {\n handler: 'handleLogSame',\n kind: EthereumHandlerKind.Event,\n filter: {\n topics: ['Transfer(address, address, uint256)'],\n },\n },\n {\n handler: 'handleTx',\n kind: EthereumHandlerKind.Call,\n filter: {\n function: 'setminimumStakingAmount(uint256 amount)',\n from: 'mockAddress',\n },\n },\n {\n handler: 'handleTxSame',\n kind: EthereumHandlerKind.Call,\n filter: {\n function: 'setminimumStakingAmount(uint256 amount)',\n from: 'mockAddress',\n },\n },\n ],\n },\n };\n const result = buildDictionaryV2QueryEntry([ds]);\n\n expect(result).toEqual({\n logs: [\n {\n address: ['0x7ceb23fd6bc0add59e62ac25578270cff1b9f619'],\n topics0: [\n '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef',\n ],\n },\n ],\n transactions: [\n {\n from: ['mockaddress'],\n to: ['0x7ceb23fd6bc0add59e62ac25578270cff1b9f619'],\n data: ['0x7ef9ea98'],\n },\n ],\n });\n });\n\n it('should group a small number of dynamic ds', () => {\n const ds: SubqlRuntimeDatasource[] = [];\n\n for (let i = 0; i < 10; i++) {\n // Bad nodejs types\n const tmp = (global as any).structuredClone(templateTs);\n (tmp.options.address = `0x${i}`), ds.push(tmp);\n }\n\n const result = buildDictionaryV2QueryEntry(ethFilterDs(ds));\n\n expect(result).toEqual({\n logs: [\n {\n address: [\n '0x0',\n '0x1',\n '0x2',\n '0x3',\n '0x4',\n '0x5',\n '0x6',\n '0x7',\n '0x8',\n '0x9',\n ],\n topics0: [\n '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef',\n ],\n },\n ],\n });\n });\n\n it('should remove address filter with large number of dynamic ds', () => {\n const ds: SubqlRuntimeDatasource[] = [];\n\n for (let i = 0; i < 200; i++) {\n // Bad nodejs types\n const tmp = (global as any).structuredClone(templateTs);\n (tmp.options.address = `0x${i}`), ds.push(tmp);\n }\n\n const result = buildDictionaryV2QueryEntry(ethFilterDs(ds));\n\n expect(result).toEqual({\n logs: [\n {\n address: [],\n topics0: [\n '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef',\n ],\n },\n ],\n });\n });\n});\n"]}
|
|
1
|
+
{"version":3,"file":"ethDictionaryV2.spec.js","sourceRoot":"","sources":["../../../../src/indexer/dictionary/v2/ethDictionaryV2.spec.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;;;;AAEnC,gDAK0B;AAC1B,0DAM+B;AAC/B,kEAA0C;AAM1C,gDAAgD;AAChD,oCAAuC;AACvC,uDAG2B;AAE3B,MAAM,kBAAkB,GAAG,+CAA+C,CAAC;AAC3E,MAAM,aAAa,GAAG,0BAA0B,CAAC;AACjD,MAAM,MAAM,GAAwB;IAClC;QACE,IAAI,EAAE,uCAAsB,CAAC,OAAO;QACpC,MAAM,EAAE,IAAI,GAAG,EAAE;QACjB,UAAU,EAAE,QAAQ;QACpB,OAAO,EAAE;YACP,IAAI,EAAE,iBAAiB;YACvB,QAAQ,EAAE;gBACR;oBACE,OAAO,EAAE,mBAAmB;oBAC5B,IAAI,EAAE,oCAAmB,CAAC,IAAI;oBAC9B,MAAM,EAAE;wBACN,QAAQ,EAAE,6CAA6C;qBACxD;iBACF;gBACD;oBACE,OAAO,EAAE,WAAW;oBACpB,IAAI,EAAE,oCAAmB,CAAC,KAAK;oBAC/B,MAAM,EAAE;wBACN,MAAM,EAAE;4BACN,oEAAoE;yBACrE;qBACF;iBACF;aACF;SACF;KACF;CACF,CAAC;AAEF,MAAM,UAAU,GAA8B;IAC5C,IAAI,EAAE,UAAU;IAChB,IAAI,EAAE,uCAAsB,CAAC,OAAO;IACpC,MAAM,EAAE,IAAI,GAAG,EAAE;IACjB,OAAO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AC,KAAK;wBAC/B,MAAM,EAAE;4BACN,MAAM,EAAE,GAAG;yBACZ;qBACF;oBACD;wBACE,OAAO,EAAE,UAAU;wBACnB,IAAI,EAAE,oCAAmB,CAAC,IAAI;wBAC9B,MAAM,EAAE;4BACN,QAAQ,EAAE,yCAAyC;yBACpD;qBACF;iBACF;aACF;SACF,CAAC;QACF,MAAM,MAAM,GAAG,IAAA,6CAA2B,EAAC,CAAC,EAAE,CAAC,CAAC,CAAC;QAEjD,MAAM,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC;YACrB,YAAY,EAAE;gBACZ;oBACE,EAAE,EAAE,CAAC,4CAA4C,CAAC;oBAClD,IAAI,EAAE,CAAC,YAAY,CAAC;iBACrB;aACF;SACF,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["// Copyright 2020-2024 SubQuery Pte Ltd authors & contributors\n// SPDX-License-Identifier: GPL-3.0\n\nimport {\n BlockHeightMap,\n DictionaryResponse,\n IBlock,\n NodeConfig,\n} from '@subql/node-core';\nimport {\n EthereumBlock,\n EthereumDatasourceKind,\n EthereumHandlerKind,\n SubqlDatasource,\n SubqlRuntimeDatasource,\n} from '@subql/types-ethereum';\nimport EventEmitter2 from 'eventemitter2';\nimport {\n EthereumProjectDs,\n EthereumProjectDsTemplate,\n SubqueryProject,\n} from '../../../configure/SubqueryProject';\nimport { EthereumApi } from '../../../ethereum';\nimport { ethFilterDs } from '../utils';\nimport {\n buildDictionaryV2QueryEntry,\n EthDictionaryV2,\n} from './ethDictionaryV2';\n\nconst DEFAULT_DICTIONARY = 'https://ethereum.node.subquery.network/public';\nconst HTTP_ENDPOINT = 'https://eth.llamarpc.com';\nconst mockDs: EthereumProjectDs[] = [\n {\n kind: EthereumDatasourceKind.Runtime,\n assets: new Map(),\n startBlock: 19217803,\n mapping: {\n file: './dist/index.js',\n handlers: [\n {\n handler: 'handleTransaction',\n kind: EthereumHandlerKind.Call,\n filter: {\n function: 'approve(address spender, uint256 rawAmount)',\n },\n },\n {\n handler: 'handleLog',\n kind: EthereumHandlerKind.Event,\n filter: {\n topics: [\n 'Transfer(address indexed from, address indexed to, uint256 amount)',\n ],\n },\n },\n ],\n },\n },\n];\n\nconst templateTs: EthereumProjectDsTemplate = {\n name: 'template',\n kind: EthereumDatasourceKind.Runtime,\n assets: new Map(),\n options: {\n abi: 'erc20',\n // address: '0x7ceB23fD6bC0adD59E62ac25578270cFf1b9f619',\n },\n // startBlock: 1,\n mapping: {\n file: '',\n handlers: [\n {\n handler: 'handleLog',\n kind: EthereumHandlerKind.Event,\n filter: {\n topics: ['Transfer(address, address, uint256)'],\n },\n },\n ],\n },\n};\n\n// tx to is null\nconst mockDs2: EthereumProjectDs[] = [\n {\n kind: EthereumDatasourceKind.Runtime,\n assets: new Map(),\n startBlock: 19217803,\n mapping: {\n file: './dist/index.js',\n handlers: [\n {\n handler: 'handleTransaction',\n kind: EthereumHandlerKind.Call,\n filter: {\n to: null,\n },\n },\n ],\n },\n },\n];\n\nconst nodeConfig = new NodeConfig({\n subquery: 'eth-starter',\n subqueryName: 'eth-starter',\n dictionaryTimeout: 10,\n networkEndpoint: [HTTP_ENDPOINT],\n networkDictionary: [DEFAULT_DICTIONARY],\n});\n\nfunction makeBlockHeightMap(mockDs: SubqlDatasource[]): BlockHeightMap<any> {\n const m = new Map<number, any>();\n mockDs.forEach((ds, index, dataSources) => {\n m.set(ds.startBlock, dataSources.slice(0, index + 1));\n });\n return new BlockHeightMap(m);\n}\n\n// enable this once dictionary v2 is online\ndescribe('eth dictionary v2', () => {\n let ethDictionaryV2: EthDictionaryV2;\n\n const dsMap = makeBlockHeightMap(mockDs);\n\n beforeAll(async () => {\n ethDictionaryV2 = await EthDictionaryV2.create(\n DEFAULT_DICTIONARY,\n nodeConfig,\n { network: { chainId: '1' } } as SubqueryProject,\n new EthereumApi(HTTP_ENDPOINT, 1, new EventEmitter2()),\n );\n }, 10000);\n\n beforeEach(() => {\n ethDictionaryV2.updateQueriesMap(dsMap);\n });\n\n it('converts ds to v2 dictionary queries', () => {\n const query = (ethDictionaryV2 as any).queriesMap.get(19217803);\n expect(query.logs.length).toBe(1);\n expect(query.transactions.length).toBe(1);\n });\n\n it('query response match with entries', async () => {\n const ethBlocks = (await ethDictionaryV2.getData(\n 19217803,\n (ethDictionaryV2 as any)._metadata.end,\n 2,\n )) as DictionaryResponse<IBlock<EthereumBlock>>;\n\n expect(ethBlocks.batchBlocks.map((b) => b.block.number)).toStrictEqual([\n 19217803, 19217804,\n ]);\n\n const ethBlock19217803 = ethBlocks.batchBlocks[0].block;\n const ethBlock19217804 = ethBlocks.batchBlocks[1].block;\n\n expect(ethBlock19217803.number).toBe(19217803);\n expect(ethBlock19217804.number).toBe(19217804);\n\n // Sighash of approval tx\n expect(\n ethBlock19217803.transactions.filter(\n (tx) => tx.input.indexOf('0x095ea7b3') === 0,\n ).length,\n ).toBe(4);\n\n expect(ethBlock19217804.logs.length).toBe(233);\n\n // This matches with dictionaryQueryEntries[0].topics\n expect(ethBlock19217804.logs[0].topics).toContain(\n '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef',\n );\n }, 10000);\n\n // Geth currently throwing errors with this request\n it.skip('is able to get transaction with field to is null', async () => {\n const dsMap = makeBlockHeightMap(mockDs2);\n ethDictionaryV2.updateQueriesMap(dsMap);\n\n const { conditions } = (ethDictionaryV2 as any).getQueryConditions(\n 19217803,\n (ethDictionaryV2 as any)._metadata.end,\n );\n\n expect(conditions).toEqual({ transactions: [{ to: [null] }] });\n\n const ethBlocks = (await ethDictionaryV2.getData(\n 19217803,\n (ethDictionaryV2 as any)._metadata.end,\n 1,\n )) as DictionaryResponse<IBlock<EthereumBlock>>;\n\n const { hash, transactions } = ethBlocks.batchBlocks[0].block;\n\n expect(hash).toBe(\n '0xa9ba70126240a8418739a103527860948a2be32de2eb9a8f590591faa174c08b',\n );\n\n // https://etherscan.io/tx/0x57e8cd9483cb5d308151372b0cf33fdc615999283c80ee3c28e94f074dda61f1\n expect(\n transactions.find(\n (tx) =>\n tx.hash ===\n '0x57e8cd9483cb5d308151372b0cf33fdc615999283c80ee3c28e94f074dda61f1',\n ),\n ).toBeDefined();\n });\n\n it('is able to query with not null topics', async () => {\n /**\n * Dictionary v1 supported filtering logs where a topic was null or not null.\n * V2 doesn't yet support this but we should still be able to make a dictionary query that gets relevant logs.\n * It will just include events that will be filtered out later.\n * */\n\n const ds: SubqlRuntimeDatasource = {\n kind: EthereumDatasourceKind.Runtime,\n assets: new Map(),\n options: {\n abi: 'erc20',\n },\n startBlock: 19476187,\n mapping: {\n file: '',\n handlers: [\n {\n handler: 'handleLog',\n kind: EthereumHandlerKind.Event,\n filter: {\n topics: [\n 'Transfer(address, address, uint256)',\n undefined,\n undefined,\n '!null',\n ],\n },\n },\n ],\n },\n };\n\n const dsMap = makeBlockHeightMap([ds]);\n ethDictionaryV2.updateQueriesMap(dsMap);\n\n const { conditions } = (ethDictionaryV2 as any).getQueryConditions(\n 19476187,\n (ethDictionaryV2 as any)._metadata.end,\n );\n\n expect(conditions).toEqual({\n logs: [\n {\n address: [],\n topics0: [\n '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef',\n ],\n topics3: [],\n },\n ],\n });\n\n const ethBlocks = (await ethDictionaryV2.getData(\n 19476187,\n (ethDictionaryV2 as any)._metadata.end,\n 2,\n )) as DictionaryResponse<IBlock<EthereumBlock>>;\n\n const { hash, logs } = ethBlocks.batchBlocks[0].block;\n\n expect(hash).toEqual(\n '0xa798861151ed58ad67d80d1cf61dc30e65d003bc958e99a7969a05a67e69e0b2',\n );\n\n const log = logs.find((l) => l.logIndex === 184);\n expect(log).toBeDefined();\n expect(log.transactionHash).toEqual(\n '0x5491f3f4b7ca6cc81f992a17e19bc9bafff408518c643c5a254de44b5a7b6d72',\n );\n\n // Uncomment this when not null filter supported\n // expect(logs.filter(l => !l.topics[3]).length).toEqual(6) // There are 6 events with no topic3\n }, 100000);\n});\n\ndescribe('buildDictionaryV2QueryEntry', () => {\n it('Build filter for !null', () => {\n const ds: SubqlRuntimeDatasource = {\n kind: EthereumDatasourceKind.Runtime,\n assets: new Map(),\n options: {\n abi: 'erc20',\n address: '0x7ceB23fD6bC0adD59E62ac25578270cFf1b9f619',\n },\n startBlock: 1,\n mapping: {\n file: '',\n handlers: [\n {\n handler: 'handleLog',\n kind: EthereumHandlerKind.Event,\n filter: {\n topics: [\n 'Transfer(address, address, uint256)',\n undefined,\n undefined,\n '!null',\n ],\n },\n },\n ],\n },\n };\n const result = buildDictionaryV2QueryEntry([ds]);\n\n expect(result).toEqual({\n logs: [\n {\n address: ['0x7ceb23fd6bc0add59e62ac25578270cff1b9f619'],\n topics0: [\n '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef',\n ],\n topics3: [],\n },\n ],\n });\n });\n\n it('Build filter tx filter', () => {\n const ds: SubqlRuntimeDatasource = {\n kind: EthereumDatasourceKind.Runtime,\n assets: new Map(),\n options: {\n abi: 'erc20',\n address: '0x7ceB23fD6bC0adD59E62ac25578270cFf1b9f619',\n },\n startBlock: 1,\n mapping: {\n file: '',\n handlers: [\n {\n handler: 'handleTx',\n kind: EthereumHandlerKind.Call,\n filter: {\n function: 'setminimumStakingAmount(uint256 amount)',\n },\n },\n ],\n },\n };\n const result = buildDictionaryV2QueryEntry([ds]);\n\n expect(result).toEqual({\n transactions: [\n {\n to: ['0x7ceb23fd6bc0add59e62ac25578270cff1b9f619'],\n data: ['0x7ef9ea98'],\n },\n ],\n });\n });\n\n it('build query entries for multiple ds', () => {\n const ds: SubqlRuntimeDatasource[] = [\n {\n kind: EthereumDatasourceKind.Runtime,\n startBlock: 3327417,\n options: {\n abi: 'EnsRegistry',\n address: '0x314159265dd8dbb310642f98f50c066173c1259b',\n },\n assets: new Map(),\n mapping: {\n file: './dist/index.js',\n handlers: [\n // one duplicate one\n {\n kind: EthereumHandlerKind.Event,\n handler: 'handleTransferOldRegistry',\n filter: {\n topics: ['Transfer(bytes32,address)'],\n },\n },\n {\n kind: EthereumHandlerKind.Event,\n handler: 'handleTransferOldRegistry',\n filter: {\n topics: ['Transfer(bytes32,address)'],\n },\n },\n {\n kind: EthereumHandlerKind.Event,\n handler: 'handleNewOwnerOldRegistry',\n filter: {\n topics: ['NewOwner(bytes32,bytes32,address)'],\n },\n },\n ],\n },\n },\n {\n kind: EthereumDatasourceKind.Runtime,\n startBlock: 3327417,\n options: {\n abi: 'Resolver',\n },\n assets: new Map(),\n mapping: {\n file: './dist/index.js',\n handlers: [\n {\n kind: EthereumHandlerKind.Event,\n handler: 'handleABIChanged',\n filter: {\n topics: ['ABIChanged(bytes32,uint256)'],\n },\n },\n {\n kind: EthereumHandlerKind.Event,\n handler: 'handleAddrChanged',\n filter: {\n topics: ['AddrChanged(bytes32,address)'],\n },\n },\n {\n kind: EthereumHandlerKind.Event,\n handler: 'handleMulticoinAddrChanged',\n filter: {\n topics: ['AddressChanged(bytes32,uint256,bytes)'],\n },\n },\n {\n kind: EthereumHandlerKind.Event,\n handler: 'handleAuthorisationChanged',\n filter: {\n topics: ['AuthorisationChanged(bytes32,address,address,bool)'],\n },\n },\n ],\n },\n },\n ];\n\n const queryEntry = buildDictionaryV2QueryEntry(ds);\n // Total 7 handlers were given, 1 is duplicate\n expect(queryEntry.logs.length).toBe(6);\n });\n\n it('should unique QueryEntry for duplicate dataSources', () => {\n const ds: SubqlRuntimeDatasource = {\n kind: EthereumDatasourceKind.Runtime,\n assets: new Map(),\n options: {\n abi: 'erc20',\n address: '0x7ceB23fD6bC0adD59E62ac25578270cFf1b9f619',\n },\n startBlock: 1,\n mapping: {\n file: '',\n handlers: [\n {\n handler: 'handleLog',\n kind: EthereumHandlerKind.Event,\n filter: {\n topics: ['Transfer(address, address, uint256)'],\n },\n },\n {\n handler: 'handleLogSame',\n kind: EthereumHandlerKind.Event,\n filter: {\n topics: ['Transfer(address, address, uint256)'],\n },\n },\n {\n handler: 'handleTx',\n kind: EthereumHandlerKind.Call,\n filter: {\n function: 'setminimumStakingAmount(uint256 amount)',\n from: 'mockAddress',\n },\n },\n {\n handler: 'handleTxSame',\n kind: EthereumHandlerKind.Call,\n filter: {\n function: 'setminimumStakingAmount(uint256 amount)',\n from: 'mockAddress',\n },\n },\n ],\n },\n };\n const result = buildDictionaryV2QueryEntry([ds]);\n\n expect(result).toEqual({\n logs: [\n {\n address: ['0x7ceb23fd6bc0add59e62ac25578270cff1b9f619'],\n topics0: [\n '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef',\n ],\n },\n ],\n transactions: [\n {\n from: ['mockaddress'],\n to: ['0x7ceb23fd6bc0add59e62ac25578270cff1b9f619'],\n data: ['0x7ef9ea98'],\n },\n ],\n });\n });\n\n it('should group a small number of dynamic ds', () => {\n const ds: SubqlRuntimeDatasource[] = [];\n\n for (let i = 0; i < 10; i++) {\n // Bad nodejs types\n const tmp = (global as any).structuredClone(templateTs);\n (tmp.options.address = `0x${i}`), ds.push(tmp);\n }\n\n const result = buildDictionaryV2QueryEntry(ethFilterDs(ds));\n\n expect(result).toEqual({\n logs: [\n {\n address: [\n '0x0',\n '0x1',\n '0x2',\n '0x3',\n '0x4',\n '0x5',\n '0x6',\n '0x7',\n '0x8',\n '0x9',\n ],\n topics0: [\n '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef',\n ],\n },\n ],\n });\n });\n\n it('should remove address filter with large number of dynamic ds', () => {\n const ds: SubqlRuntimeDatasource[] = [];\n\n for (let i = 0; i < 200; i++) {\n // Bad nodejs types\n const tmp = (global as any).structuredClone(templateTs);\n (tmp.options.address = `0x${i}`), ds.push(tmp);\n }\n\n const result = buildDictionaryV2QueryEntry(ethFilterDs(ds));\n\n expect(result).toEqual({\n logs: [\n {\n address: [],\n topics0: [\n '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef',\n ],\n },\n ],\n });\n });\n\n it('builds a filter when theres a block handler with modulo filter', () => {\n const ds: SubqlRuntimeDatasource = {\n kind: EthereumDatasourceKind.Runtime,\n assets: new Map(),\n options: {\n abi: 'erc20',\n address: '0x7ceB23fD6bC0adD59E62ac25578270cFf1b9f619',\n },\n startBlock: 1,\n mapping: {\n file: '',\n handlers: [\n {\n handler: 'handleBlock',\n kind: EthereumHandlerKind.Block,\n filter: {\n modulo: 100,\n },\n },\n {\n handler: 'handleTx',\n kind: EthereumHandlerKind.Call,\n filter: {\n function: 'setminimumStakingAmount(uint256 amount)',\n },\n },\n ],\n },\n };\n const result = buildDictionaryV2QueryEntry([ds]);\n\n expect(result).toEqual({\n transactions: [\n {\n to: ['0x7ceb23fd6bc0add59e62ac25578270cff1b9f619'],\n data: ['0x7ef9ea98'],\n },\n ],\n });\n });\n});\n"]}
|
|
@@ -59,8 +59,8 @@ export interface RawEthLog {
|
|
|
59
59
|
* Eth dictionary RPC request filter conditions
|
|
60
60
|
*/
|
|
61
61
|
export interface EthDictionaryV2QueryEntry extends DictionaryV2QueryEntry {
|
|
62
|
-
logs
|
|
63
|
-
transactions
|
|
62
|
+
logs?: EthDictionaryLogConditions[];
|
|
63
|
+
transactions?: EthDictionaryTxConditions[];
|
|
64
64
|
}
|
|
65
65
|
export interface EthDictionaryLogConditions {
|
|
66
66
|
address?: string[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/indexer/dictionary/v2/types.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC","sourcesContent":["// Copyright 2020-2024 SubQuery Pte Ltd authors & contributors\n// SPDX-License-Identifier: GPL-3.0\n\nimport { DictionaryV2QueryEntry } from '@subql/node-core';\n\nexport interface RawEthBlock {\n header: {\n parentHash: string;\n sha3Uncles: string;\n miner: string;\n stateRoot: string;\n transactionRoot: string;\n receiptsRoot: string;\n logsBloom: string;\n difficulty: bigint;\n number: bigint;\n gasLimit: bigint;\n gasUsed: bigint;\n timestamp: bigint;\n extraData: string;\n mixHash: string;\n nonce: string;\n baseFeePerGas: bigint;\n withdrawalsRoot: string;\n blobGasUsed: bigint;\n excessBlobGas: bigint;\n parentBeaconBlockRoot: string;\n hash: string;\n };\n transactions: RawEthTransaction[];\n logs: RawEthLog[];\n}\n\nexport interface RawEthTransaction {\n type: string;\n nonce: bigint;\n to: string;\n gas: bigint;\n gasPrice: bigint;\n maxPriorityFeePerGas: bigint;\n maxFeePerGas: bigint;\n value: bigint;\n v: bigint;\n r: string;\n s: string;\n input: string;\n hash: string;\n from: string;\n func: string;\n gasLimit: bigint;\n}\n\nexport interface RawEthLog {\n address: string;\n topics: string[];\n data: string;\n blockNumber: bigint;\n transactionHash: string;\n transactionIndex: bigint;\n blockHash: string;\n logIndex: bigint;\n removed: boolean;\n}\n\n/**\n * Eth dictionary RPC request filter conditions\n */\nexport interface EthDictionaryV2QueryEntry extends DictionaryV2QueryEntry {\n logs
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/indexer/dictionary/v2/types.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC","sourcesContent":["// Copyright 2020-2024 SubQuery Pte Ltd authors & contributors\n// SPDX-License-Identifier: GPL-3.0\n\nimport { DictionaryV2QueryEntry } from '@subql/node-core';\n\nexport interface RawEthBlock {\n header: {\n parentHash: string;\n sha3Uncles: string;\n miner: string;\n stateRoot: string;\n transactionRoot: string;\n receiptsRoot: string;\n logsBloom: string;\n difficulty: bigint;\n number: bigint;\n gasLimit: bigint;\n gasUsed: bigint;\n timestamp: bigint;\n extraData: string;\n mixHash: string;\n nonce: string;\n baseFeePerGas: bigint;\n withdrawalsRoot: string;\n blobGasUsed: bigint;\n excessBlobGas: bigint;\n parentBeaconBlockRoot: string;\n hash: string;\n };\n transactions: RawEthTransaction[];\n logs: RawEthLog[];\n}\n\nexport interface RawEthTransaction {\n type: string;\n nonce: bigint;\n to: string;\n gas: bigint;\n gasPrice: bigint;\n maxPriorityFeePerGas: bigint;\n maxFeePerGas: bigint;\n value: bigint;\n v: bigint;\n r: string;\n s: string;\n input: string;\n hash: string;\n from: string;\n func: string;\n gasLimit: bigint;\n}\n\nexport interface RawEthLog {\n address: string;\n topics: string[];\n data: string;\n blockNumber: bigint;\n transactionHash: string;\n transactionIndex: bigint;\n blockHash: string;\n logIndex: bigint;\n removed: boolean;\n}\n\n/**\n * Eth dictionary RPC request filter conditions\n */\nexport interface EthDictionaryV2QueryEntry extends DictionaryV2QueryEntry {\n logs?: EthDictionaryLogConditions[];\n transactions?: EthDictionaryTxConditions[];\n}\n\nexport interface EthDictionaryLogConditions {\n address?: string[];\n topics0?: string[];\n topics1?: string[];\n topics2?: string[];\n}\n\nexport interface EthDictionaryTxConditions {\n to?: string[];\n from?: string[];\n data?: string[];\n}\n"]}
|