@subql/node-ethereum 3.3.4 → 3.3.5-poi-logs
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/dist/.tsbuildinfo +1 -1
- package/dist/ethereum/api.ethereum.js +2 -4
- package/dist/ethereum/api.ethereum.js.map +1 -1
- package/dist/ethereum/api.ethereum.test.js +0 -15
- package/dist/ethereum/api.ethereum.test.js.map +1 -1
- package/dist/ethereum/utils.ethereum.d.ts +2 -0
- package/dist/ethereum/utils.ethereum.js +2 -1
- package/dist/ethereum/utils.ethereum.js.map +1 -1
- package/dist/indexer/blockDispatcher/block-dispatcher.service.d.ts +1 -0
- package/dist/indexer/blockDispatcher/block-dispatcher.service.js +3 -0
- package/dist/indexer/blockDispatcher/block-dispatcher.service.js.map +1 -1
- package/dist/indexer/blockDispatcher/ethereum-block-dispatcher.d.ts +2 -1
- package/dist/indexer/blockDispatcher/ethereum-block-dispatcher.js.map +1 -1
- package/dist/indexer/blockDispatcher/worker-block-dispatcher.service.d.ts +3 -1
- package/dist/indexer/blockDispatcher/worker-block-dispatcher.service.js +3 -0
- package/dist/indexer/blockDispatcher/worker-block-dispatcher.service.js.map +1 -1
- package/dist/indexer/dictionary.service.js +4 -7
- package/dist/indexer/dictionary.service.js.map +1 -1
- package/dist/indexer/eth-fat-dictionary.service.d.ts +83 -0
- package/dist/indexer/eth-fat-dictionary.service.js +246 -0
- package/dist/indexer/eth-fat-dictionary.service.js.map +1 -0
- package/dist/indexer/fetch.module.js +16 -0
- package/dist/indexer/fetch.module.js.map +1 -1
- package/dist/indexer/fetch.service.d.ts +4 -3
- package/dist/indexer/fetch.service.js +5 -3
- package/dist/indexer/fetch.service.js.map +1 -1
- package/dist/indexer/fetch.service.spec.js +1 -1
- package/dist/indexer/fetch.service.spec.js.map +1 -1
- package/dist/yargs.d.ts +232 -1
- package/dist/yargs.js +270 -7
- package/dist/yargs.js.map +1 -1
- package/package.json +5 -5
- package/CHANGELOG.md +0 -383
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright 2020-2023 SubQuery Pte Ltd authors & contributors
|
|
3
|
+
// SPDX-License-Identifier: GPL-3.0
|
|
4
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
5
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
6
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
7
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
8
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
9
|
+
};
|
|
10
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
11
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
12
|
+
};
|
|
13
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.EthFatDictionaryService = void 0;
|
|
18
|
+
const assert_1 = __importDefault(require("assert"));
|
|
19
|
+
const common_1 = require("@nestjs/common");
|
|
20
|
+
const node_core_1 = require("@subql/node-core");
|
|
21
|
+
const fat_dictionary_service_1 = require("@subql/node-core/indexer/fat-dictionary.service");
|
|
22
|
+
const utils_ethereum_1 = require("../ethereum/utils.ethereum");
|
|
23
|
+
let EthFatDictionaryService = class EthFatDictionaryService extends fat_dictionary_service_1.FatDictionaryService {
|
|
24
|
+
constructor(nodeConfig) {
|
|
25
|
+
super(nodeConfig);
|
|
26
|
+
}
|
|
27
|
+
get dictionaryEndpoint() {
|
|
28
|
+
(0, assert_1.default)(this.nodeConfig.fatDictionary, 'fat dictionary not in node config');
|
|
29
|
+
return this.nodeConfig.fatDictionary;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
*
|
|
33
|
+
* @param startBlock
|
|
34
|
+
* @param queryEndBlock this block number will limit the max query range, increase dictionary query speed
|
|
35
|
+
* @param batchSize
|
|
36
|
+
* @param conditions
|
|
37
|
+
*/
|
|
38
|
+
// eslint-disable-next-line @typescript-eslint/require-await
|
|
39
|
+
// TODO, move to eth
|
|
40
|
+
async queryFatDictionary(startBlock, queryEndBlock, limit = 200, conditions) {
|
|
41
|
+
if (!conditions) {
|
|
42
|
+
return undefined;
|
|
43
|
+
}
|
|
44
|
+
const requestConditions = this.dictionaryFatQuery(conditions);
|
|
45
|
+
const requestData = {
|
|
46
|
+
jsonrpc: "2.0",
|
|
47
|
+
method: "subql_filterBlocks",
|
|
48
|
+
id: 1,
|
|
49
|
+
params: [startBlock, queryEndBlock, limit, requestConditions, { "blockHeader": true, "logs": true, "transactions": { "data": true } }]
|
|
50
|
+
};
|
|
51
|
+
try {
|
|
52
|
+
const response = await this.dictionaryApi.post(this.dictionaryEndpoint, requestData, {
|
|
53
|
+
headers: {
|
|
54
|
+
'Content-Type': 'application/json',
|
|
55
|
+
},
|
|
56
|
+
});
|
|
57
|
+
return response.data.result;
|
|
58
|
+
}
|
|
59
|
+
catch (error) {
|
|
60
|
+
// Handle the error as needed
|
|
61
|
+
throw new Error(`Fat dictionary get capacity failed ${error}`);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
// eslint-disable-next-line complexity
|
|
65
|
+
dictionaryFatQuery(dictionaryQueryEntries) {
|
|
66
|
+
const logsFilters = [];
|
|
67
|
+
const transactionsFilters = [];
|
|
68
|
+
for (const entry of dictionaryQueryEntries) {
|
|
69
|
+
if (entry.entity === 'evmTransactions') {
|
|
70
|
+
const filter = {};
|
|
71
|
+
const toArray = [];
|
|
72
|
+
const fromArray = [];
|
|
73
|
+
// const funcArray = []
|
|
74
|
+
for (const condition of entry.conditions) {
|
|
75
|
+
if (condition.field === 'to' && condition.matcher === "equalTo") {
|
|
76
|
+
toArray.push(condition.value);
|
|
77
|
+
}
|
|
78
|
+
if (condition.field === 'from' && condition.matcher === "equalTo") {
|
|
79
|
+
fromArray.push(condition.value);
|
|
80
|
+
}
|
|
81
|
+
// if(condition.field==='func' && condition.matcher === "equalTo"){
|
|
82
|
+
// funcArray.push(condition.value)
|
|
83
|
+
// }
|
|
84
|
+
}
|
|
85
|
+
if (toArray.length !== 0) {
|
|
86
|
+
// @ts-ignore
|
|
87
|
+
filter.to = toArray;
|
|
88
|
+
}
|
|
89
|
+
if (fromArray.length !== 0) {
|
|
90
|
+
// @ts-ignore
|
|
91
|
+
filter.from = fromArray;
|
|
92
|
+
}
|
|
93
|
+
// if(funcArray.length!==0){
|
|
94
|
+
// // @ts-ignore
|
|
95
|
+
// filter.function = funcArray;
|
|
96
|
+
// }
|
|
97
|
+
if (toArray.length !== 0 || fromArray.length !== 0) {
|
|
98
|
+
transactionsFilters.push(filter);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
if (entry.entity === 'evmLogs') {
|
|
102
|
+
const filter = {};
|
|
103
|
+
const addressArray = [];
|
|
104
|
+
const topicsArray = [];
|
|
105
|
+
for (const condition of entry.conditions) {
|
|
106
|
+
if (condition.field === 'address' && condition.matcher === "equalTo") {
|
|
107
|
+
addressArray.push(condition.value);
|
|
108
|
+
}
|
|
109
|
+
if (condition.field === 'topics0' && condition.matcher === "equalTo") {
|
|
110
|
+
topicsArray.push(condition.value);
|
|
111
|
+
}
|
|
112
|
+
if (condition.field === 'topics1' && condition.matcher === "equalTo") {
|
|
113
|
+
topicsArray.push(condition.value);
|
|
114
|
+
}
|
|
115
|
+
if (condition.field === 'topics2' && condition.matcher === "equalTo") {
|
|
116
|
+
topicsArray.push(condition.value);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
if (addressArray.length !== 0) {
|
|
120
|
+
// @ts-ignore
|
|
121
|
+
filter.address = addressArray;
|
|
122
|
+
}
|
|
123
|
+
if (topicsArray.length !== 0) {
|
|
124
|
+
// @ts-ignore
|
|
125
|
+
filter.topics0 = topicsArray;
|
|
126
|
+
}
|
|
127
|
+
if (addressArray.length !== 0 || topicsArray.length !== 0) {
|
|
128
|
+
logsFilters.push(filter);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
return { "logs": logsFilters, "transactions": transactionsFilters };
|
|
133
|
+
}
|
|
134
|
+
buildDictionaryEntryMap(dataSources, buildDictionaryQueryEntries) {
|
|
135
|
+
this.queriesMap = dataSources.map(buildDictionaryQueryEntries);
|
|
136
|
+
}
|
|
137
|
+
convertResponseBlocks(data) {
|
|
138
|
+
var _a;
|
|
139
|
+
const blocks = [];
|
|
140
|
+
for (const block of data.Blocks) {
|
|
141
|
+
const logs = [];
|
|
142
|
+
const transactions = [];
|
|
143
|
+
try {
|
|
144
|
+
const ethBlock = {
|
|
145
|
+
blockExtraData: block.Header.extraData,
|
|
146
|
+
difficulty: block.Header.difficulty,
|
|
147
|
+
extDataGasUsed: (_a = block.Header.excessBlobGas) === null || _a === void 0 ? void 0 : _a.toString(),
|
|
148
|
+
extDataHash: block.Header.extraData,
|
|
149
|
+
gasLimit: block.Header.gasLimit,
|
|
150
|
+
gasUsed: block.Header.gasUsed,
|
|
151
|
+
hash: block.Header.hash,
|
|
152
|
+
logs: [],
|
|
153
|
+
logsBloom: block.Header.logsBloom,
|
|
154
|
+
miner: block.Header.miner,
|
|
155
|
+
mixHash: block.Header.mixHash,
|
|
156
|
+
nonce: block.Header.nonce,
|
|
157
|
+
number: Number(block.Header.number),
|
|
158
|
+
parentHash: block.Header.parentHash,
|
|
159
|
+
receiptsRoot: block.Header.receiptsRoot,
|
|
160
|
+
sha3Uncles: block.Header.sha3Uncles,
|
|
161
|
+
size: undefined,
|
|
162
|
+
stateRoot: block.Header.stateRoot,
|
|
163
|
+
timestamp: block.Header.timestamp,
|
|
164
|
+
totalDifficulty: block.Header.difficulty,
|
|
165
|
+
transactions: [],
|
|
166
|
+
transactionsRoot: block.Header.transactionRoot,
|
|
167
|
+
uncles: [block.Header.sha3Uncles],
|
|
168
|
+
baseFeePerGas: block.Header.baseFeePerGas,
|
|
169
|
+
blockGasCost: undefined, //TODO, seems missing
|
|
170
|
+
};
|
|
171
|
+
if (block.Transactions !== null && block.Transactions.length) {
|
|
172
|
+
for (const tx of block.Transactions) {
|
|
173
|
+
const _ethTransaction = {
|
|
174
|
+
blockHash: ethBlock.hash,
|
|
175
|
+
blockNumber: ethBlock.number,
|
|
176
|
+
blockTimestamp: ethBlock.timestamp,
|
|
177
|
+
from: tx.from,
|
|
178
|
+
gas: tx.gas,
|
|
179
|
+
gasPrice: tx.gasPrice,
|
|
180
|
+
hash: tx.hash,
|
|
181
|
+
input: tx.input,
|
|
182
|
+
nonce: tx.nonce,
|
|
183
|
+
to: tx.to,
|
|
184
|
+
transactionIndex: undefined,
|
|
185
|
+
value: tx.value,
|
|
186
|
+
type: tx.type,
|
|
187
|
+
v: tx.v,
|
|
188
|
+
r: tx.r,
|
|
189
|
+
s: tx.s,
|
|
190
|
+
receipt: undefined,
|
|
191
|
+
logs: [],
|
|
192
|
+
accessList: [],
|
|
193
|
+
chainId: '',
|
|
194
|
+
maxFeePerGas: tx.maxFeePerGas,
|
|
195
|
+
maxPriorityFeePerGas: tx.maxPriorityFeePerGas,
|
|
196
|
+
args: undefined, //todo
|
|
197
|
+
};
|
|
198
|
+
transactions.push(_ethTransaction);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
ethBlock.transactions = transactions;
|
|
202
|
+
if (block.Logs !== null && block.Logs.length) {
|
|
203
|
+
for (const log of block.Logs) {
|
|
204
|
+
const _ethLog = {
|
|
205
|
+
address: log.address,
|
|
206
|
+
topics: log.topics,
|
|
207
|
+
data: log.data,
|
|
208
|
+
blockHash: log.blockHash,
|
|
209
|
+
blockNumber: Number(log.blockNumber),
|
|
210
|
+
transactionHash: log.transactionHash,
|
|
211
|
+
transactionIndex: Number(log.transactionIndex),
|
|
212
|
+
logIndex: Number(log.logIndex),
|
|
213
|
+
removed: log.removed,
|
|
214
|
+
args: undefined,
|
|
215
|
+
block: ethBlock,
|
|
216
|
+
transaction: undefined,
|
|
217
|
+
};
|
|
218
|
+
logs.push(_ethLog);
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
ethBlock.logs = logs.map((l) => (0, utils_ethereum_1.formatLog)(l, ethBlock));
|
|
222
|
+
//TODO, maybe need FORMAT transaction
|
|
223
|
+
blocks.push(ethBlock);
|
|
224
|
+
}
|
|
225
|
+
catch (e) {
|
|
226
|
+
throw new Error(`Convert fat block to Eth block failed at ${block.Header.number},${e.message}`);
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
if (blocks.length !== 0) {
|
|
230
|
+
return {
|
|
231
|
+
blocks: blocks,
|
|
232
|
+
start: blocks[0].number,
|
|
233
|
+
end: blocks[blocks.length - 1].number,
|
|
234
|
+
};
|
|
235
|
+
}
|
|
236
|
+
else {
|
|
237
|
+
return undefined;
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
};
|
|
241
|
+
EthFatDictionaryService = __decorate([
|
|
242
|
+
(0, common_1.Injectable)(),
|
|
243
|
+
__metadata("design:paramtypes", [node_core_1.NodeConfig])
|
|
244
|
+
], EthFatDictionaryService);
|
|
245
|
+
exports.EthFatDictionaryService = EthFatDictionaryService;
|
|
246
|
+
//# sourceMappingURL=eth-fat-dictionary.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"eth-fat-dictionary.service.js","sourceRoot":"","sources":["../../src/indexer/eth-fat-dictionary.service.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;;;;;;;;;;;;;;AAEnC,oDAA4B;AAC5B,2CAA0C;AAC1C,gDAA4C;AAC5C,4FAA4G;AAI5G,+DAAqD;AAI9C,IAAM,uBAAuB,GAA7B,MAAM,uBAAwB,SAAQ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ChG;SAEF;QAED,IAAG,MAAM,CAAC,MAAM,KAAG,CAAC,EAAC;YACnB,OAAO;gBACL,MAAM,EAAE,MAAM;gBACd,KAAK,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM;gBACvB,GAAG,EAAE,MAAM,CAAC,MAAM,CAAC,MAAM,GAAC,CAAC,CAAC,CAAC,MAAM;aACpC,CAAA;SACF;aAAI;YACH,OAAO,SAAS,CAAA;SACjB;IACH,CAAC;CAEF,CAAA;AAzPY,uBAAuB;IADnC,IAAA,mBAAU,GAAE;qCAIa,sBAAU;GAHvB,uBAAuB,CAyPnC;AAzPY,0DAAuB","sourcesContent":["// Copyright 2020-2023 SubQuery Pte Ltd authors & contributors\n// SPDX-License-Identifier: GPL-3.0\n\nimport assert from 'assert';\nimport {Injectable} from '@nestjs/common';\nimport {NodeConfig} from '@subql/node-core';\nimport {FatDictionaryResponse, FatDictionaryService} from '@subql/node-core/indexer/fat-dictionary.service';\nimport {BlockHeightMap} from '@subql/node-core/utils/blockHeightMap';\nimport {DictionaryQueryEntry, BaseDataSource} from '@subql/types-core';\nimport {EthereumBlock, EthereumLog, EthereumReceipt, EthereumTransaction} from '@subql/types-ethereum';\nimport {formatLog} from '../ethereum/utils.ethereum';\n\n\n@Injectable()\nexport class EthFatDictionaryService extends FatDictionaryService<EthereumBlock>{\n\n\n constructor(nodeConfig: NodeConfig) {\n super(nodeConfig);\n }\n\n\n get dictionaryEndpoint(): string{\n\n assert(this.nodeConfig.fatDictionary, 'fat dictionary not in node config')\n return this.nodeConfig.fatDictionary\n }\n\n\n\n\n /**\n *\n * @param startBlock\n * @param queryEndBlock this block number will limit the max query range, increase dictionary query speed\n * @param batchSize\n * @param conditions\n */\n // eslint-disable-next-line @typescript-eslint/require-await\n // TODO, move to eth\n async queryFatDictionary(\n startBlock: number,\n queryEndBlock: number,\n limit: number =200,\n conditions?: DictionaryQueryEntry[]\n ): Promise<UnwrappedFatDictionaryResponseData | undefined> {\n if (!conditions) {\n return undefined;\n }\n const requestConditions = this.dictionaryFatQuery(conditions);\n\n const requestData = {\n jsonrpc: \"2.0\",\n method: \"subql_filterBlocks\",\n id: 1,\n params: [startBlock,queryEndBlock,limit, requestConditions,{\"blockHeader\":true,\"logs\":true,\"transactions\":{\"data\":true}}]\n };\n\n try {\n const response = await this.dictionaryApi.post(this.dictionaryEndpoint, requestData, {\n headers: {\n 'Content-Type': 'application/json',\n },\n });\n return response.data.result as UnwrappedFatDictionaryResponseData;\n } catch (error) {\n // Handle the error as needed\n throw new Error(`Fat dictionary get capacity failed ${error}` );\n }\n }\n\n // eslint-disable-next-line complexity\n dictionaryFatQuery(\n dictionaryQueryEntries: DictionaryQueryEntry[]\n ){\n const logsFilters = []\n const transactionsFilters= []\n for (const entry of dictionaryQueryEntries){\n if(entry.entity === 'evmTransactions'){\n const filter = {}\n const toArray = [];\n const fromArray = []\n // const funcArray = []\n for(const condition of entry.conditions){\n if(condition.field==='to' && condition.matcher === \"equalTo\"){\n toArray.push(condition.value)\n }\n if(condition.field==='from' && condition.matcher === \"equalTo\"){\n fromArray.push(condition.value)\n }\n // if(condition.field==='func' && condition.matcher === \"equalTo\"){\n // funcArray.push(condition.value)\n // }\n }\n\n if(toArray.length!==0){\n // @ts-ignore\n filter.to = toArray;\n }\n if(fromArray.length!==0){\n // @ts-ignore\n filter.from = fromArray;\n }\n // if(funcArray.length!==0){\n // // @ts-ignore\n // filter.function = funcArray;\n // }\n\n if(toArray.length!==0 || fromArray.length!==0){\n transactionsFilters.push(filter)\n }\n }\n if(entry.entity === 'evmLogs'){\n const filter = {}\n const addressArray =[]\n const topicsArray = []\n for(const condition of entry.conditions){\n\n if(condition.field==='address' && condition.matcher === \"equalTo\"){\n addressArray.push(condition.value)\n }\n if(condition.field==='topics0' && condition.matcher === \"equalTo\"){\n topicsArray.push(condition.value)\n }\n if(condition.field==='topics1' && condition.matcher === \"equalTo\"){\n topicsArray.push(condition.value)\n }\n if(condition.field==='topics2' && condition.matcher === \"equalTo\"){\n topicsArray.push(condition.value)\n }\n\n }\n if(addressArray.length!==0){\n // @ts-ignore\n filter.address = addressArray;\n }\n if(topicsArray.length!==0){\n // @ts-ignore\n filter.topics0 = topicsArray;\n }\n if(addressArray.length!==0 || topicsArray.length!==0){\n logsFilters.push(filter)\n }\n }\n }\n return {\"logs\":logsFilters,\"transactions\":transactionsFilters}\n }\n\n buildDictionaryEntryMap<DS extends BaseDataSource>(\n dataSources: BlockHeightMap<DS[]>,\n buildDictionaryQueryEntries: (dataSources: DS[]) => DictionaryQueryEntry[]\n ): void {\n this.queriesMap = dataSources.map(buildDictionaryQueryEntries);\n }\n\n convertResponseBlocks(data: UnwrappedFatDictionaryResponseData):FatDictionaryResponse<EthereumBlock>|undefined{\n\n const blocks:EthereumBlock[] = [];\n for(const block of data.Blocks){\n\n const logs: EthereumLog[] =[];\n const transactions: EthereumTransaction[] = [];\n try{\n const ethBlock:EthereumBlock = {\n blockExtraData: block.Header.extraData,\n difficulty: block.Header.difficulty,\n extDataGasUsed: block.Header.excessBlobGas?.toString(), //TODO, is this right?\n extDataHash: block.Header.extraData,\n gasLimit: block.Header.gasLimit,\n gasUsed: block.Header.gasUsed,\n hash: block.Header.hash,\n logs: [],//\n logsBloom: block.Header.logsBloom,\n miner: block.Header.miner,\n mixHash: block.Header.mixHash,\n nonce: block.Header.nonce,\n number: Number(block.Header.number),\n parentHash: block.Header.parentHash,\n receiptsRoot: block.Header.receiptsRoot,\n sha3Uncles: block.Header.sha3Uncles,\n size: undefined,// TODO, unknown from data\n stateRoot: block.Header.stateRoot,\n timestamp: block.Header.timestamp, //TODO, seems wrong from source\n totalDifficulty: block.Header.difficulty,\n transactions: [],\n transactionsRoot: block.Header.transactionRoot,\n uncles: [block.Header.sha3Uncles],\n baseFeePerGas: block.Header.baseFeePerGas,\n blockGasCost: undefined, //TODO, seems missing\n }\n\n if(block.Transactions!==null && block.Transactions.length){\n for(const tx of block.Transactions){\n const _ethTransaction:EthereumTransaction = {\n blockHash: ethBlock.hash,\n blockNumber: ethBlock.number,\n blockTimestamp: ethBlock.timestamp,\n from: tx.from,\n gas: tx.gas,\n gasPrice: tx.gasPrice,\n hash: tx.hash,\n input: tx.input,\n nonce: tx.nonce,\n to: tx.to,\n transactionIndex: undefined,//todo\n value: tx.value,\n type: tx.type,\n v: tx.v,\n r: tx.r,\n s: tx.s,\n receipt: undefined, //todo\n logs: [],\n accessList: [],\n chainId: '',\n maxFeePerGas: tx.maxFeePerGas,\n maxPriorityFeePerGas: tx.maxPriorityFeePerGas,\n args: undefined, //todo\n }\n transactions.push(_ethTransaction);\n }\n }\n ethBlock.transactions = transactions;\n\n if(block.Logs!==null && block.Logs.length){\n for(const log of block.Logs){\n const _ethLog:EthereumLog = {\n address: log.address,\n topics: log.topics,\n data: log.data,\n blockHash: log.blockHash,\n blockNumber: Number(log.blockNumber),\n transactionHash: log.transactionHash,\n transactionIndex: Number(log.transactionIndex),\n logIndex: Number(log.logIndex),\n removed: log.removed,\n args: undefined, //TODO, unknown\n block: ethBlock,\n transaction: undefined,\n }\n logs.push(_ethLog)\n }\n }\n ethBlock.logs = logs.map((l) => formatLog(l, ethBlock));\n //TODO, maybe need FORMAT transaction\n\n blocks.push(ethBlock);\n }catch (e) {\n throw new Error(`Convert fat block to Eth block failed at ${block.Header.number},${e.message}`)\n }\n\n }\n\n if(blocks.length!==0){\n return {\n blocks: blocks,\n start: blocks[0].number,\n end: blocks[blocks.length-1].number,\n }\n }else{\n return undefined\n }\n }\n\n}\n\ninterface UnwrappedEthFatBlock{\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:UnwrappedEthFatTransaction[],\n Logs:UnwrappedEthFatLog[],\n}\n\ninterface UnwrappedEthFatTransaction{\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}\n\ninterface UnwrappedEthFatLog{\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\ninterface UnwrappedFatDictionaryResponseData{\n Blocks: UnwrappedEthFatBlock[],\n BlockRange: number[];\n GenesisHash: string;\n}\n"]}
|
|
@@ -17,6 +17,7 @@ const blockDispatcher_1 = require("./blockDispatcher");
|
|
|
17
17
|
const dictionary_service_1 = require("./dictionary.service");
|
|
18
18
|
const ds_processor_service_1 = require("./ds-processor.service");
|
|
19
19
|
const dynamic_ds_service_1 = require("./dynamic-ds.service");
|
|
20
|
+
const eth_fat_dictionary_service_1 = require("./eth-fat-dictionary.service");
|
|
20
21
|
const fetch_service_1 = require("./fetch.service");
|
|
21
22
|
const indexer_manager_1 = require("./indexer.manager");
|
|
22
23
|
const project_service_1 = require("./project.service");
|
|
@@ -89,6 +90,21 @@ FetchModule = __decorate([
|
|
|
89
90
|
node_core_1.ConnectionPoolService,
|
|
90
91
|
node_core_1.IndexingBenchmarkService,
|
|
91
92
|
node_core_1.PoiBenchmarkService,
|
|
93
|
+
eth_fat_dictionary_service_1.EthFatDictionaryService,
|
|
94
|
+
// {
|
|
95
|
+
// provide: FatDictionaryService,
|
|
96
|
+
// useFactory: async (
|
|
97
|
+
// project: SubqueryProject,
|
|
98
|
+
// nodeConfig: NodeConfig,
|
|
99
|
+
// eventEmitter: EventEmitter2,
|
|
100
|
+
// ) => {
|
|
101
|
+
// const fatDictionaryService = await FatDictionaryService.create(
|
|
102
|
+
// nodeConfig
|
|
103
|
+
// );
|
|
104
|
+
// return fatDictionaryService;
|
|
105
|
+
// },
|
|
106
|
+
// inject: ['ISubqueryProject', NodeConfig, EventEmitter2],
|
|
107
|
+
// },
|
|
92
108
|
{
|
|
93
109
|
provide: dictionary_service_1.DictionaryService,
|
|
94
110
|
useFactory: async (project, nodeConfig, eventEmitter) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetch.module.js","sourceRoot":"","sources":["../../src/indexer/fetch.module.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;;;;;;;;AAEnC,2CAAwC;AACxC,yDAAsD;AACtD,gDAc0B;AAG1B,2EAAsE;AACtE,uDAG2B;AAC3B,6DAAyD;AACzD,iEAA4D;AAC5D,6DAAwD;AACxD,mDAA+C;AAC/C,uDAAmD;AACnD,uDAAmD;AACnD,uDAAmD;AACnD,2EAAuE;
|
|
1
|
+
{"version":3,"file":"fetch.module.js","sourceRoot":"","sources":["../../src/indexer/fetch.module.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;;;;;;;;AAEnC,2CAAwC;AACxC,yDAAsD;AACtD,gDAc0B;AAG1B,2EAAsE;AACtE,uDAG2B;AAC3B,6DAAyD;AACzD,iEAA4D;AAC5D,6DAAwD;AACxD,6EAAqE;AACrE,mDAA+C;AAC/C,uDAAmD;AACnD,uDAAmD;AACnD,uDAAmD;AACnD,2EAAuE;AAuKhE,IAAM,WAAW,GAAjB,MAAM,WAAW;CAAG,CAAA;AAAd,WAAW;IArKvB,IAAA,eAAM,EAAC;QACN,SAAS,EAAE;YACT,gCAAoB;YACpB,wBAAY;YACZ,6BAAiB;YACjB;gBACE,OAAO,EAAE,sBAAU;gBACnB,UAAU,EAAE,KAAK,EACf,OAAwB,EACxB,qBAAmE,EACnE,YAA2B,EAC3B,UAAsB,EACtB,EAAE;oBACF,MAAM,UAAU,GAAG,IAAI,yCAAkB,CACvC,OAAO,EACP,qBAAqB,EACrB,YAAY,EACZ,UA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020-2023 SubQuery Pte Ltd authors & contributors\n// SPDX-License-Identifier: GPL-3.0\n\nimport { Module } from '@nestjs/common';\nimport { EventEmitter2 } from '@nestjs/event-emitter';\nimport {\n PoiBenchmarkService,\n IndexingBenchmarkService,\n StoreService,\n PoiService,\n ApiService,\n NodeConfig,\n ConnectionPoolService,\n ConnectionPoolStateManager,\n SmartBatchService,\n StoreCacheService,\n IProjectUpgradeService,\n PoiSyncService,\n InMemoryCacheService,\n} from '@subql/node-core';\nimport { SubqueryProject } from '../configure/SubqueryProject';\nimport { EthereumApiConnection } from '../ethereum/api.connection';\nimport { EthereumApiService } from '../ethereum/api.service.ethereum';\nimport {\n BlockDispatcherService,\n WorkerBlockDispatcherService,\n} from './blockDispatcher';\nimport { DictionaryService } from './dictionary.service';\nimport { DsProcessorService } from './ds-processor.service';\nimport { DynamicDsService } from './dynamic-ds.service';\nimport {EthFatDictionaryService} from './eth-fat-dictionary.service';\nimport { FetchService } from './fetch.service';\nimport { IndexerManager } from './indexer.manager';\nimport { ProjectService } from './project.service';\nimport { SandboxService } from './sandbox.service';\nimport { UnfinalizedBlocksService } from './unfinalizedBlocks.service';\n\n@Module({\n providers: [\n InMemoryCacheService,\n StoreService,\n StoreCacheService,\n {\n provide: ApiService,\n useFactory: async (\n project: SubqueryProject,\n connectionPoolService: ConnectionPoolService<EthereumApiConnection>,\n eventEmitter: EventEmitter2,\n nodeConfig: NodeConfig,\n ) => {\n const apiService = new EthereumApiService(\n project,\n connectionPoolService,\n eventEmitter,\n nodeConfig,\n );\n await apiService.init();\n return apiService;\n },\n inject: [\n 'ISubqueryProject',\n ConnectionPoolService,\n EventEmitter2,\n NodeConfig,\n ],\n },\n IndexerManager,\n ConnectionPoolStateManager,\n ConnectionPoolService,\n {\n provide: SmartBatchService,\n useFactory: (nodeConfig: NodeConfig) => {\n return new SmartBatchService(nodeConfig.batchSize);\n },\n inject: [NodeConfig],\n },\n {\n provide: SmartBatchService,\n useFactory: (nodeConfig: NodeConfig) => {\n return new SmartBatchService(nodeConfig.batchSize);\n },\n inject: [NodeConfig],\n },\n {\n provide: 'IBlockDispatcher',\n useFactory: (\n nodeConfig: NodeConfig,\n eventEmitter: EventEmitter2,\n projectService: ProjectService,\n projectUpgradeService: IProjectUpgradeService,\n apiService: EthereumApiService,\n indexerManager: IndexerManager,\n smartBatchService: SmartBatchService,\n cacheService: InMemoryCacheService,\n storeService: StoreService,\n storeCacheService: StoreCacheService,\n poiService: PoiService,\n poiSyncService: PoiSyncService,\n project: SubqueryProject,\n dynamicDsService: DynamicDsService,\n unfinalizedBlocks: UnfinalizedBlocksService,\n connectionPoolState: ConnectionPoolStateManager<EthereumApiConnection>,\n ) =>\n nodeConfig.workers !== undefined\n ? new WorkerBlockDispatcherService(\n nodeConfig,\n eventEmitter,\n projectService,\n projectUpgradeService,\n smartBatchService,\n cacheService,\n storeService,\n storeCacheService,\n poiService,\n poiSyncService,\n project,\n dynamicDsService,\n unfinalizedBlocks,\n connectionPoolState,\n )\n : new BlockDispatcherService(\n apiService,\n nodeConfig,\n indexerManager,\n eventEmitter,\n projectService,\n projectUpgradeService,\n smartBatchService,\n storeService,\n storeCacheService,\n poiService,\n poiSyncService,\n project,\n dynamicDsService,\n ),\n inject: [\n NodeConfig,\n EventEmitter2,\n 'IProjectService',\n 'IProjectUpgradeService',\n ApiService,\n IndexerManager,\n SmartBatchService,\n InMemoryCacheService,\n StoreService,\n StoreCacheService,\n PoiService,\n PoiSyncService,\n 'ISubqueryProject',\n DynamicDsService,\n UnfinalizedBlocksService,\n ConnectionPoolStateManager,\n ],\n },\n FetchService,\n ConnectionPoolService,\n IndexingBenchmarkService,\n PoiBenchmarkService,\n EthFatDictionaryService,\n // {\n // provide: FatDictionaryService,\n // useFactory: async (\n // project: SubqueryProject,\n // nodeConfig: NodeConfig,\n // eventEmitter: EventEmitter2,\n // ) => {\n // const fatDictionaryService = await FatDictionaryService.create(\n // nodeConfig\n // );\n // return fatDictionaryService;\n // },\n // inject: ['ISubqueryProject', NodeConfig, EventEmitter2],\n // },\n {\n provide: DictionaryService,\n useFactory: async (\n project: SubqueryProject,\n nodeConfig: NodeConfig,\n eventEmitter: EventEmitter2,\n ) => {\n const dictionaryService = await DictionaryService.create(\n project,\n nodeConfig,\n eventEmitter,\n );\n return dictionaryService;\n },\n inject: ['ISubqueryProject', NodeConfig, EventEmitter2],\n },\n SandboxService,\n DsProcessorService,\n DynamicDsService,\n PoiService,\n PoiSyncService,\n {\n useClass: ProjectService,\n provide: 'IProjectService',\n },\n UnfinalizedBlocksService,\n ],\n exports: [StoreService, StoreCacheService],\n})\nexport class FetchModule {}\n"]}
|
|
@@ -3,22 +3,23 @@ import { SchedulerRegistry } from '@nestjs/schedule';
|
|
|
3
3
|
import { SubqlEthereumProcessorOptions } from '@subql/common-ethereum';
|
|
4
4
|
import { NodeConfig, BaseFetchService, ApiService } from '@subql/node-core';
|
|
5
5
|
import { DictionaryQueryEntry } from '@subql/types-core';
|
|
6
|
-
import { SubqlDatasource } from '@subql/types-ethereum';
|
|
6
|
+
import { EthereumBlock, SubqlDatasource } from '@subql/types-ethereum';
|
|
7
7
|
import { SubqueryProject } from '../configure/SubqueryProject';
|
|
8
8
|
import { EthereumApi } from '../ethereum';
|
|
9
9
|
import { IEthereumBlockDispatcher } from './blockDispatcher';
|
|
10
10
|
import { DictionaryService } from './dictionary.service';
|
|
11
11
|
import { DynamicDsService } from './dynamic-ds.service';
|
|
12
|
+
import { EthFatDictionaryService } from './eth-fat-dictionary.service';
|
|
12
13
|
import { ProjectService } from './project.service';
|
|
13
14
|
import { UnfinalizedBlocksService } from './unfinalizedBlocks.service';
|
|
14
15
|
type GroupedEthereumProjectDs = SubqlDatasource & {
|
|
15
16
|
groupedOptions?: SubqlEthereumProcessorOptions[];
|
|
16
17
|
};
|
|
17
18
|
export declare function buildDictionaryQueryEntries(dataSources: GroupedEthereumProjectDs[]): DictionaryQueryEntry[];
|
|
18
|
-
export declare class FetchService extends BaseFetchService<SubqlDatasource, IEthereumBlockDispatcher, DictionaryService> {
|
|
19
|
+
export declare class FetchService extends BaseFetchService<SubqlDatasource, IEthereumBlockDispatcher, DictionaryService, EthereumBlock> {
|
|
19
20
|
private apiService;
|
|
20
21
|
private unfinalizedBlocksService;
|
|
21
|
-
constructor(apiService: ApiService, nodeConfig: NodeConfig, projectService: ProjectService, project: SubqueryProject, blockDispatcher: IEthereumBlockDispatcher, dictionaryService: DictionaryService, dynamicDsService: DynamicDsService, unfinalizedBlocksService: UnfinalizedBlocksService, eventEmitter: EventEmitter2, schedulerRegistry: SchedulerRegistry);
|
|
22
|
+
constructor(apiService: ApiService, nodeConfig: NodeConfig, projectService: ProjectService, project: SubqueryProject, blockDispatcher: IEthereumBlockDispatcher, dictionaryService: DictionaryService, dynamicDsService: DynamicDsService, unfinalizedBlocksService: UnfinalizedBlocksService, eventEmitter: EventEmitter2, schedulerRegistry: SchedulerRegistry, fatDictionaryService: EthFatDictionaryService);
|
|
22
23
|
get api(): EthereumApi;
|
|
23
24
|
protected buildDictionaryQueryEntries(dataSources: (SubqlDatasource & {
|
|
24
25
|
name?: string;
|
|
@@ -27,6 +27,7 @@ const string_1 = require("../utils/string");
|
|
|
27
27
|
const yargs_1 = require("../yargs");
|
|
28
28
|
const dictionary_service_1 = require("./dictionary.service");
|
|
29
29
|
const dynamic_ds_service_1 = require("./dynamic-ds.service");
|
|
30
|
+
const eth_fat_dictionary_service_1 = require("./eth-fat-dictionary.service");
|
|
30
31
|
const project_service_1 = require("./project.service");
|
|
31
32
|
const unfinalizedBlocks_service_1 = require("./unfinalizedBlocks.service");
|
|
32
33
|
const logger = (0, node_core_1.getLogger)('fetch.service');
|
|
@@ -179,8 +180,8 @@ function buildDictionaryQueryEntries(dataSources) {
|
|
|
179
180
|
}
|
|
180
181
|
exports.buildDictionaryQueryEntries = buildDictionaryQueryEntries;
|
|
181
182
|
let FetchService = class FetchService extends node_core_1.BaseFetchService {
|
|
182
|
-
constructor(apiService, nodeConfig, projectService, project, blockDispatcher, dictionaryService, dynamicDsService, unfinalizedBlocksService, eventEmitter, schedulerRegistry) {
|
|
183
|
-
super(nodeConfig, projectService, project.network, blockDispatcher, dictionaryService, dynamicDsService, eventEmitter, schedulerRegistry);
|
|
183
|
+
constructor(apiService, nodeConfig, projectService, project, blockDispatcher, dictionaryService, dynamicDsService, unfinalizedBlocksService, eventEmitter, schedulerRegistry, fatDictionaryService) {
|
|
184
|
+
super(nodeConfig, projectService, project.network, blockDispatcher, dictionaryService, dynamicDsService, eventEmitter, schedulerRegistry, fatDictionaryService);
|
|
184
185
|
this.apiService = apiService;
|
|
185
186
|
this.unfinalizedBlocksService = unfinalizedBlocksService;
|
|
186
187
|
}
|
|
@@ -243,7 +244,8 @@ FetchService = __decorate([
|
|
|
243
244
|
dynamic_ds_service_1.DynamicDsService,
|
|
244
245
|
unfinalizedBlocks_service_1.UnfinalizedBlocksService,
|
|
245
246
|
event_emitter_1.EventEmitter2,
|
|
246
|
-
schedule_1.SchedulerRegistry
|
|
247
|
+
schedule_1.SchedulerRegistry,
|
|
248
|
+
eth_fat_dictionary_service_1.EthFatDictionaryService])
|
|
247
249
|
], FetchService);
|
|
248
250
|
exports.FetchService = FetchService;
|
|
249
251
|
//# sourceMappingURL=fetch.service.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetch.service.js","sourceRoot":"","sources":["../../src/indexer/fetch.service.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;;;;;;;;;;;;;;AAEnC,2CAAoD;AACpD,yDAAsD;AACtD,+CAAqD;AAErD,4DAMgC;AAChC,gDAM0B;AAM1B,mCAA4D;AAC5D,kEAA+D;AAE/D,+DAA0D;AAC1D,4CAAkE;AAClE,oCAAwC;AAExC,6DAAyD;AACzD,6DAAwD;AACxD,uDAAmD;AACnD,2EAGqC;AAErC,MAAM,MAAM,GAAG,IAAA,qBAAS,EAAC,eAAe,CAAC,CAAC;AAE1C,MAAM,mBAAmB,GAAG,IAAI,CAAC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pB,iCAAe,UAGjC,sCAAiB;QAClB,qCAAgB;QACA,oDAAwB;QAC5C,6BAAa;QACR,4BAAiB;GAhB3B,YAAY,CAyGxB;AAzGY,oCAAY","sourcesContent":["// Copyright 2020-2023 SubQuery Pte Ltd authors & contributors\n// SPDX-License-Identifier: GPL-3.0\n\nimport { Inject, Injectable } from '@nestjs/common';\nimport { EventEmitter2 } from '@nestjs/event-emitter';\nimport { SchedulerRegistry } from '@nestjs/schedule';\n\nimport {\n isCustomDs,\n EthereumHandlerKind,\n EthereumLogFilter,\n SubqlEthereumProcessorOptions,\n EthereumTransactionFilter,\n} from '@subql/common-ethereum';\nimport {\n NodeConfig,\n BaseFetchService,\n ApiService,\n getLogger,\n getModulos,\n} from '@subql/node-core';\nimport {\n DictionaryQueryCondition,\n DictionaryQueryEntry,\n} from '@subql/types-core';\nimport { SubqlDatasource } from '@subql/types-ethereum';\nimport { groupBy, partition, sortBy, uniqBy } from 'lodash';\nimport { SubqueryProject } from '../configure/SubqueryProject';\nimport { EthereumApi } from '../ethereum';\nimport { calcInterval } from '../ethereum/utils.ethereum';\nimport { eventToTopic, functionToSighash } from '../utils/string';\nimport { yargsOptions } from '../yargs';\nimport { IEthereumBlockDispatcher } from './blockDispatcher';\nimport { DictionaryService } from './dictionary.service';\nimport { DynamicDsService } from './dynamic-ds.service';\nimport { ProjectService } from './project.service';\nimport {\n blockToHeader,\n UnfinalizedBlocksService,\n} from './unfinalizedBlocks.service';\n\nconst logger = getLogger('fetch.service');\n\nconst BLOCK_TIME_VARIANCE = 5000;\n\nconst INTERVAL_PERCENT = 0.9;\n\nfunction 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.warn(\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): DictionaryQueryEntry {\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): DictionaryQueryEntry {\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) {\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\ntype GroupedEthereumProjectDs = SubqlDatasource & {\n groupedOptions?: SubqlEthereumProcessorOptions[];\n};\nexport function buildDictionaryQueryEntries(\n dataSources: GroupedEthereumProjectDs[],\n): DictionaryQueryEntry[] {\n const queryEntries: DictionaryQueryEntry[] = [];\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\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\n@Injectable()\nexport class FetchService extends BaseFetchService<\n SubqlDatasource,\n IEthereumBlockDispatcher,\n DictionaryService\n> {\n constructor(\n private apiService: ApiService,\n nodeConfig: NodeConfig,\n @Inject('IProjectService') projectService: ProjectService,\n @Inject('ISubqueryProject') project: SubqueryProject,\n @Inject('IBlockDispatcher')\n blockDispatcher: IEthereumBlockDispatcher,\n dictionaryService: DictionaryService,\n dynamicDsService: DynamicDsService,\n private unfinalizedBlocksService: UnfinalizedBlocksService,\n eventEmitter: EventEmitter2,\n schedulerRegistry: SchedulerRegistry,\n ) {\n super(\n nodeConfig,\n projectService,\n project.network,\n blockDispatcher,\n dictionaryService,\n dynamicDsService,\n eventEmitter,\n schedulerRegistry,\n );\n }\n\n get api(): EthereumApi {\n return this.apiService.unsafeApi;\n }\n\n protected buildDictionaryQueryEntries(\n // Add name to dataousrces as templates have this set\n dataSources: (SubqlDatasource & { name?: string })[],\n ): DictionaryQueryEntry[] {\n const [normalDataSources, templateDataSources] = partition(\n dataSources,\n (ds) => !ds.name,\n );\n\n // Group templ\n const groupedDataSources = Object.values(\n groupBy(templateDataSources, (ds) => ds.name),\n ).map((grouped) => {\n if (grouped.length === 1) {\n return grouped[0];\n }\n\n const options = grouped.map((ds) => ds.options);\n const ref = grouped[0];\n\n return {\n ...ref,\n groupedOptions: options,\n };\n });\n\n const filteredDs = [...normalDataSources, ...groupedDataSources];\n\n return buildDictionaryQueryEntries(filteredDs);\n }\n\n protected getGenesisHash(): string {\n return this.apiService.networkMeta.genesisHash;\n }\n\n protected async getFinalizedHeight(): Promise<number> {\n const block = await this.api.getFinalizedBlock();\n\n const header = blockToHeader(block);\n\n this.unfinalizedBlocksService.registerFinalizedBlock(header);\n return header.blockHeight;\n }\n\n protected async getBestHeight(): Promise<number> {\n return this.api.getBestBlockHeight();\n }\n\n // eslint-disable-next-line @typescript-eslint/require-await\n protected async getChainInterval(): Promise<number> {\n const CHAIN_INTERVAL = calcInterval(this.api) * INTERVAL_PERCENT;\n\n return Math.min(BLOCK_TIME_VARIANCE, CHAIN_INTERVAL);\n }\n\n protected getModulos(): number[] {\n return getModulos(\n this.projectService.getAllDataSources(),\n isCustomDs,\n EthereumHandlerKind.Block,\n );\n }\n\n protected async initBlockDispatcher(): Promise<void> {\n await this.blockDispatcher.init(this.resetForNewDs.bind(this));\n }\n\n protected async preLoopHook(): Promise<void> {\n // Ethereum doesn't need to do anything here\n return Promise.resolve();\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"fetch.service.js","sourceR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IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;IACjE,CAAC;IAES,KAAK,CAAC,WAAW;QACzB,4CAA4C;QAC5C,OAAO,OAAO,CAAC,OAAO,EAAE,CAAC;IAC3B,CAAC;CACF,CAAA;AA5GY,YAAY;IADxB,IAAA,mBAAU,GAAE;IAUR,WAAA,IAAA,eAAM,EAAC,iBAAiB,CAAC,CAAA;IACzB,WAAA,IAAA,eAAM,EAAC,kBAAkB,CAAC,CAAA;IAC1B,WAAA,IAAA,eAAM,EAAC,kBAAkB,CAAC,CAAA;qCAJP,sBAAU;QAClB,sBAAU;QACqB,gCAAc;QACpB,iCAAe,UAGjC,sCAAiB;QAClB,qCAAgB;QACA,oDAAwB;QAC5C,6BAAa;QACR,4BAAiB;QACd,oDAAuB;GAlBpC,YAAY,CA4GxB;AA5GY,oCAAY","sourcesContent":["// Copyright 2020-2023 SubQuery Pte Ltd authors & contributors\n// SPDX-License-Identifier: GPL-3.0\n\nimport { Inject, Injectable } from '@nestjs/common';\nimport { EventEmitter2 } from '@nestjs/event-emitter';\nimport { SchedulerRegistry } from '@nestjs/schedule';\n\nimport {\n isCustomDs,\n EthereumHandlerKind,\n EthereumLogFilter,\n SubqlEthereumProcessorOptions,\n EthereumTransactionFilter,\n} from '@subql/common-ethereum';\nimport {\n NodeConfig,\n BaseFetchService,\n ApiService,\n getLogger,\n getModulos,\n} from '@subql/node-core';\nimport {\n DictionaryQueryCondition,\n DictionaryQueryEntry,\n} from '@subql/types-core';\nimport {EthereumBlock, SubqlDatasource} from '@subql/types-ethereum';\nimport { groupBy, partition, sortBy, uniqBy } from 'lodash';\nimport { SubqueryProject } from '../configure/SubqueryProject';\nimport { EthereumApi } from '../ethereum';\nimport { calcInterval } from '../ethereum/utils.ethereum';\nimport { eventToTopic, functionToSighash } from '../utils/string';\nimport { yargsOptions } from '../yargs';\nimport { IEthereumBlockDispatcher } from './blockDispatcher';\nimport { DictionaryService } from './dictionary.service';\nimport { DynamicDsService } from './dynamic-ds.service';\nimport {EthFatDictionaryService} from './eth-fat-dictionary.service';\nimport { ProjectService } from './project.service';\nimport {\n blockToHeader,\n UnfinalizedBlocksService,\n} from './unfinalizedBlocks.service';\n\nconst logger = getLogger('fetch.service');\n\nconst BLOCK_TIME_VARIANCE = 5000;\n\nconst INTERVAL_PERCENT = 0.9;\n\nfunction 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.warn(\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): DictionaryQueryEntry {\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): DictionaryQueryEntry {\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) {\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\ntype GroupedEthereumProjectDs = SubqlDatasource & {\n groupedOptions?: SubqlEthereumProcessorOptions[];\n};\nexport function buildDictionaryQueryEntries(\n dataSources: GroupedEthereumProjectDs[],\n): DictionaryQueryEntry[] {\n const queryEntries: DictionaryQueryEntry[] = [];\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\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\n@Injectable()\nexport class FetchService extends BaseFetchService<\n SubqlDatasource,\n IEthereumBlockDispatcher,\n DictionaryService,\n EthereumBlock\n> {\n constructor(\n private apiService: ApiService,\n nodeConfig: NodeConfig,\n @Inject('IProjectService') projectService: ProjectService,\n @Inject('ISubqueryProject') project: SubqueryProject,\n @Inject('IBlockDispatcher')\n blockDispatcher: IEthereumBlockDispatcher,\n dictionaryService: DictionaryService,\n dynamicDsService: DynamicDsService,\n private unfinalizedBlocksService: UnfinalizedBlocksService,\n eventEmitter: EventEmitter2,\n schedulerRegistry: SchedulerRegistry,\n fatDictionaryService: EthFatDictionaryService,\n ) {\n super(\n nodeConfig,\n projectService,\n project.network,\n blockDispatcher,\n dictionaryService,\n dynamicDsService,\n eventEmitter,\n schedulerRegistry,\n fatDictionaryService\n );\n }\n\n get api(): EthereumApi {\n return this.apiService.unsafeApi;\n }\n\n protected buildDictionaryQueryEntries(\n // Add name to dataousrces as templates have this set\n dataSources: (SubqlDatasource & { name?: string })[],\n ): DictionaryQueryEntry[] {\n const [normalDataSources, templateDataSources] = partition(\n dataSources,\n (ds) => !ds.name,\n );\n\n // Group templ\n const groupedDataSources = Object.values(\n groupBy(templateDataSources, (ds) => ds.name),\n ).map((grouped) => {\n if (grouped.length === 1) {\n return grouped[0];\n }\n\n const options = grouped.map((ds) => ds.options);\n const ref = grouped[0];\n\n return {\n ...ref,\n groupedOptions: options,\n };\n });\n\n const filteredDs = [...normalDataSources, ...groupedDataSources];\n\n return buildDictionaryQueryEntries(filteredDs);\n }\n\n protected getGenesisHash(): string {\n return this.apiService.networkMeta.genesisHash;\n }\n\n protected async getFinalizedHeight(): Promise<number> {\n const block = await this.api.getFinalizedBlock();\n\n const header = blockToHeader(block);\n\n this.unfinalizedBlocksService.registerFinalizedBlock(header);\n return header.blockHeight;\n }\n\n protected async getBestHeight(): Promise<number> {\n return this.api.getBestBlockHeight();\n }\n\n // eslint-disable-next-line @typescript-eslint/require-await\n protected async getChainInterval(): Promise<number> {\n const CHAIN_INTERVAL = calcInterval(this.api) * INTERVAL_PERCENT;\n\n return Math.min(BLOCK_TIME_VARIANCE, CHAIN_INTERVAL);\n }\n\n protected getModulos(): number[] {\n return getModulos(\n this.projectService.getAllDataSources(),\n isCustomDs,\n EthereumHandlerKind.Block,\n );\n }\n\n protected async initBlockDispatcher(): Promise<void> {\n await this.blockDispatcher.init(this.resetForNewDs.bind(this));\n }\n\n protected async preLoopHook(): Promise<void> {\n // Ethereum doesn't need to do anything here\n return Promise.resolve();\n }\n}\n"]}
|
|
@@ -353,7 +353,7 @@ describe('Dictionary queries', () => {
|
|
|
353
353
|
];
|
|
354
354
|
const dataSources = [ds, ...duplicateDataSources];
|
|
355
355
|
const project = testSubqueryProject(HTTP_ENDPOINT, dataSources, mockTempDs);
|
|
356
|
-
const fetchService = new fetch_service_1.FetchService(null, null, null, project, null, null, null, null, null, null);
|
|
356
|
+
const fetchService = new fetch_service_1.FetchService(null, null, null, project, null, null, null, null, null, null, null);
|
|
357
357
|
const queryEntry = fetchService.buildDictionaryQueryEntries(dataSources);
|
|
358
358
|
expect(queryEntry).toEqual([
|
|
359
359
|
{
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetch.service.spec.js","sourceRoot":"","sources":["../../src/indexer/fetch.service.spec.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;AAEnC,0DAI+B;AAC/B,qCAAwC;AAKxC,mDAA4E;AAE5E,gEAAgE;AAChE,MAAM,aAAa,GAAG,0BAA0B,CAAC;AACjD,MAAM,UAAU,GAAgC;IAC9C;QACE,IAAI,EAAE,QAAQ;QACd,IAAI,EAAE,uCAAsB,CAAC,OAA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MAAM,EAAE,SAAS;oBACjB,UAAU,EAAE;wBACV,0FAA0F;wBAC1F;4BACE,KAAK,EAAE,SAAS;4BAChB,KAAK,EAAE,UAAU;4BACjB,OAAO,EAAE,SAAS;yBACnB;wBACD;4BACE,KAAK,EAAE,SAAS;4BAChB,KAAK,EACH,oEAAoE;4BACtE,OAAO,EAAE,SAAS;yBACnB;qBACF;iBACF;aACF,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["// Copyright 2020-2023 SubQuery Pte Ltd authors & contributors\n// SPDX-License-Identifier: GPL-3.0\n\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 { buildDictionaryQueryEntries, FetchService } from './fetch.service';\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 entryScript: '',\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 entryScript: '',\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];\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('Dictionary queries', () => {\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 = buildDictionaryQueryEntries([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 = buildDictionaryQueryEntries([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 = buildDictionaryQueryEntries([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 = buildDictionaryQueryEntries([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 = buildDictionaryQueryEntries([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 = buildDictionaryQueryEntries([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 = buildDictionaryQueryEntries([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 project = testSubqueryProject(\n HTTP_ENDPOINT,\n dataSources,\n mockTempDs,\n );\n\n const fetchService = new FetchService(\n null,\n null,\n null,\n project,\n null,\n null,\n null,\n null,\n null,\n null,\n );\n\n const queryEntry = (fetchService as any).buildDictionaryQueryEntries(\n dataSources,\n );\n\n expect(queryEntry).toEqual([\n {\n entity: 'evmLogs',\n conditions: [\n {\n field: 'topics0',\n value:\n '0xc3d58168c5ae7397731d063d5bbf3d657854427343f4c083240f7aacaa2d0f62',\n matcher: 'equalTo',\n },\n ],\n },\n {\n entity: 'evmLogs',\n conditions: [\n {\n field: 'address',\n // This is what we're looking to happen with multiple instances of template\n value: ['address1', 'address2'],\n matcher: 'in',\n },\n {\n field: 'topics0',\n value:\n '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef',\n matcher: 'equalTo',\n },\n ],\n },\n {\n entity: 'evmLogs',\n conditions: [\n // This condition should not be grouped because there is a single instance of the tamplate\n {\n field: 'address',\n value: 'address3',\n matcher: 'equalTo',\n },\n {\n field: 'topics0',\n value:\n '0xc3d58168c5ae7397731d063d5bbf3d657854427343f4c083240f7aacaa2d0f62',\n matcher: 'equalTo',\n },\n ],\n },\n ]);\n });\n });\n});\n"]}
|
|
1
|
+
{"version":3,"file":"fetch.service.spec.js","sourceRoot":"","sources":["../../src/indexer/fetch.service.spec.ts"],"names":[],"mappings":";AAAA,8DAA8D;AAC9D,mCAAmC;;AAEnC,0DAI+B;AAC/B,qCAAwC;AAKxC,mDAA4E;AAE5E,gEAAgE;AAChE,MAAM,aAAa,GAAG,0BAA0B,CAAC;AACjD,MAAM,UAAU,GAAgC;IAC9C;QACE,IAAI,EAAE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BACtE,OAAO,EAAE,SAAS;yBACnB;qBACF;iBACF;gBACD;oBACE,MAAM,EAAE,SAAS;oBACjB,UAAU,EAAE;wBACV,0FAA0F;wBAC1F;4BACE,KAAK,EAAE,SAAS;4BAChB,KAAK,EAAE,UAAU;4BACjB,OAAO,EAAE,SAAS;yBACnB;wBACD;4BACE,KAAK,EAAE,SAAS;4BAChB,KAAK,EACH,oEAAoE;4BACtE,OAAO,EAAE,SAAS;yBACnB;qBACF;iBACF;aACF,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["// Copyright 2020-2023 SubQuery Pte Ltd authors & contributors\n// SPDX-License-Identifier: GPL-3.0\n\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 { buildDictionaryQueryEntries, FetchService } from './fetch.service';\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 entryScript: '',\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 entryScript: '',\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];\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('Dictionary queries', () => {\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 = buildDictionaryQueryEntries([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 = buildDictionaryQueryEntries([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 = buildDictionaryQueryEntries([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 = buildDictionaryQueryEntries([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 = buildDictionaryQueryEntries([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 = buildDictionaryQueryEntries([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 = buildDictionaryQueryEntries([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 project = testSubqueryProject(\n HTTP_ENDPOINT,\n dataSources,\n mockTempDs,\n );\n\n const fetchService = new FetchService(\n null,\n null,\n null,\n project,\n null,\n null,\n null,\n null,\n null,\n null,\n null,\n );\n\n const queryEntry = (fetchService as any).buildDictionaryQueryEntries(\n dataSources,\n );\n\n expect(queryEntry).toEqual([\n {\n entity: 'evmLogs',\n conditions: [\n {\n field: 'topics0',\n value:\n '0xc3d58168c5ae7397731d063d5bbf3d657854427343f4c083240f7aacaa2d0f62',\n matcher: 'equalTo',\n },\n ],\n },\n {\n entity: 'evmLogs',\n conditions: [\n {\n field: 'address',\n // This is what we're looking to happen with multiple instances of template\n value: ['address1', 'address2'],\n matcher: 'in',\n },\n {\n field: 'topics0',\n value:\n '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef',\n matcher: 'equalTo',\n },\n ],\n },\n {\n entity: 'evmLogs',\n conditions: [\n // This condition should not be grouped because there is a single instance of the tamplate\n {\n field: 'address',\n value: 'address3',\n matcher: 'equalTo',\n },\n {\n field: 'topics0',\n value:\n '0xc3d58168c5ae7397731d063d5bbf3d657854427343f4c083240f7aacaa2d0f62',\n matcher: 'equalTo',\n },\n ],\n },\n ]);\n });\n });\n});\n"]}
|