@sentio/sdk 2.13.7 → 2.14.0-rc.2
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 +15 -3
- 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/lib/tsup.config.ts +4 -3
- 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 +16 -3
- package/src/eth/eth-plugin.ts +57 -22
- package/src/sui/sui-plugin.ts +23 -10
- package/src/tsup.config.ts +4 -3
@@ -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,CA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,CAAA;SACF;QACD,OAAO,mBAAmB,CAAC,MAAM,OAAO,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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I,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\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,10 +20,21 @@ 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
|
-
console.log(
|
37
|
+
console.log(`Same address can be bind to one template only once, ignore duplicate bind: ${sig}`);
|
27
38
|
return;
|
28
39
|
}
|
29
40
|
this.binds.add(sig);
|
@@ -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,CA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AAO,IAAI,CAAC,UAAU,CACpB,OAAO,EACP,EAAE,cAAc,EAAE,qBAAqB,EAAE,gBAAgB,EAAE,qBAAqB,EAAE,EAClF,SAAS,EACT,WAAW,CACZ,CAAA;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, ignore duplicate bind: ${sig}`)\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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Aa,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_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,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S,CAAC,CAAC,cAAc,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE;gBACvE,MAAM,IAAI,WAAW,CACnB,MAAM,CAAC,QAAQ,EACf,gCAAgC,GAAG,IAAI,CAAC,SAAS,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"]}
|