@sentio/sdk 1.37.0-rc.6 → 1.37.0-rc.8
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/lib/binds.d.ts +1 -1
- package/lib/binds.js +2 -2
- package/lib/binds.js.map +1 -1
- package/lib/core/account-processor.d.ts +1 -1
- package/lib/core/account-processor.js +2 -2
- package/lib/core/account-processor.js.map +1 -1
- package/lib/core/base-processor-template.d.ts +1 -1
- package/lib/core/base-processor-template.js +3 -3
- package/lib/core/base-processor-template.js.map +1 -1
- package/lib/core/core-plugin.d.ts +6 -0
- package/lib/core/core-plugin.js +37 -0
- package/lib/core/core-plugin.js.map +1 -0
- package/lib/core/eth-plugin.d.ts +5 -3
- package/lib/core/eth-plugin.js +34 -11
- package/lib/core/eth-plugin.js.map +1 -1
- package/lib/core/event-tracker.d.ts +1 -1
- package/lib/core/event-tracker.js +2 -2
- package/lib/core/event-tracker.js.map +1 -1
- package/lib/core/exporter.d.ts +1 -1
- package/lib/core/exporter.js +2 -2
- package/lib/core/exporter.js.map +1 -1
- package/lib/core/generic-processor.js +2 -2
- package/lib/core/generic-processor.js.map +1 -1
- package/lib/core/index.d.ts +1 -0
- package/lib/core/index.js +3 -1
- package/lib/core/index.js.map +1 -1
- package/lib/core/meter.d.ts +1 -1
- package/lib/core/meter.js +2 -2
- package/lib/core/meter.js.map +1 -1
- package/lib/core/sui-plugin.d.ts +4 -4
- package/lib/core/sui-plugin.js +6 -7
- package/lib/core/sui-plugin.js.map +1 -1
- package/lib/core/sui-processor.d.ts +1 -1
- package/lib/core/sui-processor.js +2 -2
- package/lib/core/sui-processor.js.map +1 -1
- package/lib/index.d.ts +1 -1
- package/lib/index.js +4 -4
- package/lib/index.js.map +1 -1
- package/lib/testing/test-processor-server.d.ts +1 -1
- package/lib/testing/test-processor-server.js +5 -10
- package/lib/testing/test-processor-server.js.map +1 -1
- package/lib/testing/test-provider.js +2 -2
- package/lib/testing/test-provider.js.map +1 -1
- package/lib/utils/dex-price.test.js.map +1 -1
- package/lib/utils/erc20.test.js.map +1 -1
- package/lib/utils/price.js +2 -1
- package/lib/utils/price.js.map +1 -1
- package/package.json +9 -18
- package/src/binds.ts +1 -1
- package/src/core/account-processor.ts +1 -1
- package/src/core/base-processor-template.ts +1 -1
- package/src/core/core-plugin.ts +39 -0
- package/src/core/eth-plugin.ts +30 -3
- package/src/core/event-tracker.ts +1 -1
- package/src/core/exporter.ts +1 -1
- package/src/core/generic-processor.ts +1 -1
- package/src/core/index.ts +1 -0
- package/src/core/meter.ts +1 -1
- package/src/core/sui-plugin.ts +4 -6
- package/src/core/sui-processor.ts +1 -1
- package/src/index.ts +1 -1
- package/src/testing/test-processor-server.ts +2 -8
- package/src/testing/test-provider.ts +1 -2
- package/src/utils/price.ts +2 -1
- package/lib/chain-config.d.ts +0 -6
- package/lib/chain-config.js +0 -3
- package/lib/chain-config.js.map +0 -1
- package/lib/endpoints.d.ts +0 -6
- package/lib/endpoints.js +0 -11
- package/lib/endpoints.js.map +0 -1
- package/lib/loader.d.ts +0 -5
- package/lib/loader.js +0 -30
- package/lib/loader.js.map +0 -1
- package/lib/processor-runner.d.ts +0 -2
- package/lib/processor-runner.js +0 -102
- package/lib/processor-runner.js.map +0 -1
- package/lib/provider.d.ts +0 -6
- package/lib/provider.js +0 -66
- package/lib/provider.js.map +0 -1
- package/lib/service.d.ts +0 -21
- package/lib/service.js +0 -190
- package/lib/service.js.map +0 -1
- package/src/chain-config.ts +0 -6
- package/src/endpoints.ts +0 -9
- package/src/loader.ts +0 -24
- package/src/processor-runner.ts +0 -93
- package/src/provider.ts +0 -74
- package/src/service.ts +0 -197
- package/src/types/global.d.ts +0 -15
package/lib/service.js
DELETED
|
@@ -1,190 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.ProcessorServiceImpl = exports.USER_PROCESSOR = void 0;
|
|
27
|
-
const nice_grpc_1 = require("nice-grpc");
|
|
28
|
-
const protos_1 = require("@sentio/protos");
|
|
29
|
-
const meter_1 = require("./core/meter");
|
|
30
|
-
const exporter_1 = require("./core/exporter");
|
|
31
|
-
const event_tracker_1 = require("./core/event-tracker");
|
|
32
|
-
const base_processor_template_1 = require("./core/base-processor-template");
|
|
33
|
-
// (Long.prototype as any).toBigInt = function() {
|
|
34
|
-
// return BigInt(this.toString())
|
|
35
|
-
// };
|
|
36
|
-
const base_1 = require("@sentio/base");
|
|
37
|
-
const console = __importStar(require("console"));
|
|
38
|
-
BigInt.prototype.toJSON = function () {
|
|
39
|
-
return this.toString();
|
|
40
|
-
};
|
|
41
|
-
exports.USER_PROCESSOR = 'user_processor';
|
|
42
|
-
class ProcessorServiceImpl {
|
|
43
|
-
started = false;
|
|
44
|
-
processorConfig;
|
|
45
|
-
loader;
|
|
46
|
-
shutdownHandler;
|
|
47
|
-
constructor(loader, shutdownHandler) {
|
|
48
|
-
this.loader = loader;
|
|
49
|
-
this.shutdownHandler = shutdownHandler;
|
|
50
|
-
}
|
|
51
|
-
async getConfig(request, context) {
|
|
52
|
-
if (!this.started) {
|
|
53
|
-
throw new nice_grpc_1.ServerError(nice_grpc_1.Status.UNAVAILABLE, 'Service Not started.');
|
|
54
|
-
}
|
|
55
|
-
if (!this.processorConfig) {
|
|
56
|
-
throw new nice_grpc_1.ServerError(nice_grpc_1.Status.INTERNAL, 'Process config empty.');
|
|
57
|
-
}
|
|
58
|
-
return this.processorConfig;
|
|
59
|
-
}
|
|
60
|
-
async configure() {
|
|
61
|
-
this.processorConfig = protos_1.ProcessConfigResponse.fromPartial({});
|
|
62
|
-
// This syntax is to copy values instead of using references
|
|
63
|
-
this.processorConfig.templateInstances = [...base_processor_template_1.TemplateInstanceState.INSTANCE.getValues()];
|
|
64
|
-
// part 0, prepare metrics and event tracking configs
|
|
65
|
-
for (const metric of meter_1.MetricState.INSTANCE.getValues()) {
|
|
66
|
-
this.processorConfig.metricConfigs.push({
|
|
67
|
-
...metric.config,
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
|
-
for (const eventTracker of event_tracker_1.EventTrackerState.INSTANCE.getValues()) {
|
|
71
|
-
this.processorConfig.eventTrackingConfigs.push({
|
|
72
|
-
distinctAggregationByDays: eventTracker.options.distinctByDays || [],
|
|
73
|
-
eventName: eventTracker.name,
|
|
74
|
-
retentionConfig: undefined,
|
|
75
|
-
totalByDay: eventTracker.options.totalByDay || false,
|
|
76
|
-
totalPerEntity: undefined,
|
|
77
|
-
unique: eventTracker.options.unique || false,
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
for (const exporter of exporter_1.ExporterState.INSTANCE.getValues()) {
|
|
81
|
-
this.processorConfig.exportConfigs.push({
|
|
82
|
-
name: exporter.name,
|
|
83
|
-
channel: exporter.channel,
|
|
84
|
-
});
|
|
85
|
-
}
|
|
86
|
-
base_1.PluginManager.INSTANCE.configure(this.processorConfig);
|
|
87
|
-
}
|
|
88
|
-
async start(request, context) {
|
|
89
|
-
if (this.started) {
|
|
90
|
-
return {};
|
|
91
|
-
}
|
|
92
|
-
try {
|
|
93
|
-
for (const plugin of [
|
|
94
|
-
'@sentio/sdk/lib/core/eth-plugin',
|
|
95
|
-
'@sentio/sdk/lib/core/sui-plugin',
|
|
96
|
-
'@sentio/sdk-aptos/lib/aptos-plugin',
|
|
97
|
-
'@sentio/sdk-solana/lib/solana-plugin',
|
|
98
|
-
]) {
|
|
99
|
-
try {
|
|
100
|
-
require(plugin);
|
|
101
|
-
}
|
|
102
|
-
catch (e) {
|
|
103
|
-
console.error('Failed to load plugin: ', plugin);
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
this.loader();
|
|
107
|
-
}
|
|
108
|
-
catch (e) {
|
|
109
|
-
throw new nice_grpc_1.ServerError(nice_grpc_1.Status.INVALID_ARGUMENT, 'Failed to load processor: ' + (0, base_1.errorString)(e));
|
|
110
|
-
}
|
|
111
|
-
for (const instance of request.templateInstances) {
|
|
112
|
-
const template = base_processor_template_1.ProcessorTemplateProcessorState.INSTANCE.getValues()[instance.templateId];
|
|
113
|
-
if (!template) {
|
|
114
|
-
throw new nice_grpc_1.ServerError(nice_grpc_1.Status.INVALID_ARGUMENT, 'Invalid template contract:' + instance);
|
|
115
|
-
}
|
|
116
|
-
if (!instance.contract) {
|
|
117
|
-
throw new nice_grpc_1.ServerError(nice_grpc_1.Status.INVALID_ARGUMENT, 'Contract Empty from:' + instance);
|
|
118
|
-
}
|
|
119
|
-
template.bind({
|
|
120
|
-
name: instance.contract.name,
|
|
121
|
-
address: instance.contract.address,
|
|
122
|
-
network: Number(instance.contract.chainId),
|
|
123
|
-
startBlock: instance.startBlock,
|
|
124
|
-
endBlock: instance.endBlock,
|
|
125
|
-
});
|
|
126
|
-
}
|
|
127
|
-
try {
|
|
128
|
-
await this.configure();
|
|
129
|
-
}
|
|
130
|
-
catch (e) {
|
|
131
|
-
throw new nice_grpc_1.ServerError(nice_grpc_1.Status.INTERNAL, 'Failed to start processor : ' + (0, base_1.errorString)(e));
|
|
132
|
-
}
|
|
133
|
-
this.started = true;
|
|
134
|
-
return {};
|
|
135
|
-
}
|
|
136
|
-
async stop(request, context) {
|
|
137
|
-
console.log('Server Shutting down in 5 seconds');
|
|
138
|
-
if (this.shutdownHandler) {
|
|
139
|
-
setTimeout(this.shutdownHandler, 5000);
|
|
140
|
-
}
|
|
141
|
-
return {};
|
|
142
|
-
}
|
|
143
|
-
async processBindings(request, options) {
|
|
144
|
-
if (!this.started) {
|
|
145
|
-
throw new nice_grpc_1.ServerError(nice_grpc_1.Status.UNAVAILABLE, 'Service Not started.');
|
|
146
|
-
}
|
|
147
|
-
const promises = request.bindings.map((binding) => this.processBinding(binding));
|
|
148
|
-
const result = (0, base_1.mergeProcessResults)(await Promise.all(promises));
|
|
149
|
-
let updated = false;
|
|
150
|
-
const t = base_processor_template_1.TemplateInstanceState.INSTANCE.getValues();
|
|
151
|
-
if (base_processor_template_1.TemplateInstanceState.INSTANCE.getValues().length !== this.processorConfig.templateInstances.length) {
|
|
152
|
-
await this.configure();
|
|
153
|
-
updated = true;
|
|
154
|
-
}
|
|
155
|
-
return {
|
|
156
|
-
result,
|
|
157
|
-
configUpdated: updated,
|
|
158
|
-
};
|
|
159
|
-
}
|
|
160
|
-
async processBinding(request, options) {
|
|
161
|
-
const result = await base_1.PluginManager.INSTANCE.processBinding(request);
|
|
162
|
-
recordRuntimeInfo(result, request.handlerType);
|
|
163
|
-
return result;
|
|
164
|
-
}
|
|
165
|
-
async *processBindingsStream(requests, context) {
|
|
166
|
-
for await (const request of requests) {
|
|
167
|
-
const result = await this.processBinding(request);
|
|
168
|
-
let updated = false;
|
|
169
|
-
if (base_processor_template_1.TemplateInstanceState.INSTANCE.getValues().length !== this.processorConfig.templateInstances.length) {
|
|
170
|
-
await this.configure();
|
|
171
|
-
updated = true;
|
|
172
|
-
}
|
|
173
|
-
yield {
|
|
174
|
-
result,
|
|
175
|
-
configUpdated: updated,
|
|
176
|
-
};
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
exports.ProcessorServiceImpl = ProcessorServiceImpl;
|
|
181
|
-
function recordRuntimeInfo(results, handlerType) {
|
|
182
|
-
for (const list of [results.gauges, results.counters, results.logs, results.events, results.exports]) {
|
|
183
|
-
list.forEach((e) => {
|
|
184
|
-
e.runtimeInfo = {
|
|
185
|
-
from: handlerType,
|
|
186
|
-
};
|
|
187
|
-
});
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
//# sourceMappingURL=service.js.map
|
package/lib/service.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"service.js","sourceRoot":"","sources":["../src/service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,yCAA4D;AAE5D,2CAUuB;AAIvB,wCAA0C;AAC1C,8CAA+C;AAC/C,wDAAwD;AACxD,4EAAuG;AAEvG,kDAAkD;AAClD,mCAAmC;AACnC,KAAK;AACL,uCAA8E;AAC9E,iDACC;AAAC,MAAM,CAAC,SAAiB,CAAC,MAAM,GAAG;IAClC,OAAO,IAAI,CAAC,QAAQ,EAAE,CAAA;AACxB,CAAC,CAAA;AAEY,QAAA,cAAc,GAAG,gBAAgB,CAAA;AAE9C,MAAa,oBAAoB;IACvB,OAAO,GAAG,KAAK,CAAA;IACf,eAAe,CAAuB;IAE7B,MAAM,CAAY;IAElB,eAAe,CAAa;IAE7C,YAAY,MAAkB,EAAE,eAA4B;QAC1D,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;QACpB,IAAI,CAAC,eAAe,GAAG,eAAe,CAAA;IACxC,CAAC;IAED,KAAK,CAAC,SAAS,CAA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AI,CAAC,OAAO,CAAC,MAAM,EAAE,OAAO,CAAC,QAAQ,EAAE,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,MAAM,EAAE,OAAO,CAAC,OAAO,CAAC,EAAE;QACpG,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE;YACjB,CAAC,CAAC,WAAW,GAAG;gBACd,IAAI,EAAE,WAAW;aAClB,CAAA;QACH,CAAC,CAAC,CAAA;KACH;AACH,CAAC","sourcesContent":["import { CallContext, ServerError, Status } from 'nice-grpc'\n\nimport {\n DataBinding,\n HandlerType,\n ProcessBindingResponse,\n ProcessBindingsRequest,\n ProcessConfigRequest,\n ProcessConfigResponse,\n ProcessorServiceImplementation,\n ProcessResult,\n StartRequest,\n} from '@sentio/protos'\n\nimport { Empty } from '@sentio/protos/lib/google/protobuf/empty'\n\nimport { MetricState } from './core/meter'\nimport { ExporterState } from './core/exporter'\nimport { EventTrackerState } from './core/event-tracker'\nimport { ProcessorTemplateProcessorState, TemplateInstanceState } from './core/base-processor-template'\n\n// (Long.prototype as any).toBigInt = function() {\n// return BigInt(this.toString())\n// };\nimport { errorString, mergeProcessResults, PluginManager } from '@sentio/base'\nimport * as console from 'console'\n;(BigInt.prototype as any).toJSON = function () {\n return this.toString()\n}\n\nexport const USER_PROCESSOR = 'user_processor'\n\nexport class ProcessorServiceImpl implements ProcessorServiceImplementation {\n private started = false\n private processorConfig: ProcessConfigResponse\n\n private readonly loader: () => void\n\n private readonly shutdownHandler?: () => void\n\n constructor(loader: () => void, shutdownHandler?: () => void) {\n this.loader = loader\n this.shutdownHandler = shutdownHandler\n }\n\n async getConfig(request: ProcessConfigRequest, context: CallContext): Promise<ProcessConfigResponse> {\n if (!this.started) {\n throw new ServerError(Status.UNAVAILABLE, 'Service Not started.')\n }\n if (!this.processorConfig) {\n throw new ServerError(Status.INTERNAL, 'Process config empty.')\n }\n return this.processorConfig\n }\n\n async configure() {\n this.processorConfig = ProcessConfigResponse.fromPartial({})\n // This syntax is to copy values instead of using references\n this.processorConfig.templateInstances = [...TemplateInstanceState.INSTANCE.getValues()]\n\n // part 0, prepare metrics and event tracking configs\n for (const metric of MetricState.INSTANCE.getValues()) {\n this.processorConfig.metricConfigs.push({\n ...metric.config,\n })\n }\n\n for (const eventTracker of EventTrackerState.INSTANCE.getValues()) {\n this.processorConfig.eventTrackingConfigs.push({\n distinctAggregationByDays: eventTracker.options.distinctByDays || [],\n eventName: eventTracker.name,\n retentionConfig: undefined,\n totalByDay: eventTracker.options.totalByDay || false,\n totalPerEntity: undefined,\n unique: eventTracker.options.unique || false,\n })\n }\n\n for (const exporter of ExporterState.INSTANCE.getValues()) {\n this.processorConfig.exportConfigs.push({\n name: exporter.name,\n channel: exporter.channel,\n })\n }\n\n PluginManager.INSTANCE.configure(this.processorConfig)\n }\n\n async start(request: StartRequest, context: CallContext): Promise<Empty> {\n if (this.started) {\n return {}\n }\n\n try {\n for (const plugin of [\n '@sentio/sdk/lib/core/eth-plugin',\n '@sentio/sdk/lib/core/sui-plugin',\n '@sentio/sdk-aptos/lib/aptos-plugin',\n '@sentio/sdk-solana/lib/solana-plugin',\n ]) {\n try {\n require(plugin)\n } catch (e) {\n console.error('Failed to load plugin: ', plugin)\n }\n }\n\n this.loader()\n } catch (e) {\n throw new ServerError(Status.INVALID_ARGUMENT, 'Failed to load processor: ' + errorString(e))\n }\n\n for (const instance of request.templateInstances) {\n const template = ProcessorTemplateProcessorState.INSTANCE.getValues()[instance.templateId]\n if (!template) {\n throw new ServerError(Status.INVALID_ARGUMENT, 'Invalid template contract:' + instance)\n }\n if (!instance.contract) {\n throw new ServerError(Status.INVALID_ARGUMENT, 'Contract Empty from:' + instance)\n }\n template.bind({\n name: instance.contract.name,\n address: instance.contract.address,\n network: Number(instance.contract.chainId),\n startBlock: instance.startBlock,\n endBlock: instance.endBlock,\n })\n }\n try {\n await this.configure()\n } catch (e) {\n throw new ServerError(Status.INTERNAL, 'Failed to start processor : ' + errorString(e))\n }\n this.started = true\n return {}\n }\n\n async stop(request: Empty, context: CallContext): Promise<Empty> {\n console.log('Server Shutting down in 5 seconds')\n if (this.shutdownHandler) {\n setTimeout(this.shutdownHandler, 5000)\n }\n return {}\n }\n\n async processBindings(request: ProcessBindingsRequest, options?: CallContext): Promise<ProcessBindingResponse> {\n if (!this.started) {\n throw new ServerError(Status.UNAVAILABLE, 'Service Not started.')\n }\n\n const promises = request.bindings.map((binding) => this.processBinding(binding))\n const result = mergeProcessResults(await Promise.all(promises))\n\n let updated = false\n const t = TemplateInstanceState.INSTANCE.getValues()\n if (TemplateInstanceState.INSTANCE.getValues().length !== this.processorConfig.templateInstances.length) {\n await this.configure()\n updated = true\n }\n\n return {\n result,\n configUpdated: updated,\n }\n }\n\n async processBinding(request: DataBinding, options?: CallContext): Promise<ProcessResult> {\n const result = await PluginManager.INSTANCE.processBinding(request)\n recordRuntimeInfo(result, request.handlerType)\n return result\n }\n\n async *processBindingsStream(requests: AsyncIterable<DataBinding>, context: CallContext) {\n for await (const request of requests) {\n const result = await this.processBinding(request)\n let updated = false\n if (TemplateInstanceState.INSTANCE.getValues().length !== this.processorConfig.templateInstances.length) {\n await this.configure()\n updated = true\n }\n yield {\n result,\n configUpdated: updated,\n }\n }\n }\n}\n\nfunction recordRuntimeInfo(results: ProcessResult, handlerType: HandlerType) {\n for (const list of [results.gauges, results.counters, results.logs, results.events, results.exports]) {\n list.forEach((e) => {\n e.runtimeInfo = {\n from: handlerType,\n }\n })\n }\n}\n"]}
|
package/src/chain-config.ts
DELETED
package/src/endpoints.ts
DELETED
package/src/loader.ts
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
export function load(name: string): { module: any; name: string; path: string } | undefined {
|
|
2
|
-
const req = eval('require')
|
|
3
|
-
|
|
4
|
-
try {
|
|
5
|
-
let path: string
|
|
6
|
-
try {
|
|
7
|
-
path = req.resolve(name, { paths: [process.cwd()] })
|
|
8
|
-
} catch {
|
|
9
|
-
path = req.resolve(name)
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
const module = { module: req(path), name, path }
|
|
13
|
-
console.log('Processor Load successfully')
|
|
14
|
-
return module
|
|
15
|
-
} catch (err) {
|
|
16
|
-
if (err instanceof Error && err.message.startsWith(`Cannot find module '${name}'`)) {
|
|
17
|
-
// this error is expected
|
|
18
|
-
console.log("Couldn't load (expected): ", name)
|
|
19
|
-
return undefined
|
|
20
|
-
} else {
|
|
21
|
-
throw err
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
}
|
package/src/processor-runner.ts
DELETED
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
import path from 'path'
|
|
4
|
-
import fs from 'fs-extra'
|
|
5
|
-
import * as util from 'util'
|
|
6
|
-
|
|
7
|
-
import commandLineArgs from 'command-line-args'
|
|
8
|
-
import { createServer } from 'nice-grpc'
|
|
9
|
-
import { createLogger, transports, format } from 'winston'
|
|
10
|
-
import { CompressionAlgorithms } from '@grpc/grpc-js/build/src/compression-algorithms'
|
|
11
|
-
|
|
12
|
-
import { ProcessorDefinition } from '@sentio/protos'
|
|
13
|
-
import { ProcessorServiceImpl } from './service'
|
|
14
|
-
import { setProvider } from './provider'
|
|
15
|
-
import { State } from '@sentio/base'
|
|
16
|
-
import { load } from './loader'
|
|
17
|
-
import { Endpoints } from './endpoints'
|
|
18
|
-
|
|
19
|
-
State.reset()
|
|
20
|
-
global.ENDPOINTS = new Endpoints()
|
|
21
|
-
|
|
22
|
-
const optionDefinitions = [
|
|
23
|
-
{ name: 'target', type: String, defaultOption: true },
|
|
24
|
-
{ name: 'port', alias: 'p', type: String, defaultValue: '4000' },
|
|
25
|
-
{ name: 'concurrency', type: Number, defaultValue: 4 },
|
|
26
|
-
{ name: 'use-chainserver', type: Boolean, defaultValue: false },
|
|
27
|
-
{
|
|
28
|
-
name: 'chains-config',
|
|
29
|
-
alias: 'c',
|
|
30
|
-
type: String,
|
|
31
|
-
defaultValue: 'chains-config.json',
|
|
32
|
-
},
|
|
33
|
-
{ name: 'chainquery-server', type: String, defaultValue: '' },
|
|
34
|
-
{ name: 'pricefeed-server', type: String, defaultValue: '' },
|
|
35
|
-
{ name: 'log-format', type: String, defaultValue: 'console' },
|
|
36
|
-
{ name: 'debug', type: Boolean, defaultValue: false },
|
|
37
|
-
]
|
|
38
|
-
|
|
39
|
-
const options = commandLineArgs(optionDefinitions, { partial: true })
|
|
40
|
-
|
|
41
|
-
if (options['log-format'] === 'json') {
|
|
42
|
-
const utilFormatter = {
|
|
43
|
-
transform: (info: any) => {
|
|
44
|
-
const args = info[Symbol.for('splat')]
|
|
45
|
-
if (args) {
|
|
46
|
-
info.message = util.format(info.message, ...args)
|
|
47
|
-
}
|
|
48
|
-
return info
|
|
49
|
-
},
|
|
50
|
-
}
|
|
51
|
-
const logger = createLogger({
|
|
52
|
-
format: format.combine(
|
|
53
|
-
format.timestamp({ format: 'YYYY-MM-DDTHH:mm:ssZ' }),
|
|
54
|
-
utilFormatter,
|
|
55
|
-
format.errors({ stack: true }),
|
|
56
|
-
format.json()
|
|
57
|
-
),
|
|
58
|
-
transports: [new transports.Console()],
|
|
59
|
-
})
|
|
60
|
-
|
|
61
|
-
console.log = (...args) => logger.info.call(logger, ...args)
|
|
62
|
-
console.info = (...args) => logger.info.call(logger, ...args)
|
|
63
|
-
console.warn = (...args) => logger.warn.call(logger, ...args)
|
|
64
|
-
console.error = (...args) => logger.error.call(logger, ...args)
|
|
65
|
-
console.debug = (...args) => logger.debug.call(logger, ...args)
|
|
66
|
-
}
|
|
67
|
-
if (options.debug) {
|
|
68
|
-
console.log('Starting with', options.target)
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
const fullPath = path.resolve(options['chains-config'])
|
|
72
|
-
const chainsConfig = fs.readJsonSync(fullPath)
|
|
73
|
-
|
|
74
|
-
setProvider(chainsConfig, options.concurrency, options['use-chainserver'])
|
|
75
|
-
globalThis.ENDPOINTS.chainQueryAPI = options['chainquery-server']
|
|
76
|
-
globalThis.ENDPOINTS.priceFeedAPI = options['pricefeed-server']
|
|
77
|
-
|
|
78
|
-
if (options.debug) {
|
|
79
|
-
console.log('Starting Server', options)
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
const server = createServer({
|
|
83
|
-
'grpc.max_send_message_length': 128 * 1024 * 1024,
|
|
84
|
-
'grpc.max_receive_message_length': 128 * 1024 * 1024,
|
|
85
|
-
'grpc.default_compression_algorithm': CompressionAlgorithms.gzip,
|
|
86
|
-
})
|
|
87
|
-
|
|
88
|
-
const service = new ProcessorServiceImpl(() => load(options.target), server.shutdown)
|
|
89
|
-
server.add(ProcessorDefinition, service)
|
|
90
|
-
|
|
91
|
-
server.listen('0.0.0.0:' + options.port)
|
|
92
|
-
|
|
93
|
-
console.log('Processor Server Started')
|
package/src/provider.ts
DELETED
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
import { getNetwork, Provider, StaticJsonRpcProvider } from '@ethersproject/providers'
|
|
2
|
-
import { Networkish } from '@ethersproject/networks'
|
|
3
|
-
import PQueue from 'p-queue'
|
|
4
|
-
import { ConnectionInfo } from '@ethersproject/web'
|
|
5
|
-
import { ChainConfig } from './chain-config'
|
|
6
|
-
|
|
7
|
-
export const DummyProvider = new StaticJsonRpcProvider(undefined, 1)
|
|
8
|
-
|
|
9
|
-
export function getProvider(networkish?: Networkish): Provider {
|
|
10
|
-
if (!networkish) {
|
|
11
|
-
networkish = 1
|
|
12
|
-
}
|
|
13
|
-
const network = getNetwork(networkish)
|
|
14
|
-
|
|
15
|
-
if (!global.ENDPOINTS.providers) {
|
|
16
|
-
throw Error('Provider not set')
|
|
17
|
-
}
|
|
18
|
-
const value = global.ENDPOINTS.providers.get(network.chainId)
|
|
19
|
-
if (value === undefined) {
|
|
20
|
-
throw Error(
|
|
21
|
-
'Provider not found for chain ' +
|
|
22
|
-
network.chainId +
|
|
23
|
-
', configured chains: ' +
|
|
24
|
-
[...global.ENDPOINTS.providers.keys()].join(' ')
|
|
25
|
-
)
|
|
26
|
-
}
|
|
27
|
-
return value
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export function setProvider(config: Record<string, ChainConfig>, concurrency = 4, useChainServer = false) {
|
|
31
|
-
globalThis.ENDPOINTS.providers = new Map<number, Provider>()
|
|
32
|
-
|
|
33
|
-
for (const chainIdStr in config) {
|
|
34
|
-
if (isNaN(Number.parseInt(chainIdStr))) {
|
|
35
|
-
continue
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
const chainConfig = config[chainIdStr]
|
|
39
|
-
const chainId = Number(chainIdStr)
|
|
40
|
-
|
|
41
|
-
// let providers: StaticJsonRpcProvider[] = []
|
|
42
|
-
// for (const http of chainConfig.Https) {
|
|
43
|
-
// providers.push(new StaticJsonRpcProvider(http, chainId))
|
|
44
|
-
// }
|
|
45
|
-
// random shuffle
|
|
46
|
-
// providers = providers.sort(() => Math.random() - 0.5)
|
|
47
|
-
|
|
48
|
-
// const provider = new FallbackProvider(providers)
|
|
49
|
-
|
|
50
|
-
let rpcAddress = ''
|
|
51
|
-
if (useChainServer && chainConfig.ChainServer) {
|
|
52
|
-
rpcAddress = chainConfig.ChainServer
|
|
53
|
-
} else {
|
|
54
|
-
const idx = Math.floor(Math.random() * chainConfig.Https.length)
|
|
55
|
-
rpcAddress = chainConfig.Https[idx]
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
const provider = new QueuedStaticJsonRpcProvider(rpcAddress, chainId, concurrency)
|
|
59
|
-
global.ENDPOINTS.providers.set(chainId, provider)
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
class QueuedStaticJsonRpcProvider extends StaticJsonRpcProvider {
|
|
64
|
-
executor: PQueue
|
|
65
|
-
|
|
66
|
-
constructor(url: ConnectionInfo | string, network: Networkish, concurrency: number) {
|
|
67
|
-
super(url, network)
|
|
68
|
-
this.executor = new PQueue({ concurrency: concurrency })
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
send(method: string, params: Array<any>): Promise<any> {
|
|
72
|
-
return this.executor.add(() => super.send(method, params))
|
|
73
|
-
}
|
|
74
|
-
}
|
package/src/service.ts
DELETED
|
@@ -1,197 +0,0 @@
|
|
|
1
|
-
import { CallContext, ServerError, Status } from 'nice-grpc'
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
DataBinding,
|
|
5
|
-
HandlerType,
|
|
6
|
-
ProcessBindingResponse,
|
|
7
|
-
ProcessBindingsRequest,
|
|
8
|
-
ProcessConfigRequest,
|
|
9
|
-
ProcessConfigResponse,
|
|
10
|
-
ProcessorServiceImplementation,
|
|
11
|
-
ProcessResult,
|
|
12
|
-
StartRequest,
|
|
13
|
-
} from '@sentio/protos'
|
|
14
|
-
|
|
15
|
-
import { Empty } from '@sentio/protos/lib/google/protobuf/empty'
|
|
16
|
-
|
|
17
|
-
import { MetricState } from './core/meter'
|
|
18
|
-
import { ExporterState } from './core/exporter'
|
|
19
|
-
import { EventTrackerState } from './core/event-tracker'
|
|
20
|
-
import { ProcessorTemplateProcessorState, TemplateInstanceState } from './core/base-processor-template'
|
|
21
|
-
|
|
22
|
-
// (Long.prototype as any).toBigInt = function() {
|
|
23
|
-
// return BigInt(this.toString())
|
|
24
|
-
// };
|
|
25
|
-
import { errorString, mergeProcessResults, PluginManager } from '@sentio/base'
|
|
26
|
-
import * as console from 'console'
|
|
27
|
-
;(BigInt.prototype as any).toJSON = function () {
|
|
28
|
-
return this.toString()
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export const USER_PROCESSOR = 'user_processor'
|
|
32
|
-
|
|
33
|
-
export class ProcessorServiceImpl implements ProcessorServiceImplementation {
|
|
34
|
-
private started = false
|
|
35
|
-
private processorConfig: ProcessConfigResponse
|
|
36
|
-
|
|
37
|
-
private readonly loader: () => void
|
|
38
|
-
|
|
39
|
-
private readonly shutdownHandler?: () => void
|
|
40
|
-
|
|
41
|
-
constructor(loader: () => void, shutdownHandler?: () => void) {
|
|
42
|
-
this.loader = loader
|
|
43
|
-
this.shutdownHandler = shutdownHandler
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
async getConfig(request: ProcessConfigRequest, context: CallContext): Promise<ProcessConfigResponse> {
|
|
47
|
-
if (!this.started) {
|
|
48
|
-
throw new ServerError(Status.UNAVAILABLE, 'Service Not started.')
|
|
49
|
-
}
|
|
50
|
-
if (!this.processorConfig) {
|
|
51
|
-
throw new ServerError(Status.INTERNAL, 'Process config empty.')
|
|
52
|
-
}
|
|
53
|
-
return this.processorConfig
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
async configure() {
|
|
57
|
-
this.processorConfig = ProcessConfigResponse.fromPartial({})
|
|
58
|
-
// This syntax is to copy values instead of using references
|
|
59
|
-
this.processorConfig.templateInstances = [...TemplateInstanceState.INSTANCE.getValues()]
|
|
60
|
-
|
|
61
|
-
// part 0, prepare metrics and event tracking configs
|
|
62
|
-
for (const metric of MetricState.INSTANCE.getValues()) {
|
|
63
|
-
this.processorConfig.metricConfigs.push({
|
|
64
|
-
...metric.config,
|
|
65
|
-
})
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
for (const eventTracker of EventTrackerState.INSTANCE.getValues()) {
|
|
69
|
-
this.processorConfig.eventTrackingConfigs.push({
|
|
70
|
-
distinctAggregationByDays: eventTracker.options.distinctByDays || [],
|
|
71
|
-
eventName: eventTracker.name,
|
|
72
|
-
retentionConfig: undefined,
|
|
73
|
-
totalByDay: eventTracker.options.totalByDay || false,
|
|
74
|
-
totalPerEntity: undefined,
|
|
75
|
-
unique: eventTracker.options.unique || false,
|
|
76
|
-
})
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
for (const exporter of ExporterState.INSTANCE.getValues()) {
|
|
80
|
-
this.processorConfig.exportConfigs.push({
|
|
81
|
-
name: exporter.name,
|
|
82
|
-
channel: exporter.channel,
|
|
83
|
-
})
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
PluginManager.INSTANCE.configure(this.processorConfig)
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
async start(request: StartRequest, context: CallContext): Promise<Empty> {
|
|
90
|
-
if (this.started) {
|
|
91
|
-
return {}
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
try {
|
|
95
|
-
for (const plugin of [
|
|
96
|
-
'@sentio/sdk/lib/core/eth-plugin',
|
|
97
|
-
'@sentio/sdk/lib/core/sui-plugin',
|
|
98
|
-
'@sentio/sdk-aptos/lib/aptos-plugin',
|
|
99
|
-
'@sentio/sdk-solana/lib/solana-plugin',
|
|
100
|
-
]) {
|
|
101
|
-
try {
|
|
102
|
-
require(plugin)
|
|
103
|
-
} catch (e) {
|
|
104
|
-
console.error('Failed to load plugin: ', plugin)
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
this.loader()
|
|
109
|
-
} catch (e) {
|
|
110
|
-
throw new ServerError(Status.INVALID_ARGUMENT, 'Failed to load processor: ' + errorString(e))
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
for (const instance of request.templateInstances) {
|
|
114
|
-
const template = ProcessorTemplateProcessorState.INSTANCE.getValues()[instance.templateId]
|
|
115
|
-
if (!template) {
|
|
116
|
-
throw new ServerError(Status.INVALID_ARGUMENT, 'Invalid template contract:' + instance)
|
|
117
|
-
}
|
|
118
|
-
if (!instance.contract) {
|
|
119
|
-
throw new ServerError(Status.INVALID_ARGUMENT, 'Contract Empty from:' + instance)
|
|
120
|
-
}
|
|
121
|
-
template.bind({
|
|
122
|
-
name: instance.contract.name,
|
|
123
|
-
address: instance.contract.address,
|
|
124
|
-
network: Number(instance.contract.chainId),
|
|
125
|
-
startBlock: instance.startBlock,
|
|
126
|
-
endBlock: instance.endBlock,
|
|
127
|
-
})
|
|
128
|
-
}
|
|
129
|
-
try {
|
|
130
|
-
await this.configure()
|
|
131
|
-
} catch (e) {
|
|
132
|
-
throw new ServerError(Status.INTERNAL, 'Failed to start processor : ' + errorString(e))
|
|
133
|
-
}
|
|
134
|
-
this.started = true
|
|
135
|
-
return {}
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
async stop(request: Empty, context: CallContext): Promise<Empty> {
|
|
139
|
-
console.log('Server Shutting down in 5 seconds')
|
|
140
|
-
if (this.shutdownHandler) {
|
|
141
|
-
setTimeout(this.shutdownHandler, 5000)
|
|
142
|
-
}
|
|
143
|
-
return {}
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
async processBindings(request: ProcessBindingsRequest, options?: CallContext): Promise<ProcessBindingResponse> {
|
|
147
|
-
if (!this.started) {
|
|
148
|
-
throw new ServerError(Status.UNAVAILABLE, 'Service Not started.')
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
const promises = request.bindings.map((binding) => this.processBinding(binding))
|
|
152
|
-
const result = mergeProcessResults(await Promise.all(promises))
|
|
153
|
-
|
|
154
|
-
let updated = false
|
|
155
|
-
const t = TemplateInstanceState.INSTANCE.getValues()
|
|
156
|
-
if (TemplateInstanceState.INSTANCE.getValues().length !== this.processorConfig.templateInstances.length) {
|
|
157
|
-
await this.configure()
|
|
158
|
-
updated = true
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
return {
|
|
162
|
-
result,
|
|
163
|
-
configUpdated: updated,
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
async processBinding(request: DataBinding, options?: CallContext): Promise<ProcessResult> {
|
|
168
|
-
const result = await PluginManager.INSTANCE.processBinding(request)
|
|
169
|
-
recordRuntimeInfo(result, request.handlerType)
|
|
170
|
-
return result
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
async *processBindingsStream(requests: AsyncIterable<DataBinding>, context: CallContext) {
|
|
174
|
-
for await (const request of requests) {
|
|
175
|
-
const result = await this.processBinding(request)
|
|
176
|
-
let updated = false
|
|
177
|
-
if (TemplateInstanceState.INSTANCE.getValues().length !== this.processorConfig.templateInstances.length) {
|
|
178
|
-
await this.configure()
|
|
179
|
-
updated = true
|
|
180
|
-
}
|
|
181
|
-
yield {
|
|
182
|
-
result,
|
|
183
|
-
configUpdated: updated,
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
function recordRuntimeInfo(results: ProcessResult, handlerType: HandlerType) {
|
|
190
|
-
for (const list of [results.gauges, results.counters, results.logs, results.events, results.exports]) {
|
|
191
|
-
list.forEach((e) => {
|
|
192
|
-
e.runtimeInfo = {
|
|
193
|
-
from: handlerType,
|
|
194
|
-
}
|
|
195
|
-
})
|
|
196
|
-
}
|
|
197
|
-
}
|
package/src/types/global.d.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
// import { State } from '../../../base/src/state'
|
|
2
|
-
import { Endpoints } from "../endpoints";
|
|
3
|
-
|
|
4
|
-
declare global {
|
|
5
|
-
// var PROCESSOR_STATE: State
|
|
6
|
-
var ENDPOINTS: Endpoints
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
// declare module "long" {
|
|
11
|
-
// export interface Long {
|
|
12
|
-
// toBigInt(): bigint;
|
|
13
|
-
// }
|
|
14
|
-
// }
|
|
15
|
-
//
|