@sentio/sdk 2.13.7 → 2.14.0-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/lib/aptos/aptos-plugin.d.ts +8 -4
- package/lib/aptos/aptos-plugin.js +17 -9
- package/lib/aptos/aptos-plugin.js.map +1 -1
- package/lib/core/base-context.d.ts +4 -2
- package/lib/core/base-context.js +3 -0
- package/lib/core/base-context.js.map +1 -1
- package/lib/eth/base-processor-template.d.ts +7 -1
- package/lib/eth/base-processor-template.js +14 -2
- package/lib/eth/base-processor-template.js.map +1 -1
- package/lib/eth/eth-plugin.d.ts +9 -5
- package/lib/eth/eth-plugin.js +38 -16
- package/lib/eth/eth-plugin.js.map +1 -1
- package/lib/sui/sui-plugin.d.ts +8 -4
- package/lib/sui/sui-plugin.js +17 -9
- package/lib/sui/sui-plugin.js.map +1 -1
- package/package.json +3 -3
- package/src/aptos/aptos-plugin.ts +22 -10
- package/src/core/base-context.ts +5 -2
- package/src/eth/base-processor-template.ts +15 -2
- package/src/eth/eth-plugin.ts +57 -22
- package/src/sui/sui-plugin.ts +23 -10
@@ -1,10 +1,13 @@
|
|
1
1
|
import { Plugin } from '@sentio/runtime';
|
2
|
-
import { DataBinding, HandlerType, ProcessConfigResponse, ProcessResult, StartRequest } from '@sentio/protos';
|
2
|
+
import { Data_AptCall, Data_AptEvent, Data_AptResource, DataBinding, HandlerType, ProcessConfigResponse, ProcessResult, StartRequest } from '@sentio/protos';
|
3
|
+
interface Handlers {
|
4
|
+
aptosEventHandlers: ((event: Data_AptEvent) => Promise<ProcessResult>)[];
|
5
|
+
aptosCallHandlers: ((func: Data_AptCall) => Promise<ProcessResult>)[];
|
6
|
+
aptosResourceHandlers: ((resourceWithVersion: Data_AptResource) => Promise<ProcessResult>)[];
|
7
|
+
}
|
3
8
|
export declare class AptosPlugin extends Plugin {
|
4
9
|
name: string;
|
5
|
-
|
6
|
-
private aptosCallHandlers;
|
7
|
-
private aptosResourceHandlers;
|
10
|
+
handlers: Handlers;
|
8
11
|
start(start: StartRequest): Promise<void>;
|
9
12
|
configure(config: ProcessConfigResponse): Promise<void>;
|
10
13
|
supportedHandlers: HandlerType[];
|
@@ -13,3 +16,4 @@ export declare class AptosPlugin extends Plugin {
|
|
13
16
|
processAptosResource(binding: DataBinding): Promise<ProcessResult>;
|
14
17
|
processAptosFunctionCall(binding: DataBinding): Promise<ProcessResult>;
|
15
18
|
}
|
19
|
+
export {};
|
@@ -6,13 +6,20 @@ import { initCoinList } from './ext/coin.js';
|
|
6
6
|
import { validateAndNormalizeAddress } from './utils.js';
|
7
7
|
export class AptosPlugin extends Plugin {
|
8
8
|
name = 'AptosPlugin';
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
handlers = {
|
10
|
+
aptosEventHandlers: [],
|
11
|
+
aptosCallHandlers: [],
|
12
|
+
aptosResourceHandlers: [],
|
13
|
+
};
|
12
14
|
async start(start) {
|
13
15
|
await initCoinList();
|
14
16
|
}
|
15
17
|
async configure(config) {
|
18
|
+
const handlers = {
|
19
|
+
aptosEventHandlers: [],
|
20
|
+
aptosCallHandlers: [],
|
21
|
+
aptosResourceHandlers: [],
|
22
|
+
};
|
16
23
|
for (const aptosProcessor of AptosProcessorState.INSTANCE.getValues()) {
|
17
24
|
const contractConfig = ContractConfig.fromPartial({
|
18
25
|
processorType: USER_PROCESSOR,
|
@@ -26,7 +33,7 @@ export class AptosPlugin extends Plugin {
|
|
26
33
|
});
|
27
34
|
// 1. Prepare event handlers
|
28
35
|
for (const handler of aptosProcessor.eventHandlers) {
|
29
|
-
const handlerId =
|
36
|
+
const handlerId = handlers.aptosEventHandlers.push(handler.handler) - 1;
|
30
37
|
const eventHandlerConfig = {
|
31
38
|
filters: handler.filters.map((f) => {
|
32
39
|
return {
|
@@ -41,7 +48,7 @@ export class AptosPlugin extends Plugin {
|
|
41
48
|
}
|
42
49
|
// 2. Prepare function handlers
|
43
50
|
for (const handler of aptosProcessor.callHandlers) {
|
44
|
-
const handlerId =
|
51
|
+
const handlerId = handlers.aptosCallHandlers.push(handler.handler) - 1;
|
45
52
|
const functionHandlerConfig = {
|
46
53
|
filters: handler.filters.map((filter) => {
|
47
54
|
return {
|
@@ -65,7 +72,7 @@ export class AptosPlugin extends Plugin {
|
|
65
72
|
startBlock: aptosProcessor.config.startVersion,
|
66
73
|
});
|
67
74
|
for (const handler of aptosProcessor.resourcesHandlers) {
|
68
|
-
const handlerId =
|
75
|
+
const handlerId = handlers.aptosResourceHandlers.push(handler.handler) - 1;
|
69
76
|
// TODO move to only use moveIntervalConfigs
|
70
77
|
accountConfig.aptosIntervalConfigs.push({
|
71
78
|
intervalConfig: {
|
@@ -93,6 +100,7 @@ export class AptosPlugin extends Plugin {
|
|
93
100
|
}
|
94
101
|
config.accountConfigs.push(accountConfig);
|
95
102
|
}
|
103
|
+
this.handlers = handlers;
|
96
104
|
}
|
97
105
|
supportedHandlers = [HandlerType.APT_CALL, HandlerType.APT_RESOURCE, HandlerType.APT_EVENT];
|
98
106
|
async processBinding(request) {
|
@@ -115,7 +123,7 @@ export class AptosPlugin extends Plugin {
|
|
115
123
|
const event = binding.data.aptEvent;
|
116
124
|
for (const handlerId of binding.handlerIds) {
|
117
125
|
// only support aptos event for now
|
118
|
-
promises.push(this.aptosEventHandlers[handlerId](event).catch((e) => {
|
126
|
+
promises.push(this.handlers.aptosEventHandlers[handlerId](event).catch((e) => {
|
119
127
|
throw new ServerError(Status.INTERNAL, 'error processing event: ' + JSON.stringify(event) + '\n' + errorString(e));
|
120
128
|
}));
|
121
129
|
}
|
@@ -128,7 +136,7 @@ export class AptosPlugin extends Plugin {
|
|
128
136
|
const resource = binding.data.aptResource;
|
129
137
|
const promises = [];
|
130
138
|
for (const handlerId of binding.handlerIds) {
|
131
|
-
promises.push(this.aptosResourceHandlers[handlerId](resource).catch((e) => {
|
139
|
+
promises.push(this.handlers.aptosResourceHandlers[handlerId](resource).catch((e) => {
|
132
140
|
throw new ServerError(Status.INTERNAL, 'error processing resource: ' + JSON.stringify(resource) + '\n' + errorString(e));
|
133
141
|
}));
|
134
142
|
}
|
@@ -142,7 +150,7 @@ export class AptosPlugin extends Plugin {
|
|
142
150
|
const promises = [];
|
143
151
|
for (const handlerId of binding.handlerIds) {
|
144
152
|
// only support aptos call for now
|
145
|
-
const promise = this.aptosCallHandlers[handlerId](call).catch((e) => {
|
153
|
+
const promise = this.handlers.aptosCallHandlers[handlerId](call).catch((e) => {
|
146
154
|
throw new ServerError(Status.INTERNAL, 'error processing call: ' + JSON.stringify(call) + '\n' + errorString(e));
|
147
155
|
});
|
148
156
|
promises.push(promise);
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"aptos-plugin.js","sourceRoot":"","sources":["../../src/aptos/aptos-plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,mBAAmB,EAAE,MAAM,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAA;AACzG,OAAO,EACL,aAAa,EACb,cAAc,EAKd,WAAW,EAMX,8BAA8B,GAC/B,MAAM,gBAAgB,CAAA;AAEvB,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,WAAW,CAAA;AAE/C,OAAO,EAAE,0BAA0B,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAA;AAEtF,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAA;AAC5C,OAAO,EAAE,2BAA2B,EAAE,MAAM,YAAY,CAAA;AAExD,MAAM,OAAO,WAAY,SAAQ,MAAM;IACrC,IAAI,GAAW,aAAa,CAAA;IAEpB,kBAAkB,GAAyD,EAAE,CAAA;IAC7E,iBAAiB,GAAuD,EAAE,CAAA;IAC1E,qBAAqB,GAA0E,EAAE,CAAA;IAEzG,KAAK,CAAC,KAAK,CAAC,KAAmB;QAC7B,MAAM,YAAY,EAAE,CAAA;IACtB,CAAC;IAED,KAAK,CAAC,SAAS,CAAC,MAA6B;QAC3C,KAAK,MAAM,cAAc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O,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAA;IACzD,CAAC;IAED,KAAK,CAAC,wBAAwB,CAAC,OAAoB;QACjD,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,OAAO,EAAE;YAC1B,MAAM,IAAI,WAAW,CAAC,MAAM,CAAC,gBAAgB,EAAE,qBAAqB,CAAC,CAAA;SACtE;QACD,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,OAAO,CAAA;QAEjC,MAAM,QAAQ,GAA6B,EAAE,CAAA;QAC7C,KAAK,MAAM,SAAS,IAAI,OAAO,CAAC,UAAU,EAAE;YAC1C,kCAAkC;YAClC,MAAM,OAAO,GAAG,IAAI,CAAC,iBAAiB,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE;gBAClE,MAAM,IAAI,WAAW,CAAC,MAAM,CAAC,QAAQ,EAAE,yBAAyB,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,GAAG,IAAI,GAAG,WAAW,CAAC,CAAC,CAAC,CAAC,CAAA;YAClH,CAAC,CAAC,CAAA;YACF,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;SACvB;QACD,OAAO,mBAAmB,CAAC,MAAM,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAA;IACzD,CAAC;CACF;AAED,aAAa,CAAC,QAAQ,CAAC,QAAQ,CAAC,IAAI,WAAW,EAAE,CAAC,CAAA","sourcesContent":["import { errorString, mergeProcessResults, Plugin, PluginManager, USER_PROCESSOR } from '@sentio/runtime'\nimport {\n AccountConfig,\n ContractConfig,\n Data_AptCall,\n Data_AptEvent,\n Data_AptResource,\n DataBinding,\n HandlerType,\n MoveCallHandlerConfig,\n MoveEventHandlerConfig,\n ProcessConfigResponse,\n ProcessResult,\n StartRequest,\n MoveOnIntervalConfig_OwnerType,\n} from '@sentio/protos'\n\nimport { ServerError, Status } from 'nice-grpc'\n\nimport { AptosAccountProcessorState, AptosProcessorState } from './aptos-processor.js'\n\nimport { initCoinList } from './ext/coin.js'\nimport { validateAndNormalizeAddress } from './utils.js'\n\nexport class AptosPlugin extends Plugin {\n name: string = 'AptosPlugin'\n\n private aptosEventHandlers: ((event: Data_AptEvent) => Promise<ProcessResult>)[] = []\n private aptosCallHandlers: ((func: Data_AptCall) => Promise<ProcessResult>)[] = []\n private aptosResourceHandlers: ((resourceWithVersion: Data_AptResource) => Promise<ProcessResult>)[] = []\n\n async start(start: StartRequest) {\n await initCoinList()\n }\n\n async configure(config: ProcessConfigResponse) {\n for (const aptosProcessor of AptosProcessorState.INSTANCE.getValues()) {\n const contractConfig = ContractConfig.fromPartial({\n processorType: USER_PROCESSOR,\n contract: {\n name: aptosProcessor.moduleName,\n chainId: aptosProcessor.getChainId(),\n address: validateAndNormalizeAddress(aptosProcessor.config.address),\n abi: '',\n },\n startBlock: aptosProcessor.config.startVersion,\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: MoveEventHandlerConfig = {\n filters: handler.filters.map((f) => {\n return {\n type: f.type,\n account: f.account || '',\n }\n }),\n fetchConfig: handler.fetchConfig,\n handlerId,\n }\n contractConfig.moveEventConfigs.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: MoveCallHandlerConfig = {\n filters: handler.filters.map((filter) => {\n return {\n function: filter.function,\n typeArguments: filter.typeArguments || [],\n withTypeArguments: !!filter.typeArguments,\n includeFailed: filter.includeFailed || false,\n }\n }),\n fetchConfig: handler.fetchConfig,\n handlerId,\n }\n contractConfig.moveCallConfigs.push(functionHandlerConfig)\n }\n config.contractConfigs.push(contractConfig)\n }\n\n for (const aptosProcessor of AptosAccountProcessorState.INSTANCE.getValues()) {\n const accountConfig = AccountConfig.fromPartial({\n address: validateAndNormalizeAddress(aptosProcessor.config.address),\n chainId: aptosProcessor.getChainId(),\n startBlock: aptosProcessor.config.startVersion,\n })\n for (const handler of aptosProcessor.resourcesHandlers) {\n const handlerId = this.aptosResourceHandlers.push(handler.handler) - 1\n // TODO move to only use moveIntervalConfigs\n accountConfig.aptosIntervalConfigs.push({\n intervalConfig: {\n handlerId: handlerId,\n minutes: 0,\n minutesInterval: handler.timeIntervalInMinutes,\n slot: 0,\n slotInterval: handler.versionInterval,\n fetchConfig: undefined,\n },\n type: handler.type || '',\n })\n\n accountConfig.moveIntervalConfigs.push({\n intervalConfig: {\n handlerId: handlerId,\n minutes: 0,\n minutesInterval: handler.timeIntervalInMinutes,\n slot: 0,\n slotInterval: handler.versionInterval,\n fetchConfig: undefined,\n },\n type: handler.type || '',\n ownerType: MoveOnIntervalConfig_OwnerType.ADDRESS,\n })\n }\n config.accountConfigs.push(accountConfig)\n }\n }\n\n supportedHandlers = [HandlerType.APT_CALL, HandlerType.APT_RESOURCE, HandlerType.APT_EVENT]\n\n async 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 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?.aptEvent) {\n throw new ServerError(Status.INVALID_ARGUMENT, \"Event can't be empty\")\n }\n const promises: Promise<ProcessResult>[] = []\n const event = binding.data.aptEvent\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?.aptResource) {\n throw new ServerError(Status.INVALID_ARGUMENT, \"Resource can't be empty\")\n }\n const resource = binding.data.aptResource\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 resource: ' + 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?.aptCall) {\n throw new ServerError(Status.INVALID_ARGUMENT, \"Call can't be empty\")\n }\n const call = binding.data.aptCall\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"]}
|
1
|
+
{"version":3,"file":"aptos-plugin.js","sourceRoot":"","sources":["../../src/aptos/aptos-plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,mBAAmB,EAAE,MAAM,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAA;AACzG,OAAO,EACL,aAAa,EACb,cAAc,EAKd,WAAW,EAMX,8BAA8B,GAC/B,MAAM,gBAAgB,CAAA;AAEvB,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,WAAW,CAAA;AAE/C,OAAO,EAAE,0BAA0B,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAA;AAEtF,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAA;AAC5C,OAAO,EAAE,2BAA2B,EAAE,MAAM,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ClH,CAAC,CAAC,CAAA;YACF,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;SACvB;QACD,OAAO,mBAAmB,CAAC,MAAM,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAA;IACzD,CAAC;CACF;AAED,aAAa,CAAC,QAAQ,CAAC,QAAQ,CAAC,IAAI,WAAW,EAAE,CAAC,CAAA","sourcesContent":["import { errorString, mergeProcessResults, Plugin, PluginManager, USER_PROCESSOR } from '@sentio/runtime'\nimport {\n AccountConfig,\n ContractConfig,\n Data_AptCall,\n Data_AptEvent,\n Data_AptResource,\n DataBinding,\n HandlerType,\n MoveCallHandlerConfig,\n MoveEventHandlerConfig,\n ProcessConfigResponse,\n ProcessResult,\n StartRequest,\n MoveOnIntervalConfig_OwnerType,\n} from '@sentio/protos'\n\nimport { ServerError, Status } from 'nice-grpc'\n\nimport { AptosAccountProcessorState, AptosProcessorState } from './aptos-processor.js'\n\nimport { initCoinList } from './ext/coin.js'\nimport { validateAndNormalizeAddress } from './utils.js'\n\ninterface Handlers {\n aptosEventHandlers: ((event: Data_AptEvent) => Promise<ProcessResult>)[]\n aptosCallHandlers: ((func: Data_AptCall) => Promise<ProcessResult>)[]\n aptosResourceHandlers: ((resourceWithVersion: Data_AptResource) => Promise<ProcessResult>)[]\n}\nexport class AptosPlugin extends Plugin {\n name: string = 'AptosPlugin'\n handlers: Handlers = {\n aptosEventHandlers: [],\n aptosCallHandlers: [],\n aptosResourceHandlers: [],\n }\n\n async start(start: StartRequest) {\n await initCoinList()\n }\n\n async configure(config: ProcessConfigResponse) {\n const handlers: Handlers = {\n aptosEventHandlers: [],\n aptosCallHandlers: [],\n aptosResourceHandlers: [],\n }\n for (const aptosProcessor of AptosProcessorState.INSTANCE.getValues()) {\n const contractConfig = ContractConfig.fromPartial({\n processorType: USER_PROCESSOR,\n contract: {\n name: aptosProcessor.moduleName,\n chainId: aptosProcessor.getChainId(),\n address: validateAndNormalizeAddress(aptosProcessor.config.address),\n abi: '',\n },\n startBlock: aptosProcessor.config.startVersion,\n })\n // 1. Prepare event handlers\n for (const handler of aptosProcessor.eventHandlers) {\n const handlerId = handlers.aptosEventHandlers.push(handler.handler) - 1\n const eventHandlerConfig: MoveEventHandlerConfig = {\n filters: handler.filters.map((f) => {\n return {\n type: f.type,\n account: f.account || '',\n }\n }),\n fetchConfig: handler.fetchConfig,\n handlerId,\n }\n contractConfig.moveEventConfigs.push(eventHandlerConfig)\n }\n\n // 2. Prepare function handlers\n for (const handler of aptosProcessor.callHandlers) {\n const handlerId = handlers.aptosCallHandlers.push(handler.handler) - 1\n const functionHandlerConfig: MoveCallHandlerConfig = {\n filters: handler.filters.map((filter) => {\n return {\n function: filter.function,\n typeArguments: filter.typeArguments || [],\n withTypeArguments: !!filter.typeArguments,\n includeFailed: filter.includeFailed || false,\n }\n }),\n fetchConfig: handler.fetchConfig,\n handlerId,\n }\n contractConfig.moveCallConfigs.push(functionHandlerConfig)\n }\n config.contractConfigs.push(contractConfig)\n }\n\n for (const aptosProcessor of AptosAccountProcessorState.INSTANCE.getValues()) {\n const accountConfig = AccountConfig.fromPartial({\n address: validateAndNormalizeAddress(aptosProcessor.config.address),\n chainId: aptosProcessor.getChainId(),\n startBlock: aptosProcessor.config.startVersion,\n })\n for (const handler of aptosProcessor.resourcesHandlers) {\n const handlerId = handlers.aptosResourceHandlers.push(handler.handler) - 1\n // TODO move to only use moveIntervalConfigs\n accountConfig.aptosIntervalConfigs.push({\n intervalConfig: {\n handlerId: handlerId,\n minutes: 0,\n minutesInterval: handler.timeIntervalInMinutes,\n slot: 0,\n slotInterval: handler.versionInterval,\n fetchConfig: undefined,\n },\n type: handler.type || '',\n })\n\n accountConfig.moveIntervalConfigs.push({\n intervalConfig: {\n handlerId: handlerId,\n minutes: 0,\n minutesInterval: handler.timeIntervalInMinutes,\n slot: 0,\n slotInterval: handler.versionInterval,\n fetchConfig: undefined,\n },\n type: handler.type || '',\n ownerType: MoveOnIntervalConfig_OwnerType.ADDRESS,\n })\n }\n config.accountConfigs.push(accountConfig)\n }\n this.handlers = handlers\n }\n\n supportedHandlers = [HandlerType.APT_CALL, HandlerType.APT_RESOURCE, HandlerType.APT_EVENT]\n\n async 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 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?.aptEvent) {\n throw new ServerError(Status.INVALID_ARGUMENT, \"Event can't be empty\")\n }\n const promises: Promise<ProcessResult>[] = []\n const event = binding.data.aptEvent\n\n for (const handlerId of binding.handlerIds) {\n // only support aptos event for now\n promises.push(\n this.handlers.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?.aptResource) {\n throw new ServerError(Status.INVALID_ARGUMENT, \"Resource can't be empty\")\n }\n const resource = binding.data.aptResource\n\n const promises: Promise<ProcessResult>[] = []\n for (const handlerId of binding.handlerIds) {\n promises.push(\n this.handlers.aptosResourceHandlers[handlerId](resource).catch((e) => {\n throw new ServerError(\n Status.INTERNAL,\n 'error processing resource: ' + 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?.aptCall) {\n throw new ServerError(Status.INVALID_ARGUMENT, \"Call can't be empty\")\n }\n const call = binding.data.aptCall\n\n const promises: Promise<ProcessResult>[] = []\n for (const handlerId of binding.handlerIds) {\n // only support aptos call for now\n const promise = this.handlers.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"]}
|
@@ -1,10 +1,12 @@
|
|
1
|
-
import { ProcessResult, RecordMetaData } from '@sentio/protos';
|
1
|
+
import { ProcessResult, RecordMetaData, StateResult } from '@sentio/protos';
|
2
2
|
import { EventLogger } from './event-logger.js';
|
3
3
|
import { Meter, Labels } from './meter.js';
|
4
4
|
export declare abstract class BaseContext {
|
5
5
|
meter: Meter;
|
6
6
|
eventLogger: EventLogger;
|
7
|
-
_res: ProcessResult
|
7
|
+
_res: ProcessResult & {
|
8
|
+
states: StateResult;
|
9
|
+
};
|
8
10
|
protected constructor();
|
9
11
|
getProcessResult(): ProcessResult;
|
10
12
|
abstract getMetaData(name: string, labels: Labels): RecordMetaData;
|
package/lib/core/base-context.js
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"base-context.js","sourceRoot":"","sources":["../../src/core/base-context.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAC/C,OAAO,EAAE,KAAK,EAAU,MAAM,YAAY,CAAA;AAE1C,MAAM,OAAgB,WAAW;IAC/B,KAAK,CAAO;IACZ,WAAW,CAAa;IAExB,IAAI,
|
1
|
+
{"version":3,"file":"base-context.js","sourceRoot":"","sources":["../../src/core/base-context.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAC/C,OAAO,EAAE,KAAK,EAAU,MAAM,YAAY,CAAA;AAE1C,MAAM,OAAgB,WAAW;IAC/B,KAAK,CAAO;IACZ,WAAW,CAAa;IAExB,IAAI,GAA4C;QAC9C,QAAQ,EAAE,EAAE;QACZ,MAAM,EAAE,EAAE;QACV,OAAO,EAAE,EAAE;QACX,MAAM,EAAE,EAAE;QACV,MAAM,EAAE;YACN,aAAa,EAAE,KAAK;SACrB;KACF,CAAA;IAED;QACE,IAAI,CAAC,KAAK,GAAG,IAAI,KAAK,CAAC,IAAI,CAAC,CAAA;QAC5B,IAAI,CAAC,WAAW,GAAG,IAAI,WAAW,CAAC,IAAI,CAAC,CAAA;IAC1C,CAAC;IAED,gBAAgB;QACd,OAAO,IAAI,CAAC,IAAI,CAAA;IAClB,CAAC;CAKF","sourcesContent":["import { ProcessResult, RecordMetaData, StateResult } from '@sentio/protos'\nimport { EventLogger } from './event-logger.js'\nimport { Meter, Labels } from './meter.js'\n\nexport abstract class BaseContext {\n meter: Meter\n eventLogger: EventLogger\n\n _res: ProcessResult & { states: StateResult } = {\n counters: [],\n events: [],\n exports: [],\n gauges: [],\n states: {\n configUpdated: false,\n },\n }\n\n protected constructor() {\n this.meter = new Meter(this)\n this.eventLogger = new EventLogger(this)\n }\n\n getProcessResult(): ProcessResult {\n return this._res\n }\n\n abstract getMetaData(name: string, labels: Labels): RecordMetaData\n\n abstract getChainId(): string\n}\n"]}
|
@@ -8,6 +8,7 @@ import { ListStateStorage } from '@sentio/runtime';
|
|
8
8
|
import { BlockParams } from 'ethers/providers';
|
9
9
|
import { DeferredTopicFilter } from 'ethers/contract';
|
10
10
|
import { TypedEvent, TypedCallTrace } from './eth.js';
|
11
|
+
import { BaseContext } from '../core/index.js';
|
11
12
|
export declare class ProcessorTemplateProcessorState extends ListStateStorage<BaseProcessorTemplate<BaseContract, BoundContractView<BaseContract, any>>> {
|
12
13
|
static INSTANCE: ProcessorTemplateProcessorState;
|
13
14
|
}
|
@@ -34,7 +35,12 @@ export declare abstract class BaseProcessorTemplate<TContract extends BaseContra
|
|
34
35
|
fetchConfig?: EthFetchConfig;
|
35
36
|
}[];
|
36
37
|
constructor();
|
37
|
-
|
38
|
+
/**
|
39
|
+
* Bind template using {@param options}, using {@param ctx}'s network value if not provided in the option
|
40
|
+
* @param options
|
41
|
+
* @param ctx
|
42
|
+
*/
|
43
|
+
bind(options: BindOptions, ctx: BaseContext): void;
|
38
44
|
onEvent(handler: (event: TypedEvent, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid, filter: DeferredTopicFilter | DeferredTopicFilter[], fetchConfig?: Partial<EthFetchConfig>): this;
|
39
45
|
onBlockInterval(handler: (block: BlockParams, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid, blockInterval?: number, backfillBlockInterval?: number, fetchConfig?: EthFetchConfig): this;
|
40
46
|
onTimeInterval(handler: (block: BlockParams, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid, timeIntervalInMinutes?: number, backfillBlockInterval?: number, fetchConfig?: EthFetchConfig): this;
|
@@ -20,8 +20,19 @@ export class BaseProcessorTemplate {
|
|
20
20
|
this.id = ProcessorTemplateProcessorState.INSTANCE.getValues().length;
|
21
21
|
ProcessorTemplateProcessorState.INSTANCE.addValue(this);
|
22
22
|
}
|
23
|
-
|
24
|
-
|
23
|
+
/**
|
24
|
+
* Bind template using {@param options}, using {@param ctx}'s network value if not provided in the option
|
25
|
+
* @param options
|
26
|
+
* @param ctx
|
27
|
+
*/
|
28
|
+
bind(options, ctx) {
|
29
|
+
if (!options.network) {
|
30
|
+
options.network = ctx.getChainId();
|
31
|
+
}
|
32
|
+
const sig = getOptionsSignature({
|
33
|
+
address: options.address,
|
34
|
+
network: options.network,
|
35
|
+
});
|
25
36
|
if (this.binds.has(sig)) {
|
26
37
|
console.log('Same address can be bind to one template only once');
|
27
38
|
return;
|
@@ -55,6 +66,7 @@ export class BaseProcessorTemplate {
|
|
55
66
|
instance.endBlock = BigInt(options.endBlock);
|
56
67
|
}
|
57
68
|
TemplateInstanceState.INSTANCE.addValue(instance);
|
69
|
+
ctx._res.states.configUpdated = true;
|
58
70
|
}
|
59
71
|
onEvent(handler, filter, fetchConfig) {
|
60
72
|
this.eventHandlers.push({
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"base-processor-template.js","sourceRoot":"","sources":["../../src/eth/base-processor-template.ts"],"names":[],"mappings":"AAGA,OAAO,EAAe,mBAAmB,EAAE,MAAM,mBAAmB,CAAA;AACpE,OAAO,EAAE,cAAc,EAAoC,MAAM,gBAAgB,CAAA;AAEjF,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAIlD,OAAO,EAAE,6BAA6B,EAAE,MAAM,eAAe,CAAA;
|
1
|
+
{"version":3,"file":"base-processor-template.js","sourceRoot":"","sources":["../../src/eth/base-processor-template.ts"],"names":[],"mappings":"AAGA,OAAO,EAAe,mBAAmB,EAAE,MAAM,mBAAmB,CAAA;AACpE,OAAO,EAAE,cAAc,EAAoC,MAAM,gBAAgB,CAAA;AAEjF,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAIlD,OAAO,EAAE,6BAA6B,EAAE,MAAM,eAAe,CAAA;AAG7D,MAAa,+BAAgC,SAAQ,gBAEpD;IACC,MAAM,CAAC,QAAQ,GAAG,IAAI,+BAA+B,EAAE,CAAA;;SAH5C,+BAA+B;AAM5C,MAAa,qBAAsB,SAAQ,gBAAkC;IAC3E,MAAM,CAAC,QAAQ,GAAG,IAAI,qBAAqB,EAAE,CAAA;;SADlC,qBAAqB;AAIlC,MAAM,OAAgB,qBAAqB;IAIzC,EAAE,CAAQ;IACV,KAAK,GAAG,IAAI,GAAG,EAAU,CAAA;IACzB,aAAa,GAKP,EAAE,CAAA;IACR,aAAa,GAIP,EAAE,CAAA;IACR,aAAa,GAIP,EAAE,CAAA;IAER;QACE,IAAI,CAAC,EAAE,GAAG,+BAA+B,CAAC,QAAQ,CAAC,SAAS,EAAE,CAAC,MAAM,CAAA;QACrE,+BAA+B,CAAC,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAA;IACzD,CAAC;IAED;;;;OAIG;IACI,IAAI,CAAC,OAAoB,EAAE,GAAgB;QAChD,IAAI,CAAC,OA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AAA;IACH,CAAC;IAEM,UAAU,CACf,OAAmG,EACnG,YAAwC,EACxC,aAAyC,EACzC,WAAuC;QAEvC,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,qBAAqB,EAAE,YAAY,EAAE,aAAa,EAAE,WAAW,EAAE,CAAC,CAAA;QACrG,OAAO,IAAI,CAAA;IACb,CAAC;IAEM,OAAO,CACZ,SAAiB,EACjB,OAAsG,EACtG,WAAqC;QAErC,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,EAAE,SAAS,EAAE,OAAO,EAAE,WAAW,EAAE,cAAc,CAAC,WAAW,CAAC,WAAW,IAAI,EAAE,CAAC,EAAE,CAAC,CAAA;QAC3G,OAAO,IAAI,CAAA;IACb,CAAC;CAGF","sourcesContent":["import { BoundContractView, ContractContext, ContractView } from './context.js'\nimport { BaseContract } from 'ethers'\nimport { BaseProcessor } from './base-processor.js'\nimport { BindOptions, getOptionsSignature } from './bind-options.js'\nimport { EthFetchConfig, HandleInterval, TemplateInstance } from '@sentio/protos'\nimport { PromiseOrVoid } from '../core/promises.js'\nimport { ListStateStorage } from '@sentio/runtime'\nimport { BlockParams } from 'ethers/providers'\nimport { DeferredTopicFilter } from 'ethers/contract'\nimport { TypedEvent, TypedCallTrace } from './eth.js'\nimport { getNetworkFromCtxOrNetworkish } from './provider.js'\nimport { BaseContext } from '../core/index.js'\n\nexport class ProcessorTemplateProcessorState extends ListStateStorage<\n BaseProcessorTemplate<BaseContract, BoundContractView<BaseContract, any>>\n> {\n static INSTANCE = new ProcessorTemplateProcessorState()\n}\n\nexport class TemplateInstanceState extends ListStateStorage<TemplateInstance> {\n static INSTANCE = new TemplateInstanceState()\n}\n\nexport abstract class BaseProcessorTemplate<\n TContract extends BaseContract,\n TBoundContractView extends BoundContractView<TContract, ContractView<TContract>>\n> {\n id: number\n binds = new Set<string>()\n blockHandlers: {\n handler: (block: BlockParams, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid\n blockInterval?: HandleInterval\n timeIntervalInMinutes?: HandleInterval\n fetchConfig?: EthFetchConfig\n }[] = []\n traceHandlers: {\n signature: string\n handler: (trace: TypedCallTrace, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid\n fetchConfig?: EthFetchConfig\n }[] = []\n eventHandlers: {\n handler: (event: TypedEvent, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid\n filter: DeferredTopicFilter | DeferredTopicFilter[]\n fetchConfig?: EthFetchConfig\n }[] = []\n\n constructor() {\n this.id = ProcessorTemplateProcessorState.INSTANCE.getValues().length\n ProcessorTemplateProcessorState.INSTANCE.addValue(this)\n }\n\n /**\n * Bind template using {@param options}, using {@param ctx}'s network value if not provided in the option\n * @param options\n * @param ctx\n */\n public bind(options: BindOptions, ctx: BaseContext): void {\n if (!options.network) {\n options.network = ctx.getChainId()\n }\n const sig = getOptionsSignature({\n address: options.address,\n network: options.network,\n })\n if (this.binds.has(sig)) {\n console.log('Same address can be bind to one template only once')\n return\n }\n this.binds.add(sig)\n\n const processor = this.bindInternal(options)\n\n for (const eh of this.eventHandlers) {\n processor.onEvent(eh.handler, eh.filter, eh.fetchConfig)\n }\n for (const th of this.traceHandlers) {\n processor.onTrace(th.signature, th.handler, th.fetchConfig)\n }\n for (const bh of this.blockHandlers) {\n processor.onInterval(bh.handler, bh.timeIntervalInMinutes, bh.blockInterval, bh.fetchConfig)\n }\n\n const instance: TemplateInstance = {\n templateId: this.id,\n contract: {\n address: options.address,\n name: options.name || '',\n chainId: getNetworkFromCtxOrNetworkish(options.network).chainId.toString(),\n abi: '',\n },\n startBlock: 0n,\n endBlock: 0n,\n }\n if (options.startBlock) {\n instance.startBlock = BigInt(options.startBlock)\n }\n if (options.endBlock) {\n instance.endBlock = BigInt(options.endBlock)\n }\n TemplateInstanceState.INSTANCE.addValue(instance)\n ctx._res.states.configUpdated = true\n }\n\n public onEvent(\n handler: (event: TypedEvent, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid,\n filter: DeferredTopicFilter | DeferredTopicFilter[],\n fetchConfig?: Partial<EthFetchConfig>\n ) {\n this.eventHandlers.push({\n handler: handler,\n filter: filter,\n fetchConfig: EthFetchConfig.fromPartial(fetchConfig || {}),\n })\n return this\n }\n\n public onBlockInterval(\n handler: (block: BlockParams, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid,\n blockInterval = 1000,\n backfillBlockInterval = 4000,\n fetchConfig?: EthFetchConfig\n ) {\n return this.onInterval(\n handler,\n undefined,\n {\n recentInterval: blockInterval,\n backfillInterval: backfillBlockInterval,\n },\n fetchConfig\n )\n }\n\n public onTimeInterval(\n handler: (block: BlockParams, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid,\n timeIntervalInMinutes = 60,\n backfillBlockInterval = 240,\n fetchConfig?: EthFetchConfig\n ) {\n return this.onInterval(\n handler,\n { recentInterval: timeIntervalInMinutes, backfillInterval: backfillBlockInterval },\n undefined,\n fetchConfig\n )\n }\n\n public onInterval(\n handler: (block: BlockParams, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid,\n timeInterval: HandleInterval | undefined,\n blockInterval: HandleInterval | undefined,\n fetchConfig: EthFetchConfig | undefined\n ) {\n this.blockHandlers.push({ handler, timeIntervalInMinutes: timeInterval, blockInterval, fetchConfig })\n return this\n }\n\n public onTrace(\n signature: string,\n handler: (trace: TypedCallTrace, ctx: ContractContext<TContract, TBoundContractView>) => PromiseOrVoid,\n fetchConfig?: Partial<EthFetchConfig>\n ) {\n this.traceHandlers.push({ signature, handler, fetchConfig: EthFetchConfig.fromPartial(fetchConfig || {}) })\n return this\n }\n\n protected abstract bindInternal(options: BindOptions): BaseProcessor<TContract, TBoundContractView>\n}\n"]}
|
package/lib/eth/eth-plugin.d.ts
CHANGED
@@ -1,11 +1,14 @@
|
|
1
1
|
import { Plugin } from '@sentio/runtime';
|
2
|
-
import { DataBinding, HandlerType, ProcessConfigResponse, ProcessResult, StartRequest } from '@sentio/protos';
|
2
|
+
import { Data_EthBlock, Data_EthLog, Data_EthTrace, Data_EthTransaction, DataBinding, HandlerType, ProcessConfigResponse, ProcessResult, StartRequest } from '@sentio/protos';
|
3
|
+
interface Handlers {
|
4
|
+
eventHandlers: ((event: Data_EthLog) => Promise<ProcessResult>)[];
|
5
|
+
traceHandlers: ((trace: Data_EthTrace) => Promise<ProcessResult>)[];
|
6
|
+
blockHandlers: ((block: Data_EthBlock) => Promise<ProcessResult>)[];
|
7
|
+
transactionHandlers: ((trace: Data_EthTransaction) => Promise<ProcessResult>)[];
|
8
|
+
}
|
3
9
|
export declare class EthPlugin extends Plugin {
|
4
10
|
name: string;
|
5
|
-
|
6
|
-
private traceHandlers;
|
7
|
-
private blockHandlers;
|
8
|
-
private transactionHandlers;
|
11
|
+
handlers: Handlers;
|
9
12
|
configure(config: ProcessConfigResponse): Promise<void>;
|
10
13
|
supportedHandlers: HandlerType[];
|
11
14
|
processBinding(request: DataBinding): Promise<ProcessResult>;
|
@@ -16,3 +19,4 @@ export declare class EthPlugin extends Plugin {
|
|
16
19
|
processBlock(binding: DataBinding): Promise<ProcessResult>;
|
17
20
|
processTransaction(binding: DataBinding): Promise<ProcessResult>;
|
18
21
|
}
|
22
|
+
export {};
|
package/lib/eth/eth-plugin.js
CHANGED
@@ -1,18 +1,27 @@
|
|
1
1
|
import { errorString, mergeProcessResults, Plugin, PluginManager, USER_PROCESSOR } from '@sentio/runtime';
|
2
|
-
import { AccountConfig, ContractConfig, HandlerType, } from '@sentio/protos';
|
2
|
+
import { AccountConfig, ContractConfig, HandlerType, RecordMetaData, } from '@sentio/protos';
|
3
3
|
import { ServerError, Status } from 'nice-grpc';
|
4
4
|
import { ProcessorState } from './binds.js';
|
5
5
|
import { AccountProcessorState } from './account-processor-state.js';
|
6
6
|
import { ProcessorTemplateProcessorState, TemplateInstanceState } from './base-processor-template.js';
|
7
7
|
import { GlobalProcessorState } from './base-processor.js';
|
8
8
|
import { validateAndNormalizeAddress } from './eth.js';
|
9
|
+
import { BaseContext } from '../core/index.js';
|
9
10
|
export class EthPlugin extends Plugin {
|
10
11
|
name = 'EthPlugin';
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
12
|
+
handlers = {
|
13
|
+
blockHandlers: [],
|
14
|
+
eventHandlers: [],
|
15
|
+
traceHandlers: [],
|
16
|
+
transactionHandlers: [],
|
17
|
+
};
|
15
18
|
async configure(config) {
|
19
|
+
const handlers = {
|
20
|
+
blockHandlers: [],
|
21
|
+
eventHandlers: [],
|
22
|
+
traceHandlers: [],
|
23
|
+
transactionHandlers: [],
|
24
|
+
};
|
16
25
|
// This syntax is to copy values instead of using references
|
17
26
|
config.templateInstances = [...TemplateInstanceState.INSTANCE.getValues()];
|
18
27
|
for (const processor of ProcessorState.INSTANCE.getValues()) {
|
@@ -33,7 +42,7 @@ export class EthPlugin extends Plugin {
|
|
33
42
|
});
|
34
43
|
// Step 1. Prepare all the block handlers
|
35
44
|
for (const blockHandler of processor.blockHandlers) {
|
36
|
-
const handlerId =
|
45
|
+
const handlerId = handlers.blockHandlers.push(blockHandler.handler) - 1;
|
37
46
|
// TODO wrap the block handler into one
|
38
47
|
contractConfig.intervalConfigs.push({
|
39
48
|
slot: 0,
|
@@ -46,7 +55,7 @@ export class EthPlugin extends Plugin {
|
|
46
55
|
}
|
47
56
|
// Step 2. Prepare all trace handlers
|
48
57
|
for (const traceHandler of processor.traceHandlers) {
|
49
|
-
const handlerId =
|
58
|
+
const handlerId = handlers.traceHandlers.push(traceHandler.handler) - 1;
|
50
59
|
for (const signature of traceHandler.signatures) {
|
51
60
|
contractConfig.traceConfigs.push({
|
52
61
|
signature: signature,
|
@@ -58,7 +67,7 @@ export class EthPlugin extends Plugin {
|
|
58
67
|
// Step 3. Prepare all the event handlers
|
59
68
|
for (const eventsHandler of processor.eventHandlers) {
|
60
69
|
// associate id with filter
|
61
|
-
const handlerId =
|
70
|
+
const handlerId = handlers.eventHandlers.push(eventsHandler.handler) - 1;
|
62
71
|
const logConfig = {
|
63
72
|
handlerId: handlerId,
|
64
73
|
filters: [],
|
@@ -105,7 +114,7 @@ export class EthPlugin extends Plugin {
|
|
105
114
|
endBlock: processor.config.endBlock,
|
106
115
|
});
|
107
116
|
for (const blockHandler of processor.blockHandlers) {
|
108
|
-
const handlerId =
|
117
|
+
const handlerId = handlers.blockHandlers.push(blockHandler.handler) - 1;
|
109
118
|
contractConfig.intervalConfigs.push({
|
110
119
|
slot: 0,
|
111
120
|
slotInterval: blockHandler.blockInterval,
|
@@ -116,7 +125,7 @@ export class EthPlugin extends Plugin {
|
|
116
125
|
});
|
117
126
|
}
|
118
127
|
for (const transactionHandler of processor.transactionHandler) {
|
119
|
-
const handlerId =
|
128
|
+
const handlerId = handlers.transactionHandlers.push(transactionHandler.handler) - 1;
|
120
129
|
contractConfig.transactionConfig.push({
|
121
130
|
handlerId: handlerId,
|
122
131
|
fetchConfig: transactionHandler.fetchConfig,
|
@@ -134,7 +143,7 @@ export class EthPlugin extends Plugin {
|
|
134
143
|
// TODO add interval
|
135
144
|
for (const eventsHandler of processor.eventHandlers) {
|
136
145
|
// associate id with filter
|
137
|
-
const handlerId =
|
146
|
+
const handlerId = handlers.eventHandlers.push(eventsHandler.handler) - 1;
|
138
147
|
const logConfig = {
|
139
148
|
handlerId: handlerId,
|
140
149
|
filters: [],
|
@@ -170,6 +179,7 @@ export class EthPlugin extends Plugin {
|
|
170
179
|
}
|
171
180
|
config.accountConfigs.push(accountConfig);
|
172
181
|
}
|
182
|
+
this.handlers = handlers;
|
173
183
|
}
|
174
184
|
supportedHandlers = [HandlerType.ETH_LOG, HandlerType.ETH_BLOCK, HandlerType.ETH_TRACE, HandlerType.ETH_TRANSACTION];
|
175
185
|
processBinding(request) {
|
@@ -188,6 +198,7 @@ export class EthPlugin extends Plugin {
|
|
188
198
|
}
|
189
199
|
}
|
190
200
|
async start(request) {
|
201
|
+
const ctx = new NoopContext();
|
191
202
|
for (const instance of request.templateInstances) {
|
192
203
|
const template = ProcessorTemplateProcessorState.INSTANCE.getValues()[instance.templateId];
|
193
204
|
if (!template) {
|
@@ -202,7 +213,7 @@ export class EthPlugin extends Plugin {
|
|
202
213
|
network: Number(instance.contract.chainId),
|
203
214
|
startBlock: instance.startBlock,
|
204
215
|
endBlock: instance.endBlock,
|
205
|
-
});
|
216
|
+
}, ctx);
|
206
217
|
}
|
207
218
|
}
|
208
219
|
stateDiff(config) {
|
@@ -215,7 +226,7 @@ export class EthPlugin extends Plugin {
|
|
215
226
|
const ethLog = request.data.ethLog;
|
216
227
|
const promises = [];
|
217
228
|
for (const handlerId of request.handlerIds) {
|
218
|
-
const handler = this.eventHandlers[handlerId];
|
229
|
+
const handler = this.handlers.eventHandlers[handlerId];
|
219
230
|
promises.push(handler(ethLog).catch((e) => {
|
220
231
|
throw new ServerError(Status.INTERNAL, 'error processing log: ' + JSON.stringify(ethLog.log) + '\n' + errorString(e));
|
221
232
|
}));
|
@@ -229,7 +240,7 @@ export class EthPlugin extends Plugin {
|
|
229
240
|
const ethTrace = binding.data.ethTrace;
|
230
241
|
const promises = [];
|
231
242
|
for (const handlerId of binding.handlerIds) {
|
232
|
-
promises.push(this.traceHandlers[handlerId](ethTrace).catch((e) => {
|
243
|
+
promises.push(this.handlers.traceHandlers[handlerId](ethTrace).catch((e) => {
|
233
244
|
throw new ServerError(Status.INTERNAL, 'error processing trace: ' + JSON.stringify(ethTrace.trace) + '\n' + errorString(e));
|
234
245
|
}));
|
235
246
|
}
|
@@ -242,7 +253,7 @@ export class EthPlugin extends Plugin {
|
|
242
253
|
const ethBlock = binding.data.ethBlock;
|
243
254
|
const promises = [];
|
244
255
|
for (const handlerId of binding.handlerIds) {
|
245
|
-
promises.push(this.blockHandlers[handlerId](ethBlock).catch((e) => {
|
256
|
+
promises.push(this.handlers.blockHandlers[handlerId](ethBlock).catch((e) => {
|
246
257
|
throw new ServerError(Status.INTERNAL, 'error processing block: ' + ethBlock.block?.number + '\n' + errorString(e));
|
247
258
|
}));
|
248
259
|
}
|
@@ -255,7 +266,7 @@ export class EthPlugin extends Plugin {
|
|
255
266
|
const ethTransaction = binding.data.ethTransaction;
|
256
267
|
const promises = [];
|
257
268
|
for (const handlerId of binding.handlerIds) {
|
258
|
-
promises.push(this.transactionHandlers[handlerId](ethTransaction).catch((e) => {
|
269
|
+
promises.push(this.handlers.transactionHandlers[handlerId](ethTransaction).catch((e) => {
|
259
270
|
throw new ServerError(Status.INTERNAL, 'error processing transaction: ' + JSON.stringify(ethTransaction.transaction) + '\n' + errorString(e));
|
260
271
|
}));
|
261
272
|
}
|
@@ -263,4 +274,15 @@ export class EthPlugin extends Plugin {
|
|
263
274
|
}
|
264
275
|
}
|
265
276
|
PluginManager.INSTANCE.register(new EthPlugin());
|
277
|
+
class NoopContext extends BaseContext {
|
278
|
+
constructor() {
|
279
|
+
super();
|
280
|
+
}
|
281
|
+
getChainId() {
|
282
|
+
return '';
|
283
|
+
}
|
284
|
+
getMetaData(name, labels) {
|
285
|
+
return RecordMetaData.create();
|
286
|
+
}
|
287
|
+
}
|
266
288
|
//# sourceMappingURL=eth-plugin.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"eth-plugin.js","sourceRoot":"","sources":["../../src/eth/eth-plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,mBAAmB,EAAE,MAAM,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAA;AACzG,OAAO,EACL,aAAa,EACb,cAAc,EAMd,WAAW,GAMZ,MAAM,gBAAgB,CAAA;AAEvB,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,WAAW,CAAA;AAC/C,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AAC3C,OAAO,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAA;AACpE,OAAO,EAAE,+BAA+B,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAA;AACrG,OAAO,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CA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ContractConfig,\n Data_EthBlock,\n Data_EthLog,\n Data_EthTrace,\n Data_EthTransaction,\n DataBinding,\n HandlerType,\n LogFilter,\n LogHandlerConfig,\n ProcessConfigResponse,\n ProcessResult,\n StartRequest,\n} from '@sentio/protos'\n\nimport { ServerError, Status } from 'nice-grpc'\nimport { ProcessorState } from './binds.js'\nimport { AccountProcessorState } from './account-processor-state.js'\nimport { ProcessorTemplateProcessorState, TemplateInstanceState } from './base-processor-template.js'\nimport { GlobalProcessorState } from './base-processor.js'\nimport { validateAndNormalizeAddress } from './eth.js'\n\nexport class EthPlugin extends Plugin {\n name: string = 'EthPlugin'\n\n private eventHandlers: ((event: Data_EthLog) => Promise<ProcessResult>)[] = []\n private traceHandlers: ((trace: Data_EthTrace) => Promise<ProcessResult>)[] = []\n private blockHandlers: ((block: Data_EthBlock) => Promise<ProcessResult>)[] = []\n private transactionHandlers: ((trace: Data_EthTransaction) => Promise<ProcessResult>)[] = []\n\n async configure(config: ProcessConfigResponse) {\n // This syntax is to copy values instead of using references\n config.templateInstances = [...TemplateInstanceState.INSTANCE.getValues()]\n\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.fromPartial({\n processorType: USER_PROCESSOR,\n contract: {\n name: processor.config.name,\n chainId: chainId.toString(),\n address: validateAndNormalizeAddress(processor.config.address),\n abi: '',\n },\n startBlock: processor.config.startBlock,\n 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 fetchConfig: blockHandler.fetchConfig,\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 for (const signature of traceHandler.signatures) {\n contractConfig.traceConfigs.push({\n signature: signature,\n handlerId: handlerId,\n fetchConfig: traceHandler.fetchConfig,\n })\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 fetchConfig: eventsHandler.fetchConfig,\n }\n\n for (const filter of eventsHandler.filters) {\n const topics = await filter.getTopicFilter()\n\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 && validateAndNormalizeAddress(contractConfig.contract.address),\n topics: [],\n }\n\n for (const ts of 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 for (const processor of GlobalProcessorState.INSTANCE.getValues()) {\n const chainId = processor.getChainId()\n\n const contractConfig = ContractConfig.fromPartial({\n processorType: USER_PROCESSOR,\n contract: {\n name: processor.config.name,\n chainId: chainId.toString(),\n address: processor.config.address, // can only be *\n abi: '',\n },\n startBlock: processor.config.startBlock,\n endBlock: processor.config.endBlock,\n })\n\n for (const blockHandler of processor.blockHandlers) {\n const handlerId = this.blockHandlers.push(blockHandler.handler) - 1\n contractConfig.intervalConfigs.push({\n slot: 0,\n slotInterval: blockHandler.blockInterval,\n minutes: 0,\n minutesInterval: blockHandler.timeIntervalInMinutes,\n handlerId: handlerId,\n fetchConfig: blockHandler.fetchConfig,\n })\n }\n\n for (const transactionHandler of processor.transactionHandler) {\n const handlerId = this.transactionHandlers.push(transactionHandler.handler) - 1\n contractConfig.transactionConfig.push({\n handlerId: handlerId,\n fetchConfig: transactionHandler.fetchConfig,\n })\n }\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.fromPartial({\n address: validateAndNormalizeAddress(processor.config.address),\n chainId: processor.getChainId().toString(),\n startBlock: processor.config.startBlock ? BigInt(processor.config.startBlock) : 0n,\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 fetchConfig: eventsHandler.fetchConfig,\n }\n\n for (const filter of eventsHandler.filters) {\n const topics = await filter.getTopicFilter()\n // if (!filter.topics) {\n // throw new ServerError(Status.INVALID_ARGUMENT, 'Topic should not be null')\n // }\n let address = undefined\n if (filter.address) {\n address = filter.address.toString()\n }\n const logFilter: LogFilter = {\n addressType: filter.addressType,\n address: address && validateAndNormalizeAddress(address),\n topics: [],\n }\n\n for (const ts of 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, HandlerType.ETH_TRANSACTION]\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 case HandlerType.ETH_TRANSACTION:\n return this.processTransaction(request)\n default:\n throw new ServerError(Status.INVALID_ARGUMENT, 'No handle type registered ' + request.handlerType)\n }\n }\n\n async start(request: StartRequest) {\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: validateAndNormalizeAddress(instance.contract.address),\n network: Number(instance.contract.chainId),\n startBlock: instance.startBlock,\n endBlock: instance.endBlock,\n })\n }\n }\n\n stateDiff(config: ProcessConfigResponse): boolean {\n return TemplateInstanceState.INSTANCE.getValues().length !== config.templateInstances.length\n }\n\n async processLog(request: DataBinding): Promise<ProcessResult> {\n if (!request.data?.ethLog?.log) {\n throw new ServerError(Status.INVALID_ARGUMENT, \"Log can't be null\")\n }\n const ethLog = request.data.ethLog\n\n const promises: Promise<ProcessResult>[] = []\n for (const handlerId of request.handlerIds) {\n const handler = this.eventHandlers[handlerId]\n promises.push(\n handler(ethLog).catch((e) => {\n throw new ServerError(\n Status.INTERNAL,\n 'error processing log: ' + JSON.stringify(ethLog.log) + '\\n' + errorString(e)\n )\n })\n )\n }\n return mergeProcessResults(await Promise.all(promises))\n }\n\n async processTrace(binding: DataBinding): Promise<ProcessResult> {\n if (!binding.data?.ethTrace?.trace) {\n throw new ServerError(Status.INVALID_ARGUMENT, \"Trace can't be null\")\n }\n const ethTrace = binding.data.ethTrace\n\n const promises: Promise<ProcessResult>[] = []\n\n for (const handlerId of binding.handlerIds) {\n promises.push(\n this.traceHandlers[handlerId](ethTrace).catch((e) => {\n throw new ServerError(\n Status.INTERNAL,\n 'error processing trace: ' + JSON.stringify(ethTrace.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?.ethBlock?.block) {\n throw new ServerError(Status.INVALID_ARGUMENT, \"Block can't be empty\")\n }\n const ethBlock = binding.data.ethBlock\n\n const promises: Promise<ProcessResult>[] = []\n for (const handlerId of binding.handlerIds) {\n promises.push(\n this.blockHandlers[handlerId](ethBlock).catch((e) => {\n throw new ServerError(\n Status.INTERNAL,\n 'error processing block: ' + ethBlock.block?.number + '\\n' + errorString(e)\n )\n })\n )\n }\n return mergeProcessResults(await Promise.all(promises))\n }\n\n async processTransaction(binding: DataBinding): Promise<ProcessResult> {\n if (!binding.data?.ethTransaction?.transaction) {\n throw new ServerError(Status.INVALID_ARGUMENT, \"transaction can't be null\")\n }\n const ethTransaction = binding.data.ethTransaction\n\n const promises: Promise<ProcessResult>[] = []\n\n for (const handlerId of binding.handlerIds) {\n promises.push(\n this.transactionHandlers[handlerId](ethTransaction).catch((e) => {\n throw new ServerError(\n Status.INTERNAL,\n 'error processing transaction: ' + JSON.stringify(ethTransaction.transaction) + '\\n' + errorString(e)\n )\n })\n )\n }\n return mergeProcessResults(await Promise.all(promises))\n }\n}\n\nPluginManager.INSTANCE.register(new EthPlugin())\n"]}
|
1
|
+
{"version":3,"file":"eth-plugin.js","sourceRoot":"","sources":["../../src/eth/eth-plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,mBAAmB,EAAE,MAAM,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAA;AACzG,OAAO,EACL,aAAa,EACb,cAAc,EAMd,WAAW,EAKX,cAAc,GAEf,MAAM,gBAAgB,CAAA;AAEvB,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,WAAW,CAAA;AAC/C,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AAC3C,OAAO,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAA;AACpE,OAAO,EAAE,+BAA+B,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAA;AACrG,OAAO,EAAE,o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AS,CAAC,cAAc,CAAC,WAAW,CAAC,GAAG,IAAI,GAAG,WAAW,CAAC,CAAC,CAAC,CACtG,CAAA;YACH,CAAC,CAAC,CACH,CAAA;SACF;QACD,OAAO,mBAAmB,CAAC,MAAM,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAA;IACzD,CAAC;CACF;AAED,aAAa,CAAC,QAAQ,CAAC,QAAQ,CAAC,IAAI,SAAS,EAAE,CAAC,CAAA;AAEhD,MAAM,WAAY,SAAQ,WAAW;IACnC;QACE,KAAK,EAAE,CAAA;IACT,CAAC;IACD,UAAU;QACR,OAAO,EAAE,CAAA;IACX,CAAC;IAED,WAAW,CAAC,IAAY,EAAE,MAAc;QACtC,OAAO,cAAc,CAAC,MAAM,EAAE,CAAA;IAChC,CAAC;CACF","sourcesContent":["import { errorString, mergeProcessResults, Plugin, PluginManager, USER_PROCESSOR } from '@sentio/runtime'\nimport {\n AccountConfig,\n ContractConfig,\n Data_EthBlock,\n Data_EthLog,\n Data_EthTrace,\n Data_EthTransaction,\n DataBinding,\n HandlerType,\n LogFilter,\n LogHandlerConfig,\n ProcessConfigResponse,\n ProcessResult,\n RecordMetaData,\n StartRequest,\n} from '@sentio/protos'\n\nimport { ServerError, Status } from 'nice-grpc'\nimport { ProcessorState } from './binds.js'\nimport { AccountProcessorState } from './account-processor-state.js'\nimport { ProcessorTemplateProcessorState, TemplateInstanceState } from './base-processor-template.js'\nimport { GlobalProcessorState } from './base-processor.js'\nimport { validateAndNormalizeAddress } from './eth.js'\nimport { BaseContext, Labels } from '../core/index.js'\n\ninterface Handlers {\n eventHandlers: ((event: Data_EthLog) => Promise<ProcessResult>)[]\n traceHandlers: ((trace: Data_EthTrace) => Promise<ProcessResult>)[]\n blockHandlers: ((block: Data_EthBlock) => Promise<ProcessResult>)[]\n transactionHandlers: ((trace: Data_EthTransaction) => Promise<ProcessResult>)[]\n}\n\nexport class EthPlugin extends Plugin {\n name: string = 'EthPlugin'\n handlers: Handlers = {\n blockHandlers: [],\n eventHandlers: [],\n traceHandlers: [],\n transactionHandlers: [],\n }\n\n async configure(config: ProcessConfigResponse) {\n const handlers: Handlers = {\n blockHandlers: [],\n eventHandlers: [],\n traceHandlers: [],\n transactionHandlers: [],\n }\n // This syntax is to copy values instead of using references\n config.templateInstances = [...TemplateInstanceState.INSTANCE.getValues()]\n\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.fromPartial({\n processorType: USER_PROCESSOR,\n contract: {\n name: processor.config.name,\n chainId: chainId.toString(),\n address: validateAndNormalizeAddress(processor.config.address),\n abi: '',\n },\n startBlock: processor.config.startBlock,\n endBlock: processor.config.endBlock,\n })\n\n // Step 1. Prepare all the block handlers\n for (const blockHandler of processor.blockHandlers) {\n const handlerId = handlers.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 fetchConfig: blockHandler.fetchConfig,\n })\n }\n\n // Step 2. Prepare all trace handlers\n for (const traceHandler of processor.traceHandlers) {\n const handlerId = handlers.traceHandlers.push(traceHandler.handler) - 1\n for (const signature of traceHandler.signatures) {\n contractConfig.traceConfigs.push({\n signature: signature,\n handlerId: handlerId,\n fetchConfig: traceHandler.fetchConfig,\n })\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 = handlers.eventHandlers.push(eventsHandler.handler) - 1\n const logConfig: LogHandlerConfig = {\n handlerId: handlerId,\n filters: [],\n fetchConfig: eventsHandler.fetchConfig,\n }\n\n for (const filter of eventsHandler.filters) {\n const topics = await filter.getTopicFilter()\n\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 && validateAndNormalizeAddress(contractConfig.contract.address),\n topics: [],\n }\n\n for (const ts of 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 for (const processor of GlobalProcessorState.INSTANCE.getValues()) {\n const chainId = processor.getChainId()\n\n const contractConfig = ContractConfig.fromPartial({\n processorType: USER_PROCESSOR,\n contract: {\n name: processor.config.name,\n chainId: chainId.toString(),\n address: processor.config.address, // can only be *\n abi: '',\n },\n startBlock: processor.config.startBlock,\n endBlock: processor.config.endBlock,\n })\n\n for (const blockHandler of processor.blockHandlers) {\n const handlerId = handlers.blockHandlers.push(blockHandler.handler) - 1\n contractConfig.intervalConfigs.push({\n slot: 0,\n slotInterval: blockHandler.blockInterval,\n minutes: 0,\n minutesInterval: blockHandler.timeIntervalInMinutes,\n handlerId: handlerId,\n fetchConfig: blockHandler.fetchConfig,\n })\n }\n\n for (const transactionHandler of processor.transactionHandler) {\n const handlerId = handlers.transactionHandlers.push(transactionHandler.handler) - 1\n contractConfig.transactionConfig.push({\n handlerId: handlerId,\n fetchConfig: transactionHandler.fetchConfig,\n })\n }\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.fromPartial({\n address: validateAndNormalizeAddress(processor.config.address),\n chainId: processor.getChainId().toString(),\n startBlock: processor.config.startBlock ? BigInt(processor.config.startBlock) : 0n,\n })\n // TODO add interval\n for (const eventsHandler of processor.eventHandlers) {\n // associate id with filter\n const handlerId = handlers.eventHandlers.push(eventsHandler.handler) - 1\n const logConfig: LogHandlerConfig = {\n handlerId: handlerId,\n filters: [],\n fetchConfig: eventsHandler.fetchConfig,\n }\n\n for (const filter of eventsHandler.filters) {\n const topics = await filter.getTopicFilter()\n // if (!filter.topics) {\n // throw new ServerError(Status.INVALID_ARGUMENT, 'Topic should not be null')\n // }\n let address = undefined\n if (filter.address) {\n address = filter.address.toString()\n }\n const logFilter: LogFilter = {\n addressType: filter.addressType,\n address: address && validateAndNormalizeAddress(address),\n topics: [],\n }\n\n for (const ts of 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 this.handlers = handlers\n }\n\n supportedHandlers = [HandlerType.ETH_LOG, HandlerType.ETH_BLOCK, HandlerType.ETH_TRACE, HandlerType.ETH_TRANSACTION]\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 case HandlerType.ETH_TRANSACTION:\n return this.processTransaction(request)\n default:\n throw new ServerError(Status.INVALID_ARGUMENT, 'No handle type registered ' + request.handlerType)\n }\n }\n\n async start(request: StartRequest) {\n const ctx = new NoopContext()\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 {\n name: instance.contract.name,\n address: validateAndNormalizeAddress(instance.contract.address),\n network: Number(instance.contract.chainId),\n startBlock: instance.startBlock,\n endBlock: instance.endBlock,\n },\n ctx\n )\n }\n }\n\n stateDiff(config: ProcessConfigResponse): boolean {\n return TemplateInstanceState.INSTANCE.getValues().length !== config.templateInstances.length\n }\n\n async processLog(request: DataBinding): Promise<ProcessResult> {\n if (!request.data?.ethLog?.log) {\n throw new ServerError(Status.INVALID_ARGUMENT, \"Log can't be null\")\n }\n const ethLog = request.data.ethLog\n\n const promises: Promise<ProcessResult>[] = []\n for (const handlerId of request.handlerIds) {\n const handler = this.handlers.eventHandlers[handlerId]\n promises.push(\n handler(ethLog).catch((e) => {\n throw new ServerError(\n Status.INTERNAL,\n 'error processing log: ' + JSON.stringify(ethLog.log) + '\\n' + errorString(e)\n )\n })\n )\n }\n return mergeProcessResults(await Promise.all(promises))\n }\n\n async processTrace(binding: DataBinding): Promise<ProcessResult> {\n if (!binding.data?.ethTrace?.trace) {\n throw new ServerError(Status.INVALID_ARGUMENT, \"Trace can't be null\")\n }\n const ethTrace = binding.data.ethTrace\n\n const promises: Promise<ProcessResult>[] = []\n\n for (const handlerId of binding.handlerIds) {\n promises.push(\n this.handlers.traceHandlers[handlerId](ethTrace).catch((e) => {\n throw new ServerError(\n Status.INTERNAL,\n 'error processing trace: ' + JSON.stringify(ethTrace.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?.ethBlock?.block) {\n throw new ServerError(Status.INVALID_ARGUMENT, \"Block can't be empty\")\n }\n const ethBlock = binding.data.ethBlock\n\n const promises: Promise<ProcessResult>[] = []\n for (const handlerId of binding.handlerIds) {\n promises.push(\n this.handlers.blockHandlers[handlerId](ethBlock).catch((e) => {\n throw new ServerError(\n Status.INTERNAL,\n 'error processing block: ' + ethBlock.block?.number + '\\n' + errorString(e)\n )\n })\n )\n }\n return mergeProcessResults(await Promise.all(promises))\n }\n\n async processTransaction(binding: DataBinding): Promise<ProcessResult> {\n if (!binding.data?.ethTransaction?.transaction) {\n throw new ServerError(Status.INVALID_ARGUMENT, \"transaction can't be null\")\n }\n const ethTransaction = binding.data.ethTransaction\n\n const promises: Promise<ProcessResult>[] = []\n\n for (const handlerId of binding.handlerIds) {\n promises.push(\n this.handlers.transactionHandlers[handlerId](ethTransaction).catch((e) => {\n throw new ServerError(\n Status.INTERNAL,\n 'error processing transaction: ' + JSON.stringify(ethTransaction.transaction) + '\\n' + errorString(e)\n )\n })\n )\n }\n return mergeProcessResults(await Promise.all(promises))\n }\n}\n\nPluginManager.INSTANCE.register(new EthPlugin())\n\nclass NoopContext extends BaseContext {\n public constructor() {\n super()\n }\n getChainId(): string {\n return ''\n }\n\n getMetaData(name: string, labels: Labels): RecordMetaData {\n return RecordMetaData.create()\n }\n}\n"]}
|
package/lib/sui/sui-plugin.d.ts
CHANGED
@@ -1,10 +1,13 @@
|
|
1
1
|
import { Plugin } from '@sentio/runtime';
|
2
|
-
import { DataBinding, HandlerType, ProcessConfigResponse, ProcessResult } from '@sentio/protos';
|
2
|
+
import { Data_SuiCall, Data_SuiEvent, Data_SuiObject, DataBinding, HandlerType, ProcessConfigResponse, ProcessResult } from '@sentio/protos';
|
3
|
+
interface Handlers {
|
4
|
+
suiEventHandlers: ((event: Data_SuiEvent) => Promise<ProcessResult>)[];
|
5
|
+
suiCallHandlers: ((func: Data_SuiCall) => Promise<ProcessResult>)[];
|
6
|
+
suiObjectHandlers: ((object: Data_SuiObject) => Promise<ProcessResult>)[];
|
7
|
+
}
|
3
8
|
export declare class SuiPlugin extends Plugin {
|
4
9
|
name: string;
|
5
|
-
|
6
|
-
private suiCallHandlers;
|
7
|
-
private suiObjectHandlers;
|
10
|
+
handlers: Handlers;
|
8
11
|
configure(config: ProcessConfigResponse): Promise<void>;
|
9
12
|
supportedHandlers: HandlerType[];
|
10
13
|
processSuiEvent(binding: DataBinding): Promise<ProcessResult>;
|
@@ -12,3 +15,4 @@ export declare class SuiPlugin extends Plugin {
|
|
12
15
|
processSuiObject(binding: DataBinding): Promise<ProcessResult>;
|
13
16
|
processBinding(request: DataBinding): Promise<ProcessResult>;
|
14
17
|
}
|
18
|
+
export {};
|
package/lib/sui/sui-plugin.js
CHANGED
@@ -6,10 +6,17 @@ import { getChainId } from './network.js';
|
|
6
6
|
import { validateAndNormalizeAddress } from './utils.js';
|
7
7
|
export class SuiPlugin extends Plugin {
|
8
8
|
name = 'SuiPlugin';
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
handlers = {
|
10
|
+
suiCallHandlers: [],
|
11
|
+
suiEventHandlers: [],
|
12
|
+
suiObjectHandlers: [],
|
13
|
+
};
|
12
14
|
async configure(config) {
|
15
|
+
const handlers = {
|
16
|
+
suiCallHandlers: [],
|
17
|
+
suiEventHandlers: [],
|
18
|
+
suiObjectHandlers: [],
|
19
|
+
};
|
13
20
|
for (const suiProcessor of SuiProcessorState.INSTANCE.getValues()) {
|
14
21
|
const contractConfig = ContractConfig.fromPartial({
|
15
22
|
transactionConfig: [],
|
@@ -23,7 +30,7 @@ export class SuiPlugin extends Plugin {
|
|
23
30
|
startBlock: suiProcessor.config.startCheckpoint,
|
24
31
|
});
|
25
32
|
for (const handler of suiProcessor.eventHandlers) {
|
26
|
-
const handlerId =
|
33
|
+
const handlerId = handlers.suiEventHandlers.push(handler.handler) - 1;
|
27
34
|
const eventHandlerConfig = {
|
28
35
|
filters: handler.filters.map((f) => {
|
29
36
|
return {
|
@@ -37,7 +44,7 @@ export class SuiPlugin extends Plugin {
|
|
37
44
|
contractConfig.moveEventConfigs.push(eventHandlerConfig);
|
38
45
|
}
|
39
46
|
for (const handler of suiProcessor.callHandlers) {
|
40
|
-
const handlerId =
|
47
|
+
const handlerId = handlers.suiCallHandlers.push(handler.handler) - 1;
|
41
48
|
const functionHandlerConfig = {
|
42
49
|
filters: handler.filters.map((filter) => {
|
43
50
|
return {
|
@@ -61,7 +68,7 @@ export class SuiPlugin extends Plugin {
|
|
61
68
|
startBlock: processor.config.startCheckpoint, // TODO maybe use another field
|
62
69
|
});
|
63
70
|
for (const handler of processor.objectHandlers) {
|
64
|
-
const handlerId =
|
71
|
+
const handlerId = handlers.suiObjectHandlers.push(handler.handler) - 1;
|
65
72
|
accountConfig.moveIntervalConfigs.push({
|
66
73
|
intervalConfig: {
|
67
74
|
handlerId: handlerId,
|
@@ -77,6 +84,7 @@ export class SuiPlugin extends Plugin {
|
|
77
84
|
}
|
78
85
|
config.accountConfigs.push(accountConfig);
|
79
86
|
}
|
87
|
+
this.handlers = handlers;
|
80
88
|
}
|
81
89
|
supportedHandlers = [HandlerType.SUI_EVENT, HandlerType.SUI_CALL, HandlerType.SUI_OBJECT];
|
82
90
|
async processSuiEvent(binding) {
|
@@ -86,7 +94,7 @@ export class SuiPlugin extends Plugin {
|
|
86
94
|
const promises = [];
|
87
95
|
const event = binding.data.suiEvent;
|
88
96
|
for (const handlerId of binding.handlerIds) {
|
89
|
-
promises.push(this.suiEventHandlers[handlerId](event).catch((e) => {
|
97
|
+
promises.push(this.handlers.suiEventHandlers[handlerId](event).catch((e) => {
|
90
98
|
throw new ServerError(Status.INTERNAL, 'error processing event: ' + JSON.stringify(event) + '\n' + errorString(e));
|
91
99
|
}));
|
92
100
|
}
|
@@ -99,7 +107,7 @@ export class SuiPlugin extends Plugin {
|
|
99
107
|
const call = binding.data.suiCall;
|
100
108
|
const promises = [];
|
101
109
|
for (const handlerId of binding.handlerIds) {
|
102
|
-
const promise = this.suiCallHandlers[handlerId](call).catch((e) => {
|
110
|
+
const promise = this.handlers.suiCallHandlers[handlerId](call).catch((e) => {
|
103
111
|
throw new ServerError(Status.INTERNAL, 'error processing call: ' + JSON.stringify(call) + '\n' + errorString(e));
|
104
112
|
});
|
105
113
|
promises.push(promise);
|
@@ -113,7 +121,7 @@ export class SuiPlugin extends Plugin {
|
|
113
121
|
const object = binding.data.suiObject;
|
114
122
|
const promises = [];
|
115
123
|
for (const handlerId of binding.handlerIds) {
|
116
|
-
promises.push(this.suiObjectHandlers[handlerId](object).catch((e) => {
|
124
|
+
promises.push(this.handlers.suiObjectHandlers[handlerId](object).catch((e) => {
|
117
125
|
throw new ServerError(Status.INTERNAL, 'error processing object: ' + JSON.stringify(object) + '\n' + errorString(e));
|
118
126
|
}));
|
119
127
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"sui-plugin.js","sourceRoot":"","sources":["../../src/sui/sui-plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,mBAAmB,EAAE,MAAM,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAA;AACzG,OAAO,EACL,aAAa,EACb,cAAc,EAKd,WAAW,GAKZ,MAAM,gBAAgB,CAAA;AAEvB,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,WAAW,CAAA;AAE/C,OAAO,EAAE,wBAAwB,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAA;AAChF,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AACzC,OAAO,EAAE,2BAA2B,EAAE,MAAM,YAAY,CAAA;AAExD,MAAM,OAAO,SAAU,SAAQ,MAAM;IACnC,IAAI,GAAW,WAAW,CAAA;IAElB,gBAAgB,GAAyD,EAAE,CAAA;IAC3E,eAAe,GAAuD,EAAE,CAAA;IACxE,iBAAiB,GAA2D,EAAE,CAAA;IAEtF,KAAK,CAAC,SAAS,CAAC,MAA6B;QAC3C,KAAK,MAAM,YAAY,IAAI,iBAAiB,CAAC,QAAQ,CAAC,SAAS,EAAE,EAAE;YACjE,MAAM,cAAc,GAAG,cAAc,CAAC,WAAW,CAAC;gBAChD,iBAAiB,EAAE,EAAE;gBACrB,aAAa,EAAE,cAAc;gBAC7B,QAAQ,EAAE;oBACR,IAAI,EAAE,YAAY,CAAC,UAAU;oBAC7B,OAAO,EAAE,UAAU,CAAC,YAAY,CAAC,MAAM,CAAC,OAAO,CAAC;oBAChD,OAAO,EAAE,2BAA2B,CAAC,YAAY,CAAC,MAAM,CAAC,OAAO,CAAC;oBACjE,GAAG,EAAE,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,CAAA;YACvC;gBACE,MAAM,IAAI,WAAW,CAAC,MAAM,CAAC,gBAAgB,EAAE,4BAA4B,GAAG,OAAO,CAAC,WAAW,CAAC,CAAA;SACrG;IACH,CAAC;CACF;AAED,aAAa,CAAC,QAAQ,CAAC,QAAQ,CAAC,IAAI,SAAS,EAAE,CAAC,CAAA","sourcesContent":["import { errorString, mergeProcessResults, Plugin, PluginManager, USER_PROCESSOR } from '@sentio/runtime'\nimport {\n AccountConfig,\n ContractConfig,\n Data_SuiCall,\n Data_SuiEvent,\n Data_SuiObject,\n DataBinding,\n HandlerType,\n MoveCallHandlerConfig,\n MoveEventHandlerConfig,\n ProcessConfigResponse,\n ProcessResult,\n} from '@sentio/protos'\n\nimport { ServerError, Status } from 'nice-grpc'\n\nimport { SuiAccountProcessorState, SuiProcessorState } from './sui-processor.js'\nimport { getChainId } from './network.js'\nimport { validateAndNormalizeAddress } from './utils.js'\n\nexport class SuiPlugin extends Plugin {\n name: string = 'SuiPlugin'\n\n private suiEventHandlers: ((event: Data_SuiEvent) => Promise<ProcessResult>)[] = []\n private suiCallHandlers: ((func: Data_SuiCall) => Promise<ProcessResult>)[] = []\n private suiObjectHandlers: ((object: Data_SuiObject) => Promise<ProcessResult>)[] = []\n\n async configure(config: ProcessConfigResponse) {\n for (const suiProcessor of SuiProcessorState.INSTANCE.getValues()) {\n const contractConfig = ContractConfig.fromPartial({\n transactionConfig: [],\n processorType: USER_PROCESSOR,\n contract: {\n name: suiProcessor.moduleName,\n chainId: getChainId(suiProcessor.config.network),\n address: validateAndNormalizeAddress(suiProcessor.config.address),\n abi: '',\n },\n startBlock: suiProcessor.config.startCheckpoint,\n })\n for (const handler of suiProcessor.eventHandlers) {\n const handlerId = this.suiEventHandlers.push(handler.handler) - 1\n const eventHandlerConfig: MoveEventHandlerConfig = {\n filters: handler.filters.map((f) => {\n return {\n type: f.type,\n account: f.account || '',\n }\n }),\n fetchConfig: handler.fetchConfig,\n handlerId,\n }\n contractConfig.moveEventConfigs.push(eventHandlerConfig)\n }\n for (const handler of suiProcessor.callHandlers) {\n const handlerId = this.suiCallHandlers.push(handler.handler) - 1\n const functionHandlerConfig: MoveCallHandlerConfig = {\n filters: handler.filters.map((filter) => {\n return {\n function: filter.function,\n typeArguments: filter.typeArguments || [],\n withTypeArguments: !!filter.typeArguments,\n includeFailed: filter.includeFailed || false,\n }\n }),\n fetchConfig: handler.fetchConfig,\n handlerId,\n }\n contractConfig.moveCallConfigs.push(functionHandlerConfig)\n }\n config.contractConfigs.push(contractConfig)\n }\n\n for (const processor of SuiAccountProcessorState.INSTANCE.getValues()) {\n const accountConfig = AccountConfig.fromPartial({\n address: validateAndNormalizeAddress(processor.config.address),\n chainId: processor.getChainId(),\n startBlock: processor.config.startCheckpoint, // TODO maybe use another field\n })\n for (const handler of processor.objectHandlers) {\n const handlerId = this.suiObjectHandlers.push(handler.handler) - 1\n accountConfig.moveIntervalConfigs.push({\n intervalConfig: {\n handlerId: handlerId,\n minutes: 0,\n minutesInterval: handler.timeIntervalInMinutes,\n slot: 0,\n slotInterval: handler.versionInterval,\n fetchConfig: undefined,\n },\n type: handler.type || '',\n ownerType: processor.ownerType,\n })\n }\n config.accountConfigs.push(accountConfig)\n }\n }\n\n supportedHandlers = [HandlerType.SUI_EVENT, HandlerType.SUI_CALL, HandlerType.SUI_OBJECT]\n\n async processSuiEvent(binding: DataBinding): Promise<ProcessResult> {\n if (!binding.data?.suiEvent) {\n throw new ServerError(Status.INVALID_ARGUMENT, \"Event can't be empty\")\n }\n const promises: Promise<ProcessResult>[] = []\n const event = binding.data.suiEvent\n\n for (const handlerId of binding.handlerIds) {\n promises.push(\n this.suiEventHandlers[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 processSuiFunctionCall(binding: DataBinding): Promise<ProcessResult> {\n if (!binding.data?.suiCall) {\n throw new ServerError(Status.INVALID_ARGUMENT, \"Call can't be empty\")\n }\n const call = binding.data.suiCall\n\n const promises: Promise<ProcessResult>[] = []\n for (const handlerId of binding.handlerIds) {\n const promise = this.suiCallHandlers[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 async processSuiObject(binding: DataBinding): Promise<ProcessResult> {\n if (!binding.data?.suiObject) {\n throw new ServerError(Status.INVALID_ARGUMENT, \"Object can't be empty\")\n }\n const object = binding.data.suiObject\n\n const promises: Promise<ProcessResult>[] = []\n for (const handlerId of binding.handlerIds) {\n promises.push(\n this.suiObjectHandlers[handlerId](object).catch((e) => {\n throw new ServerError(\n Status.INTERNAL,\n 'error processing object: ' + JSON.stringify(object) + '\\n' + errorString(e)\n )\n })\n )\n }\n return mergeProcessResults(await Promise.all(promises))\n }\n\n processBinding(request: DataBinding): Promise<ProcessResult> {\n switch (request.handlerType) {\n case HandlerType.SUI_EVENT:\n return this.processSuiEvent(request)\n case HandlerType.SUI_CALL:\n return this.processSuiFunctionCall(request)\n case HandlerType.SUI_OBJECT:\n return this.processSuiObject(request)\n default:\n throw new ServerError(Status.INVALID_ARGUMENT, 'No handle type registered ' + request.handlerType)\n }\n }\n}\n\nPluginManager.INSTANCE.register(new SuiPlugin())\n"]}
|
1
|
+
{"version":3,"file":"sui-plugin.js","sourceRoot":"","sources":["../../src/sui/sui-plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,mBAAmB,EAAE,MAAM,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAA;AACzG,OAAO,EACL,aAAa,EACb,cAAc,EAKd,WAAW,GAKZ,MAAM,gBAAgB,CAAA;AAEvB,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,WAAW,CAAA;AAE/C,OAAO,EAAE,wBAAwB,EAAE,iBAA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ig,\n ContractConfig,\n Data_SuiCall,\n Data_SuiEvent,\n Data_SuiObject,\n DataBinding,\n HandlerType,\n MoveCallHandlerConfig,\n MoveEventHandlerConfig,\n ProcessConfigResponse,\n ProcessResult,\n} from '@sentio/protos'\n\nimport { ServerError, Status } from 'nice-grpc'\n\nimport { SuiAccountProcessorState, SuiProcessorState } from './sui-processor.js'\nimport { getChainId } from './network.js'\nimport { validateAndNormalizeAddress } from './utils.js'\n\ninterface Handlers {\n suiEventHandlers: ((event: Data_SuiEvent) => Promise<ProcessResult>)[]\n suiCallHandlers: ((func: Data_SuiCall) => Promise<ProcessResult>)[]\n suiObjectHandlers: ((object: Data_SuiObject) => Promise<ProcessResult>)[]\n}\n\nexport class SuiPlugin extends Plugin {\n name: string = 'SuiPlugin'\n handlers: Handlers = {\n suiCallHandlers: [],\n suiEventHandlers: [],\n suiObjectHandlers: [],\n }\n\n async configure(config: ProcessConfigResponse) {\n const handlers: Handlers = {\n suiCallHandlers: [],\n suiEventHandlers: [],\n suiObjectHandlers: [],\n }\n for (const suiProcessor of SuiProcessorState.INSTANCE.getValues()) {\n const contractConfig = ContractConfig.fromPartial({\n transactionConfig: [],\n processorType: USER_PROCESSOR,\n contract: {\n name: suiProcessor.moduleName,\n chainId: getChainId(suiProcessor.config.network),\n address: validateAndNormalizeAddress(suiProcessor.config.address),\n abi: '',\n },\n startBlock: suiProcessor.config.startCheckpoint,\n })\n for (const handler of suiProcessor.eventHandlers) {\n const handlerId = handlers.suiEventHandlers.push(handler.handler) - 1\n const eventHandlerConfig: MoveEventHandlerConfig = {\n filters: handler.filters.map((f) => {\n return {\n type: f.type,\n account: f.account || '',\n }\n }),\n fetchConfig: handler.fetchConfig,\n handlerId,\n }\n contractConfig.moveEventConfigs.push(eventHandlerConfig)\n }\n for (const handler of suiProcessor.callHandlers) {\n const handlerId = handlers.suiCallHandlers.push(handler.handler) - 1\n const functionHandlerConfig: MoveCallHandlerConfig = {\n filters: handler.filters.map((filter) => {\n return {\n function: filter.function,\n typeArguments: filter.typeArguments || [],\n withTypeArguments: !!filter.typeArguments,\n includeFailed: filter.includeFailed || false,\n }\n }),\n fetchConfig: handler.fetchConfig,\n handlerId,\n }\n contractConfig.moveCallConfigs.push(functionHandlerConfig)\n }\n config.contractConfigs.push(contractConfig)\n }\n\n for (const processor of SuiAccountProcessorState.INSTANCE.getValues()) {\n const accountConfig = AccountConfig.fromPartial({\n address: validateAndNormalizeAddress(processor.config.address),\n chainId: processor.getChainId(),\n startBlock: processor.config.startCheckpoint, // TODO maybe use another field\n })\n for (const handler of processor.objectHandlers) {\n const handlerId = handlers.suiObjectHandlers.push(handler.handler) - 1\n accountConfig.moveIntervalConfigs.push({\n intervalConfig: {\n handlerId: handlerId,\n minutes: 0,\n minutesInterval: handler.timeIntervalInMinutes,\n slot: 0,\n slotInterval: handler.versionInterval,\n fetchConfig: undefined,\n },\n type: handler.type || '',\n ownerType: processor.ownerType,\n })\n }\n config.accountConfigs.push(accountConfig)\n }\n this.handlers = handlers\n }\n\n supportedHandlers = [HandlerType.SUI_EVENT, HandlerType.SUI_CALL, HandlerType.SUI_OBJECT]\n\n async processSuiEvent(binding: DataBinding): Promise<ProcessResult> {\n if (!binding.data?.suiEvent) {\n throw new ServerError(Status.INVALID_ARGUMENT, \"Event can't be empty\")\n }\n const promises: Promise<ProcessResult>[] = []\n const event = binding.data.suiEvent\n\n for (const handlerId of binding.handlerIds) {\n promises.push(\n this.handlers.suiEventHandlers[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 processSuiFunctionCall(binding: DataBinding): Promise<ProcessResult> {\n if (!binding.data?.suiCall) {\n throw new ServerError(Status.INVALID_ARGUMENT, \"Call can't be empty\")\n }\n const call = binding.data.suiCall\n\n const promises: Promise<ProcessResult>[] = []\n for (const handlerId of binding.handlerIds) {\n const promise = this.handlers.suiCallHandlers[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 async processSuiObject(binding: DataBinding): Promise<ProcessResult> {\n if (!binding.data?.suiObject) {\n throw new ServerError(Status.INVALID_ARGUMENT, \"Object can't be empty\")\n }\n const object = binding.data.suiObject\n\n const promises: Promise<ProcessResult>[] = []\n for (const handlerId of binding.handlerIds) {\n promises.push(\n this.handlers.suiObjectHandlers[handlerId](object).catch((e) => {\n throw new ServerError(\n Status.INTERNAL,\n 'error processing object: ' + JSON.stringify(object) + '\\n' + errorString(e)\n )\n })\n )\n }\n return mergeProcessResults(await Promise.all(promises))\n }\n\n processBinding(request: DataBinding): Promise<ProcessResult> {\n switch (request.handlerType) {\n case HandlerType.SUI_EVENT:\n return this.processSuiEvent(request)\n case HandlerType.SUI_CALL:\n return this.processSuiFunctionCall(request)\n case HandlerType.SUI_OBJECT:\n return this.processSuiObject(request)\n default:\n throw new ServerError(Status.INVALID_ARGUMENT, 'No handle type registered ' + request.handlerType)\n }\n }\n}\n\nPluginManager.INSTANCE.register(new SuiPlugin())\n"]}
|
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "@sentio/sdk",
|
3
3
|
"license": "Apache-2.0",
|
4
|
-
"version": "2.
|
4
|
+
"version": "2.14.0-rc.1",
|
5
5
|
"type": "module",
|
6
6
|
"dependencies": {
|
7
7
|
"@mysten/sui.js": "npm:@sentio/sui.js@^0.32.0-patch.1",
|
@@ -30,8 +30,8 @@
|
|
30
30
|
"nice-grpc-common": "^2.0.2",
|
31
31
|
"@coral-xyz/borsh": "^0.27.0",
|
32
32
|
"typedoc": "^0.24.1",
|
33
|
-
"@sentio/protos": "^2.
|
34
|
-
"@sentio/runtime": "^2.
|
33
|
+
"@sentio/protos": "^2.14.0-rc.1",
|
34
|
+
"@sentio/runtime": "^2.14.0-rc.1"
|
35
35
|
},
|
36
36
|
"devDependencies": {
|
37
37
|
"@certusone/wormhole-sdk": "^0.9.10",
|
@@ -22,18 +22,29 @@ import { AptosAccountProcessorState, AptosProcessorState } from './aptos-process
|
|
22
22
|
import { initCoinList } from './ext/coin.js'
|
23
23
|
import { validateAndNormalizeAddress } from './utils.js'
|
24
24
|
|
25
|
+
interface Handlers {
|
26
|
+
aptosEventHandlers: ((event: Data_AptEvent) => Promise<ProcessResult>)[]
|
27
|
+
aptosCallHandlers: ((func: Data_AptCall) => Promise<ProcessResult>)[]
|
28
|
+
aptosResourceHandlers: ((resourceWithVersion: Data_AptResource) => Promise<ProcessResult>)[]
|
29
|
+
}
|
25
30
|
export class AptosPlugin extends Plugin {
|
26
31
|
name: string = 'AptosPlugin'
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
32
|
+
handlers: Handlers = {
|
33
|
+
aptosEventHandlers: [],
|
34
|
+
aptosCallHandlers: [],
|
35
|
+
aptosResourceHandlers: [],
|
36
|
+
}
|
31
37
|
|
32
38
|
async start(start: StartRequest) {
|
33
39
|
await initCoinList()
|
34
40
|
}
|
35
41
|
|
36
42
|
async configure(config: ProcessConfigResponse) {
|
43
|
+
const handlers: Handlers = {
|
44
|
+
aptosEventHandlers: [],
|
45
|
+
aptosCallHandlers: [],
|
46
|
+
aptosResourceHandlers: [],
|
47
|
+
}
|
37
48
|
for (const aptosProcessor of AptosProcessorState.INSTANCE.getValues()) {
|
38
49
|
const contractConfig = ContractConfig.fromPartial({
|
39
50
|
processorType: USER_PROCESSOR,
|
@@ -47,7 +58,7 @@ export class AptosPlugin extends Plugin {
|
|
47
58
|
})
|
48
59
|
// 1. Prepare event handlers
|
49
60
|
for (const handler of aptosProcessor.eventHandlers) {
|
50
|
-
const handlerId =
|
61
|
+
const handlerId = handlers.aptosEventHandlers.push(handler.handler) - 1
|
51
62
|
const eventHandlerConfig: MoveEventHandlerConfig = {
|
52
63
|
filters: handler.filters.map((f) => {
|
53
64
|
return {
|
@@ -63,7 +74,7 @@ export class AptosPlugin extends Plugin {
|
|
63
74
|
|
64
75
|
// 2. Prepare function handlers
|
65
76
|
for (const handler of aptosProcessor.callHandlers) {
|
66
|
-
const handlerId =
|
77
|
+
const handlerId = handlers.aptosCallHandlers.push(handler.handler) - 1
|
67
78
|
const functionHandlerConfig: MoveCallHandlerConfig = {
|
68
79
|
filters: handler.filters.map((filter) => {
|
69
80
|
return {
|
@@ -88,7 +99,7 @@ export class AptosPlugin extends Plugin {
|
|
88
99
|
startBlock: aptosProcessor.config.startVersion,
|
89
100
|
})
|
90
101
|
for (const handler of aptosProcessor.resourcesHandlers) {
|
91
|
-
const handlerId =
|
102
|
+
const handlerId = handlers.aptosResourceHandlers.push(handler.handler) - 1
|
92
103
|
// TODO move to only use moveIntervalConfigs
|
93
104
|
accountConfig.aptosIntervalConfigs.push({
|
94
105
|
intervalConfig: {
|
@@ -117,6 +128,7 @@ export class AptosPlugin extends Plugin {
|
|
117
128
|
}
|
118
129
|
config.accountConfigs.push(accountConfig)
|
119
130
|
}
|
131
|
+
this.handlers = handlers
|
120
132
|
}
|
121
133
|
|
122
134
|
supportedHandlers = [HandlerType.APT_CALL, HandlerType.APT_RESOURCE, HandlerType.APT_EVENT]
|
@@ -144,7 +156,7 @@ export class AptosPlugin extends Plugin {
|
|
144
156
|
for (const handlerId of binding.handlerIds) {
|
145
157
|
// only support aptos event for now
|
146
158
|
promises.push(
|
147
|
-
this.aptosEventHandlers[handlerId](event).catch((e) => {
|
159
|
+
this.handlers.aptosEventHandlers[handlerId](event).catch((e) => {
|
148
160
|
throw new ServerError(
|
149
161
|
Status.INTERNAL,
|
150
162
|
'error processing event: ' + JSON.stringify(event) + '\n' + errorString(e)
|
@@ -164,7 +176,7 @@ export class AptosPlugin extends Plugin {
|
|
164
176
|
const promises: Promise<ProcessResult>[] = []
|
165
177
|
for (const handlerId of binding.handlerIds) {
|
166
178
|
promises.push(
|
167
|
-
this.aptosResourceHandlers[handlerId](resource).catch((e) => {
|
179
|
+
this.handlers.aptosResourceHandlers[handlerId](resource).catch((e) => {
|
168
180
|
throw new ServerError(
|
169
181
|
Status.INTERNAL,
|
170
182
|
'error processing resource: ' + JSON.stringify(resource) + '\n' + errorString(e)
|
@@ -184,7 +196,7 @@ export class AptosPlugin extends Plugin {
|
|
184
196
|
const promises: Promise<ProcessResult>[] = []
|
185
197
|
for (const handlerId of binding.handlerIds) {
|
186
198
|
// only support aptos call for now
|
187
|
-
const promise = this.aptosCallHandlers[handlerId](call).catch((e) => {
|
199
|
+
const promise = this.handlers.aptosCallHandlers[handlerId](call).catch((e) => {
|
188
200
|
throw new ServerError(Status.INTERNAL, 'error processing call: ' + JSON.stringify(call) + '\n' + errorString(e))
|
189
201
|
})
|
190
202
|
promises.push(promise)
|
package/src/core/base-context.ts
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
import { ProcessResult, RecordMetaData } from '@sentio/protos'
|
1
|
+
import { ProcessResult, RecordMetaData, StateResult } from '@sentio/protos'
|
2
2
|
import { EventLogger } from './event-logger.js'
|
3
3
|
import { Meter, Labels } from './meter.js'
|
4
4
|
|
@@ -6,11 +6,14 @@ export abstract class BaseContext {
|
|
6
6
|
meter: Meter
|
7
7
|
eventLogger: EventLogger
|
8
8
|
|
9
|
-
_res: ProcessResult = {
|
9
|
+
_res: ProcessResult & { states: StateResult } = {
|
10
10
|
counters: [],
|
11
11
|
events: [],
|
12
12
|
exports: [],
|
13
13
|
gauges: [],
|
14
|
+
states: {
|
15
|
+
configUpdated: false,
|
16
|
+
},
|
14
17
|
}
|
15
18
|
|
16
19
|
protected constructor() {
|
@@ -9,6 +9,7 @@ import { BlockParams } from 'ethers/providers'
|
|
9
9
|
import { DeferredTopicFilter } from 'ethers/contract'
|
10
10
|
import { TypedEvent, TypedCallTrace } from './eth.js'
|
11
11
|
import { getNetworkFromCtxOrNetworkish } from './provider.js'
|
12
|
+
import { BaseContext } from '../core/index.js'
|
12
13
|
|
13
14
|
export class ProcessorTemplateProcessorState extends ListStateStorage<
|
14
15
|
BaseProcessorTemplate<BaseContract, BoundContractView<BaseContract, any>>
|
@@ -48,8 +49,19 @@ export abstract class BaseProcessorTemplate<
|
|
48
49
|
ProcessorTemplateProcessorState.INSTANCE.addValue(this)
|
49
50
|
}
|
50
51
|
|
51
|
-
|
52
|
-
|
52
|
+
/**
|
53
|
+
* Bind template using {@param options}, using {@param ctx}'s network value if not provided in the option
|
54
|
+
* @param options
|
55
|
+
* @param ctx
|
56
|
+
*/
|
57
|
+
public bind(options: BindOptions, ctx: BaseContext): void {
|
58
|
+
if (!options.network) {
|
59
|
+
options.network = ctx.getChainId()
|
60
|
+
}
|
61
|
+
const sig = getOptionsSignature({
|
62
|
+
address: options.address,
|
63
|
+
network: options.network,
|
64
|
+
})
|
53
65
|
if (this.binds.has(sig)) {
|
54
66
|
console.log('Same address can be bind to one template only once')
|
55
67
|
return
|
@@ -86,6 +98,7 @@ export abstract class BaseProcessorTemplate<
|
|
86
98
|
instance.endBlock = BigInt(options.endBlock)
|
87
99
|
}
|
88
100
|
TemplateInstanceState.INSTANCE.addValue(instance)
|
101
|
+
ctx._res.states.configUpdated = true
|
89
102
|
}
|
90
103
|
|
91
104
|
public onEvent(
|
package/src/eth/eth-plugin.ts
CHANGED
@@ -12,6 +12,7 @@ import {
|
|
12
12
|
LogHandlerConfig,
|
13
13
|
ProcessConfigResponse,
|
14
14
|
ProcessResult,
|
15
|
+
RecordMetaData,
|
15
16
|
StartRequest,
|
16
17
|
} from '@sentio/protos'
|
17
18
|
|
@@ -21,16 +22,31 @@ import { AccountProcessorState } from './account-processor-state.js'
|
|
21
22
|
import { ProcessorTemplateProcessorState, TemplateInstanceState } from './base-processor-template.js'
|
22
23
|
import { GlobalProcessorState } from './base-processor.js'
|
23
24
|
import { validateAndNormalizeAddress } from './eth.js'
|
25
|
+
import { BaseContext, Labels } from '../core/index.js'
|
26
|
+
|
27
|
+
interface Handlers {
|
28
|
+
eventHandlers: ((event: Data_EthLog) => Promise<ProcessResult>)[]
|
29
|
+
traceHandlers: ((trace: Data_EthTrace) => Promise<ProcessResult>)[]
|
30
|
+
blockHandlers: ((block: Data_EthBlock) => Promise<ProcessResult>)[]
|
31
|
+
transactionHandlers: ((trace: Data_EthTransaction) => Promise<ProcessResult>)[]
|
32
|
+
}
|
24
33
|
|
25
34
|
export class EthPlugin extends Plugin {
|
26
35
|
name: string = 'EthPlugin'
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
36
|
+
handlers: Handlers = {
|
37
|
+
blockHandlers: [],
|
38
|
+
eventHandlers: [],
|
39
|
+
traceHandlers: [],
|
40
|
+
transactionHandlers: [],
|
41
|
+
}
|
32
42
|
|
33
43
|
async configure(config: ProcessConfigResponse) {
|
44
|
+
const handlers: Handlers = {
|
45
|
+
blockHandlers: [],
|
46
|
+
eventHandlers: [],
|
47
|
+
traceHandlers: [],
|
48
|
+
transactionHandlers: [],
|
49
|
+
}
|
34
50
|
// This syntax is to copy values instead of using references
|
35
51
|
config.templateInstances = [...TemplateInstanceState.INSTANCE.getValues()]
|
36
52
|
|
@@ -54,7 +70,7 @@ export class EthPlugin extends Plugin {
|
|
54
70
|
|
55
71
|
// Step 1. Prepare all the block handlers
|
56
72
|
for (const blockHandler of processor.blockHandlers) {
|
57
|
-
const handlerId =
|
73
|
+
const handlerId = handlers.blockHandlers.push(blockHandler.handler) - 1
|
58
74
|
// TODO wrap the block handler into one
|
59
75
|
|
60
76
|
contractConfig.intervalConfigs.push({
|
@@ -69,7 +85,7 @@ export class EthPlugin extends Plugin {
|
|
69
85
|
|
70
86
|
// Step 2. Prepare all trace handlers
|
71
87
|
for (const traceHandler of processor.traceHandlers) {
|
72
|
-
const handlerId =
|
88
|
+
const handlerId = handlers.traceHandlers.push(traceHandler.handler) - 1
|
73
89
|
for (const signature of traceHandler.signatures) {
|
74
90
|
contractConfig.traceConfigs.push({
|
75
91
|
signature: signature,
|
@@ -82,7 +98,7 @@ export class EthPlugin extends Plugin {
|
|
82
98
|
// Step 3. Prepare all the event handlers
|
83
99
|
for (const eventsHandler of processor.eventHandlers) {
|
84
100
|
// associate id with filter
|
85
|
-
const handlerId =
|
101
|
+
const handlerId = handlers.eventHandlers.push(eventsHandler.handler) - 1
|
86
102
|
const logConfig: LogHandlerConfig = {
|
87
103
|
handlerId: handlerId,
|
88
104
|
filters: [],
|
@@ -135,7 +151,7 @@ export class EthPlugin extends Plugin {
|
|
135
151
|
})
|
136
152
|
|
137
153
|
for (const blockHandler of processor.blockHandlers) {
|
138
|
-
const handlerId =
|
154
|
+
const handlerId = handlers.blockHandlers.push(blockHandler.handler) - 1
|
139
155
|
contractConfig.intervalConfigs.push({
|
140
156
|
slot: 0,
|
141
157
|
slotInterval: blockHandler.blockInterval,
|
@@ -147,7 +163,7 @@ export class EthPlugin extends Plugin {
|
|
147
163
|
}
|
148
164
|
|
149
165
|
for (const transactionHandler of processor.transactionHandler) {
|
150
|
-
const handlerId =
|
166
|
+
const handlerId = handlers.transactionHandlers.push(transactionHandler.handler) - 1
|
151
167
|
contractConfig.transactionConfig.push({
|
152
168
|
handlerId: handlerId,
|
153
169
|
fetchConfig: transactionHandler.fetchConfig,
|
@@ -166,7 +182,7 @@ export class EthPlugin extends Plugin {
|
|
166
182
|
// TODO add interval
|
167
183
|
for (const eventsHandler of processor.eventHandlers) {
|
168
184
|
// associate id with filter
|
169
|
-
const handlerId =
|
185
|
+
const handlerId = handlers.eventHandlers.push(eventsHandler.handler) - 1
|
170
186
|
const logConfig: LogHandlerConfig = {
|
171
187
|
handlerId: handlerId,
|
172
188
|
filters: [],
|
@@ -204,6 +220,8 @@ export class EthPlugin extends Plugin {
|
|
204
220
|
|
205
221
|
config.accountConfigs.push(accountConfig)
|
206
222
|
}
|
223
|
+
|
224
|
+
this.handlers = handlers
|
207
225
|
}
|
208
226
|
|
209
227
|
supportedHandlers = [HandlerType.ETH_LOG, HandlerType.ETH_BLOCK, HandlerType.ETH_TRACE, HandlerType.ETH_TRANSACTION]
|
@@ -225,6 +243,7 @@ export class EthPlugin extends Plugin {
|
|
225
243
|
}
|
226
244
|
|
227
245
|
async start(request: StartRequest) {
|
246
|
+
const ctx = new NoopContext()
|
228
247
|
for (const instance of request.templateInstances) {
|
229
248
|
const template = ProcessorTemplateProcessorState.INSTANCE.getValues()[instance.templateId]
|
230
249
|
if (!template) {
|
@@ -233,13 +252,16 @@ export class EthPlugin extends Plugin {
|
|
233
252
|
if (!instance.contract) {
|
234
253
|
throw new ServerError(Status.INVALID_ARGUMENT, 'Contract Empty from:' + instance)
|
235
254
|
}
|
236
|
-
template.bind(
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
255
|
+
template.bind(
|
256
|
+
{
|
257
|
+
name: instance.contract.name,
|
258
|
+
address: validateAndNormalizeAddress(instance.contract.address),
|
259
|
+
network: Number(instance.contract.chainId),
|
260
|
+
startBlock: instance.startBlock,
|
261
|
+
endBlock: instance.endBlock,
|
262
|
+
},
|
263
|
+
ctx
|
264
|
+
)
|
243
265
|
}
|
244
266
|
}
|
245
267
|
|
@@ -255,7 +277,7 @@ export class EthPlugin extends Plugin {
|
|
255
277
|
|
256
278
|
const promises: Promise<ProcessResult>[] = []
|
257
279
|
for (const handlerId of request.handlerIds) {
|
258
|
-
const handler = this.eventHandlers[handlerId]
|
280
|
+
const handler = this.handlers.eventHandlers[handlerId]
|
259
281
|
promises.push(
|
260
282
|
handler(ethLog).catch((e) => {
|
261
283
|
throw new ServerError(
|
@@ -278,7 +300,7 @@ export class EthPlugin extends Plugin {
|
|
278
300
|
|
279
301
|
for (const handlerId of binding.handlerIds) {
|
280
302
|
promises.push(
|
281
|
-
this.traceHandlers[handlerId](ethTrace).catch((e) => {
|
303
|
+
this.handlers.traceHandlers[handlerId](ethTrace).catch((e) => {
|
282
304
|
throw new ServerError(
|
283
305
|
Status.INTERNAL,
|
284
306
|
'error processing trace: ' + JSON.stringify(ethTrace.trace) + '\n' + errorString(e)
|
@@ -298,7 +320,7 @@ export class EthPlugin extends Plugin {
|
|
298
320
|
const promises: Promise<ProcessResult>[] = []
|
299
321
|
for (const handlerId of binding.handlerIds) {
|
300
322
|
promises.push(
|
301
|
-
this.blockHandlers[handlerId](ethBlock).catch((e) => {
|
323
|
+
this.handlers.blockHandlers[handlerId](ethBlock).catch((e) => {
|
302
324
|
throw new ServerError(
|
303
325
|
Status.INTERNAL,
|
304
326
|
'error processing block: ' + ethBlock.block?.number + '\n' + errorString(e)
|
@@ -319,7 +341,7 @@ export class EthPlugin extends Plugin {
|
|
319
341
|
|
320
342
|
for (const handlerId of binding.handlerIds) {
|
321
343
|
promises.push(
|
322
|
-
this.transactionHandlers[handlerId](ethTransaction).catch((e) => {
|
344
|
+
this.handlers.transactionHandlers[handlerId](ethTransaction).catch((e) => {
|
323
345
|
throw new ServerError(
|
324
346
|
Status.INTERNAL,
|
325
347
|
'error processing transaction: ' + JSON.stringify(ethTransaction.transaction) + '\n' + errorString(e)
|
@@ -332,3 +354,16 @@ export class EthPlugin extends Plugin {
|
|
332
354
|
}
|
333
355
|
|
334
356
|
PluginManager.INSTANCE.register(new EthPlugin())
|
357
|
+
|
358
|
+
class NoopContext extends BaseContext {
|
359
|
+
public constructor() {
|
360
|
+
super()
|
361
|
+
}
|
362
|
+
getChainId(): string {
|
363
|
+
return ''
|
364
|
+
}
|
365
|
+
|
366
|
+
getMetaData(name: string, labels: Labels): RecordMetaData {
|
367
|
+
return RecordMetaData.create()
|
368
|
+
}
|
369
|
+
}
|
package/src/sui/sui-plugin.ts
CHANGED
@@ -19,14 +19,26 @@ import { SuiAccountProcessorState, SuiProcessorState } from './sui-processor.js'
|
|
19
19
|
import { getChainId } from './network.js'
|
20
20
|
import { validateAndNormalizeAddress } from './utils.js'
|
21
21
|
|
22
|
+
interface Handlers {
|
23
|
+
suiEventHandlers: ((event: Data_SuiEvent) => Promise<ProcessResult>)[]
|
24
|
+
suiCallHandlers: ((func: Data_SuiCall) => Promise<ProcessResult>)[]
|
25
|
+
suiObjectHandlers: ((object: Data_SuiObject) => Promise<ProcessResult>)[]
|
26
|
+
}
|
27
|
+
|
22
28
|
export class SuiPlugin extends Plugin {
|
23
29
|
name: string = 'SuiPlugin'
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
30
|
+
handlers: Handlers = {
|
31
|
+
suiCallHandlers: [],
|
32
|
+
suiEventHandlers: [],
|
33
|
+
suiObjectHandlers: [],
|
34
|
+
}
|
28
35
|
|
29
36
|
async configure(config: ProcessConfigResponse) {
|
37
|
+
const handlers: Handlers = {
|
38
|
+
suiCallHandlers: [],
|
39
|
+
suiEventHandlers: [],
|
40
|
+
suiObjectHandlers: [],
|
41
|
+
}
|
30
42
|
for (const suiProcessor of SuiProcessorState.INSTANCE.getValues()) {
|
31
43
|
const contractConfig = ContractConfig.fromPartial({
|
32
44
|
transactionConfig: [],
|
@@ -40,7 +52,7 @@ export class SuiPlugin extends Plugin {
|
|
40
52
|
startBlock: suiProcessor.config.startCheckpoint,
|
41
53
|
})
|
42
54
|
for (const handler of suiProcessor.eventHandlers) {
|
43
|
-
const handlerId =
|
55
|
+
const handlerId = handlers.suiEventHandlers.push(handler.handler) - 1
|
44
56
|
const eventHandlerConfig: MoveEventHandlerConfig = {
|
45
57
|
filters: handler.filters.map((f) => {
|
46
58
|
return {
|
@@ -54,7 +66,7 @@ export class SuiPlugin extends Plugin {
|
|
54
66
|
contractConfig.moveEventConfigs.push(eventHandlerConfig)
|
55
67
|
}
|
56
68
|
for (const handler of suiProcessor.callHandlers) {
|
57
|
-
const handlerId =
|
69
|
+
const handlerId = handlers.suiCallHandlers.push(handler.handler) - 1
|
58
70
|
const functionHandlerConfig: MoveCallHandlerConfig = {
|
59
71
|
filters: handler.filters.map((filter) => {
|
60
72
|
return {
|
@@ -79,7 +91,7 @@ export class SuiPlugin extends Plugin {
|
|
79
91
|
startBlock: processor.config.startCheckpoint, // TODO maybe use another field
|
80
92
|
})
|
81
93
|
for (const handler of processor.objectHandlers) {
|
82
|
-
const handlerId =
|
94
|
+
const handlerId = handlers.suiObjectHandlers.push(handler.handler) - 1
|
83
95
|
accountConfig.moveIntervalConfigs.push({
|
84
96
|
intervalConfig: {
|
85
97
|
handlerId: handlerId,
|
@@ -95,6 +107,7 @@ export class SuiPlugin extends Plugin {
|
|
95
107
|
}
|
96
108
|
config.accountConfigs.push(accountConfig)
|
97
109
|
}
|
110
|
+
this.handlers = handlers
|
98
111
|
}
|
99
112
|
|
100
113
|
supportedHandlers = [HandlerType.SUI_EVENT, HandlerType.SUI_CALL, HandlerType.SUI_OBJECT]
|
@@ -108,7 +121,7 @@ export class SuiPlugin extends Plugin {
|
|
108
121
|
|
109
122
|
for (const handlerId of binding.handlerIds) {
|
110
123
|
promises.push(
|
111
|
-
this.suiEventHandlers[handlerId](event).catch((e) => {
|
124
|
+
this.handlers.suiEventHandlers[handlerId](event).catch((e) => {
|
112
125
|
throw new ServerError(
|
113
126
|
Status.INTERNAL,
|
114
127
|
'error processing event: ' + JSON.stringify(event) + '\n' + errorString(e)
|
@@ -127,7 +140,7 @@ export class SuiPlugin extends Plugin {
|
|
127
140
|
|
128
141
|
const promises: Promise<ProcessResult>[] = []
|
129
142
|
for (const handlerId of binding.handlerIds) {
|
130
|
-
const promise = this.suiCallHandlers[handlerId](call).catch((e) => {
|
143
|
+
const promise = this.handlers.suiCallHandlers[handlerId](call).catch((e) => {
|
131
144
|
throw new ServerError(Status.INTERNAL, 'error processing call: ' + JSON.stringify(call) + '\n' + errorString(e))
|
132
145
|
})
|
133
146
|
promises.push(promise)
|
@@ -144,7 +157,7 @@ export class SuiPlugin extends Plugin {
|
|
144
157
|
const promises: Promise<ProcessResult>[] = []
|
145
158
|
for (const handlerId of binding.handlerIds) {
|
146
159
|
promises.push(
|
147
|
-
this.suiObjectHandlers[handlerId](object).catch((e) => {
|
160
|
+
this.handlers.suiObjectHandlers[handlerId](object).catch((e) => {
|
148
161
|
throw new ServerError(
|
149
162
|
Status.INTERNAL,
|
150
163
|
'error processing object: ' + JSON.stringify(object) + '\n' + errorString(e)
|