@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.
@@ -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
- private suiEventHandlers;
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 {};
@@ -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
- suiEventHandlers = [];
10
- suiCallHandlers = [];
11
- suiObjectHandlers = [];
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 = this.suiEventHandlers.push(handler.handler) - 1;
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 = this.suiCallHandlers.push(handler.handler) - 1;
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 = this.suiObjectHandlers.push(handler.handler) - 1;
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,E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AM,CAAC,GAAG,IAAI,GAAG,WAAW,CAAC,CAAC,CAAC,CAC7E,CAAA;YACH,CAAC,CAAC,CACH,CAAA;SACF;QACD,OAAO,mBAAmB,CAAC,MAAM,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAA;IACzD,CAAC;IAED,cAAc,CAAC,OAAoB;QACjC,QAAQ,OAAO,CAAC,WAAW,EAAE;YAC3B,KAAK,WAAW,CAAC,SAAS;gBACxB,OAAO,IAAI,CAAC,eAAe,CAAC,OAAO,CAAC,CAAA;YACtC,KAAK,WAAW,CAAC,QAAQ;gBACvB,OAAO,IAAI,CAAC,sBAAsB,CAAC,OAAO,CAAC,CAAA;YAC7C,KAAK,WAAW,CAAC,UAAU;gBACzB,OAAO,IAAI,CAAC,gBAAgB,CAAC,OAAO,CAAC,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,iBAAiB,EAAE,MAAM,oBAAoB,CAAA;AAChF,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AACzC,OAAO,EAAE,2BAA2B,EAAE,MAAM,YAAY,CAAA;AAQxD,MAAM,OAAO,SAAU,SAAQ,MAAM;IACnC,IAAI,GAAW,WAAW,CAAA;IAC1B,QAAQ,GAAa;QACnB,eAAe,EAAE,EAAE;QACnB,gBAAgB,EAAE,EAAE;QACpB,iBAAiB,EAAE,EAAE;KACtB,CAAA;IAED,KAAK,CAAC,SAAS,CAAC,MAA6B;QAC3C,MAAM,QAAQ,GAAa;YACzB,eAAe,EAAE,EAAE;YACnB,gBAAgB,EAAE,EAAE;YACpB,iBAAiB,EAAE,EAAE;SACtB,CAAA;QACD,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,YAA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IAAI,CAAC,eAAe,CAAC,OAAO,CAAC,CAAA;YACtC,KAAK,WAAW,CAAC,QAAQ;gBACvB,OAAO,IAAI,CAAC,sBAAsB,CAAC,OAAO,CAAC,CAAA;YAC7C,KAAK,WAAW,CAAC,UAAU;gBACzB,OAAO,IAAI,CAAC,gBAAgB,CAAC,OAAO,CAAC,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\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"]}
@@ -13,9 +13,10 @@ export default defineConfig({
13
13
  sourcemap: 'inline',
14
14
  clean: true,
15
15
  format: 'esm',
16
- dts: {
17
- resolve: true,
18
- },
16
+ // dts: {
17
+ // resolve: true,
18
+ // },
19
+ publicDir: '../abis',
19
20
  splitting: false,
20
21
  external: [
21
22
  'protobufjs',
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@sentio/sdk",
3
3
  "license": "Apache-2.0",
4
- "version": "2.13.7",
4
+ "version": "2.14.0-rc.2",
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.13.7",
34
- "@sentio/runtime": "^2.13.7"
33
+ "@sentio/protos": "^2.14.0-rc.2",
34
+ "@sentio/runtime": "^2.14.0-rc.2"
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
- private aptosEventHandlers: ((event: Data_AptEvent) => Promise<ProcessResult>)[] = []
29
- private aptosCallHandlers: ((func: Data_AptCall) => Promise<ProcessResult>)[] = []
30
- private aptosResourceHandlers: ((resourceWithVersion: Data_AptResource) => Promise<ProcessResult>)[] = []
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 = this.aptosEventHandlers.push(handler.handler) - 1
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 = this.aptosCallHandlers.push(handler.handler) - 1
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 = this.aptosResourceHandlers.push(handler.handler) - 1
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)
@@ -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,10 +49,21 @@ export abstract class BaseProcessorTemplate<
48
49
  ProcessorTemplateProcessorState.INSTANCE.addValue(this)
49
50
  }
50
51
 
51
- public bind(options: BindOptions): void {
52
- const sig = getOptionsSignature({ address: options.address, network: options.network })
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
- console.log('Same address can be bind to one template only once')
66
+ console.log(`Same address can be bind to one template only once, ignore duplicate bind: ${sig}`)
55
67
  return
56
68
  }
57
69
  this.binds.add(sig)
@@ -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(
@@ -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
- private eventHandlers: ((event: Data_EthLog) => Promise<ProcessResult>)[] = []
29
- private traceHandlers: ((trace: Data_EthTrace) => Promise<ProcessResult>)[] = []
30
- private blockHandlers: ((block: Data_EthBlock) => Promise<ProcessResult>)[] = []
31
- private transactionHandlers: ((trace: Data_EthTransaction) => Promise<ProcessResult>)[] = []
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 = this.blockHandlers.push(blockHandler.handler) - 1
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 = this.traceHandlers.push(traceHandler.handler) - 1
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 = this.eventHandlers.push(eventsHandler.handler) - 1
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 = this.blockHandlers.push(blockHandler.handler) - 1
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 = this.transactionHandlers.push(transactionHandler.handler) - 1
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 = this.eventHandlers.push(eventsHandler.handler) - 1
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
- name: instance.contract.name,
238
- address: validateAndNormalizeAddress(instance.contract.address),
239
- network: Number(instance.contract.chainId),
240
- startBlock: instance.startBlock,
241
- endBlock: instance.endBlock,
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
+ }
@@ -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
- private suiEventHandlers: ((event: Data_SuiEvent) => Promise<ProcessResult>)[] = []
26
- private suiCallHandlers: ((func: Data_SuiCall) => Promise<ProcessResult>)[] = []
27
- private suiObjectHandlers: ((object: Data_SuiObject) => Promise<ProcessResult>)[] = []
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 = this.suiEventHandlers.push(handler.handler) - 1
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 = this.suiCallHandlers.push(handler.handler) - 1
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 = this.suiObjectHandlers.push(handler.handler) - 1
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)
@@ -13,9 +13,10 @@ export default defineConfig({
13
13
  sourcemap: 'inline',
14
14
  clean: true,
15
15
  format: 'esm',
16
- dts: {
17
- resolve: true,
18
- },
16
+ // dts: {
17
+ // resolve: true,
18
+ // },
19
+ publicDir: '../abis',
19
20
  splitting: false,
20
21
  external: [
21
22
  'protobufjs',