@sentio/sdk 1.36.3 → 1.36.4
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/LICENSE
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
|
|
5
|
+
http://www.apache.org/licenses/
|
|
6
|
+
|
|
7
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
8
|
+
|
|
9
|
+
1. Definitions.
|
|
10
|
+
|
|
11
|
+
"License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity.
|
|
16
|
+
|
|
17
|
+
"You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License.
|
|
18
|
+
|
|
19
|
+
"Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files.
|
|
20
|
+
|
|
21
|
+
"Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types.
|
|
22
|
+
|
|
23
|
+
"Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below).
|
|
24
|
+
|
|
25
|
+
"Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof.
|
|
26
|
+
|
|
27
|
+
"Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution."
|
|
28
|
+
|
|
29
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work.
|
|
30
|
+
|
|
31
|
+
2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form.
|
|
32
|
+
|
|
33
|
+
3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed.
|
|
34
|
+
|
|
35
|
+
4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions:
|
|
36
|
+
|
|
37
|
+
You must give any other recipients of the Work or Derivative Works a copy of this License; and
|
|
38
|
+
|
|
39
|
+
You must cause any modified files to carry prominent notices stating that You changed the files; and
|
|
40
|
+
|
|
41
|
+
You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and
|
|
42
|
+
|
|
43
|
+
If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License.
|
|
44
|
+
|
|
45
|
+
5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions.
|
|
46
|
+
|
|
47
|
+
6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file.
|
|
48
|
+
|
|
49
|
+
7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License.
|
|
50
|
+
|
|
51
|
+
8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages.
|
|
52
|
+
|
|
53
|
+
9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability.
|
|
54
|
+
|
|
55
|
+
END OF TERMS AND CONDITIONS
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Plugin } from '../plugin';
|
|
2
|
+
import { DataBinding, HandlerType, ProcessConfigResponse, ProcessResult } from '../gen/processor/protos/processor';
|
|
3
|
+
export declare class AptosPlugin implements Plugin {
|
|
4
|
+
name: string;
|
|
5
|
+
private aptosEventHandlers;
|
|
6
|
+
private aptosCallHandlers;
|
|
7
|
+
private aptosResourceHandlers;
|
|
8
|
+
configure(config: ProcessConfigResponse): void;
|
|
9
|
+
supportedHandlers: HandlerType[];
|
|
10
|
+
processBinding(request: DataBinding): Promise<ProcessResult>;
|
|
11
|
+
processAptosEvent(binding: DataBinding): Promise<ProcessResult>;
|
|
12
|
+
processAptosResource(binding: DataBinding): Promise<ProcessResult>;
|
|
13
|
+
processAptosFunctionCall(binding: DataBinding): Promise<ProcessResult>;
|
|
14
|
+
}
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.AptosPlugin = void 0;
|
|
7
|
+
const plugin_1 = require("../plugin");
|
|
8
|
+
const processor_1 = require("../gen/processor/protos/processor");
|
|
9
|
+
const service_1 = require("../service");
|
|
10
|
+
const nice_grpc_1 = require("nice-grpc");
|
|
11
|
+
const aptos_processor_1 = require("./aptos-processor");
|
|
12
|
+
const numberish_1 = require("../core/numberish");
|
|
13
|
+
const long_1 = __importDefault(require("long"));
|
|
14
|
+
class AptosPlugin {
|
|
15
|
+
name = 'AptosPlugin';
|
|
16
|
+
aptosEventHandlers = [];
|
|
17
|
+
aptosCallHandlers = [];
|
|
18
|
+
aptosResourceHandlers = [];
|
|
19
|
+
configure(config) {
|
|
20
|
+
for (const aptosProcessor of aptos_processor_1.AptosProcessorState.INSTANCE.getValues()) {
|
|
21
|
+
const contractConfig = {
|
|
22
|
+
processorType: service_1.USER_PROCESSOR,
|
|
23
|
+
contract: {
|
|
24
|
+
name: aptosProcessor.moduleName,
|
|
25
|
+
chainId: aptosProcessor.getChainId(),
|
|
26
|
+
address: aptosProcessor.config.address,
|
|
27
|
+
abi: '',
|
|
28
|
+
},
|
|
29
|
+
intervalConfigs: [],
|
|
30
|
+
logConfigs: [],
|
|
31
|
+
traceConfigs: [],
|
|
32
|
+
startBlock: long_1.default.fromString(aptosProcessor.config.startVersion.toString()),
|
|
33
|
+
endBlock: service_1.DEFAULT_MAX_BLOCK,
|
|
34
|
+
instructionConfig: undefined,
|
|
35
|
+
aptosEventConfigs: [],
|
|
36
|
+
aptosCallConfigs: [],
|
|
37
|
+
};
|
|
38
|
+
// 1. Prepare event handlers
|
|
39
|
+
for (const handler of aptosProcessor.eventHandlers) {
|
|
40
|
+
const handlerId = this.aptosEventHandlers.push(handler.handler) - 1;
|
|
41
|
+
const eventHandlerConfig = {
|
|
42
|
+
filters: handler.filters.map((f) => {
|
|
43
|
+
return {
|
|
44
|
+
type: f.type,
|
|
45
|
+
account: f.account || '',
|
|
46
|
+
};
|
|
47
|
+
}),
|
|
48
|
+
handlerId,
|
|
49
|
+
};
|
|
50
|
+
contractConfig.aptosEventConfigs.push(eventHandlerConfig);
|
|
51
|
+
}
|
|
52
|
+
// 2. Prepare function handlers
|
|
53
|
+
for (const handler of aptosProcessor.callHandlers) {
|
|
54
|
+
const handlerId = this.aptosCallHandlers.push(handler.handler) - 1;
|
|
55
|
+
const functionHandlerConfig = {
|
|
56
|
+
filters: handler.filters.map((filter) => {
|
|
57
|
+
return {
|
|
58
|
+
function: filter.function,
|
|
59
|
+
typeArguments: filter.typeArguments || [],
|
|
60
|
+
withTypeArguments: filter.typeArguments ? true : false,
|
|
61
|
+
includeFailed: filter.includeFailed || false,
|
|
62
|
+
};
|
|
63
|
+
}),
|
|
64
|
+
handlerId,
|
|
65
|
+
};
|
|
66
|
+
contractConfig.aptosCallConfigs.push(functionHandlerConfig);
|
|
67
|
+
}
|
|
68
|
+
config.contractConfigs.push(contractConfig);
|
|
69
|
+
}
|
|
70
|
+
for (const aptosProcessor of aptos_processor_1.AptosAccountProcessorState.INSTANCE.getValues()) {
|
|
71
|
+
const accountConfig = {
|
|
72
|
+
address: aptosProcessor.config.address,
|
|
73
|
+
chainId: aptosProcessor.getChainId(),
|
|
74
|
+
startBlock: long_1.default.fromValue(aptosProcessor.config.startVersion.toString()),
|
|
75
|
+
aptosIntervalConfigs: [],
|
|
76
|
+
intervalConfigs: [],
|
|
77
|
+
logConfigs: [],
|
|
78
|
+
};
|
|
79
|
+
for (const handler of aptosProcessor.resourcesHandlers) {
|
|
80
|
+
const handlerId = this.aptosResourceHandlers.push(handler.handler) - 1;
|
|
81
|
+
accountConfig.aptosIntervalConfigs.push({
|
|
82
|
+
intervalConfig: {
|
|
83
|
+
handlerId: handlerId,
|
|
84
|
+
minutes: 0,
|
|
85
|
+
minutesInterval: handler.timeIntervalInMinutes,
|
|
86
|
+
slot: 0,
|
|
87
|
+
slotInterval: handler.versionInterval,
|
|
88
|
+
},
|
|
89
|
+
type: handler.type || '',
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
config.accountConfigs.push(accountConfig);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
supportedHandlers = [processor_1.HandlerType.APT_CALL, processor_1.HandlerType.APT_RESOURCE, processor_1.HandlerType.APT_EVENT];
|
|
96
|
+
processBinding(request) {
|
|
97
|
+
switch (request.handlerType) {
|
|
98
|
+
case processor_1.HandlerType.APT_CALL:
|
|
99
|
+
return this.processAptosFunctionCall(request);
|
|
100
|
+
case processor_1.HandlerType.APT_EVENT:
|
|
101
|
+
return this.processAptosEvent(request);
|
|
102
|
+
case processor_1.HandlerType.APT_RESOURCE:
|
|
103
|
+
return this.processAptosResource(request);
|
|
104
|
+
// case HandlerType.INSTRUCTION:
|
|
105
|
+
// return this.processInstruction(request)
|
|
106
|
+
default:
|
|
107
|
+
throw new nice_grpc_1.ServerError(nice_grpc_1.Status.INVALID_ARGUMENT, 'No handle type registered ' + request.handlerType);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
async processAptosEvent(binding) {
|
|
111
|
+
if (!binding.data) {
|
|
112
|
+
throw new nice_grpc_1.ServerError(nice_grpc_1.Status.INVALID_ARGUMENT, "Event can't be empty");
|
|
113
|
+
}
|
|
114
|
+
const promises = [];
|
|
115
|
+
let event;
|
|
116
|
+
if (binding.data.aptEvent?.event) {
|
|
117
|
+
event = binding.data.aptEvent?.event;
|
|
118
|
+
}
|
|
119
|
+
else {
|
|
120
|
+
const jsonString = (0, service_1.Utf8ArrayToStr)(binding.data.raw);
|
|
121
|
+
event = JSON.parse(jsonString);
|
|
122
|
+
}
|
|
123
|
+
for (const handlerId of binding.handlerIds) {
|
|
124
|
+
// only support aptos event for now
|
|
125
|
+
promises.push(this.aptosEventHandlers[handlerId](event).catch((e) => {
|
|
126
|
+
throw new nice_grpc_1.ServerError(nice_grpc_1.Status.INTERNAL, 'error processing event: ' + JSON.stringify(event) + '\n' + (0, service_1.errorString)(e));
|
|
127
|
+
}));
|
|
128
|
+
}
|
|
129
|
+
return (0, service_1.mergeProcessResults)(await Promise.all(promises));
|
|
130
|
+
}
|
|
131
|
+
async processAptosResource(binding) {
|
|
132
|
+
if (!binding.data) {
|
|
133
|
+
throw new nice_grpc_1.ServerError(nice_grpc_1.Status.INVALID_ARGUMENT, "Event can't be empty");
|
|
134
|
+
}
|
|
135
|
+
const resource = {
|
|
136
|
+
resources: [],
|
|
137
|
+
version: 0n,
|
|
138
|
+
timestamp: 0,
|
|
139
|
+
};
|
|
140
|
+
if (binding.data.aptResource?.resources) {
|
|
141
|
+
if (binding.data.aptResource.timestampMicros.greaterThan(Number.MAX_SAFE_INTEGER)) {
|
|
142
|
+
throw new nice_grpc_1.ServerError(nice_grpc_1.Status.INVALID_ARGUMENT, 'timestamp is too large');
|
|
143
|
+
}
|
|
144
|
+
resource.timestamp = binding.data.aptResource.timestampMicros.toNumber();
|
|
145
|
+
resource.version = (0, numberish_1.toBigInt)(binding.data.aptResource.version);
|
|
146
|
+
resource.resources = binding.data.aptResource.resources;
|
|
147
|
+
}
|
|
148
|
+
else {
|
|
149
|
+
const jsonString = (0, service_1.Utf8ArrayToStr)(binding.data.raw);
|
|
150
|
+
const json = JSON.parse(jsonString);
|
|
151
|
+
if (long_1.default.fromString(json.timestamp).greaterThan(Number.MAX_SAFE_INTEGER)) {
|
|
152
|
+
throw new nice_grpc_1.ServerError(nice_grpc_1.Status.INVALID_ARGUMENT, 'timestamp is too large');
|
|
153
|
+
}
|
|
154
|
+
resource.timestamp = parseInt(json.timestamp);
|
|
155
|
+
resource.version = (0, numberish_1.toBigInt)(json.version);
|
|
156
|
+
}
|
|
157
|
+
const promises = [];
|
|
158
|
+
for (const handlerId of binding.handlerIds) {
|
|
159
|
+
promises.push(this.aptosResourceHandlers[handlerId](resource).catch((e) => {
|
|
160
|
+
throw new nice_grpc_1.ServerError(nice_grpc_1.Status.INTERNAL, 'error processing event: ' + JSON.stringify(resource) + '\n' + (0, service_1.errorString)(e));
|
|
161
|
+
}));
|
|
162
|
+
}
|
|
163
|
+
return (0, service_1.mergeProcessResults)(await Promise.all(promises));
|
|
164
|
+
}
|
|
165
|
+
async processAptosFunctionCall(binding) {
|
|
166
|
+
if (!binding.data) {
|
|
167
|
+
throw new nice_grpc_1.ServerError(nice_grpc_1.Status.INVALID_ARGUMENT, "Event can't be empty");
|
|
168
|
+
}
|
|
169
|
+
let call;
|
|
170
|
+
if (binding.data.aptCall?.call) {
|
|
171
|
+
call = binding.data.aptCall?.call;
|
|
172
|
+
}
|
|
173
|
+
else {
|
|
174
|
+
const jsonString = (0, service_1.Utf8ArrayToStr)(binding.data.raw);
|
|
175
|
+
call = JSON.parse(jsonString);
|
|
176
|
+
}
|
|
177
|
+
const promises = [];
|
|
178
|
+
for (const handlerId of binding.handlerIds) {
|
|
179
|
+
// only support aptos call for now
|
|
180
|
+
const promise = this.aptosCallHandlers[handlerId](call).catch((e) => {
|
|
181
|
+
throw new nice_grpc_1.ServerError(nice_grpc_1.Status.INTERNAL, 'error processing call: ' + JSON.stringify(call) + '\n' + (0, service_1.errorString)(e));
|
|
182
|
+
});
|
|
183
|
+
promises.push(promise);
|
|
184
|
+
}
|
|
185
|
+
return (0, service_1.mergeProcessResults)(await Promise.all(promises));
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
exports.AptosPlugin = AptosPlugin;
|
|
189
|
+
plugin_1.PluginManager.INSTANCE.register(new AptosPlugin());
|
|
190
|
+
//# sourceMappingURL=aptos-plugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"aptos-plugin.js","sourceRoot":"","sources":["../../src/aptos/aptos-plugin.ts"],"names":[],"mappings":";;;;;;AAAA,sCAAiD;AACjD,iEAS0C;AAC1C,wCAAgH;AAEhH,yCAA+C;AAG/C,uDAAoH;AACpH,iDAA4C;AAC5C,gDAAuB;AAEvB,MAAa,WAAW;IACtB,IAAI,GAAW,aAAa,CAAA;IAEpB,kBAAkB,GAA+C,EAAE,CAAA;IACnE,iBAAiB,GAA8C,EAAE,CAAA;IACjE,qBAAqB,GAC3B,EAAE,CAAA;IAEJ,SAAS,CAAC,MAA6B;QACrC,KAAK,MAAM,cAAc,IAAI,qCAAmB,CAAC,QAAQ,CAAC,SAAS,EAAE,EAAE;YACrE,MAAM,cAAc,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fig,\n DataBinding,\n HandlerType,\n ProcessConfigResponse,\n ProcessResult,\n} from '../gen/processor/protos/processor'\nimport { DEFAULT_MAX_BLOCK, errorString, mergeProcessResults, USER_PROCESSOR, Utf8ArrayToStr } from '../service'\n\nimport { ServerError, Status } from 'nice-grpc'\n\nimport { MoveResource, Transaction_UserTransaction } from 'aptos-sdk/src/generated'\nimport { AptosAccountProcessorState, AptosProcessorState, MoveResourcesWithVersionPayload } from './aptos-processor'\nimport { toBigInt } from '../core/numberish'\nimport Long from 'long'\n\nexport class AptosPlugin implements Plugin {\n name: string = 'AptosPlugin'\n\n private aptosEventHandlers: ((event: any) => Promise<ProcessResult>)[] = []\n private aptosCallHandlers: ((func: any) => Promise<ProcessResult>)[] = []\n private aptosResourceHandlers: ((resourceWithVersion: MoveResourcesWithVersionPayload) => Promise<ProcessResult>)[] =\n []\n\n configure(config: ProcessConfigResponse): void {\n for (const aptosProcessor of AptosProcessorState.INSTANCE.getValues()) {\n const contractConfig: ContractConfig = {\n processorType: USER_PROCESSOR,\n contract: {\n name: aptosProcessor.moduleName,\n chainId: aptosProcessor.getChainId(),\n address: aptosProcessor.config.address,\n abi: '',\n },\n intervalConfigs: [],\n logConfigs: [],\n traceConfigs: [],\n startBlock: Long.fromString(aptosProcessor.config.startVersion.toString()),\n endBlock: DEFAULT_MAX_BLOCK,\n instructionConfig: undefined,\n aptosEventConfigs: [],\n aptosCallConfigs: [],\n }\n // 1. Prepare event handlers\n for (const handler of aptosProcessor.eventHandlers) {\n const handlerId = this.aptosEventHandlers.push(handler.handler) - 1\n const eventHandlerConfig: AptosEventHandlerConfig = {\n filters: handler.filters.map((f) => {\n return {\n type: f.type,\n account: f.account || '',\n }\n }),\n handlerId,\n }\n contractConfig.aptosEventConfigs.push(eventHandlerConfig)\n }\n\n // 2. Prepare function handlers\n for (const handler of aptosProcessor.callHandlers) {\n const handlerId = this.aptosCallHandlers.push(handler.handler) - 1\n const functionHandlerConfig: AptosCallHandlerConfig = {\n filters: handler.filters.map((filter) => {\n return {\n function: filter.function,\n typeArguments: filter.typeArguments || [],\n withTypeArguments: filter.typeArguments ? true : false,\n includeFailed: filter.includeFailed || false,\n }\n }),\n handlerId,\n }\n contractConfig.aptosCallConfigs.push(functionHandlerConfig)\n }\n config.contractConfigs.push(contractConfig)\n }\n\n for (const aptosProcessor of AptosAccountProcessorState.INSTANCE.getValues()) {\n const accountConfig: AccountConfig = {\n address: aptosProcessor.config.address,\n chainId: aptosProcessor.getChainId(),\n startBlock: Long.fromValue(aptosProcessor.config.startVersion.toString()),\n aptosIntervalConfigs: [],\n intervalConfigs: [],\n logConfigs: [],\n }\n for (const handler of aptosProcessor.resourcesHandlers) {\n const handlerId = this.aptosResourceHandlers.push(handler.handler) - 1\n accountConfig.aptosIntervalConfigs.push({\n intervalConfig: {\n handlerId: handlerId,\n minutes: 0,\n minutesInterval: handler.timeIntervalInMinutes,\n slot: 0,\n slotInterval: handler.versionInterval,\n },\n type: handler.type || '',\n })\n }\n config.accountConfigs.push(accountConfig)\n }\n }\n\n supportedHandlers = [HandlerType.APT_CALL, HandlerType.APT_RESOURCE, HandlerType.APT_EVENT]\n\n processBinding(request: DataBinding): Promise<ProcessResult> {\n switch (request.handlerType) {\n case HandlerType.APT_CALL:\n return this.processAptosFunctionCall(request)\n case HandlerType.APT_EVENT:\n return this.processAptosEvent(request)\n case HandlerType.APT_RESOURCE:\n return this.processAptosResource(request)\n // case HandlerType.INSTRUCTION:\n // return this.processInstruction(request)\n default:\n throw new ServerError(Status.INVALID_ARGUMENT, 'No handle type registered ' + request.handlerType)\n }\n }\n\n async processAptosEvent(binding: DataBinding): Promise<ProcessResult> {\n if (!binding.data) {\n throw new ServerError(Status.INVALID_ARGUMENT, \"Event can't be empty\")\n }\n const promises: Promise<ProcessResult>[] = []\n let event: Transaction_UserTransaction\n if (binding.data.aptEvent?.event) {\n event = binding.data.aptEvent?.event as Transaction_UserTransaction\n } else {\n const jsonString = Utf8ArrayToStr(binding.data.raw)\n event = JSON.parse(jsonString)\n }\n\n for (const handlerId of binding.handlerIds) {\n // only support aptos event for now\n promises.push(\n this.aptosEventHandlers[handlerId](event).catch((e) => {\n throw new ServerError(\n Status.INTERNAL,\n 'error processing event: ' + JSON.stringify(event) + '\\n' + errorString(e)\n )\n })\n )\n }\n return mergeProcessResults(await Promise.all(promises))\n }\n\n async processAptosResource(binding: DataBinding): Promise<ProcessResult> {\n if (!binding.data) {\n throw new ServerError(Status.INVALID_ARGUMENT, \"Event can't be empty\")\n }\n\n const resource: MoveResourcesWithVersionPayload = {\n resources: [],\n version: 0n,\n timestamp: 0,\n }\n if (binding.data.aptResource?.resources) {\n if (binding.data.aptResource.timestampMicros.greaterThan(Number.MAX_SAFE_INTEGER)) {\n throw new ServerError(Status.INVALID_ARGUMENT, 'timestamp is too large')\n }\n resource.timestamp = binding.data.aptResource.timestampMicros.toNumber()\n resource.version = toBigInt(binding.data.aptResource.version)\n resource.resources = binding.data.aptResource.resources as MoveResource[]\n } else {\n const jsonString = Utf8ArrayToStr(binding.data.raw)\n const json = JSON.parse(jsonString)\n if (Long.fromString(json.timestamp).greaterThan(Number.MAX_SAFE_INTEGER)) {\n throw new ServerError(Status.INVALID_ARGUMENT, 'timestamp is too large')\n }\n resource.timestamp = parseInt(json.timestamp)\n resource.version = toBigInt(json.version)\n }\n\n const promises: Promise<ProcessResult>[] = []\n for (const handlerId of binding.handlerIds) {\n promises.push(\n this.aptosResourceHandlers[handlerId](resource).catch((e) => {\n throw new ServerError(\n Status.INTERNAL,\n 'error processing event: ' + JSON.stringify(resource) + '\\n' + errorString(e)\n )\n })\n )\n }\n return mergeProcessResults(await Promise.all(promises))\n }\n\n async processAptosFunctionCall(binding: DataBinding): Promise<ProcessResult> {\n if (!binding.data) {\n throw new ServerError(Status.INVALID_ARGUMENT, \"Event can't be empty\")\n }\n let call: Transaction_UserTransaction\n if (binding.data.aptCall?.call) {\n call = binding.data.aptCall?.call as Transaction_UserTransaction\n } else {\n const jsonString = Utf8ArrayToStr(binding.data.raw)\n call = JSON.parse(jsonString)\n }\n\n const promises: Promise<ProcessResult>[] = []\n for (const handlerId of binding.handlerIds) {\n // only support aptos call for now\n const promise = this.aptosCallHandlers[handlerId](call).catch((e) => {\n throw new ServerError(Status.INTERNAL, 'error processing call: ' + JSON.stringify(call) + '\\n' + errorString(e))\n })\n promises.push(promise)\n }\n return mergeProcessResults(await Promise.all(promises))\n }\n}\n\nPluginManager.INSTANCE.register(new AptosPlugin())\n"]}
|
package/lib/aptos/index.d.ts
CHANGED
|
@@ -6,3 +6,4 @@ export { AptosBaseProcessor, AptosAccountProcessor } from './aptos-processor';
|
|
|
6
6
|
export { AptosContext, AptosResourceContext } from './context';
|
|
7
7
|
export { AptosBindOptions, AptosNetwork, getRpcClient } from './network';
|
|
8
8
|
export * from './api';
|
|
9
|
+
export { AptosPlugin } from './aptos-plugin';
|
package/lib/aptos/index.js
CHANGED
|
@@ -14,7 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.getRpcClient = exports.AptosNetwork = exports.AptosBindOptions = exports.AptosResourceContext = exports.AptosContext = exports.AptosAccountProcessor = exports.AptosBaseProcessor = exports.TypeRegistry = exports.TYPE_REGISTRY = void 0;
|
|
17
|
+
exports.AptosPlugin = exports.getRpcClient = exports.AptosNetwork = exports.AptosBindOptions = exports.AptosResourceContext = exports.AptosContext = exports.AptosAccountProcessor = exports.AptosBaseProcessor = exports.TypeRegistry = exports.TYPE_REGISTRY = void 0;
|
|
18
18
|
var type_registry_1 = require("./type-registry");
|
|
19
19
|
Object.defineProperty(exports, "TYPE_REGISTRY", { enumerable: true, get: function () { return type_registry_1.TYPE_REGISTRY; } });
|
|
20
20
|
Object.defineProperty(exports, "TypeRegistry", { enumerable: true, get: function () { return type_registry_1.TypeRegistry; } });
|
|
@@ -29,4 +29,6 @@ Object.defineProperty(exports, "AptosBindOptions", { enumerable: true, get: func
|
|
|
29
29
|
Object.defineProperty(exports, "AptosNetwork", { enumerable: true, get: function () { return network_1.AptosNetwork; } });
|
|
30
30
|
Object.defineProperty(exports, "getRpcClient", { enumerable: true, get: function () { return network_1.getRpcClient; } });
|
|
31
31
|
__exportStar(require("./api"), exports);
|
|
32
|
+
var aptos_plugin_1 = require("./aptos-plugin");
|
|
33
|
+
Object.defineProperty(exports, "AptosPlugin", { enumerable: true, get: function () { return aptos_plugin_1.AptosPlugin; } });
|
|
32
34
|
//# sourceMappingURL=index.js.map
|
package/lib/aptos/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/aptos/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAEA,iDAA6D;AAApD,8GAAA,aAAa,OAAA;AAAE,6GAAA,YAAY,OAAA;AAEpC,qDAA6E;AAApE,qHAAA,kBAAkB,OAAA;AAAE,wHAAA,qBAAqB,OAAA;AAClD,qCAA8D;AAArD,uGAAA,YAAY,OAAA;AAAE,+GAAA,oBAAoB,OAAA;AAC3C,qCAAwE;AAA/D,2GAAA,gBAAgB,OAAA;AAAE,uGAAA,YAAY,OAAA;AAAE,uGAAA,YAAY,OAAA;AACrD,wCAAqB","sourcesContent":["export type { Transaction_UserTransaction, TransactionPayload_EntryFunctionPayload } from 'aptos-sdk/src/generated'\nexport type { EventInstance, TypedEventInstance, TypedEntryFunctionPayload, TypedMoveResource } from './models'\nexport { TYPE_REGISTRY, TypeRegistry } from './type-registry'\nexport type { FunctionNameAndCallFilter, EventFilter, CallFilter, ArgumentsFilter } from './aptos-processor'\nexport { AptosBaseProcessor, AptosAccountProcessor } from './aptos-processor'\nexport { AptosContext, AptosResourceContext } from './context'\nexport { AptosBindOptions, AptosNetwork, getRpcClient } from './network'\nexport * from './api'\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/aptos/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAEA,iDAA6D;AAApD,8GAAA,aAAa,OAAA;AAAE,6GAAA,YAAY,OAAA;AAEpC,qDAA6E;AAApE,qHAAA,kBAAkB,OAAA;AAAE,wHAAA,qBAAqB,OAAA;AAClD,qCAA8D;AAArD,uGAAA,YAAY,OAAA;AAAE,+GAAA,oBAAoB,OAAA;AAC3C,qCAAwE;AAA/D,2GAAA,gBAAgB,OAAA;AAAE,uGAAA,YAAY,OAAA;AAAE,uGAAA,YAAY,OAAA;AACrD,wCAAqB;AAErB,+CAA4C;AAAnC,2GAAA,WAAW,OAAA","sourcesContent":["export type { Transaction_UserTransaction, TransactionPayload_EntryFunctionPayload } from 'aptos-sdk/src/generated'\nexport type { EventInstance, TypedEventInstance, TypedEntryFunctionPayload, TypedMoveResource } from './models'\nexport { TYPE_REGISTRY, TypeRegistry } from './type-registry'\nexport type { FunctionNameAndCallFilter, EventFilter, CallFilter, ArgumentsFilter } from './aptos-processor'\nexport { AptosBaseProcessor, AptosAccountProcessor } from './aptos-processor'\nexport { AptosContext, AptosResourceContext } from './context'\nexport { AptosBindOptions, AptosNetwork, getRpcClient } from './network'\nexport * from './api'\n\nexport { AptosPlugin } from './aptos-plugin'\n"]}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Plugin } from '../plugin';
|
|
2
|
+
import { DataBinding, HandlerType, ProcessConfigResponse, ProcessResult } from '../gen/processor/protos/processor';
|
|
3
|
+
export declare class EthPlugin implements Plugin {
|
|
4
|
+
name: string;
|
|
5
|
+
private eventHandlers;
|
|
6
|
+
private traceHandlers;
|
|
7
|
+
private blockHandlers;
|
|
8
|
+
configure(config: ProcessConfigResponse): void;
|
|
9
|
+
supportedHandlers: HandlerType[];
|
|
10
|
+
processBinding(request: DataBinding): Promise<ProcessResult>;
|
|
11
|
+
processLog(request: DataBinding): Promise<ProcessResult>;
|
|
12
|
+
processTrace(binding: DataBinding): Promise<ProcessResult>;
|
|
13
|
+
processBlock(binding: DataBinding): Promise<ProcessResult>;
|
|
14
|
+
}
|
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.EthPlugin = void 0;
|
|
7
|
+
const plugin_1 = require("../plugin");
|
|
8
|
+
const processor_1 = require("../gen/processor/protos/processor");
|
|
9
|
+
const service_1 = require("../service");
|
|
10
|
+
const nice_grpc_1 = require("nice-grpc");
|
|
11
|
+
const binds_1 = require("../binds");
|
|
12
|
+
const account_processor_1 = require("./account-processor");
|
|
13
|
+
const long_1 = __importDefault(require("long"));
|
|
14
|
+
class EthPlugin {
|
|
15
|
+
name = 'EthPlugin';
|
|
16
|
+
eventHandlers = [];
|
|
17
|
+
traceHandlers = [];
|
|
18
|
+
blockHandlers = [];
|
|
19
|
+
configure(config) {
|
|
20
|
+
for (const processor of binds_1.ProcessorState.INSTANCE.getValues()) {
|
|
21
|
+
// If server favor incremental update this need to change
|
|
22
|
+
// Start basic config for contract
|
|
23
|
+
const chainId = processor.getChainId();
|
|
24
|
+
// this.processorsByChainId.set(chainId, processor)
|
|
25
|
+
const contractConfig = {
|
|
26
|
+
processorType: service_1.USER_PROCESSOR,
|
|
27
|
+
contract: {
|
|
28
|
+
name: processor.config.name,
|
|
29
|
+
chainId: chainId.toString(),
|
|
30
|
+
address: processor.config.address,
|
|
31
|
+
abi: '',
|
|
32
|
+
},
|
|
33
|
+
intervalConfigs: [],
|
|
34
|
+
logConfigs: [],
|
|
35
|
+
traceConfigs: [],
|
|
36
|
+
startBlock: processor.config.startBlock,
|
|
37
|
+
endBlock: service_1.DEFAULT_MAX_BLOCK,
|
|
38
|
+
instructionConfig: undefined,
|
|
39
|
+
aptosEventConfigs: [],
|
|
40
|
+
aptosCallConfigs: [],
|
|
41
|
+
};
|
|
42
|
+
if (processor.config.endBlock) {
|
|
43
|
+
contractConfig.endBlock = processor.config.endBlock;
|
|
44
|
+
}
|
|
45
|
+
// Step 1. Prepare all the block handlers
|
|
46
|
+
for (const blockHandler of processor.blockHandlers) {
|
|
47
|
+
const handlerId = this.blockHandlers.push(blockHandler.handler) - 1;
|
|
48
|
+
// TODO wrap the block handler into one
|
|
49
|
+
contractConfig.intervalConfigs.push({
|
|
50
|
+
slot: 0,
|
|
51
|
+
slotInterval: blockHandler.blockInterval,
|
|
52
|
+
minutes: 0,
|
|
53
|
+
minutesInterval: blockHandler.timeIntervalInMinutes,
|
|
54
|
+
handlerId: handlerId,
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
// Step 2. Prepare all trace handlers
|
|
58
|
+
for (const traceHandler of processor.traceHandlers) {
|
|
59
|
+
const handlerId = this.traceHandlers.push(traceHandler.handler) - 1;
|
|
60
|
+
contractConfig.traceConfigs.push({
|
|
61
|
+
signature: traceHandler.signature,
|
|
62
|
+
handlerId: handlerId,
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
// Step 3. Prepare all the event handlers
|
|
66
|
+
for (const eventsHandler of processor.eventHandlers) {
|
|
67
|
+
// associate id with filter
|
|
68
|
+
const handlerId = this.eventHandlers.push(eventsHandler.handler) - 1;
|
|
69
|
+
const logConfig = {
|
|
70
|
+
handlerId: handlerId,
|
|
71
|
+
filters: [],
|
|
72
|
+
};
|
|
73
|
+
for (const filter of eventsHandler.filters) {
|
|
74
|
+
if (!filter.topics) {
|
|
75
|
+
throw new nice_grpc_1.ServerError(nice_grpc_1.Status.INVALID_ARGUMENT, 'Topic should not be null');
|
|
76
|
+
}
|
|
77
|
+
const logFilter = {
|
|
78
|
+
addressType: undefined,
|
|
79
|
+
address: contractConfig.contract?.address,
|
|
80
|
+
topics: [],
|
|
81
|
+
};
|
|
82
|
+
for (const ts of filter.topics) {
|
|
83
|
+
let hashes = [];
|
|
84
|
+
if (Array.isArray(ts)) {
|
|
85
|
+
hashes = hashes.concat(ts);
|
|
86
|
+
}
|
|
87
|
+
else if (ts) {
|
|
88
|
+
hashes.push(ts);
|
|
89
|
+
}
|
|
90
|
+
logFilter.topics.push({ hashes: hashes });
|
|
91
|
+
}
|
|
92
|
+
logConfig.filters.push(logFilter);
|
|
93
|
+
}
|
|
94
|
+
contractConfig.logConfigs.push(logConfig);
|
|
95
|
+
}
|
|
96
|
+
// Finish up a contract
|
|
97
|
+
config.contractConfigs.push(contractConfig);
|
|
98
|
+
}
|
|
99
|
+
// part 1.b prepare EVM account processors
|
|
100
|
+
for (const processor of account_processor_1.AccountProcessorState.INSTANCE.getValues()) {
|
|
101
|
+
const accountConfig = {
|
|
102
|
+
address: processor.config.address,
|
|
103
|
+
chainId: processor.getChainId().toString(),
|
|
104
|
+
startBlock: processor.config.startBlock ? long_1.default.fromValue(processor.config.startBlock) : long_1.default.ZERO,
|
|
105
|
+
aptosIntervalConfigs: [],
|
|
106
|
+
intervalConfigs: [],
|
|
107
|
+
logConfigs: [],
|
|
108
|
+
};
|
|
109
|
+
// TODO add interval
|
|
110
|
+
for (const eventsHandler of processor.eventHandlers) {
|
|
111
|
+
// associate id with filter
|
|
112
|
+
const handlerId = this.eventHandlers.push(eventsHandler.handler) - 1;
|
|
113
|
+
const logConfig = {
|
|
114
|
+
handlerId: handlerId,
|
|
115
|
+
filters: [],
|
|
116
|
+
};
|
|
117
|
+
for (const filter of eventsHandler.filters) {
|
|
118
|
+
if (!filter.topics) {
|
|
119
|
+
throw new nice_grpc_1.ServerError(nice_grpc_1.Status.INVALID_ARGUMENT, 'Topic should not be null');
|
|
120
|
+
}
|
|
121
|
+
const logFilter = {
|
|
122
|
+
addressType: filter.addressType,
|
|
123
|
+
address: filter.address,
|
|
124
|
+
topics: [],
|
|
125
|
+
};
|
|
126
|
+
for (const ts of filter.topics) {
|
|
127
|
+
let hashes = [];
|
|
128
|
+
if (Array.isArray(ts)) {
|
|
129
|
+
hashes = hashes.concat(ts);
|
|
130
|
+
}
|
|
131
|
+
else if (ts) {
|
|
132
|
+
hashes.push(ts);
|
|
133
|
+
}
|
|
134
|
+
logFilter.topics.push({ hashes: hashes });
|
|
135
|
+
}
|
|
136
|
+
logConfig.filters.push(logFilter);
|
|
137
|
+
}
|
|
138
|
+
accountConfig.logConfigs.push(logConfig);
|
|
139
|
+
}
|
|
140
|
+
config.accountConfigs.push(accountConfig);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
supportedHandlers = [processor_1.HandlerType.ETH_LOG, processor_1.HandlerType.ETH_BLOCK, processor_1.HandlerType.ETH_TRACE];
|
|
144
|
+
processBinding(request) {
|
|
145
|
+
// return Promise.resolve(undefined);
|
|
146
|
+
switch (request.handlerType) {
|
|
147
|
+
case processor_1.HandlerType.ETH_LOG:
|
|
148
|
+
return this.processLog(request);
|
|
149
|
+
case processor_1.HandlerType.ETH_TRACE:
|
|
150
|
+
return this.processTrace(request);
|
|
151
|
+
case processor_1.HandlerType.ETH_BLOCK:
|
|
152
|
+
return this.processBlock(request);
|
|
153
|
+
default:
|
|
154
|
+
throw new nice_grpc_1.ServerError(nice_grpc_1.Status.INVALID_ARGUMENT, 'No handle type registered ' + request.handlerType);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
async processLog(request) {
|
|
158
|
+
if (!request.data) {
|
|
159
|
+
throw new nice_grpc_1.ServerError(nice_grpc_1.Status.INVALID_ARGUMENT, "Log can't be null");
|
|
160
|
+
}
|
|
161
|
+
const promises = [];
|
|
162
|
+
let log;
|
|
163
|
+
if (request.data.ethLog) {
|
|
164
|
+
log = request.data.ethLog.log;
|
|
165
|
+
}
|
|
166
|
+
else {
|
|
167
|
+
const jsonString = (0, service_1.Utf8ArrayToStr)(request.data.raw);
|
|
168
|
+
log = JSON.parse(jsonString);
|
|
169
|
+
}
|
|
170
|
+
for (const handlerId of request.handlerIds) {
|
|
171
|
+
const handler = this.eventHandlers[handlerId];
|
|
172
|
+
promises.push(handler(log).catch((e) => {
|
|
173
|
+
throw new nice_grpc_1.ServerError(nice_grpc_1.Status.INTERNAL, 'error processing log: ' + JSON.stringify(log) + '\n' + (0, service_1.errorString)(e));
|
|
174
|
+
}));
|
|
175
|
+
}
|
|
176
|
+
return (0, service_1.mergeProcessResults)(await Promise.all(promises));
|
|
177
|
+
}
|
|
178
|
+
async processTrace(binding) {
|
|
179
|
+
if (!binding.data) {
|
|
180
|
+
throw new nice_grpc_1.ServerError(nice_grpc_1.Status.INVALID_ARGUMENT, "Trace can't be empty");
|
|
181
|
+
}
|
|
182
|
+
let trace;
|
|
183
|
+
if (binding.data.ethTrace?.trace) {
|
|
184
|
+
trace = binding.data.ethTrace.trace;
|
|
185
|
+
}
|
|
186
|
+
else {
|
|
187
|
+
const jsonString = (0, service_1.Utf8ArrayToStr)(binding.data.raw);
|
|
188
|
+
trace = JSON.parse(jsonString);
|
|
189
|
+
}
|
|
190
|
+
const promises = [];
|
|
191
|
+
for (const handlerId of binding.handlerIds) {
|
|
192
|
+
promises.push(this.traceHandlers[handlerId](trace).catch((e) => {
|
|
193
|
+
throw new nice_grpc_1.ServerError(nice_grpc_1.Status.INTERNAL, 'error processing trace: ' + JSON.stringify(trace) + '\n' + (0, service_1.errorString)(e));
|
|
194
|
+
}));
|
|
195
|
+
}
|
|
196
|
+
return (0, service_1.mergeProcessResults)(await Promise.all(promises));
|
|
197
|
+
}
|
|
198
|
+
async processBlock(binding) {
|
|
199
|
+
if (!binding.data) {
|
|
200
|
+
throw new nice_grpc_1.ServerError(nice_grpc_1.Status.INVALID_ARGUMENT, "Block can't be empty");
|
|
201
|
+
}
|
|
202
|
+
let block;
|
|
203
|
+
if (binding.data.ethBlock?.block) {
|
|
204
|
+
block = binding.data.ethBlock.block;
|
|
205
|
+
}
|
|
206
|
+
else {
|
|
207
|
+
const jsonString = (0, service_1.Utf8ArrayToStr)(binding.data.raw);
|
|
208
|
+
block = JSON.parse(jsonString);
|
|
209
|
+
}
|
|
210
|
+
const promises = [];
|
|
211
|
+
for (const handlerId of binding.handlerIds) {
|
|
212
|
+
promises.push(this.blockHandlers[handlerId](block).catch((e) => {
|
|
213
|
+
throw new nice_grpc_1.ServerError(nice_grpc_1.Status.INTERNAL, 'error processing block: ' + block.number + '\n' + (0, service_1.errorString)(e));
|
|
214
|
+
}));
|
|
215
|
+
}
|
|
216
|
+
return (0, service_1.mergeProcessResults)(await Promise.all(promises));
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
exports.EthPlugin = EthPlugin;
|
|
220
|
+
plugin_1.PluginManager.INSTANCE.register(new EthPlugin());
|
|
221
|
+
//# sourceMappingURL=eth-plugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"eth-plugin.js","sourceRoot":"","sources":["../../src/core/eth-plugin.ts"],"names":[],"mappings":";;;;;;AAAA,sCAAiD;AACjD,iEAS0C;AAC1C,wCAAgH;AAEhH,yCAA+C;AAG/C,oCAAyC;AACzC,2DAA2D;AAC3D,gDAAuB;AAEvB,MAAa,SAAS;IACpB,IAAI,GAAW,WAAW,CAAA;IAElB,aAAa,GAA+C,EAAE,CAAA;IAC9D,aAAa,GAAiD,EAAE,CAAA;IAChE,aAAa,GAAiD,EAAE,CAAA;IAExE,SAAS,CAAC,MAA6B;QACrC,KAAK,MAAM,SAAS,IAAI,sBAAc,CAAC,QAAQ,CAAC,SAAS,EAAE,EAAE;YAC3D,yDAAyD;YACzD,kCAAkC;YAClC,MAAM,OAAO,GAAG,SAAS,CAAC,UAAU,EAAE,CAAA;YACtC,mDAAmD;YAEnD,MAAM,cAAc,GAAmB;gBACrC,aAAa,EAAE,wBAAc;gBAC7B,QAAQ,EAAE;oBACR,IAAI,EAAE,SAAS,CAAC,MAAM,CAAC,IAAI;oBAC3B,OAAO,EAAE,OAAO,CAAC,QAAQ,EAAE;oBAC3B,OAAO,EAAE,SAAS,CAAC,MAAM,CAA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AG,KAAK,CAAC,MAAM,GAAG,IAAI,GAAG,IAAA,qBAAW,EAAC,CAAC,CAAC,CAAC,CAAA;YAC3G,CAAC,CAAC,CACH,CAAA;SACF;QACD,OAAO,IAAA,6BAAmB,EAAC,MAAM,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAA;IACzD,CAAC;CACF;AAxOD,8BAwOC;AAED,sBAAa,CAAC,QAAQ,CAAC,QAAQ,CAAC,IAAI,SAAS,EAAE,CAAC,CAAA","sourcesContent":["import { Plugin, PluginManager } from '../plugin'\nimport {\n AccountConfig,\n ContractConfig,\n DataBinding,\n HandlerType,\n LogFilter,\n LogHandlerConfig,\n ProcessConfigResponse,\n ProcessResult,\n} from '../gen/processor/protos/processor'\nimport { DEFAULT_MAX_BLOCK, errorString, mergeProcessResults, USER_PROCESSOR, Utf8ArrayToStr } from '../service'\n\nimport { ServerError, Status } from 'nice-grpc'\nimport { Block, Log } from '@ethersproject/abstract-provider'\nimport { Trace } from '@sentio/sdk'\nimport { ProcessorState } from '../binds'\nimport { AccountProcessorState } from './account-processor'\nimport Long from 'long'\n\nexport class EthPlugin implements Plugin {\n name: string = 'EthPlugin'\n\n private eventHandlers: ((event: Log) => Promise<ProcessResult>)[] = []\n private traceHandlers: ((trace: Trace) => Promise<ProcessResult>)[] = []\n private blockHandlers: ((block: Block) => Promise<ProcessResult>)[] = []\n\n configure(config: ProcessConfigResponse): void {\n for (const processor of ProcessorState.INSTANCE.getValues()) {\n // If server favor incremental update this need to change\n // Start basic config for contract\n const chainId = processor.getChainId()\n // this.processorsByChainId.set(chainId, processor)\n\n const contractConfig: ContractConfig = {\n processorType: USER_PROCESSOR,\n contract: {\n name: processor.config.name,\n chainId: chainId.toString(),\n address: processor.config.address,\n abi: '',\n },\n intervalConfigs: [],\n logConfigs: [],\n traceConfigs: [],\n startBlock: processor.config.startBlock,\n endBlock: DEFAULT_MAX_BLOCK,\n instructionConfig: undefined,\n aptosEventConfigs: [],\n aptosCallConfigs: [],\n }\n if (processor.config.endBlock) {\n contractConfig.endBlock = processor.config.endBlock\n }\n\n // Step 1. Prepare all the block handlers\n for (const blockHandler of processor.blockHandlers) {\n const handlerId = this.blockHandlers.push(blockHandler.handler) - 1\n // TODO wrap the block handler into one\n\n contractConfig.intervalConfigs.push({\n slot: 0,\n slotInterval: blockHandler.blockInterval,\n minutes: 0,\n minutesInterval: blockHandler.timeIntervalInMinutes,\n handlerId: handlerId,\n })\n }\n\n // Step 2. Prepare all trace handlers\n for (const traceHandler of processor.traceHandlers) {\n const handlerId = this.traceHandlers.push(traceHandler.handler) - 1\n contractConfig.traceConfigs.push({\n signature: traceHandler.signature,\n handlerId: handlerId,\n })\n }\n\n // Step 3. Prepare all the event handlers\n for (const eventsHandler of processor.eventHandlers) {\n // associate id with filter\n const handlerId = this.eventHandlers.push(eventsHandler.handler) - 1\n const logConfig: LogHandlerConfig = {\n handlerId: handlerId,\n filters: [],\n }\n\n for (const filter of eventsHandler.filters) {\n if (!filter.topics) {\n throw new ServerError(Status.INVALID_ARGUMENT, 'Topic should not be null')\n }\n const logFilter: LogFilter = {\n addressType: undefined,\n address: contractConfig.contract?.address,\n topics: [],\n }\n\n for (const ts of filter.topics) {\n let hashes: string[] = []\n if (Array.isArray(ts)) {\n hashes = hashes.concat(ts)\n } else if (ts) {\n hashes.push(ts)\n }\n logFilter.topics.push({ hashes: hashes })\n }\n logConfig.filters.push(logFilter)\n }\n contractConfig.logConfigs.push(logConfig)\n }\n\n // Finish up a contract\n config.contractConfigs.push(contractConfig)\n }\n\n // part 1.b prepare EVM account processors\n for (const processor of AccountProcessorState.INSTANCE.getValues()) {\n const accountConfig: AccountConfig = {\n address: processor.config.address,\n chainId: processor.getChainId().toString(),\n startBlock: processor.config.startBlock ? Long.fromValue(processor.config.startBlock) : Long.ZERO,\n aptosIntervalConfigs: [],\n intervalConfigs: [],\n logConfigs: [],\n }\n // TODO add interval\n for (const eventsHandler of processor.eventHandlers) {\n // associate id with filter\n const handlerId = this.eventHandlers.push(eventsHandler.handler) - 1\n const logConfig: LogHandlerConfig = {\n handlerId: handlerId,\n filters: [],\n }\n\n for (const filter of eventsHandler.filters) {\n if (!filter.topics) {\n throw new ServerError(Status.INVALID_ARGUMENT, 'Topic should not be null')\n }\n const logFilter: LogFilter = {\n addressType: filter.addressType,\n address: filter.address,\n topics: [],\n }\n\n for (const ts of filter.topics) {\n let hashes: string[] = []\n if (Array.isArray(ts)) {\n hashes = hashes.concat(ts)\n } else if (ts) {\n hashes.push(ts)\n }\n logFilter.topics.push({ hashes: hashes })\n }\n logConfig.filters.push(logFilter)\n }\n accountConfig.logConfigs.push(logConfig)\n }\n\n config.accountConfigs.push(accountConfig)\n }\n }\n\n supportedHandlers = [HandlerType.ETH_LOG, HandlerType.ETH_BLOCK, HandlerType.ETH_TRACE]\n\n processBinding(request: DataBinding): Promise<ProcessResult> {\n // return Promise.resolve(undefined);\n switch (request.handlerType) {\n case HandlerType.ETH_LOG:\n return this.processLog(request)\n case HandlerType.ETH_TRACE:\n return this.processTrace(request)\n case HandlerType.ETH_BLOCK:\n return this.processBlock(request)\n default:\n throw new ServerError(Status.INVALID_ARGUMENT, 'No handle type registered ' + request.handlerType)\n }\n }\n\n async processLog(request: DataBinding): Promise<ProcessResult> {\n if (!request.data) {\n throw new ServerError(Status.INVALID_ARGUMENT, \"Log can't be null\")\n }\n\n const promises: Promise<ProcessResult>[] = []\n let log: Log\n if (request.data.ethLog) {\n log = request.data.ethLog.log as Log\n } else {\n const jsonString = Utf8ArrayToStr(request.data.raw)\n log = JSON.parse(jsonString)\n }\n\n for (const handlerId of request.handlerIds) {\n const handler = this.eventHandlers[handlerId]\n promises.push(\n handler(log).catch((e) => {\n throw new ServerError(Status.INTERNAL, 'error processing log: ' + JSON.stringify(log) + '\\n' + errorString(e))\n })\n )\n }\n return mergeProcessResults(await Promise.all(promises))\n }\n\n async processTrace(binding: DataBinding): Promise<ProcessResult> {\n if (!binding.data) {\n throw new ServerError(Status.INVALID_ARGUMENT, \"Trace can't be empty\")\n }\n let trace: Trace\n if (binding.data.ethTrace?.trace) {\n trace = binding.data.ethTrace.trace as Trace\n } else {\n const jsonString = Utf8ArrayToStr(binding.data.raw)\n trace = JSON.parse(jsonString)\n }\n\n const promises: Promise<ProcessResult>[] = []\n\n for (const handlerId of binding.handlerIds) {\n promises.push(\n this.traceHandlers[handlerId](trace).catch((e) => {\n throw new ServerError(\n Status.INTERNAL,\n 'error processing trace: ' + JSON.stringify(trace) + '\\n' + errorString(e)\n )\n })\n )\n }\n return mergeProcessResults(await Promise.all(promises))\n }\n\n async processBlock(binding: DataBinding): Promise<ProcessResult> {\n if (!binding.data) {\n throw new ServerError(Status.INVALID_ARGUMENT, \"Block can't be empty\")\n }\n let block: Block\n if (binding.data.ethBlock?.block) {\n block = binding.data.ethBlock.block as Block\n } else {\n const jsonString = Utf8ArrayToStr(binding.data.raw)\n block = JSON.parse(jsonString)\n }\n\n const promises: Promise<ProcessResult>[] = []\n for (const handlerId of binding.handlerIds) {\n promises.push(\n this.blockHandlers[handlerId](block).catch((e) => {\n throw new ServerError(Status.INTERNAL, 'error processing block: ' + block.number + '\\n' + errorString(e))\n })\n )\n }\n return mergeProcessResults(await Promise.all(promises))\n }\n}\n\nPluginManager.INSTANCE.register(new EthPlugin())\n"]}
|
package/lib/core/index.d.ts
CHANGED
|
@@ -12,3 +12,6 @@ export { SolanaContext } from './solana-context';
|
|
|
12
12
|
export { SolanaBindOptions } from './solana-options';
|
|
13
13
|
export { SolanaBaseProcessor } from './solana-processor';
|
|
14
14
|
export type { TypedCallTrace, Trace } from './trace';
|
|
15
|
+
export { EthPlugin } from './eth-plugin';
|
|
16
|
+
export { SolanaPlugin } from './solana-plugin';
|
|
17
|
+
export { SuiPlugin } from './sui-plugin';
|
package/lib/core/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SolanaBaseProcessor = exports.SolanaBindOptions = exports.SolanaContext = exports.SuiBindOptions = exports.SuiBaseProcessor = exports.BaseProcessorTemplate = exports.GenericProcessor = exports.BaseProcessor = exports.BindOptions = exports.toMetricValue = exports.toBigInteger = exports.AccountEventTracker = exports.EventTracker = exports.MetricOptions = exports.Gauge = exports.Counter = exports.GaugeBinding = exports.Meter = exports.CounterBinding = exports.BoundContractView = exports.ContractView = exports.ContractContext = exports.BigDecimal = void 0;
|
|
3
|
+
exports.SuiPlugin = exports.SolanaPlugin = exports.EthPlugin = exports.SolanaBaseProcessor = exports.SolanaBindOptions = exports.SolanaContext = exports.SuiBindOptions = exports.SuiBaseProcessor = exports.BaseProcessorTemplate = exports.GenericProcessor = exports.BaseProcessor = exports.BindOptions = exports.toMetricValue = exports.toBigInteger = exports.AccountEventTracker = exports.EventTracker = exports.MetricOptions = exports.Gauge = exports.Counter = exports.GaugeBinding = exports.Meter = exports.CounterBinding = exports.BoundContractView = exports.ContractView = exports.ContractContext = exports.BigDecimal = void 0;
|
|
4
4
|
var big_decimal_1 = require("./big-decimal");
|
|
5
5
|
Object.defineProperty(exports, "BigDecimal", { enumerable: true, get: function () { return big_decimal_1.BigDecimal; } });
|
|
6
6
|
var context_1 = require("./context");
|
|
@@ -37,4 +37,10 @@ var solana_options_1 = require("./solana-options");
|
|
|
37
37
|
Object.defineProperty(exports, "SolanaBindOptions", { enumerable: true, get: function () { return solana_options_1.SolanaBindOptions; } });
|
|
38
38
|
var solana_processor_1 = require("./solana-processor");
|
|
39
39
|
Object.defineProperty(exports, "SolanaBaseProcessor", { enumerable: true, get: function () { return solana_processor_1.SolanaBaseProcessor; } });
|
|
40
|
+
var eth_plugin_1 = require("./eth-plugin");
|
|
41
|
+
Object.defineProperty(exports, "EthPlugin", { enumerable: true, get: function () { return eth_plugin_1.EthPlugin; } });
|
|
42
|
+
var solana_plugin_1 = require("./solana-plugin");
|
|
43
|
+
Object.defineProperty(exports, "SolanaPlugin", { enumerable: true, get: function () { return solana_plugin_1.SolanaPlugin; } });
|
|
44
|
+
var sui_plugin_1 = require("./sui-plugin");
|
|
45
|
+
Object.defineProperty(exports, "SuiPlugin", { enumerable: true, get: function () { return sui_plugin_1.SuiPlugin; } });
|
|
40
46
|
//# sourceMappingURL=index.js.map
|