@sentio/sdk 1.36.3-rc.1 → 1.36.4-rc.1
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/LICENSE +55 -0
- package/lib/aptos/aptos-plugin.d.ts +14 -0
- package/lib/aptos/aptos-plugin.js +190 -0
- package/lib/aptos/aptos-plugin.js.map +1 -0
- package/lib/aptos/index.d.ts +1 -0
- package/lib/aptos/index.js +3 -1
- package/lib/aptos/index.js.map +1 -1
- package/lib/core/eth-plugin.d.ts +14 -0
- package/lib/core/eth-plugin.js +221 -0
- package/lib/core/eth-plugin.js.map +1 -0
- package/lib/core/index.d.ts +3 -0
- package/lib/core/index.js +7 -1
- package/lib/core/index.js.map +1 -1
- package/lib/core/solana-plugin.d.ts +9 -0
- package/lib/core/solana-plugin.js +79 -0
- package/lib/core/solana-plugin.js.map +1 -0
- package/lib/core/sui-plugin.d.ts +8 -0
- package/lib/core/sui-plugin.js +46 -0
- package/lib/core/sui-plugin.js.map +1 -0
- package/lib/gen/index.d.ts +2 -1
- package/lib/gen/index.js +2 -1
- package/lib/gen/index.js.map +1 -1
- package/lib/plugin.d.ts +15 -0
- package/lib/plugin.js +32 -0
- package/lib/plugin.js.map +1 -0
- package/lib/processor-runner.js +0 -0
- package/lib/service.d.ts +7 -19
- package/lib/service.js +36 -486
- package/lib/service.js.map +1 -1
- package/package.json +6 -12
- package/src/aptos/aptos-plugin.ts +217 -0
- package/src/aptos/index.ts +2 -0
- package/src/core/eth-plugin.ts +255 -0
- package/src/core/index.ts +4 -0
- package/src/core/solana-plugin.ts +97 -0
- package/src/core/sui-plugin.ts +54 -0
- package/src/gen/index.ts +3 -1
- package/src/plugin.ts +41 -0
- package/src/service.ts +32 -563
- package/src/target-ethers-sentio/tsconfig.json +1 -1
- package/src/types/global.d.ts +15 -0
- package/lib/release.config.js +0 -39
package/lib/service.js
CHANGED
|
@@ -3,45 +3,26 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.ProcessorServiceImpl = void 0;
|
|
6
|
+
exports.errorString = exports.mergeProcessResults = exports.Utf8ArrayToStr = exports.ProcessorServiceImpl = exports.USER_PROCESSOR = exports.DEFAULT_MAX_BLOCK = void 0;
|
|
7
7
|
const nice_grpc_1 = require("nice-grpc");
|
|
8
|
-
const chain_1 = require("./utils/chain");
|
|
9
8
|
const gen_1 = require("./gen");
|
|
10
9
|
const long_1 = __importDefault(require("long"));
|
|
11
10
|
const meter_1 = require("./core/meter");
|
|
12
11
|
const exporter_1 = require("./core/exporter");
|
|
13
12
|
const event_tracker_1 = require("./core/event-tracker");
|
|
14
|
-
const aptos_processor_1 = require("./aptos/aptos-processor");
|
|
15
|
-
const account_processor_1 = require("./core/account-processor");
|
|
16
|
-
const sui_processor_1 = require("./core/sui-processor");
|
|
17
|
-
const solana_processor_1 = require("./core/solana-processor");
|
|
18
|
-
const binds_1 = require("./binds");
|
|
19
13
|
const base_processor_template_1 = require("./core/base-processor-template");
|
|
20
|
-
|
|
14
|
+
// (Long.prototype as any).toBigInt = function() {
|
|
15
|
+
// return BigInt(this.toString())
|
|
16
|
+
// };
|
|
17
|
+
const plugin_1 = require("./plugin");
|
|
21
18
|
BigInt.prototype.toJSON = function () {
|
|
22
19
|
return this.toString();
|
|
23
20
|
};
|
|
24
|
-
|
|
25
|
-
|
|
21
|
+
exports.DEFAULT_MAX_BLOCK = long_1.default.ZERO;
|
|
22
|
+
exports.USER_PROCESSOR = 'user_processor';
|
|
26
23
|
class ProcessorServiceImpl {
|
|
27
|
-
// eth handlers
|
|
28
|
-
eventHandlers = [];
|
|
29
|
-
traceHandlers = [];
|
|
30
|
-
blockHandlers = [];
|
|
31
|
-
// aptos handlers
|
|
32
|
-
aptosEventHandlers = [];
|
|
33
|
-
aptosCallHandlers = [];
|
|
34
|
-
aptosResourceHandlers = [];
|
|
35
|
-
// map from chain id to list of processors
|
|
36
|
-
// private blockHandlers = new Map<string, ((block: Block) => Promise<ProcessResult>)[]>()
|
|
37
|
-
// private processorsByChainId = new Map<string, BaseProcessor<BaseContract, BoundContractView<BaseContract, any>>>()
|
|
38
24
|
started = false;
|
|
39
|
-
|
|
40
|
-
accountConfigs;
|
|
41
|
-
templateInstances;
|
|
42
|
-
metricConfigs;
|
|
43
|
-
eventTrackingConfigs;
|
|
44
|
-
exportConfigs;
|
|
25
|
+
processorConfig;
|
|
45
26
|
loader;
|
|
46
27
|
shutdownHandler;
|
|
47
28
|
constructor(loader, shutdownHandler) {
|
|
@@ -52,36 +33,23 @@ class ProcessorServiceImpl {
|
|
|
52
33
|
if (!this.started) {
|
|
53
34
|
throw new nice_grpc_1.ServerError(nice_grpc_1.Status.UNAVAILABLE, 'Service Not started.');
|
|
54
35
|
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
accountConfigs: this.accountConfigs,
|
|
60
|
-
templateInstances: this.templateInstances,
|
|
61
|
-
eventTrackingConfigs: this.eventTrackingConfigs,
|
|
62
|
-
metricConfigs: this.metricConfigs,
|
|
63
|
-
exportConfigs: this.exportConfigs,
|
|
64
|
-
};
|
|
36
|
+
if (!this.processorConfig) {
|
|
37
|
+
throw new nice_grpc_1.ServerError(nice_grpc_1.Status.INTERNAL, 'Process config empty.');
|
|
38
|
+
}
|
|
39
|
+
return this.processorConfig;
|
|
65
40
|
}
|
|
66
41
|
async configure() {
|
|
67
|
-
this.
|
|
68
|
-
this.templateInstances = [];
|
|
69
|
-
// this.processorsByChainId.clear()
|
|
70
|
-
this.contractConfigs = [];
|
|
71
|
-
this.accountConfigs = [];
|
|
42
|
+
this.processorConfig = gen_1.ProcessConfigResponse.fromPartial({});
|
|
72
43
|
// This syntax is to copy values instead of using references
|
|
73
|
-
this.templateInstances = [...base_processor_template_1.TemplateInstanceState.INSTANCE.getValues()];
|
|
74
|
-
this.eventTrackingConfigs = [];
|
|
75
|
-
this.metricConfigs = [];
|
|
76
|
-
this.exportConfigs = [];
|
|
44
|
+
this.processorConfig.templateInstances = [...base_processor_template_1.TemplateInstanceState.INSTANCE.getValues()];
|
|
77
45
|
// part 0, prepare metrics and event tracking configs
|
|
78
46
|
for (const metric of meter_1.MetricState.INSTANCE.getValues()) {
|
|
79
|
-
this.metricConfigs.push({
|
|
47
|
+
this.processorConfig.metricConfigs.push({
|
|
80
48
|
...metric.config,
|
|
81
49
|
});
|
|
82
50
|
}
|
|
83
51
|
for (const eventTracker of event_tracker_1.EventTrackerState.INSTANCE.getValues()) {
|
|
84
|
-
this.eventTrackingConfigs.push({
|
|
52
|
+
this.processorConfig.eventTrackingConfigs.push({
|
|
85
53
|
distinctAggregationByDays: eventTracker.options.distinctByDays || [],
|
|
86
54
|
eventName: eventTracker.name,
|
|
87
55
|
retentionConfig: undefined,
|
|
@@ -91,261 +59,30 @@ class ProcessorServiceImpl {
|
|
|
91
59
|
});
|
|
92
60
|
}
|
|
93
61
|
for (const exporter of exporter_1.ExporterState.INSTANCE.getValues()) {
|
|
94
|
-
this.exportConfigs.push({
|
|
62
|
+
this.processorConfig.exportConfigs.push({
|
|
95
63
|
name: exporter.name,
|
|
96
64
|
channel: exporter.channel,
|
|
97
65
|
});
|
|
98
66
|
}
|
|
99
|
-
|
|
100
|
-
for (const processor of binds_1.ProcessorState.INSTANCE.getValues()) {
|
|
101
|
-
// If server favor incremental update this need to change
|
|
102
|
-
// Start basic config for contract
|
|
103
|
-
const chainId = processor.getChainId();
|
|
104
|
-
// this.processorsByChainId.set(chainId, processor)
|
|
105
|
-
const contractConfig = {
|
|
106
|
-
processorType: USER_PROCESSOR,
|
|
107
|
-
contract: {
|
|
108
|
-
name: processor.config.name,
|
|
109
|
-
chainId: chainId.toString(),
|
|
110
|
-
address: processor.config.address,
|
|
111
|
-
abi: '',
|
|
112
|
-
},
|
|
113
|
-
intervalConfigs: [],
|
|
114
|
-
logConfigs: [],
|
|
115
|
-
traceConfigs: [],
|
|
116
|
-
startBlock: processor.config.startBlock,
|
|
117
|
-
endBlock: DEFAULT_MAX_BLOCK,
|
|
118
|
-
instructionConfig: undefined,
|
|
119
|
-
aptosEventConfigs: [],
|
|
120
|
-
aptosCallConfigs: [],
|
|
121
|
-
};
|
|
122
|
-
if (processor.config.endBlock) {
|
|
123
|
-
contractConfig.endBlock = processor.config.endBlock;
|
|
124
|
-
}
|
|
125
|
-
// Step 1. Prepare all the block handlers
|
|
126
|
-
for (const blockHandler of processor.blockHandlers) {
|
|
127
|
-
const handlerId = this.blockHandlers.push(blockHandler.handler) - 1;
|
|
128
|
-
// TODO wrap the block handler into one
|
|
129
|
-
contractConfig.intervalConfigs.push({
|
|
130
|
-
slot: 0,
|
|
131
|
-
slotInterval: blockHandler.blockInterval,
|
|
132
|
-
minutes: 0,
|
|
133
|
-
minutesInterval: blockHandler.timeIntervalInMinutes,
|
|
134
|
-
handlerId: handlerId,
|
|
135
|
-
});
|
|
136
|
-
}
|
|
137
|
-
// Step 2. Prepare all trace handlers
|
|
138
|
-
for (const traceHandler of processor.traceHandlers) {
|
|
139
|
-
const handlerId = this.traceHandlers.push(traceHandler.handler) - 1;
|
|
140
|
-
contractConfig.traceConfigs.push({
|
|
141
|
-
signature: traceHandler.signature,
|
|
142
|
-
handlerId: handlerId,
|
|
143
|
-
});
|
|
144
|
-
}
|
|
145
|
-
// Step 3. Prepare all the event handlers
|
|
146
|
-
for (const eventsHandler of processor.eventHandlers) {
|
|
147
|
-
// associate id with filter
|
|
148
|
-
const handlerId = this.eventHandlers.push(eventsHandler.handler) - 1;
|
|
149
|
-
const logConfig = {
|
|
150
|
-
handlerId: handlerId,
|
|
151
|
-
filters: [],
|
|
152
|
-
};
|
|
153
|
-
for (const filter of eventsHandler.filters) {
|
|
154
|
-
if (!filter.topics) {
|
|
155
|
-
throw new nice_grpc_1.ServerError(nice_grpc_1.Status.INVALID_ARGUMENT, 'Topic should not be null');
|
|
156
|
-
}
|
|
157
|
-
const logFilter = {
|
|
158
|
-
addressType: undefined,
|
|
159
|
-
address: contractConfig.contract?.address,
|
|
160
|
-
topics: [],
|
|
161
|
-
};
|
|
162
|
-
for (const ts of filter.topics) {
|
|
163
|
-
let hashes = [];
|
|
164
|
-
if (Array.isArray(ts)) {
|
|
165
|
-
hashes = hashes.concat(ts);
|
|
166
|
-
}
|
|
167
|
-
else if (ts) {
|
|
168
|
-
hashes.push(ts);
|
|
169
|
-
}
|
|
170
|
-
logFilter.topics.push({ hashes: hashes });
|
|
171
|
-
}
|
|
172
|
-
logConfig.filters.push(logFilter);
|
|
173
|
-
}
|
|
174
|
-
contractConfig.logConfigs.push(logConfig);
|
|
175
|
-
}
|
|
176
|
-
// Finish up a contract
|
|
177
|
-
this.contractConfigs.push(contractConfig);
|
|
178
|
-
}
|
|
179
|
-
// part 1.b prepare EVM account processors
|
|
180
|
-
for (const processor of account_processor_1.AccountProcessorState.INSTANCE.getValues()) {
|
|
181
|
-
const accountConfig = {
|
|
182
|
-
address: processor.config.address,
|
|
183
|
-
chainId: processor.getChainId().toString(),
|
|
184
|
-
startBlock: processor.config.startBlock ? long_1.default.fromValue(processor.config.startBlock) : long_1.default.ZERO,
|
|
185
|
-
aptosIntervalConfigs: [],
|
|
186
|
-
intervalConfigs: [],
|
|
187
|
-
logConfigs: [],
|
|
188
|
-
};
|
|
189
|
-
// TODO add interval
|
|
190
|
-
for (const eventsHandler of processor.eventHandlers) {
|
|
191
|
-
// associate id with filter
|
|
192
|
-
const handlerId = this.eventHandlers.push(eventsHandler.handler) - 1;
|
|
193
|
-
const logConfig = {
|
|
194
|
-
handlerId: handlerId,
|
|
195
|
-
filters: [],
|
|
196
|
-
};
|
|
197
|
-
for (const filter of eventsHandler.filters) {
|
|
198
|
-
if (!filter.topics) {
|
|
199
|
-
throw new nice_grpc_1.ServerError(nice_grpc_1.Status.INVALID_ARGUMENT, 'Topic should not be null');
|
|
200
|
-
}
|
|
201
|
-
const logFilter = {
|
|
202
|
-
addressType: filter.addressType,
|
|
203
|
-
address: filter.address,
|
|
204
|
-
topics: [],
|
|
205
|
-
};
|
|
206
|
-
for (const ts of filter.topics) {
|
|
207
|
-
let hashes = [];
|
|
208
|
-
if (Array.isArray(ts)) {
|
|
209
|
-
hashes = hashes.concat(ts);
|
|
210
|
-
}
|
|
211
|
-
else if (ts) {
|
|
212
|
-
hashes.push(ts);
|
|
213
|
-
}
|
|
214
|
-
logFilter.topics.push({ hashes: hashes });
|
|
215
|
-
}
|
|
216
|
-
logConfig.filters.push(logFilter);
|
|
217
|
-
}
|
|
218
|
-
accountConfig.logConfigs.push(logConfig);
|
|
219
|
-
}
|
|
220
|
-
this.accountConfigs.push(accountConfig);
|
|
221
|
-
}
|
|
222
|
-
// Part 2, prepare solana constractors
|
|
223
|
-
for (const solanaProcessor of solana_processor_1.SolanaProcessorState.INSTANCE.getValues()) {
|
|
224
|
-
const contractConfig = {
|
|
225
|
-
processorType: USER_PROCESSOR,
|
|
226
|
-
contract: {
|
|
227
|
-
name: solanaProcessor.contractName,
|
|
228
|
-
chainId: solanaProcessor.network,
|
|
229
|
-
address: solanaProcessor.address,
|
|
230
|
-
abi: '',
|
|
231
|
-
},
|
|
232
|
-
logConfigs: [],
|
|
233
|
-
traceConfigs: [],
|
|
234
|
-
intervalConfigs: [],
|
|
235
|
-
startBlock: solanaProcessor.config.startSlot,
|
|
236
|
-
endBlock: DEFAULT_MAX_BLOCK,
|
|
237
|
-
instructionConfig: {
|
|
238
|
-
innerInstruction: solanaProcessor.processInnerInstruction,
|
|
239
|
-
parsedInstruction: solanaProcessor.fromParsedInstruction !== null,
|
|
240
|
-
rawDataInstruction: solanaProcessor.decodeInstruction !== null,
|
|
241
|
-
},
|
|
242
|
-
aptosEventConfigs: [],
|
|
243
|
-
aptosCallConfigs: [],
|
|
244
|
-
};
|
|
245
|
-
this.contractConfigs.push(contractConfig);
|
|
246
|
-
}
|
|
247
|
-
// Part 3, prepare sui constractors
|
|
248
|
-
for (const suiProcessor of sui_processor_1.SuiProcessorState.INSTANCE.getValues()) {
|
|
249
|
-
const contractConfig = {
|
|
250
|
-
processorType: USER_PROCESSOR,
|
|
251
|
-
contract: {
|
|
252
|
-
name: 'sui contract',
|
|
253
|
-
chainId: chain_1.CHAIN_IDS.SUI_DEVNET,
|
|
254
|
-
address: suiProcessor.address,
|
|
255
|
-
abi: '',
|
|
256
|
-
},
|
|
257
|
-
logConfigs: [],
|
|
258
|
-
intervalConfigs: [],
|
|
259
|
-
traceConfigs: [],
|
|
260
|
-
startBlock: suiProcessor.config.startSeqNumber,
|
|
261
|
-
endBlock: DEFAULT_MAX_BLOCK,
|
|
262
|
-
instructionConfig: undefined,
|
|
263
|
-
aptosEventConfigs: [],
|
|
264
|
-
aptosCallConfigs: [],
|
|
265
|
-
};
|
|
266
|
-
this.contractConfigs.push(contractConfig);
|
|
267
|
-
}
|
|
268
|
-
// Part 4, prepare aptos constractors
|
|
269
|
-
for (const aptosProcessor of aptos_processor_1.AptosProcessorState.INSTANCE.getValues()) {
|
|
270
|
-
const contractConfig = {
|
|
271
|
-
processorType: USER_PROCESSOR,
|
|
272
|
-
contract: {
|
|
273
|
-
name: aptosProcessor.moduleName,
|
|
274
|
-
chainId: aptosProcessor.getChainId(),
|
|
275
|
-
address: aptosProcessor.config.address,
|
|
276
|
-
abi: '',
|
|
277
|
-
},
|
|
278
|
-
intervalConfigs: [],
|
|
279
|
-
logConfigs: [],
|
|
280
|
-
traceConfigs: [],
|
|
281
|
-
startBlock: long_1.default.fromString(aptosProcessor.config.startVersion.toString()),
|
|
282
|
-
endBlock: DEFAULT_MAX_BLOCK,
|
|
283
|
-
instructionConfig: undefined,
|
|
284
|
-
aptosEventConfigs: [],
|
|
285
|
-
aptosCallConfigs: [],
|
|
286
|
-
};
|
|
287
|
-
// 1. Prepare event handlers
|
|
288
|
-
for (const handler of aptosProcessor.eventHandlers) {
|
|
289
|
-
const handlerId = this.aptosEventHandlers.push(handler.handler) - 1;
|
|
290
|
-
const eventHandlerConfig = {
|
|
291
|
-
filters: handler.filters.map((f) => {
|
|
292
|
-
return {
|
|
293
|
-
type: f.type,
|
|
294
|
-
account: f.account || '',
|
|
295
|
-
};
|
|
296
|
-
}),
|
|
297
|
-
handlerId,
|
|
298
|
-
};
|
|
299
|
-
contractConfig.aptosEventConfigs.push(eventHandlerConfig);
|
|
300
|
-
}
|
|
301
|
-
// 2. Prepare function handlers
|
|
302
|
-
for (const handler of aptosProcessor.callHandlers) {
|
|
303
|
-
const handlerId = this.aptosCallHandlers.push(handler.handler) - 1;
|
|
304
|
-
const functionHandlerConfig = {
|
|
305
|
-
filters: handler.filters.map((filter) => {
|
|
306
|
-
return {
|
|
307
|
-
function: filter.function,
|
|
308
|
-
typeArguments: filter.typeArguments || [],
|
|
309
|
-
withTypeArguments: filter.typeArguments ? true : false,
|
|
310
|
-
includeFailed: filter.includeFailed || false,
|
|
311
|
-
};
|
|
312
|
-
}),
|
|
313
|
-
handlerId,
|
|
314
|
-
};
|
|
315
|
-
contractConfig.aptosCallConfigs.push(functionHandlerConfig);
|
|
316
|
-
}
|
|
317
|
-
this.contractConfigs.push(contractConfig);
|
|
318
|
-
}
|
|
319
|
-
for (const aptosProcessor of aptos_processor_1.AptosAccountProcessorState.INSTANCE.getValues()) {
|
|
320
|
-
const accountConfig = {
|
|
321
|
-
address: aptosProcessor.config.address,
|
|
322
|
-
chainId: aptosProcessor.getChainId(),
|
|
323
|
-
startBlock: long_1.default.fromValue(aptosProcessor.config.startVersion.toString()),
|
|
324
|
-
aptosIntervalConfigs: [],
|
|
325
|
-
intervalConfigs: [],
|
|
326
|
-
logConfigs: [],
|
|
327
|
-
};
|
|
328
|
-
for (const handler of aptosProcessor.resourcesHandlers) {
|
|
329
|
-
const handlerId = this.aptosResourceHandlers.push(handler.handler) - 1;
|
|
330
|
-
accountConfig.aptosIntervalConfigs.push({
|
|
331
|
-
intervalConfig: {
|
|
332
|
-
handlerId: handlerId,
|
|
333
|
-
minutes: 0,
|
|
334
|
-
minutesInterval: handler.timeIntervalInMinutes,
|
|
335
|
-
slot: 0,
|
|
336
|
-
slotInterval: handler.versionInterval,
|
|
337
|
-
},
|
|
338
|
-
type: handler.type || '',
|
|
339
|
-
});
|
|
340
|
-
}
|
|
341
|
-
this.accountConfigs.push(accountConfig);
|
|
342
|
-
}
|
|
67
|
+
plugin_1.PluginManager.INSTANCE.configure(this.processorConfig);
|
|
343
68
|
}
|
|
344
69
|
async start(request, context) {
|
|
345
70
|
if (this.started) {
|
|
346
71
|
return {};
|
|
347
72
|
}
|
|
348
73
|
try {
|
|
74
|
+
try {
|
|
75
|
+
require('./core/eth-plugin');
|
|
76
|
+
require('./core/sui-plugin');
|
|
77
|
+
require('./aptos/aptos-plugin');
|
|
78
|
+
require('./core/solana-plugin');
|
|
79
|
+
}
|
|
80
|
+
catch (e) {
|
|
81
|
+
require('@sentio/sdk/lib/core/eth-plugin');
|
|
82
|
+
require('@sentio/sdk/lib/core/sui-plugin');
|
|
83
|
+
require('@sentio/sdk/lib/aptos/aptos-plugin');
|
|
84
|
+
require('@sentio/sdk/lib/core/solana-plugin');
|
|
85
|
+
}
|
|
349
86
|
this.loader();
|
|
350
87
|
}
|
|
351
88
|
catch (e) {
|
|
@@ -391,7 +128,7 @@ class ProcessorServiceImpl {
|
|
|
391
128
|
const result = mergeProcessResults(await Promise.all(promises));
|
|
392
129
|
let updated = false;
|
|
393
130
|
const t = base_processor_template_1.TemplateInstanceState.INSTANCE.getValues();
|
|
394
|
-
if (base_processor_template_1.TemplateInstanceState.INSTANCE.getValues().length !== this.templateInstances.length) {
|
|
131
|
+
if (base_processor_template_1.TemplateInstanceState.INSTANCE.getValues().length !== this.processorConfig.templateInstances.length) {
|
|
395
132
|
await this.configure();
|
|
396
133
|
updated = true;
|
|
397
134
|
}
|
|
@@ -401,30 +138,7 @@ class ProcessorServiceImpl {
|
|
|
401
138
|
};
|
|
402
139
|
}
|
|
403
140
|
async processBinding(request, options) {
|
|
404
|
-
const
|
|
405
|
-
switch (request.handlerType) {
|
|
406
|
-
case gen_1.HandlerType.APT_CALL:
|
|
407
|
-
return this.processAptosFunctionCall(request);
|
|
408
|
-
case gen_1.HandlerType.APT_EVENT:
|
|
409
|
-
return this.processAptosEvent(request);
|
|
410
|
-
case gen_1.HandlerType.APT_RESOURCE:
|
|
411
|
-
return this.processAptosResource(request);
|
|
412
|
-
case gen_1.HandlerType.ETH_LOG:
|
|
413
|
-
return this.processLog(request);
|
|
414
|
-
case gen_1.HandlerType.ETH_TRACE:
|
|
415
|
-
return this.processTrace(request);
|
|
416
|
-
case gen_1.HandlerType.ETH_BLOCK:
|
|
417
|
-
return this.processBlock(request);
|
|
418
|
-
case gen_1.HandlerType.SOL_INSTRUCTION:
|
|
419
|
-
return this.processSolInstruction(request);
|
|
420
|
-
// TODO migrate SUI cases
|
|
421
|
-
// case HandlerType.INSTRUCTION:
|
|
422
|
-
// return this.processInstruction(request)
|
|
423
|
-
default:
|
|
424
|
-
throw new nice_grpc_1.ServerError(nice_grpc_1.Status.INVALID_ARGUMENT, 'No handle type registered ' + request.handlerType);
|
|
425
|
-
}
|
|
426
|
-
};
|
|
427
|
-
const result = await processBindingInternal(request);
|
|
141
|
+
const result = await plugin_1.PluginManager.INSTANCE.processBinding(request);
|
|
428
142
|
recordRuntimeInfo(result, request.handlerType);
|
|
429
143
|
return result;
|
|
430
144
|
}
|
|
@@ -432,7 +146,7 @@ class ProcessorServiceImpl {
|
|
|
432
146
|
for await (const request of requests) {
|
|
433
147
|
const result = await this.processBinding(request);
|
|
434
148
|
let updated = false;
|
|
435
|
-
if (base_processor_template_1.TemplateInstanceState.INSTANCE.getValues().length !== this.templateInstances.length) {
|
|
149
|
+
if (base_processor_template_1.TemplateInstanceState.INSTANCE.getValues().length !== this.processorConfig.templateInstances.length) {
|
|
436
150
|
await this.configure();
|
|
437
151
|
updated = true;
|
|
438
152
|
}
|
|
@@ -442,173 +156,6 @@ class ProcessorServiceImpl {
|
|
|
442
156
|
};
|
|
443
157
|
}
|
|
444
158
|
}
|
|
445
|
-
async processLog(request) {
|
|
446
|
-
if (!request.data) {
|
|
447
|
-
throw new nice_grpc_1.ServerError(nice_grpc_1.Status.INVALID_ARGUMENT, "Log can't be null");
|
|
448
|
-
}
|
|
449
|
-
const promises = [];
|
|
450
|
-
let log;
|
|
451
|
-
if (request.data.ethLog) {
|
|
452
|
-
log = request.data.ethLog.log;
|
|
453
|
-
}
|
|
454
|
-
else {
|
|
455
|
-
const jsonString = Utf8ArrayToStr(request.data.raw);
|
|
456
|
-
log = JSON.parse(jsonString);
|
|
457
|
-
}
|
|
458
|
-
for (const handlerId of request.handlerIds) {
|
|
459
|
-
const handler = this.eventHandlers[handlerId];
|
|
460
|
-
promises.push(handler(log).catch((e) => {
|
|
461
|
-
throw new nice_grpc_1.ServerError(nice_grpc_1.Status.INTERNAL, 'error processing log: ' + JSON.stringify(log) + '\n' + errorString(e));
|
|
462
|
-
}));
|
|
463
|
-
}
|
|
464
|
-
return mergeProcessResults(await Promise.all(promises));
|
|
465
|
-
}
|
|
466
|
-
async processSolInstruction(request) {
|
|
467
|
-
if (!request.data) {
|
|
468
|
-
throw new nice_grpc_1.ServerError(nice_grpc_1.Status.INVALID_ARGUMENT, 'instruction data cannot be empty');
|
|
469
|
-
}
|
|
470
|
-
const instruction = request.data.solInstruction || gen_1.Data_SolInstruction.decode(request.data.raw); // JSON.parse(jsonString)
|
|
471
|
-
const promises = [];
|
|
472
|
-
// Only have instruction handlers for solana processors
|
|
473
|
-
for (const processor of solana_processor_1.SolanaProcessorState.INSTANCE.getValues()) {
|
|
474
|
-
if (processor.address === instruction.programAccountId) {
|
|
475
|
-
let parsedInstruction = null;
|
|
476
|
-
if (instruction.parsed) {
|
|
477
|
-
parsedInstruction = processor.getParsedInstruction(instruction.parsed);
|
|
478
|
-
}
|
|
479
|
-
else if (instruction.instructionData) {
|
|
480
|
-
parsedInstruction = processor.getParsedInstruction(instruction.instructionData);
|
|
481
|
-
}
|
|
482
|
-
if (parsedInstruction == null) {
|
|
483
|
-
continue;
|
|
484
|
-
}
|
|
485
|
-
const insHandler = processor.getInstructionHandler(parsedInstruction);
|
|
486
|
-
if (insHandler == null) {
|
|
487
|
-
continue;
|
|
488
|
-
}
|
|
489
|
-
const res = await processor.handleInstruction(parsedInstruction, instruction.accounts, insHandler, instruction.slot);
|
|
490
|
-
promises.push(Promise.resolve(res));
|
|
491
|
-
}
|
|
492
|
-
}
|
|
493
|
-
return mergeProcessResults(await Promise.all(promises));
|
|
494
|
-
}
|
|
495
|
-
async processBlock(binding) {
|
|
496
|
-
if (!binding.data) {
|
|
497
|
-
throw new nice_grpc_1.ServerError(nice_grpc_1.Status.INVALID_ARGUMENT, "Block can't be empty");
|
|
498
|
-
}
|
|
499
|
-
let block;
|
|
500
|
-
if (binding.data.ethBlock?.block) {
|
|
501
|
-
block = binding.data.ethBlock.block;
|
|
502
|
-
}
|
|
503
|
-
else {
|
|
504
|
-
const jsonString = Utf8ArrayToStr(binding.data.raw);
|
|
505
|
-
block = JSON.parse(jsonString);
|
|
506
|
-
}
|
|
507
|
-
const promises = [];
|
|
508
|
-
for (const handlerId of binding.handlerIds) {
|
|
509
|
-
promises.push(this.blockHandlers[handlerId](block).catch((e) => {
|
|
510
|
-
throw new nice_grpc_1.ServerError(nice_grpc_1.Status.INTERNAL, 'error processing block: ' + block.number + '\n' + errorString(e));
|
|
511
|
-
}));
|
|
512
|
-
}
|
|
513
|
-
return mergeProcessResults(await Promise.all(promises));
|
|
514
|
-
}
|
|
515
|
-
async processTrace(binding) {
|
|
516
|
-
if (!binding.data) {
|
|
517
|
-
throw new nice_grpc_1.ServerError(nice_grpc_1.Status.INVALID_ARGUMENT, "Trace can't be empty");
|
|
518
|
-
}
|
|
519
|
-
let trace;
|
|
520
|
-
if (binding.data.ethTrace?.trace) {
|
|
521
|
-
trace = binding.data.ethTrace.trace;
|
|
522
|
-
}
|
|
523
|
-
else {
|
|
524
|
-
const jsonString = Utf8ArrayToStr(binding.data.raw);
|
|
525
|
-
trace = JSON.parse(jsonString);
|
|
526
|
-
}
|
|
527
|
-
const promises = [];
|
|
528
|
-
for (const handlerId of binding.handlerIds) {
|
|
529
|
-
promises.push(this.traceHandlers[handlerId](trace).catch((e) => {
|
|
530
|
-
throw new nice_grpc_1.ServerError(nice_grpc_1.Status.INTERNAL, 'error processing trace: ' + JSON.stringify(trace) + '\n' + errorString(e));
|
|
531
|
-
}));
|
|
532
|
-
}
|
|
533
|
-
return mergeProcessResults(await Promise.all(promises));
|
|
534
|
-
}
|
|
535
|
-
async processAptosEvent(binding) {
|
|
536
|
-
if (!binding.data) {
|
|
537
|
-
throw new nice_grpc_1.ServerError(nice_grpc_1.Status.INVALID_ARGUMENT, "Event can't be empty");
|
|
538
|
-
}
|
|
539
|
-
const promises = [];
|
|
540
|
-
let event;
|
|
541
|
-
if (binding.data.aptEvent?.event) {
|
|
542
|
-
event = binding.data.aptEvent?.event;
|
|
543
|
-
}
|
|
544
|
-
else {
|
|
545
|
-
const jsonString = Utf8ArrayToStr(binding.data.raw);
|
|
546
|
-
event = JSON.parse(jsonString);
|
|
547
|
-
}
|
|
548
|
-
for (const handlerId of binding.handlerIds) {
|
|
549
|
-
// only support aptos event for now
|
|
550
|
-
promises.push(this.aptosEventHandlers[handlerId](event).catch((e) => {
|
|
551
|
-
throw new nice_grpc_1.ServerError(nice_grpc_1.Status.INTERNAL, 'error processing event: ' + JSON.stringify(event) + '\n' + errorString(e));
|
|
552
|
-
}));
|
|
553
|
-
}
|
|
554
|
-
return mergeProcessResults(await Promise.all(promises));
|
|
555
|
-
}
|
|
556
|
-
async processAptosResource(binding) {
|
|
557
|
-
if (!binding.data) {
|
|
558
|
-
throw new nice_grpc_1.ServerError(nice_grpc_1.Status.INVALID_ARGUMENT, "Event can't be empty");
|
|
559
|
-
}
|
|
560
|
-
const resource = {
|
|
561
|
-
resources: [],
|
|
562
|
-
version: 0n,
|
|
563
|
-
timestamp: 0,
|
|
564
|
-
};
|
|
565
|
-
if (binding.data.aptResource?.resources) {
|
|
566
|
-
if (binding.data.aptResource.timestampMicros.greaterThan(Number.MAX_SAFE_INTEGER)) {
|
|
567
|
-
throw new nice_grpc_1.ServerError(nice_grpc_1.Status.INVALID_ARGUMENT, 'timestamp is too large');
|
|
568
|
-
}
|
|
569
|
-
resource.timestamp = binding.data.aptResource.timestampMicros.toNumber();
|
|
570
|
-
resource.version = (0, numberish_1.toBigInt)(binding.data.aptResource.version);
|
|
571
|
-
resource.resources = binding.data.aptResource.resources;
|
|
572
|
-
}
|
|
573
|
-
else {
|
|
574
|
-
const jsonString = Utf8ArrayToStr(binding.data.raw);
|
|
575
|
-
const json = JSON.parse(jsonString);
|
|
576
|
-
if (long_1.default.fromString(json.timestamp).greaterThan(Number.MAX_SAFE_INTEGER)) {
|
|
577
|
-
throw new nice_grpc_1.ServerError(nice_grpc_1.Status.INVALID_ARGUMENT, 'timestamp is too large');
|
|
578
|
-
}
|
|
579
|
-
resource.timestamp = parseInt(json.timestamp);
|
|
580
|
-
resource.version = (0, numberish_1.toBigInt)(json.version);
|
|
581
|
-
}
|
|
582
|
-
const promises = [];
|
|
583
|
-
for (const handlerId of binding.handlerIds) {
|
|
584
|
-
promises.push(this.aptosResourceHandlers[handlerId](resource).catch((e) => {
|
|
585
|
-
throw new nice_grpc_1.ServerError(nice_grpc_1.Status.INTERNAL, 'error processing event: ' + JSON.stringify(resource) + '\n' + errorString(e));
|
|
586
|
-
}));
|
|
587
|
-
}
|
|
588
|
-
return mergeProcessResults(await Promise.all(promises));
|
|
589
|
-
}
|
|
590
|
-
async processAptosFunctionCall(binding) {
|
|
591
|
-
if (!binding.data) {
|
|
592
|
-
throw new nice_grpc_1.ServerError(nice_grpc_1.Status.INVALID_ARGUMENT, "Event can't be empty");
|
|
593
|
-
}
|
|
594
|
-
let call;
|
|
595
|
-
if (binding.data.aptCall?.call) {
|
|
596
|
-
call = binding.data.aptCall?.call;
|
|
597
|
-
}
|
|
598
|
-
else {
|
|
599
|
-
const jsonString = Utf8ArrayToStr(binding.data.raw);
|
|
600
|
-
call = JSON.parse(jsonString);
|
|
601
|
-
}
|
|
602
|
-
const promises = [];
|
|
603
|
-
for (const handlerId of binding.handlerIds) {
|
|
604
|
-
// only support aptos call for now
|
|
605
|
-
const promise = this.aptosCallHandlers[handlerId](call).catch((e) => {
|
|
606
|
-
throw new nice_grpc_1.ServerError(nice_grpc_1.Status.INTERNAL, 'error processing call: ' + JSON.stringify(call) + '\n' + errorString(e));
|
|
607
|
-
});
|
|
608
|
-
promises.push(promise);
|
|
609
|
-
}
|
|
610
|
-
return mergeProcessResults(await Promise.all(promises));
|
|
611
|
-
}
|
|
612
159
|
}
|
|
613
160
|
exports.ProcessorServiceImpl = ProcessorServiceImpl;
|
|
614
161
|
// https://ourcodeworld.com/articles/read/164/how-to-convert-an-uint8array-to-string-in-javascript
|
|
@@ -649,6 +196,7 @@ function Utf8ArrayToStr(array) {
|
|
|
649
196
|
}
|
|
650
197
|
return out;
|
|
651
198
|
}
|
|
199
|
+
exports.Utf8ArrayToStr = Utf8ArrayToStr;
|
|
652
200
|
function mergeProcessResults(results) {
|
|
653
201
|
const res = gen_1.ProcessResult.fromPartial({});
|
|
654
202
|
for (const r of results) {
|
|
@@ -660,6 +208,7 @@ function mergeProcessResults(results) {
|
|
|
660
208
|
}
|
|
661
209
|
return res;
|
|
662
210
|
}
|
|
211
|
+
exports.mergeProcessResults = mergeProcessResults;
|
|
663
212
|
function recordRuntimeInfo(results, handlerType) {
|
|
664
213
|
for (const list of [results.gauges, results.counters, results.logs, results.events, results.exports]) {
|
|
665
214
|
list.forEach((e) => {
|
|
@@ -672,4 +221,5 @@ function recordRuntimeInfo(results, handlerType) {
|
|
|
672
221
|
function errorString(e) {
|
|
673
222
|
return e.stack || e.message;
|
|
674
223
|
}
|
|
224
|
+
exports.errorString = errorString;
|
|
675
225
|
//# sourceMappingURL=service.js.map
|