@sentio/sdk 2.8.0-rc.3 → 2.9.0-rc.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,5 @@
1
1
  import { Plugin, PluginManager, errorString, mergeProcessResults, USER_PROCESSOR } from '@sentio/runtime';
2
- import { ContractConfig, HandlerType, } from '@sentio/protos';
2
+ import { AccountConfig, ContractConfig, HandlerType, } from '@sentio/protos';
3
3
  import { ServerError, Status } from 'nice-grpc';
4
4
  import { AptosAccountProcessorState, AptosProcessorState } from './aptos-processor.js';
5
5
  import { initCoinList } from './ext/coin.js';
@@ -58,14 +58,11 @@ export class AptosPlugin extends Plugin {
58
58
  config.contractConfigs.push(contractConfig);
59
59
  }
60
60
  for (const aptosProcessor of AptosAccountProcessorState.INSTANCE.getValues()) {
61
- const accountConfig = {
61
+ const accountConfig = AccountConfig.fromPartial({
62
62
  address: aptosProcessor.config.address,
63
63
  chainId: aptosProcessor.getChainId(),
64
64
  startBlock: aptosProcessor.config.startVersion,
65
- aptosIntervalConfigs: [],
66
- intervalConfigs: [],
67
- logConfigs: [],
68
- };
65
+ });
69
66
  for (const handler of aptosProcessor.resourcesHandlers) {
70
67
  const handlerId = this.aptosResourceHandlers.push(handler.handler) - 1;
71
68
  accountConfig.aptosIntervalConfigs.push({
@@ -1 +1 @@
1
- {"version":3,"file":"aptos-plugin.js","sourceRoot":"","sources":["../../src/aptos/aptos-plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,WAAW,EAAE,mBAAmB,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAA;AACzG,OAAO,EAIL,cAAc,EAKd,WAAW,GAIZ,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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,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 { Plugin, PluginManager, errorString, mergeProcessResults, USER_PROCESSOR } from '@sentio/runtime'\nimport {\n AccountConfig,\n MoveCallHandlerConfig,\n MoveEventHandlerConfig,\n ContractConfig,\n Data_AptCall,\n Data_AptEvent,\n Data_AptResource,\n DataBinding,\n HandlerType,\n ProcessConfigResponse,\n ProcessResult,\n StartRequest,\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'\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: 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 = {\n address: aptosProcessor.config.address,\n chainId: aptosProcessor.getChainId(),\n startBlock: aptosProcessor.config.startVersion,\n aptosIntervalConfigs: [],\n intervalConfigs: [],\n logConfigs: [],\n }\n for (const handler of aptosProcessor.resourcesHandlers) {\n const handlerId = this.aptosResourceHandlers.push(handler.handler) - 1\n accountConfig.aptosIntervalConfigs.push({\n intervalConfig: {\n handlerId: handlerId,\n minutes: 0,\n minutesInterval: handler.timeIntervalInMinutes,\n slot: 0,\n slotInterval: handler.versionInterval,\n },\n type: handler.type || '',\n })\n }\n config.accountConfigs.push(accountConfig)\n }\n }\n\n supportedHandlers = [HandlerType.APT_CALL, HandlerType.APT_RESOURCE, HandlerType.APT_EVENT]\n\n 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,MAAM,EAAE,aAAa,EAAE,WAAW,EAAE,mBAAmB,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAA;AACzG,OAAO,EACL,aAAa,EAGb,cAAc,EAKd,WAAW,GAIZ,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;AAE5C,MAAM,OAAO,WAAY,SAAQ,MAAM;IACrC,IAAI,GAAW,aAAa,CAAA;IAEpB,kBAAkB,GAAyD,EAAE,CAAA;IAC7E,iBAAiB,GAAuD,EAAE,CAAA;IAC1E,qBAAqB,GAA0E,EAAE,CAAA;IAEzG,KAAK,CAAC,KAAK,CAAC,KAAmB;QAC7B,MAAM,YAAY,EAAE,CAAA;IACtB,CAAC;IAED,KAAK,CAAC,SAAS,CAAC,MAA6B;QAC3C,KAAK,MAAM,cAAc,IAAI,mBAAmB,CAAC,QAAQ,CAAC,SAAS,EAAE,EAAE;YACrE,MAAM,cA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AC,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 { Plugin, PluginManager, errorString, mergeProcessResults, USER_PROCESSOR } from '@sentio/runtime'\nimport {\n AccountConfig,\n MoveCallHandlerConfig,\n MoveEventHandlerConfig,\n ContractConfig,\n Data_AptCall,\n Data_AptEvent,\n Data_AptResource,\n DataBinding,\n HandlerType,\n ProcessConfigResponse,\n ProcessResult,\n StartRequest,\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'\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: 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: 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 accountConfig.aptosIntervalConfigs.push({\n intervalConfig: {\n handlerId: handlerId,\n minutes: 0,\n minutesInterval: handler.timeIntervalInMinutes,\n slot: 0,\n slotInterval: handler.versionInterval,\n },\n type: handler.type || '',\n })\n }\n config.accountConfigs.push(accountConfig)\n }\n }\n\n supportedHandlers = [HandlerType.APT_CALL, HandlerType.APT_RESOURCE, HandlerType.APT_EVENT]\n\n 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"]}
@@ -93,3 +93,4 @@ export declare const CHAIN_IDS: {
93
93
  export declare const CHAIN_MAP: Record<string, string>;
94
94
  export declare function getChainName(chainId: string | number | null | undefined): string;
95
95
  export declare function getChainType(chainId?: string | number): string;
96
+ export declare function getChainScanUrl(chainId?: string | number, hash?: string, subtype?: 'block' | 'address' | 'transaction'): string | undefined;
package/lib/core/chain.js CHANGED
@@ -126,4 +126,63 @@ export function getChainType(chainId) {
126
126
  }
127
127
  return 'EVM';
128
128
  }
129
+ export function getChainScanUrl(chainId, hash, subtype) {
130
+ const chainName = getChainName(chainId);
131
+ if (chainName === 'Ethereum') {
132
+ if (subtype === 'block') {
133
+ return `https://etherscan.io/block/${hash}`;
134
+ }
135
+ else if (subtype === 'address') {
136
+ return `https://etherscan.io/address/${hash}`;
137
+ }
138
+ else {
139
+ return `https://etherscan.io/tx/${hash}`;
140
+ }
141
+ }
142
+ if (chainName === 'Polygon') {
143
+ if (subtype === 'block') {
144
+ return `https://polygonscan.com/block/${hash}`;
145
+ }
146
+ else if (subtype === 'address') {
147
+ return `https://polygonscan.com/address/${hash}`;
148
+ }
149
+ else {
150
+ return `https://polygonscan.com/tx/${hash}`;
151
+ }
152
+ }
153
+ if (chainName.startsWith('Aptos ')) {
154
+ if (subtype === 'block') {
155
+ return `https://explorer.aptos.io/block/${hash}`;
156
+ }
157
+ else if (subtype === 'address') {
158
+ return `https://explorer.aptos.io/account/${hash}`;
159
+ }
160
+ else {
161
+ return `https://explorer.aptos.io/txn/${hash}`;
162
+ }
163
+ }
164
+ if (chainName.startsWith('Solana ')) {
165
+ if (subtype === 'block') {
166
+ return `https://explorer.solana.com/block/${hash}`;
167
+ }
168
+ else if (subtype === 'address') {
169
+ return `https://explorer.solana.com/address/${hash}`;
170
+ }
171
+ else {
172
+ return `https://explorer.solana.io/tx/${hash}`;
173
+ }
174
+ }
175
+ if (chainName.startsWith('Sui ')) {
176
+ if (subtype === 'block') {
177
+ return `https://explorer.sui.io/block/${hash}`;
178
+ }
179
+ else if (subtype === 'address') {
180
+ return `https://explorer.sui.io/address/${hash}`;
181
+ }
182
+ else {
183
+ return `https://explorer.sui.io/transaction/${hash}`;
184
+ }
185
+ }
186
+ return undefined;
187
+ }
129
188
  //# sourceMappingURL=chain.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"chain.js","sourceRoot":"","sources":["../../src/core/chain.ts"],"names":[],"mappings":"AAAA,mFAAmF;AACnF,6EAA6E;AAE7E,MAAM,CAAC,MAAM,SAAS,GAAG;IACvB,MAAM,EAAE,GAAG;IACX,QAAQ,EAAE,GAAG;IACb,OAAO,EAAE,GAAG;IACZ,OAAO,EAAE,GAAG;IACZ,OAAO,EAAE,GAAG;IACZ,MAAM,EAAE,GAAG;IACX,KAAK,EAAE,GAAG;IACV,IAAI,EAAE,GAAG;IACT,QAAQ,EAAE,IAAI;IACd,QAAQ,EAAE,IAAI;IACd,OAAO,EAAE,IAAI;IACb,MAAM,EAAE,IAAI;IACZ,GAAG,EAAE,IAAI;IACT,KAAK,EAAE,IAAI;IACX,GAAG,EAAE,IAAI;IACT,GAAG,EAAE,IAAI;IACT,GAAG,EAAE,IAAI;IACT,OAAO,EAAE,IAAI;IACb,OAAO,EAAE,IAAI;IACb,OAAO,EAAE,IAAI;IACb,UAAU,EAAE,IAAI;IAChB,MAAM,EAAE,IAAI;IACZ,SAAS,EAAE,IAAI;IACf,GAAG,EAAE,IAAI;IACT,KAAK,EAAE,IAAI;IACX,SAAS,EAAE,IAAI;IACf,YAAY,EAAE,IAAI;IAClB,IAAI,EAAE,KAAK;IACX,KAAK,EAAE,KAAK;IACZ,WAAW,EAAE,KAAK;IAClB,IAAI,EAAE,KAAK;IACX,IAAI,EAAE,KAAK;IACX,OAAO,EAAE,KAAK;IACd,OAAO,EAAE,KAAK;IACd,KAAK,EAAE,KAAK;IACZ,SAAS,EAAE,KAAK;IAChB,MAAM,EAAE,KAAK;IACb,GAAG,EAAE,KAAK;IACV,IAAI,EAAE,KAAK;IACX,MAAM,EAAE,KAAK;IACb,MAAM,EAAE,KAAK;IACb,KAAK,EAAE,KAAK;IACZ,EAAE,EAAE,KAAK;IACT,MAAM,EAAE,K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MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,EAAE;IACpD,MAAM,KAAK,GAAG,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;IAC5B,SAAS,CAAC,KAAK,CAAC,GAAG,KAAK;SACrB,GAAG,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE;QACnB,OAAO,IAAI,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,CAAA;IAC9C,CAAC,CAAC;SACD,IAAI,CAAC,GAAG,CAAC,CAAA;CACb;AAED,MAAM,UAAU,YAAY,CAAC,OAA2C;IACtE,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE;QAC/B,OAAO,GAAG,OAAO,CAAC,QAAQ,EAAE,CAAA;KAC7B;IACD,IAAI,OAAO,EAAE;QACX,MAAM,IAAI,GAAG,SAAS,CAAC,OAAO,CAAC,CAAA;QAC/B,IAAI,IAAI,EAAE;YACR,OAAO,IAAI,CAAA;SACZ;KACF;IACD,OAAO,OAAO,IAAI,EAAE,CAAA;AACtB,CAAC;AAED,MAAM,UAAU,YAAY,CAAC,OAAyB;IACpD,MAAM,EAAE,GAAG,MAAM,CAAC,OAAO,CAAC,CAAC,WAAW,EAAE,CAAA;IACxC,IAAI,EAAE,CAAC,UAAU,CAAC,KAAK,CAAC,EAAE;QACxB,OAAO,QAAQ,CAAA;KAChB;IACD,IAAI,EAAE,CAAC,UAAU,CAAC,KAAK,CAAC,EAAE;QACxB,OAAO,KAAK,CAAA;KACb;IACD,IAAI,EAAE,CAAC,UAAU,CAAC,KAAK,CAAC,EAAE;QACxB,OAAO,OAAO,CAAA;KACf;IACD,OAAO,KAAK,CAAA;AACd,CAAC","sourcesContent":["// copy from https://github.com/DefiLlama/chainlist/blob/main/constants/chainIds.js\n// and https://besu.hyperledger.org/en/stable/Concepts/NetworkID-And-ChainID/\n\nexport const CHAIN_IDS = {\n KARDIA: '0',\n ETHEREUM: '1',\n EXPANSE: '2',\n ROPSTEN: '3',\n RINKEBY: '4',\n GOERLI: '5',\n KOTTI: '6',\n UBIQ: '8',\n OPTIMISM: '10',\n SONGBIRD: '19',\n ELASTOS: '20',\n CRONOS: '25',\n RSK: '30',\n TELOS: '40',\n XDC: '50',\n CSC: '52',\n ZYX: '55',\n BINANCE: '56',\n SYSCOIN: '57',\n GOCHAIN: '60',\n ETHCLASSIC: '61',\n MORDOR: '63',\n OKEXCHAIN: '66',\n HOO: '70',\n METER: '82',\n TOMOCHAIN: '88',\n BINANCE_TEST: '97',\n XDAI: '100',\n VELAS: '106',\n THUNDERCORE: '108',\n FUSE: '122',\n HECO: '128',\n POLYGON: '137',\n XDAIARB: '200',\n ASTOR: '212',\n ENERGYWEB: '246',\n FANTOM: '250',\n HPB: '269',\n BOBA: '288',\n KUCOIN: '321',\n SHIDEN: '336',\n THETA: '361',\n SX: '416',\n CANDLE: '534',\n ASTAR: '592',\n CALLISTO: '820',\n WANCHAIN: '888',\n METIS: '1088',\n OMCHAIN: '1246',\n MOONBEAM: '1284',\n MOONRIVER: '1285',\n MOONBASE: '1287',\n DEV: '2018',\n RONIN: '2020',\n KAVA: '2222',\n EZCHAIN: '2612',\n PHI: '4181',\n IOTEX: '4689',\n XLC: '5050',\n NAHMII: '5551',\n NMACTEST: '7777',\n KLAYTN: '8217',\n EVMOS: '9001',\n BASE_GOERLI: '84531',\n SMARTBCH: '10000',\n CRYSTALEUM: '103090',\n FUSION: '32659',\n ARBITRUM: '42161',\n CELO: '42220',\n OASIS: '42262',\n AVALANCHE: '43114',\n GODWOKEN: '71402',\n AKROMA: '200625',\n POLIS: '333999',\n ARBITRUM_TEST: '421613',\n SEPOLIA: '11155111',\n AURORA: '1313161554',\n HARMONY: '1666600000',\n PALM: '11297108109',\n CURIO: '836542336838601',\n SOLANA_MAINNET: 'sol_mainnet',\n SOLANA_DEVNET: 'sol_devnet',\n SOLANA_TESTNET: 'sol_testnet',\n SOLANA_PYTH: 'sol_pyth',\n SUI_MAINNET: 'sui_mainnet',\n SUI_TESTNET: 'sui_testnet',\n SUI_DEVNET: 'sui_devnet',\n APTOS_MAINNET: 'aptos_mainnet',\n APTOS_TESTNET: 'aptos_testnet',\n APTOS_DEVNET: 'aptos_devnet',\n}\n\nexport const CHAIN_MAP: Record<string, string> = {}\n\nfor (const [key, value] of Object.entries(CHAIN_IDS)) {\n const parts = key.split('_')\n CHAIN_MAP[value] = parts\n .map((part, index) => {\n return part[0] + part.slice(1).toLowerCase()\n })\n .join(' ')\n}\n\nexport function getChainName(chainId: string | number | null | undefined): string {\n if (typeof chainId === 'number') {\n chainId = chainId.toString()\n }\n if (chainId) {\n const name = CHAIN_MAP[chainId]\n if (name) {\n return name\n }\n }\n return chainId || ''\n}\n\nexport function getChainType(chainId?: string | number): string {\n const id = String(chainId).toLowerCase()\n if (id.startsWith('sol')) {\n return 'solana'\n }\n if (id.startsWith('sui')) {\n return 'sui'\n }\n if (id.startsWith('apt')) {\n return 'aptos'\n }\n return 'EVM'\n}\n"]}
1
+ {"version":3,"file":"chain.js","sourceRoot":"","sources":["../../src/core/chain.ts"],"names":[],"mappings":"AAAA,mFAAmF;AACnF,6EAA6E;AAE7E,MAAM,CAAC,MAAM,SAAS,GAAG;IACvB,MAAM,EAAE,GAAG;IACX,QAAQ,EAAE,GAAG;IACb,OAAO,EAAE,GAAG;IACZ,OAAO,EAAE,GAAG;IACZ,OAAO,EAAE,GAAG;IACZ,MAAM,EAAE,GAAG;IACX,KAAK,EAAE,GAAG;IACV,IAAI,EAAE,GAAG;IACT,QAAQ,EAAE,IAAI;IACd,QAAQ,EAAE,IAAI;IACd,OAAO,EAAE,IAAI;IACb,MAAM,EAAE,IAAI;IACZ,GAAG,EAAE,IAAI;IACT,KAAK,EAAE,IAAI;IACX,GAAG,EAAE,IAAI;IACT,GAAG,EAAE,IAAI;IACT,GAAG,EAAE,IAAI;IACT,OAAO,EAAE,IAAI;IACb,OAAO,EAAE,IAAI;IACb,OAAO,EAAE,IAA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AA;SACnD;aAAM;YACL,OAAO,iCAAiC,IAAI,EAAE,CAAA;SAC/C;KACF;IACD,IAAI,SAAS,CAAC,UAAU,CAAC,SAAS,CAAC,EAAE;QACnC,IAAI,OAAO,KAAK,OAAO,EAAE;YACvB,OAAO,qCAAqC,IAAI,EAAE,CAAA;SACnD;aAAM,IAAI,OAAO,KAAK,SAAS,EAAE;YAChC,OAAO,uCAAuC,IAAI,EAAE,CAAA;SACrD;aAAM;YACL,OAAO,iCAAiC,IAAI,EAAE,CAAA;SAC/C;KACF;IACD,IAAI,SAAS,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE;QAChC,IAAI,OAAO,KAAK,OAAO,EAAE;YACvB,OAAO,iCAAiC,IAAI,EAAE,CAAA;SAC/C;aAAM,IAAI,OAAO,KAAK,SAAS,EAAE;YAChC,OAAO,mCAAmC,IAAI,EAAE,CAAA;SACjD;aAAM;YACL,OAAO,uCAAuC,IAAI,EAAE,CAAA;SACrD;KACF;IACD,OAAO,SAAS,CAAA;AAClB,CAAC","sourcesContent":["// copy from https://github.com/DefiLlama/chainlist/blob/main/constants/chainIds.js\n// and https://besu.hyperledger.org/en/stable/Concepts/NetworkID-And-ChainID/\n\nexport const CHAIN_IDS = {\n KARDIA: '0',\n ETHEREUM: '1',\n EXPANSE: '2',\n ROPSTEN: '3',\n RINKEBY: '4',\n GOERLI: '5',\n KOTTI: '6',\n UBIQ: '8',\n OPTIMISM: '10',\n SONGBIRD: '19',\n ELASTOS: '20',\n CRONOS: '25',\n RSK: '30',\n TELOS: '40',\n XDC: '50',\n CSC: '52',\n ZYX: '55',\n BINANCE: '56',\n SYSCOIN: '57',\n GOCHAIN: '60',\n ETHCLASSIC: '61',\n MORDOR: '63',\n OKEXCHAIN: '66',\n HOO: '70',\n METER: '82',\n TOMOCHAIN: '88',\n BINANCE_TEST: '97',\n XDAI: '100',\n VELAS: '106',\n THUNDERCORE: '108',\n FUSE: '122',\n HECO: '128',\n POLYGON: '137',\n XDAIARB: '200',\n ASTOR: '212',\n ENERGYWEB: '246',\n FANTOM: '250',\n HPB: '269',\n BOBA: '288',\n KUCOIN: '321',\n SHIDEN: '336',\n THETA: '361',\n SX: '416',\n CANDLE: '534',\n ASTAR: '592',\n CALLISTO: '820',\n WANCHAIN: '888',\n METIS: '1088',\n OMCHAIN: '1246',\n MOONBEAM: '1284',\n MOONRIVER: '1285',\n MOONBASE: '1287',\n DEV: '2018',\n RONIN: '2020',\n KAVA: '2222',\n EZCHAIN: '2612',\n PHI: '4181',\n IOTEX: '4689',\n XLC: '5050',\n NAHMII: '5551',\n NMACTEST: '7777',\n KLAYTN: '8217',\n EVMOS: '9001',\n BASE_GOERLI: '84531',\n SMARTBCH: '10000',\n CRYSTALEUM: '103090',\n FUSION: '32659',\n ARBITRUM: '42161',\n CELO: '42220',\n OASIS: '42262',\n AVALANCHE: '43114',\n GODWOKEN: '71402',\n AKROMA: '200625',\n POLIS: '333999',\n ARBITRUM_TEST: '421613',\n SEPOLIA: '11155111',\n AURORA: '1313161554',\n HARMONY: '1666600000',\n PALM: '11297108109',\n CURIO: '836542336838601',\n SOLANA_MAINNET: 'sol_mainnet',\n SOLANA_DEVNET: 'sol_devnet',\n SOLANA_TESTNET: 'sol_testnet',\n SOLANA_PYTH: 'sol_pyth',\n SUI_MAINNET: 'sui_mainnet',\n SUI_TESTNET: 'sui_testnet',\n SUI_DEVNET: 'sui_devnet',\n APTOS_MAINNET: 'aptos_mainnet',\n APTOS_TESTNET: 'aptos_testnet',\n APTOS_DEVNET: 'aptos_devnet',\n}\n\nexport const CHAIN_MAP: Record<string, string> = {}\n\nfor (const [key, value] of Object.entries(CHAIN_IDS)) {\n const parts = key.split('_')\n CHAIN_MAP[value] = parts\n .map((part, index) => {\n return part[0] + part.slice(1).toLowerCase()\n })\n .join(' ')\n}\n\nexport function getChainName(chainId: string | number | null | undefined): string {\n if (typeof chainId === 'number') {\n chainId = chainId.toString()\n }\n if (chainId) {\n const name = CHAIN_MAP[chainId]\n if (name) {\n return name\n }\n }\n return chainId || ''\n}\n\nexport function getChainType(chainId?: string | number): string {\n const id = String(chainId).toLowerCase()\n if (id.startsWith('sol')) {\n return 'solana'\n }\n if (id.startsWith('sui')) {\n return 'sui'\n }\n if (id.startsWith('apt')) {\n return 'aptos'\n }\n return 'EVM'\n}\n\nexport function getChainScanUrl(\n chainId?: string | number,\n hash?: string,\n subtype?: 'block' | 'address' | 'transaction'\n): string | undefined {\n const chainName = getChainName(chainId)\n if (chainName === 'Ethereum') {\n if (subtype === 'block') {\n return `https://etherscan.io/block/${hash}`\n } else if (subtype === 'address') {\n return `https://etherscan.io/address/${hash}`\n } else {\n return `https://etherscan.io/tx/${hash}`\n }\n }\n if (chainName === 'Polygon') {\n if (subtype === 'block') {\n return `https://polygonscan.com/block/${hash}`\n } else if (subtype === 'address') {\n return `https://polygonscan.com/address/${hash}`\n } else {\n return `https://polygonscan.com/tx/${hash}`\n }\n }\n if (chainName.startsWith('Aptos ')) {\n if (subtype === 'block') {\n return `https://explorer.aptos.io/block/${hash}`\n } else if (subtype === 'address') {\n return `https://explorer.aptos.io/account/${hash}`\n } else {\n return `https://explorer.aptos.io/txn/${hash}`\n }\n }\n if (chainName.startsWith('Solana ')) {\n if (subtype === 'block') {\n return `https://explorer.solana.com/block/${hash}`\n } else if (subtype === 'address') {\n return `https://explorer.solana.com/address/${hash}`\n } else {\n return `https://explorer.solana.io/tx/${hash}`\n }\n }\n if (chainName.startsWith('Sui ')) {\n if (subtype === 'block') {\n return `https://explorer.sui.io/block/${hash}`\n } else if (subtype === 'address') {\n return `https://explorer.sui.io/address/${hash}`\n } else {\n return `https://explorer.sui.io/transaction/${hash}`\n }\n }\n return undefined\n}\n"]}
@@ -1,7 +1,7 @@
1
1
  import { BaseContext } from './base-context.js';
2
2
  import { LogLevel } from '@sentio/protos';
3
3
  export interface Attribute<T> {
4
- [key: string]: Exclude<T | number | bigint | string | LogLevel | Attribute<T> | undefined, Promise<any>>;
4
+ [key: string]: Exclude<T | number | bigint | string | boolean | LogLevel | Attribute<T> | undefined, Promise<any>>;
5
5
  }
6
6
  export interface Event<T> extends Attribute<T> {
7
7
  distinctId?: string;
@@ -1 +1 @@
1
- {"version":3,"file":"event-logger.js","sourceRoot":"","sources":["../../src/core/event-logger.ts"],"names":[],"mappings":"AACA,OAAO,EAAuB,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AAC9D,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAA;AAevD,MAAM,OAAO,WAAW;IACL,GAAG,CAAa;IAEjC,YAAY,GAAgB;QAC1B,IAAI,CAAC,GAAG,GAAG,GAAG,CAAA;IAChB,CAAC;IAED,IAAI,CAAI,SAAiB,EAAE,KAAe;QACxC,MAAM,EAAE,UAAU,EAAE,QAAQ,EAAE,OAAO,EAAE,GAAG,OAAO,EAAE,GAAG,KAAK,CAAA;QAE3D,MAAM,GAAG,GAAwB;YAC/B,QAAQ,EAAE,IAAI,CAAC,GAAG,CAAC,WAAW,CAAC,SAAS,EAAE,EAAE,CAAC;YAC7C,QAAQ,EAAE,QAAQ,IAAI,QAAQ,CAAC,IAAI;YACnC,OAAO,EAAE,OAAO,IAAI,EAAE;YACtB,gBAAgB,EAAE,UAAU,IAAI,EAAE;YAClC,UAAU,EAAE,kBAAkB,CAAC,OAAO,CAAC;YACvC,WAAW,EAAE,SAAS;YACtB,QAAQ,EAAE,IAAI;SACf,CAAA;QACD,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;IAChC,CAAC;CACF","sourcesContent":["import { BaseContext } from './base-context.js'\nimport { EventTrackingResult, LogLevel } from '@sentio/protos'\nimport { normalizeAttribute } from './normalization.js'\n\nexport interface Attribute<T> {\n [key: string]: Exclude<T | number | bigint | string | LogLevel | Attribute<T> | undefined, Promise<any>>\n}\n\nexport interface Event<T> extends Attribute<T> {\n // The unique identifier of main identity associate with an event\n // .e.g user id / token address / account address / contract address id\n //\n distinctId?: string\n severity?: LogLevel\n message?: string\n}\n\nexport class EventLogger {\n private readonly ctx: BaseContext\n\n constructor(ctx: BaseContext) {\n this.ctx = ctx\n }\n\n emit<T>(eventName: string, event: Event<T>) {\n const { distinctId, severity, message, ...payload } = event\n\n const res: EventTrackingResult = {\n metadata: this.ctx.getMetaData(eventName, {}),\n severity: severity || LogLevel.INFO,\n message: message || '',\n distinctEntityId: distinctId || '',\n attributes: normalizeAttribute(payload),\n runtimeInfo: undefined,\n noMetric: true,\n }\n this.ctx._res.events.push(res)\n }\n}\n"]}
1
+ {"version":3,"file":"event-logger.js","sourceRoot":"","sources":["../../src/core/event-logger.ts"],"names":[],"mappings":"AACA,OAAO,EAAuB,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AAC9D,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAA;AAevD,MAAM,OAAO,WAAW;IACL,GAAG,CAAa;IAEjC,YAAY,GAAgB;QAC1B,IAAI,CAAC,GAAG,GAAG,GAAG,CAAA;IAChB,CAAC;IAED,IAAI,CAAI,SAAiB,EAAE,KAAe;QACxC,MAAM,EAAE,UAAU,EAAE,QAAQ,EAAE,OAAO,EAAE,GAAG,OAAO,EAAE,GAAG,KAAK,CAAA;QAE3D,MAAM,GAAG,GAAwB;YAC/B,QAAQ,EAAE,IAAI,CAAC,GAAG,CAAC,WAAW,CAAC,SAAS,EAAE,EAAE,CAAC;YAC7C,QAAQ,EAAE,QAAQ,IAAI,QAAQ,CAAC,IAAI;YACnC,OAAO,EAAE,OAAO,IAAI,EAAE;YACtB,gBAAgB,EAAE,UAAU,IAAI,EAAE;YAClC,UAAU,EAAE,kBAAkB,CAAC,OAAO,CAAC;YACvC,WAAW,EAAE,SAAS;YACtB,QAAQ,EAAE,IAAI;SACf,CAAA;QACD,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;IAChC,CAAC;CACF","sourcesContent":["import { BaseContext } from './base-context.js'\nimport { EventTrackingResult, LogLevel } from '@sentio/protos'\nimport { normalizeAttribute } from './normalization.js'\n\nexport interface Attribute<T> {\n [key: string]: Exclude<T | number | bigint | string | boolean | LogLevel | Attribute<T> | undefined, Promise<any>>\n}\n\nexport interface Event<T> extends Attribute<T> {\n // The unique identifier of main identity associate with an event\n // .e.g user id / token address / account address / contract address id\n //\n distinctId?: string\n severity?: LogLevel\n message?: string\n}\n\nexport class EventLogger {\n private readonly ctx: BaseContext\n\n constructor(ctx: BaseContext) {\n this.ctx = ctx\n }\n\n emit<T>(eventName: string, event: Event<T>) {\n const { distinctId, severity, message, ...payload } = event\n\n const res: EventTrackingResult = {\n metadata: this.ctx.getMetaData(eventName, {}),\n severity: severity || LogLevel.INFO,\n message: message || '',\n distinctEntityId: distinctId || '',\n attributes: normalizeAttribute(payload),\n runtimeInfo: undefined,\n noMetric: true,\n }\n this.ctx._res.events.push(res)\n }\n}\n"]}
@@ -1,5 +1,5 @@
1
1
  import { Plugin, PluginManager, errorString, mergeProcessResults, USER_PROCESSOR } from '@sentio/runtime';
2
- import { ContractConfig, HandlerType, } from '@sentio/protos';
2
+ import { AccountConfig, ContractConfig, HandlerType, } 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';
@@ -87,14 +87,11 @@ export class EthPlugin extends Plugin {
87
87
  }
88
88
  // part 1.b prepare EVM account processors
89
89
  for (const processor of AccountProcessorState.INSTANCE.getValues()) {
90
- const accountConfig = {
90
+ const accountConfig = AccountConfig.fromPartial({
91
91
  address: processor.config.address,
92
92
  chainId: processor.getChainId().toString(),
93
93
  startBlock: processor.config.startBlock ? BigInt(processor.config.startBlock) : 0n,
94
- aptosIntervalConfigs: [],
95
- intervalConfigs: [],
96
- logConfigs: [],
97
- };
94
+ });
98
95
  // TODO add interval
99
96
  for (const eventsHandler of processor.eventHandlers) {
100
97
  // associate id with filter
@@ -1 +1 @@
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AAE;gBAClD,MAAM,IAAI,WAAW,CACnB,MAAM,CAAC,QAAQ,EACf,0BAA0B,GAAG,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,WAAW,CAAC,CAAC,CAAC,CAC5E,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","sourcesContent":["import { Plugin, PluginManager, errorString, mergeProcessResults, USER_PROCESSOR } from '@sentio/runtime'\nimport {\n AccountConfig,\n ContractConfig,\n Data_EthBlock,\n Data_EthLog,\n Data_EthTrace,\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'\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\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: 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 })\n }\n\n // Step 2. Prepare all trace handlers\n for (const traceHandler of processor.traceHandlers) {\n const handlerId = this.traceHandlers.push(traceHandler.handler) - 1\n contractConfig.traceConfigs.push({\n signature: traceHandler.signature,\n handlerId: handlerId,\n fetchConfig: traceHandler.fetchConfig,\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,\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 // part 1.b prepare EVM account processors\n for (const processor of AccountProcessorState.INSTANCE.getValues()) {\n const accountConfig: AccountConfig = {\n address: processor.config.address,\n chainId: processor.getChainId().toString(),\n startBlock: processor.config.startBlock ? BigInt(processor.config.startBlock) : 0n,\n aptosIntervalConfigs: [],\n intervalConfigs: [],\n logConfigs: [],\n }\n // TODO add interval\n for (const eventsHandler of processor.eventHandlers) {\n // associate id with filter\n const handlerId = this.eventHandlers.push(eventsHandler.handler) - 1\n const logConfig: LogHandlerConfig = {\n handlerId: handlerId,\n filters: [],\n 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,\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]\n\n processBinding(request: DataBinding): Promise<ProcessResult> {\n // return Promise.resolve(undefined);\n switch (request.handlerType) {\n case HandlerType.ETH_LOG:\n return this.processLog(request)\n case HandlerType.ETH_TRACE:\n return this.processTrace(request)\n case HandlerType.ETH_BLOCK:\n return this.processBlock(request)\n default:\n throw new ServerError(Status.INVALID_ARGUMENT, 'No handle type registered ' + request.handlerType)\n }\n }\n\n async 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: 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\nPluginManager.INSTANCE.register(new EthPlugin())\n"]}
1
+ {"version":3,"file":"eth-plugin.js","sourceRoot":"","sources":["../../src/eth/eth-plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EA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,CAAC,CAAC,CAAC,CAC5E,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","sourcesContent":["import { Plugin, PluginManager, errorString, mergeProcessResults, USER_PROCESSOR } from '@sentio/runtime'\nimport {\n AccountConfig,\n ContractConfig,\n Data_EthBlock,\n Data_EthLog,\n Data_EthTrace,\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'\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\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: 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 })\n }\n\n // Step 2. Prepare all trace handlers\n for (const traceHandler of processor.traceHandlers) {\n const handlerId = this.traceHandlers.push(traceHandler.handler) - 1\n contractConfig.traceConfigs.push({\n signature: traceHandler.signature,\n handlerId: handlerId,\n fetchConfig: traceHandler.fetchConfig,\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,\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 // part 1.b prepare EVM account processors\n for (const processor of AccountProcessorState.INSTANCE.getValues()) {\n const accountConfig = AccountConfig.fromPartial({\n address: 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,\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]\n\n processBinding(request: DataBinding): Promise<ProcessResult> {\n // return Promise.resolve(undefined);\n switch (request.handlerType) {\n case HandlerType.ETH_LOG:\n return this.processLog(request)\n case HandlerType.ETH_TRACE:\n return this.processTrace(request)\n case HandlerType.ETH_BLOCK:\n return this.processBlock(request)\n default:\n throw new ServerError(Status.INVALID_ARGUMENT, 'No handle type registered ' + request.handlerType)\n }\n }\n\n async 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: 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\nPluginManager.INSTANCE.register(new EthPlugin())\n"]}
@@ -13,3 +13,12 @@ export declare class SuiContext extends BaseContext {
13
13
  getChainId(): string;
14
14
  getMetaData(name: string, labels: Labels): RecordMetaData;
15
15
  }
16
+ export declare class SuiObjectContext extends BaseContext {
17
+ address: string;
18
+ network: SuiNetwork;
19
+ slot: bigint;
20
+ timestamp: Date;
21
+ constructor(network: SuiNetwork, address: string, slot: bigint, timestamp: Date);
22
+ getChainId(): string;
23
+ getMetaData(name: string, labels: Labels): RecordMetaData;
24
+ }
@@ -35,4 +35,33 @@ export class SuiContext extends BaseContext {
35
35
  };
36
36
  }
37
37
  }
38
+ export class SuiObjectContext extends BaseContext {
39
+ address;
40
+ network;
41
+ slot;
42
+ timestamp;
43
+ constructor(network, address, slot, timestamp) {
44
+ super();
45
+ this.address = address;
46
+ this.network = network;
47
+ this.slot = slot;
48
+ this.timestamp = timestamp;
49
+ }
50
+ getChainId() {
51
+ return getChainId(this.network);
52
+ }
53
+ getMetaData(name, labels) {
54
+ return {
55
+ address: this.address,
56
+ contractName: 'objects',
57
+ blockNumber: this.slot,
58
+ transactionIndex: 0,
59
+ transactionHash: '',
60
+ logIndex: 0,
61
+ chainId: this.getChainId(),
62
+ name: name,
63
+ labels: normalizeLabels(labels),
64
+ };
65
+ }
66
+ }
38
67
  //# sourceMappingURL=context.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"context.js","sourceRoot":"","sources":["../../src/sui/context.ts"],"names":[],"mappings":"AACA,OAAO,EAAe,WAAW,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AACvE,OAAO,EAAc,UAAU,EAAE,MAAM,cAAc,CAAA;AAGrD,MAAM,OAAO,UAAW,SAAQ,WAAW;IACzC,OAAO,CAAQ;IACf,OAAO,CAAY;IACnB,UAAU,CAAQ;IAClB,SAAS,CAAM;IACf,IAAI,CAAQ;IACZ,WAAW,CAAwB;IAEnC,YACE,UAAkB,EAClB,OAAmB,EACnB,OAAe,EACf,SAAe,EACf,IAAY,EACZ,WAAoC;QAEpC,KAAK,EAAE,CAAA;QACP,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,WAAW,EAAE,CAAA;QACpC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;QACtB,IAAI,CAAC,UAAU,GAAG,UAAU,CAAA;QAC5B,IAAI,CAAC,SAAS,GAAG,SAAS,CAAA;QAC1B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;QAChB,IAAI,WAAW,EAAE;YACf,IAAI,CAAC,WAAW,GAAG,WAAW,CAAA;SAC/B;IACH,CAAC;IAED,UAAU;QACR,OAAO,UAAU,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;IACjC,CAAC;IAED,WAAW,CAAC,IAAY,EAAE,MAAc;QACtC,OAAO;YACL,OAAO,EAAE,IAAI,CAAC,OAAO;YACrB,YAAY,EAAE,IAAI,CAAC,UAAU;YAC7B,WAAW,EAAE,IAAI,CAAC,IAAI;YACtB,gBAAgB,EAAE,CAAC;YACnB,eAAe,EAAE,IAAI,CAAC,WAAW,EAAE,WAAW,CAAC,iBAAiB,IAAI,EAAE;YACtE,QAAQ,EAAE,CAAC;YACX,OAAO,EAAE,IAAI,CAAC,UAAU,EAAE;YAC1B,IAAI,EAAE,IAAI;YACV,MAAM,EAAE,eAAe,CAAC,MAAM,CAAC;SAChC,CAAA;IACH,CAAC;CACF","sourcesContent":["import { RecordMetaData } from '@sentio/protos'\nimport { type Labels, BaseContext, normalizeLabels } from '../index.js'\nimport { SuiNetwork, getChainId } from './network.js'\nimport { SuiTransactionResponse } from '@mysten/sui.js'\n\nexport class SuiContext extends BaseContext {\n address: string\n network: SuiNetwork\n moduleName: string\n timestamp: Date\n slot: bigint\n transaction: SuiTransactionResponse\n\n constructor(\n moduleName: string,\n network: SuiNetwork,\n address: string,\n timestamp: Date,\n slot: bigint,\n transaction?: SuiTransactionResponse\n ) {\n super()\n this.address = address.toLowerCase()\n this.network = network\n this.moduleName = moduleName\n this.timestamp = timestamp\n this.slot = slot\n if (transaction) {\n this.transaction = transaction\n }\n }\n\n getChainId(): string {\n return getChainId(this.network)\n }\n\n getMetaData(name: string, labels: Labels): RecordMetaData {\n return {\n address: this.address,\n contractName: this.moduleName,\n blockNumber: this.slot,\n transactionIndex: 0,\n transactionHash: this.transaction?.certificate.transactionDigest || '', // TODO\n logIndex: 0,\n chainId: this.getChainId(),\n name: name,\n labels: normalizeLabels(labels),\n }\n }\n}\n"]}
1
+ {"version":3,"file":"context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BAAiB,SAAQ,WAAW;IAC/C,OAAO,CAAQ;IACf,OAAO,CAAY;IACnB,IAAI,CAAQ;IACZ,SAAS,CAAM;IAEf,YAAY,OAAmB,EAAE,OAAe,EAAE,IAAY,EAAE,SAAe;QAC7E,KAAK,EAAE,CAAA;QACP,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;QACtB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;QACtB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;QAChB,IAAI,CAAC,SAAS,GAAG,SAAS,CAAA;IAC5B,CAAC;IAED,UAAU;QACR,OAAO,UAAU,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;IACjC,CAAC;IAED,WAAW,CAAC,IAAY,EAAE,MAAc;QACtC,OAAO;YACL,OAAO,EAAE,IAAI,CAAC,OAAO;YACrB,YAAY,EAAE,SAAS;YACvB,WAAW,EAAE,IAAI,CAAC,IAAI;YACtB,gBAAgB,EAAE,CAAC;YACnB,eAAe,EAAE,EAAE;YACnB,QAAQ,EAAE,CAAC;YACX,OAAO,EAAE,IAAI,CAAC,UAAU,EAAE;YAC1B,IAAI,EAAE,IAAI;YACV,MAAM,EAAE,eAAe,CAAC,MAAM,CAAC;SAChC,CAAA;IACH,CAAC;CACF","sourcesContent":["import { RecordMetaData } from '@sentio/protos'\nimport { type Labels, BaseContext, normalizeLabels } from '../index.js'\nimport { SuiNetwork, getChainId } from './network.js'\nimport { SuiTransactionResponse } from '@mysten/sui.js'\n\nexport class SuiContext extends BaseContext {\n address: string\n network: SuiNetwork\n moduleName: string\n timestamp: Date\n slot: bigint\n transaction: SuiTransactionResponse\n\n constructor(\n moduleName: string,\n network: SuiNetwork,\n address: string,\n timestamp: Date,\n slot: bigint,\n transaction?: SuiTransactionResponse\n ) {\n super()\n this.address = address.toLowerCase()\n this.network = network\n this.moduleName = moduleName\n this.timestamp = timestamp\n this.slot = slot\n if (transaction) {\n this.transaction = transaction\n }\n }\n\n getChainId(): string {\n return getChainId(this.network)\n }\n\n getMetaData(name: string, labels: Labels): RecordMetaData {\n return {\n address: this.address,\n contractName: this.moduleName,\n blockNumber: this.slot,\n transactionIndex: 0,\n transactionHash: this.transaction?.certificate.transactionDigest || '', // TODO\n logIndex: 0,\n chainId: this.getChainId(),\n name: name,\n labels: normalizeLabels(labels),\n }\n }\n}\n\nexport class SuiObjectContext extends BaseContext {\n address: string\n network: SuiNetwork\n slot: bigint\n timestamp: Date\n\n constructor(network: SuiNetwork, address: string, slot: bigint, timestamp: Date) {\n super()\n this.address = address\n this.network = network\n this.slot = slot\n this.timestamp = timestamp\n }\n\n getChainId(): string {\n return getChainId(this.network)\n }\n\n getMetaData(name: string, labels: Labels): RecordMetaData {\n return {\n address: this.address,\n contractName: 'objects',\n blockNumber: this.slot,\n transactionIndex: 0,\n transactionHash: '',\n logIndex: 0,\n chainId: this.getChainId(),\n name: name,\n labels: normalizeLabels(labels),\n }\n }\n}\n"]}
@@ -4,9 +4,11 @@ export declare class SuiPlugin extends Plugin {
4
4
  name: string;
5
5
  private suiEventHandlers;
6
6
  private suiCallHandlers;
7
+ private suiObjectHandlers;
7
8
  configure(config: ProcessConfigResponse): Promise<void>;
8
9
  supportedHandlers: HandlerType[];
9
10
  processSuiEvent(binding: DataBinding): Promise<ProcessResult>;
10
11
  processSuiFunctionCall(binding: DataBinding): Promise<ProcessResult>;
12
+ processSuiObject(binding: DataBinding): Promise<ProcessResult>;
11
13
  processBinding(request: DataBinding): Promise<ProcessResult>;
12
14
  }
@@ -1,12 +1,13 @@
1
1
  import { errorString, mergeProcessResults, Plugin, PluginManager, USER_PROCESSOR } from '@sentio/runtime';
2
- import { ContractConfig, HandlerType, } from '@sentio/protos';
2
+ import { AccountConfig, ContractConfig, HandlerType, } from '@sentio/protos';
3
3
  import { ServerError, Status } from 'nice-grpc';
4
- import { SuiProcessorState } from './sui-processor.js';
4
+ import { SuiAccountProcessorState, SuiProcessorState } from './sui-processor.js';
5
5
  import { getChainId } from './network.js';
6
6
  export class SuiPlugin extends Plugin {
7
7
  name = 'SuiPlugin';
8
8
  suiEventHandlers = [];
9
9
  suiCallHandlers = [];
10
+ suiObjectHandlers = [];
10
11
  async configure(config) {
11
12
  for (const suiProcessor of SuiProcessorState.INSTANCE.getValues()) {
12
13
  const contractConfig = ContractConfig.fromPartial({
@@ -52,6 +53,26 @@ export class SuiPlugin extends Plugin {
52
53
  }
53
54
  config.contractConfigs.push(contractConfig);
54
55
  }
56
+ for (const processor of SuiAccountProcessorState.INSTANCE.getValues()) {
57
+ const accountConfig = AccountConfig.fromPartial({
58
+ address: processor.config.address,
59
+ chainId: processor.getChainId(),
60
+ startBlock: BigInt(processor.config.startTimestamp), // TODO maybe use another field
61
+ });
62
+ for (const handler of processor.objectHandlers) {
63
+ const handlerId = this.suiObjectHandlers.push(handler.handler) - 1;
64
+ accountConfig.suiIntervalConfigs.push({
65
+ intervalConfig: {
66
+ handlerId: handlerId,
67
+ minutes: 0,
68
+ minutesInterval: handler.timeIntervalInMinutes,
69
+ slot: 0,
70
+ slotInterval: handler.versionInterval,
71
+ },
72
+ });
73
+ }
74
+ config.accountConfigs.push(accountConfig);
75
+ }
55
76
  }
56
77
  supportedHandlers = [HandlerType.SUI_EVENT, HandlerType.SUI_CALL];
57
78
  async processSuiEvent(binding) {
@@ -81,12 +102,27 @@ export class SuiPlugin extends Plugin {
81
102
  }
82
103
  return mergeProcessResults(await Promise.all(promises));
83
104
  }
105
+ async processSuiObject(binding) {
106
+ if (!binding.data?.suiObject) {
107
+ throw new ServerError(Status.INVALID_ARGUMENT, "Object can't be empty");
108
+ }
109
+ const object = binding.data.suiObject;
110
+ const promises = [];
111
+ for (const handlerId of binding.handlerIds) {
112
+ promises.push(this.suiObjectHandlers[handlerId](object).catch((e) => {
113
+ throw new ServerError(Status.INTERNAL, 'error processing object: ' + JSON.stringify(object) + '\n' + errorString(e));
114
+ }));
115
+ }
116
+ return mergeProcessResults(await Promise.all(promises));
117
+ }
84
118
  processBinding(request) {
85
119
  switch (request.handlerType) {
86
120
  case HandlerType.SUI_EVENT:
87
121
  return this.processSuiEvent(request);
88
122
  case HandlerType.SUI_CALL:
89
123
  return this.processSuiFunctionCall(request);
124
+ case HandlerType.SUI_OBJECT:
125
+ return this.processSuiObject(request);
90
126
  default:
91
127
  throw new ServerError(Status.INVALID_ARGUMENT, 'No handle type registered ' + request.handlerType);
92
128
  }
@@ -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,cAAc,EAId,WAAW,GAKZ,MAAM,gBAAgB,CAAA;AAEvB,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,WAAW,CAAA;AAE/C,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAA;AACtD,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AAEzC,MAAM,OAAO,SAAU,SAAQ,MAAM;IACnC,IAAI,GAAW,WAAW,CAAA;IAElB,gBAAgB,GAAyD,EAAE,CAAA;IAC3E,eAAe,GAAuD,EAAE,CAAA;IAEhF,KAAK,CAAC,SAAS,CAAC,MAA6B;QAC3C,KAAK,MAAM,YAAY,IAAI,iBAAiB,CAAC,QAAQ,CAAC,SAAS,EAAE,EAAE;YACjE,MAAM,cAAc,GAAG,cAAc,CAAC,WAAW,CAAC;gBAChD,iBAAiB,EAAE,EAAE;gBACrB,aAAa,EAAE,cAAc;gBAC7B,QAAQ,EAAE;oBACR,IAAI,EAAE,YAAY,CAAC,UAAU;oBAC7B,OAAO,EAAE,UAAU,CAAC,YAAY,CAAC,MAAM,CAAC,OAAO,CAAC;oBAChD,OAAO,EAAE,YAAY,CAAC,MAAM,CAAC,OAAO;oBACpC,GAAG,EAAE,EAAE;iBACR;gBACD,UAAU,EAAE,MA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YAC1C,MAAM,OAAO,GAAG,IAAI,CAAC,eAAe,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE;gBAChE,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;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;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 ContractConfig,\n Data_SuiCall,\n Data_SuiEvent,\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 { SuiProcessorState } from './sui-processor.js'\nimport { getChainId } from './network.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\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: suiProcessor.config.address,\n abi: '',\n },\n startBlock: BigInt(suiProcessor.config.startTimestamp),\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\n supportedHandlers = [HandlerType.SUI_EVENT, HandlerType.SUI_CALL]\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 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 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;AAEzC,MAAM,OAAO,SAAU,SAAQ,MAAM;IACnC,IAAI,GAAW,WAAW,CAAA;IAElB,gBAAgB,GAAyD,EAAE,CAAA;IAC3E,eAAe,GAAuD,EAAE,CAAA;IACxE,iBAAiB,GAA2D,EAAE,CAAA;IAEtF,KAAK,CAA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,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'\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: suiProcessor.config.address,\n abi: '',\n },\n startBlock: BigInt(suiProcessor.config.startTimestamp),\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: processor.config.address,\n chainId: processor.getChainId(),\n startBlock: BigInt(processor.config.startTimestamp), // TODO maybe use another field\n })\n for (const handler of processor.objectHandlers) {\n const handlerId = this.suiObjectHandlers.push(handler.handler) - 1\n accountConfig.suiIntervalConfigs.push({\n intervalConfig: {\n handlerId: handlerId,\n minutes: 0,\n minutesInterval: handler.timeIntervalInMinutes,\n slot: 0,\n slotInterval: handler.versionInterval,\n },\n })\n }\n config.accountConfigs.push(accountConfig)\n }\n }\n\n supportedHandlers = [HandlerType.SUI_EVENT, HandlerType.SUI_CALL]\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,8 +1,8 @@
1
- import { Data_SuiCall, Data_SuiEvent, MoveFetchConfig } from '@sentio/protos';
1
+ import { Data_SuiCall, Data_SuiEvent, MoveFetchConfig, Data_SuiObject, ProcessResult, HandleInterval } from '@sentio/protos';
2
2
  import { ListStateStorage } from '@sentio/runtime';
3
3
  import { SuiNetwork } from './network.js';
4
- import { SuiContext } from './context.js';
5
- import { MoveEvent, MoveCall } from '@mysten/sui.js';
4
+ import { SuiContext, SuiObjectContext } from './context.js';
5
+ import { MoveEvent, MoveCall, SuiMoveObject } from '@mysten/sui.js';
6
6
  import { CallHandler, EventFilter, EventHandler, FunctionNameAndCallFilter } from '../move/index.js';
7
7
  declare class IndexConfigure {
8
8
  address: string;
@@ -27,4 +27,22 @@ export declare class SuiBaseProcessor {
27
27
  onMoveEvent(handler: (event: MoveEvent, ctx: SuiContext) => void, filter: EventFilter | EventFilter[], fetchConfig?: MoveFetchConfig): SuiBaseProcessor;
28
28
  onEntryFunctionCall(handler: (call: MoveCall, ctx: SuiContext) => void, filter: FunctionNameAndCallFilter | FunctionNameAndCallFilter[], fetchConfig?: MoveFetchConfig): SuiBaseProcessor;
29
29
  }
30
+ declare class ObjectHandler {
31
+ versionInterval?: HandleInterval;
32
+ timeIntervalInMinutes?: HandleInterval;
33
+ handler: (resource: Data_SuiObject) => Promise<ProcessResult>;
34
+ }
35
+ export declare class SuiAccountProcessorState extends ListStateStorage<SuiAccountProcessor> {
36
+ static INSTANCE: SuiAccountProcessorState;
37
+ }
38
+ export declare class SuiAccountProcessor {
39
+ config: IndexConfigure;
40
+ objectHandlers: ObjectHandler[];
41
+ static bind(options: SuiBindOptions): SuiAccountProcessor;
42
+ protected constructor(options: SuiBindOptions);
43
+ getChainId(): string;
44
+ private onInterval;
45
+ onTimeInterval(handler: (objects: SuiMoveObject[], ctx: SuiObjectContext) => void, timeIntervalInMinutes?: number, backfillTimeIntervalInMinutes?: number): this;
46
+ onSlotInterval(handler: (objects: SuiMoveObject[], ctx: SuiObjectContext) => void, slotInterval?: number, backfillSlotInterval?: number): this;
47
+ }
30
48
  export {};
@@ -1,8 +1,8 @@
1
- import { MoveFetchConfig } from '@sentio/protos';
1
+ import { MoveFetchConfig, } from '@sentio/protos';
2
2
  import { ListStateStorage } from '@sentio/runtime';
3
3
  import { SuiNetwork, getChainId } from './network.js';
4
4
  import { ServerError, Status } from 'nice-grpc';
5
- import { SuiContext } from './context.js';
5
+ import { SuiContext, SuiObjectContext } from './context.js';
6
6
  import { getMoveCalls } from './utils.js';
7
7
  import { defaultMoveCoder } from './move-coder.js';
8
8
  class IndexConfigure {
@@ -105,6 +105,50 @@ export class SuiBaseProcessor {
105
105
  return this;
106
106
  }
107
107
  }
108
+ class ObjectHandler {
109
+ versionInterval;
110
+ timeIntervalInMinutes;
111
+ handler;
112
+ }
113
+ export class SuiAccountProcessorState extends ListStateStorage {
114
+ static INSTANCE = new SuiAccountProcessorState();
115
+ }
116
+ export class SuiAccountProcessor {
117
+ config;
118
+ objectHandlers = [];
119
+ static bind(options) {
120
+ return new SuiAccountProcessor(options);
121
+ }
122
+ constructor(options) {
123
+ this.config = configure(options);
124
+ SuiAccountProcessorState.INSTANCE.addValue(this);
125
+ }
126
+ getChainId() {
127
+ return getChainId(this.config.network);
128
+ }
129
+ onInterval(handler, timeInterval, versionInterval) {
130
+ const processor = this;
131
+ this.objectHandlers.push({
132
+ handler: async function (data) {
133
+ const ctx = new SuiObjectContext(processor.config.network, processor.config.address, data.slot, data.timestamp || new Date(0));
134
+ await handler(data.objects, ctx);
135
+ return ctx.getProcessResult();
136
+ },
137
+ timeIntervalInMinutes: timeInterval,
138
+ versionInterval: versionInterval,
139
+ });
140
+ return this;
141
+ }
142
+ onTimeInterval(handler, timeIntervalInMinutes = 60, backfillTimeIntervalInMinutes = 240) {
143
+ return this.onInterval(handler, {
144
+ recentInterval: timeIntervalInMinutes,
145
+ backfillInterval: backfillTimeIntervalInMinutes,
146
+ }, undefined);
147
+ }
148
+ onSlotInterval(handler, slotInterval = 100000, backfillSlotInterval = 400000) {
149
+ return this.onInterval(handler, undefined, { recentInterval: slotInterval, backfillInterval: backfillSlotInterval });
150
+ }
151
+ }
108
152
  function configure(options) {
109
153
  return {
110
154
  startTimestamp: options.startTimestamp || 0,
@@ -1 +1 @@
1
- {"version":3,"file":"sui-processor.js","sourceR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,YAAY,CAAC,EAAE,CAAC,CAAA;oBAC1C,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE;wBACtB,MAAM,IAAI,WAAW,CAAC,MAAM,CAAC,gBAAgB,EAAE,yCAAyC,GAAG,KAAK,CAAC,MAAM,CAAC,CAAA;qBACzG;oBACD,MAAM,OAAO,GAAG,KAAK,CAAC,CAAC,CAAC,CAAA;oBACxB,MAAM,OAAO,GAAG,gBAAgB,EAAE,CAAC,qBAAqB,CAAC,OAAO,CAAC,CAAA;oBACjE,MAAM,OAAO,CAAC,OAAO,EAAE,GAAG,CAAC,CAAA;iBAC5B;gBACD,OAAO,GAAG,CAAC,gBAAgB,EAAE,CAAA;YAC/B,CAAC;YACD,OAAO,EAAE,QAAQ;YACjB,WAAW,EAAE,YAAY;SAC1B,CAAC,CAAA;QACF,OAAO,IAAI,CAAA;IACb,CAAC;CACF;AAED,SAAS,SAAS,CAAC,OAAuB;IACxC,OAAO;QACL,cAAc,EAAE,OAAO,CAAC,cAAc,IAAI,CAAC;QAC3C,OAAO,EAAE,OAAO,CAAC,OAAO;QACxB,OAAO,EAAE,OAAO,CAAC,OAAO,IAAI,UAAU,CAAC,QAAQ;KAChD,CAAA;AACH,CAAC","sourcesContent":["import { Data_SuiCall, Data_SuiEvent, MoveFetchConfig } from '@sentio/protos'\nimport { ListStateStorage } from '@sentio/runtime'\nimport { SuiNetwork, getChainId } from './network.js'\nimport { ServerError, Status } from 'nice-grpc'\nimport { SuiContext } from './context.js'\nimport { MoveEvent, SuiTransactionResponse, MoveCall } from '@mysten/sui.js'\nimport { CallHandler, EventFilter, EventHandler, FunctionNameAndCallFilter } from '../move/index.js'\nimport { getMoveCalls } from './utils.js'\nimport { defaultMoveCoder } from './move-coder.js'\n\nclass IndexConfigure {\n address: string\n network: SuiNetwork\n startTimestamp: number\n}\n\nexport class SuiBindOptions {\n address: string\n network?: SuiNetwork\n startTimestamp?: number\n}\n\nexport class SuiProcessorState extends ListStateStorage<SuiBaseProcessor> {\n static INSTANCE = new SuiProcessorState()\n}\n\nexport class SuiBaseProcessor {\n readonly moduleName: string\n config: IndexConfigure\n\n eventHandlers: EventHandler<Data_SuiEvent>[] = []\n callHandlers: CallHandler<Data_SuiCall>[] = []\n\n constructor(name: string, options: SuiBindOptions) {\n this.moduleName = name\n this.config = configure(options)\n SuiProcessorState.INSTANCE.addValue(this)\n }\n\n getChainId(): string {\n return getChainId(this.config.network)\n }\n\n public onMoveEvent(\n handler: (event: MoveEvent, ctx: SuiContext) => void,\n filter: EventFilter | EventFilter[],\n fetchConfig?: MoveFetchConfig\n ): SuiBaseProcessor {\n let _filters: EventFilter[] = []\n const _fetchConfig = fetchConfig || MoveFetchConfig.fromPartial({})\n\n if (Array.isArray(filter)) {\n _filters = filter\n } else {\n _filters.push(filter)\n }\n\n // const address = this.config.address\n // const moduleName = this.moduleName\n\n const processor = this\n\n this.eventHandlers.push({\n handler: async function (data) {\n if (!data.transaction) {\n throw new ServerError(Status.INVALID_ARGUMENT, 'event is null')\n }\n const txn = data.transaction as SuiTransactionResponse\n if (!txn.effects.events || !txn.effects.events.length) {\n throw new ServerError(Status.INVALID_ARGUMENT, 'no event in the transactions')\n }\n\n const ctx = new SuiContext(\n processor.moduleName,\n processor.config.network,\n processor.config.address,\n data.timestamp || new Date(0),\n data.slot,\n txn\n )\n\n const events = txn.effects.events\n txn.effects.events = []\n for (const evt of events) {\n if ('moveEvent' in evt) {\n const eventInstance = evt.moveEvent as MoveEvent\n const decoded = defaultMoveCoder().decodeEvent<any>(eventInstance)\n await handler(decoded || eventInstance, ctx)\n }\n }\n\n return ctx.getProcessResult()\n },\n filters: _filters,\n fetchConfig: _fetchConfig,\n })\n return this\n }\n\n public onEntryFunctionCall(\n handler: (call: MoveCall, ctx: SuiContext) => void,\n filter: FunctionNameAndCallFilter | FunctionNameAndCallFilter[],\n fetchConfig?: MoveFetchConfig\n ): SuiBaseProcessor {\n let _filters: FunctionNameAndCallFilter[] = []\n const _fetchConfig = fetchConfig || MoveFetchConfig.fromPartial({})\n\n if (Array.isArray(filter)) {\n _filters = filter\n } else {\n _filters.push(filter)\n }\n\n // const address = this.config.address\n // const moduleName = this.moduleName\n const processor = this\n\n this.callHandlers.push({\n handler: async function (data) {\n if (!data.transaction) {\n throw new ServerError(Status.INVALID_ARGUMENT, 'call is null')\n }\n const tx = data.transaction as SuiTransactionResponse\n\n const ctx = new SuiContext(\n processor.moduleName,\n processor.config.network,\n processor.config.address,\n data.timestamp || new Date(0),\n data.slot,\n tx\n )\n if (tx) {\n const calls: MoveCall[] = getMoveCalls(tx)\n if (calls.length !== 1) {\n throw new ServerError(Status.INVALID_ARGUMENT, 'Unexpected number of call transactions ' + calls.length)\n }\n const payload = calls[0]\n const decoded = defaultMoveCoder().decodeFunctionPayload(payload)\n await handler(decoded, ctx)\n }\n return ctx.getProcessResult()\n },\n filters: _filters,\n fetchConfig: _fetchConfig,\n })\n return this\n }\n}\n\nfunction configure(options: SuiBindOptions): IndexConfigure {\n return {\n startTimestamp: options.startTimestamp || 0,\n address: options.address,\n network: options.network || SuiNetwork.MAIN_NET,\n }\n}\n"]}
1
+ {"version":3,"file":"sui-processor.js","sourceRoot":"","sources":["../../src/sui/sui-processor.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,eAAe,GAIhB,MAAM,gBAAgB,CAAA;AACvB,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAClD,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AACrD,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,WAAW,CAAA;AAC/C,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAA;AAG3D,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;AACzC,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAElD,MAAM,cAAc;IAClB,OAAO,CAAQ;IACf,OAAO,CAAY;IACnB,cAAc,CAAQ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C,CAAA;QACF,OAAO,IAAI,CAAA;IACb,CAAC;IAEM,cAAc,CACnB,OAAkE,EAClE,qBAAqB,GAAG,EAAE,EAC1B,6BAA6B,GAAG,GAAG;QAEnC,OAAO,IAAI,CAAC,UAAU,CACpB,OAAO,EACP;YACE,cAAc,EAAE,qBAAqB;YACrC,gBAAgB,EAAE,6BAA6B;SAChD,EACD,SAAS,CACV,CAAA;IACH,CAAC;IAEM,cAAc,CACnB,OAAkE,EAClE,YAAY,GAAG,MAAM,EACrB,oBAAoB,GAAG,MAAM;QAE7B,OAAO,IAAI,CAAC,UAAU,CAAC,OAAO,EAAE,SAAS,EAAE,EAAE,cAAc,EAAE,YAAY,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,CAAC,CAAA;IACtH,CAAC;CACF;AAED,SAAS,SAAS,CAAC,OAAuB;IACxC,OAAO;QACL,cAAc,EAAE,OAAO,CAAC,cAAc,IAAI,CAAC;QAC3C,OAAO,EAAE,OAAO,CAAC,OAAO;QACxB,OAAO,EAAE,OAAO,CAAC,OAAO,IAAI,UAAU,CAAC,QAAQ;KAChD,CAAA;AACH,CAAC","sourcesContent":["import {\n Data_SuiCall,\n Data_SuiEvent,\n MoveFetchConfig,\n Data_SuiObject,\n ProcessResult,\n HandleInterval,\n} from '@sentio/protos'\nimport { ListStateStorage } from '@sentio/runtime'\nimport { SuiNetwork, getChainId } from './network.js'\nimport { ServerError, Status } from 'nice-grpc'\nimport { SuiContext, SuiObjectContext } from './context.js'\nimport { MoveEvent, SuiTransactionResponse, MoveCall, SuiMoveObject } from '@mysten/sui.js'\nimport { CallHandler, EventFilter, EventHandler, FunctionNameAndCallFilter } from '../move/index.js'\nimport { getMoveCalls } from './utils.js'\nimport { defaultMoveCoder } from './move-coder.js'\n\nclass IndexConfigure {\n address: string\n network: SuiNetwork\n startTimestamp: number\n}\n\nexport class SuiBindOptions {\n address: string\n network?: SuiNetwork\n startTimestamp?: number\n}\n\nexport class SuiProcessorState extends ListStateStorage<SuiBaseProcessor> {\n static INSTANCE = new SuiProcessorState()\n}\n\nexport class SuiBaseProcessor {\n readonly moduleName: string\n config: IndexConfigure\n\n eventHandlers: EventHandler<Data_SuiEvent>[] = []\n callHandlers: CallHandler<Data_SuiCall>[] = []\n\n constructor(name: string, options: SuiBindOptions) {\n this.moduleName = name\n this.config = configure(options)\n SuiProcessorState.INSTANCE.addValue(this)\n }\n\n getChainId(): string {\n return getChainId(this.config.network)\n }\n\n public onMoveEvent(\n handler: (event: MoveEvent, ctx: SuiContext) => void,\n filter: EventFilter | EventFilter[],\n fetchConfig?: MoveFetchConfig\n ): SuiBaseProcessor {\n let _filters: EventFilter[] = []\n const _fetchConfig = fetchConfig || MoveFetchConfig.fromPartial({})\n\n if (Array.isArray(filter)) {\n _filters = filter\n } else {\n _filters.push(filter)\n }\n\n // const address = this.config.address\n // const moduleName = this.moduleName\n\n const processor = this\n\n this.eventHandlers.push({\n handler: async function (data) {\n if (!data.transaction) {\n throw new ServerError(Status.INVALID_ARGUMENT, 'event is null')\n }\n const txn = data.transaction as SuiTransactionResponse\n if (!txn.effects.events || !txn.effects.events.length) {\n throw new ServerError(Status.INVALID_ARGUMENT, 'no event in the transactions')\n }\n\n const ctx = new SuiContext(\n processor.moduleName,\n processor.config.network,\n processor.config.address,\n data.timestamp || new Date(0),\n data.slot,\n txn\n )\n\n const events = txn.effects.events\n txn.effects.events = []\n for (const evt of events) {\n if ('moveEvent' in evt) {\n const eventInstance = evt.moveEvent as MoveEvent\n const decoded = defaultMoveCoder().decodeEvent<any>(eventInstance)\n await handler(decoded || eventInstance, ctx)\n }\n }\n\n return ctx.getProcessResult()\n },\n filters: _filters,\n fetchConfig: _fetchConfig,\n })\n return this\n }\n\n public onEntryFunctionCall(\n handler: (call: MoveCall, ctx: SuiContext) => void,\n filter: FunctionNameAndCallFilter | FunctionNameAndCallFilter[],\n fetchConfig?: MoveFetchConfig\n ): SuiBaseProcessor {\n let _filters: FunctionNameAndCallFilter[] = []\n const _fetchConfig = fetchConfig || MoveFetchConfig.fromPartial({})\n\n if (Array.isArray(filter)) {\n _filters = filter\n } else {\n _filters.push(filter)\n }\n\n // const address = this.config.address\n // const moduleName = this.moduleName\n const processor = this\n\n this.callHandlers.push({\n handler: async function (data) {\n if (!data.transaction) {\n throw new ServerError(Status.INVALID_ARGUMENT, 'call is null')\n }\n const tx = data.transaction as SuiTransactionResponse\n\n const ctx = new SuiContext(\n processor.moduleName,\n processor.config.network,\n processor.config.address,\n data.timestamp || new Date(0),\n data.slot,\n tx\n )\n if (tx) {\n const calls: MoveCall[] = getMoveCalls(tx)\n if (calls.length !== 1) {\n throw new ServerError(Status.INVALID_ARGUMENT, 'Unexpected number of call transactions ' + calls.length)\n }\n const payload = calls[0]\n const decoded = defaultMoveCoder().decodeFunctionPayload(payload)\n await handler(decoded, ctx)\n }\n return ctx.getProcessResult()\n },\n filters: _filters,\n fetchConfig: _fetchConfig,\n })\n return this\n }\n}\n\nclass ObjectHandler {\n versionInterval?: HandleInterval\n timeIntervalInMinutes?: HandleInterval\n handler: (resource: Data_SuiObject) => Promise<ProcessResult>\n}\n\nexport class SuiAccountProcessorState extends ListStateStorage<SuiAccountProcessor> {\n static INSTANCE = new SuiAccountProcessorState()\n}\n\nexport class SuiAccountProcessor {\n config: IndexConfigure\n\n objectHandlers: ObjectHandler[] = []\n\n static bind(options: SuiBindOptions): SuiAccountProcessor {\n return new SuiAccountProcessor(options)\n }\n\n protected constructor(options: SuiBindOptions) {\n this.config = configure(options)\n SuiAccountProcessorState.INSTANCE.addValue(this)\n }\n\n getChainId(): string {\n return getChainId(this.config.network)\n }\n\n private onInterval(\n handler: (resources: SuiMoveObject[], ctx: SuiObjectContext) => void,\n timeInterval: HandleInterval | undefined,\n versionInterval: HandleInterval | undefined\n ): this {\n const processor = this\n this.objectHandlers.push({\n handler: async function (data) {\n const ctx = new SuiObjectContext(\n processor.config.network,\n processor.config.address,\n data.slot,\n data.timestamp || new Date(0)\n )\n await handler(data.objects as SuiMoveObject[], ctx)\n return ctx.getProcessResult()\n },\n timeIntervalInMinutes: timeInterval,\n versionInterval: versionInterval,\n })\n return this\n }\n\n public onTimeInterval(\n handler: (objects: SuiMoveObject[], ctx: SuiObjectContext) => void,\n timeIntervalInMinutes = 60,\n backfillTimeIntervalInMinutes = 240\n ): this {\n return this.onInterval(\n handler,\n {\n recentInterval: timeIntervalInMinutes,\n backfillInterval: backfillTimeIntervalInMinutes,\n },\n undefined\n )\n }\n\n public onSlotInterval(\n handler: (objects: SuiMoveObject[], ctx: SuiObjectContext) => void,\n slotInterval = 100000,\n backfillSlotInterval = 400000\n ): this {\n return this.onInterval(handler, undefined, { recentInterval: slotInterval, backfillInterval: backfillSlotInterval })\n }\n}\n\nfunction configure(options: SuiBindOptions): IndexConfigure {\n return {\n startTimestamp: options.startTimestamp || 0,\n address: options.address,\n network: options.network || SuiNetwork.MAIN_NET,\n }\n}\n"]}
@@ -133,12 +133,12 @@ export declare function getPriceClient(address?: string): import("nice-grpc").Ra
133
133
  create(base?: {
134
134
  limit?: number | undefined;
135
135
  offset?: number | undefined;
136
- queryString?: string | undefined;
136
+ searchQuery?: string | undefined;
137
137
  } | undefined): import("@sentio/protos/price").ListCoinsRequest;
138
138
  fromPartial(object: {
139
139
  limit?: number | undefined;
140
140
  offset?: number | undefined;
141
- queryString?: string | undefined;
141
+ searchQuery?: string | undefined;
142
142
  }): import("@sentio/protos/price").ListCoinsRequest;
143
143
  };
144
144
  readonly requestStream: false;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@sentio/sdk",
3
3
  "license": "Apache-2.0",
4
- "version": "2.8.0-rc.3",
4
+ "version": "2.9.0-rc.1",
5
5
  "type": "module",
6
6
  "scripts": {
7
7
  "compile": "tsc && cp src/utils/*.csv lib/utils && cp src/tsup.config.ts lib",
@@ -23,8 +23,8 @@
23
23
  "@project-serum/anchor": "^0.26.0",
24
24
  "@sentio/bigdecimal": "^9.1.1-patch.3",
25
25
  "@sentio/ethers-v6": "^1.0.25",
26
- "@sentio/protos": "^2.8.0-rc.3",
27
- "@sentio/runtime": "^2.8.0-rc.3",
26
+ "@sentio/protos": "^2.9.0-rc.1",
27
+ "@sentio/runtime": "^2.9.0-rc.1",
28
28
  "@solana/web3.js": "^1.73.2",
29
29
  "@types/prettier": "^2.7.2",
30
30
  "aptos-sdk": "npm:aptos@^1.7.1",
@@ -80,5 +80,5 @@
80
80
  "engines": {
81
81
  "node": ">=16"
82
82
  },
83
- "gitHead": "e7a355fbddba85e25fc8291cc0695352edc6eef4"
83
+ "gitHead": "c20b39437140f1e2059dcc5b5f54eabadfa9bf58"
84
84
  }
@@ -80,14 +80,11 @@ export class AptosPlugin extends Plugin {
80
80
  }
81
81
 
82
82
  for (const aptosProcessor of AptosAccountProcessorState.INSTANCE.getValues()) {
83
- const accountConfig: AccountConfig = {
83
+ const accountConfig = AccountConfig.fromPartial({
84
84
  address: aptosProcessor.config.address,
85
85
  chainId: aptosProcessor.getChainId(),
86
86
  startBlock: aptosProcessor.config.startVersion,
87
- aptosIntervalConfigs: [],
88
- intervalConfigs: [],
89
- logConfigs: [],
90
- }
87
+ })
91
88
  for (const handler of aptosProcessor.resourcesHandlers) {
92
89
  const handlerId = this.aptosResourceHandlers.push(handler.handler) - 1
93
90
  accountConfig.aptosIntervalConfigs.push({
package/src/core/chain.ts CHANGED
@@ -131,3 +131,57 @@ export function getChainType(chainId?: string | number): string {
131
131
  }
132
132
  return 'EVM'
133
133
  }
134
+
135
+ export function getChainScanUrl(
136
+ chainId?: string | number,
137
+ hash?: string,
138
+ subtype?: 'block' | 'address' | 'transaction'
139
+ ): string | undefined {
140
+ const chainName = getChainName(chainId)
141
+ if (chainName === 'Ethereum') {
142
+ if (subtype === 'block') {
143
+ return `https://etherscan.io/block/${hash}`
144
+ } else if (subtype === 'address') {
145
+ return `https://etherscan.io/address/${hash}`
146
+ } else {
147
+ return `https://etherscan.io/tx/${hash}`
148
+ }
149
+ }
150
+ if (chainName === 'Polygon') {
151
+ if (subtype === 'block') {
152
+ return `https://polygonscan.com/block/${hash}`
153
+ } else if (subtype === 'address') {
154
+ return `https://polygonscan.com/address/${hash}`
155
+ } else {
156
+ return `https://polygonscan.com/tx/${hash}`
157
+ }
158
+ }
159
+ if (chainName.startsWith('Aptos ')) {
160
+ if (subtype === 'block') {
161
+ return `https://explorer.aptos.io/block/${hash}`
162
+ } else if (subtype === 'address') {
163
+ return `https://explorer.aptos.io/account/${hash}`
164
+ } else {
165
+ return `https://explorer.aptos.io/txn/${hash}`
166
+ }
167
+ }
168
+ if (chainName.startsWith('Solana ')) {
169
+ if (subtype === 'block') {
170
+ return `https://explorer.solana.com/block/${hash}`
171
+ } else if (subtype === 'address') {
172
+ return `https://explorer.solana.com/address/${hash}`
173
+ } else {
174
+ return `https://explorer.solana.io/tx/${hash}`
175
+ }
176
+ }
177
+ if (chainName.startsWith('Sui ')) {
178
+ if (subtype === 'block') {
179
+ return `https://explorer.sui.io/block/${hash}`
180
+ } else if (subtype === 'address') {
181
+ return `https://explorer.sui.io/address/${hash}`
182
+ } else {
183
+ return `https://explorer.sui.io/transaction/${hash}`
184
+ }
185
+ }
186
+ return undefined
187
+ }
@@ -3,7 +3,7 @@ import { EventTrackingResult, LogLevel } from '@sentio/protos'
3
3
  import { normalizeAttribute } from './normalization.js'
4
4
 
5
5
  export interface Attribute<T> {
6
- [key: string]: Exclude<T | number | bigint | string | LogLevel | Attribute<T> | undefined, Promise<any>>
6
+ [key: string]: Exclude<T | number | bigint | string | boolean | LogLevel | Attribute<T> | undefined, Promise<any>>
7
7
  }
8
8
 
9
9
  export interface Event<T> extends Attribute<T> {
@@ -114,14 +114,11 @@ export class EthPlugin extends Plugin {
114
114
 
115
115
  // part 1.b prepare EVM account processors
116
116
  for (const processor of AccountProcessorState.INSTANCE.getValues()) {
117
- const accountConfig: AccountConfig = {
117
+ const accountConfig = AccountConfig.fromPartial({
118
118
  address: processor.config.address,
119
119
  chainId: processor.getChainId().toString(),
120
120
  startBlock: processor.config.startBlock ? BigInt(processor.config.startBlock) : 0n,
121
- aptosIntervalConfigs: [],
122
- intervalConfigs: [],
123
- logConfigs: [],
124
- }
121
+ })
125
122
  // TODO add interval
126
123
  for (const eventsHandler of processor.eventHandlers) {
127
124
  // associate id with filter
@@ -48,3 +48,36 @@ export class SuiContext extends BaseContext {
48
48
  }
49
49
  }
50
50
  }
51
+
52
+ export class SuiObjectContext extends BaseContext {
53
+ address: string
54
+ network: SuiNetwork
55
+ slot: bigint
56
+ timestamp: Date
57
+
58
+ constructor(network: SuiNetwork, address: string, slot: bigint, timestamp: Date) {
59
+ super()
60
+ this.address = address
61
+ this.network = network
62
+ this.slot = slot
63
+ this.timestamp = timestamp
64
+ }
65
+
66
+ getChainId(): string {
67
+ return getChainId(this.network)
68
+ }
69
+
70
+ getMetaData(name: string, labels: Labels): RecordMetaData {
71
+ return {
72
+ address: this.address,
73
+ contractName: 'objects',
74
+ blockNumber: this.slot,
75
+ transactionIndex: 0,
76
+ transactionHash: '',
77
+ logIndex: 0,
78
+ chainId: this.getChainId(),
79
+ name: name,
80
+ labels: normalizeLabels(labels),
81
+ }
82
+ }
83
+ }
@@ -1,8 +1,10 @@
1
1
  import { errorString, mergeProcessResults, Plugin, PluginManager, USER_PROCESSOR } from '@sentio/runtime'
2
2
  import {
3
+ AccountConfig,
3
4
  ContractConfig,
4
5
  Data_SuiCall,
5
6
  Data_SuiEvent,
7
+ Data_SuiObject,
6
8
  DataBinding,
7
9
  HandlerType,
8
10
  MoveCallHandlerConfig,
@@ -13,7 +15,7 @@ import {
13
15
 
14
16
  import { ServerError, Status } from 'nice-grpc'
15
17
 
16
- import { SuiProcessorState } from './sui-processor.js'
18
+ import { SuiAccountProcessorState, SuiProcessorState } from './sui-processor.js'
17
19
  import { getChainId } from './network.js'
18
20
 
19
21
  export class SuiPlugin extends Plugin {
@@ -21,6 +23,7 @@ export class SuiPlugin extends Plugin {
21
23
 
22
24
  private suiEventHandlers: ((event: Data_SuiEvent) => Promise<ProcessResult>)[] = []
23
25
  private suiCallHandlers: ((func: Data_SuiCall) => Promise<ProcessResult>)[] = []
26
+ private suiObjectHandlers: ((object: Data_SuiObject) => Promise<ProcessResult>)[] = []
24
27
 
25
28
  async configure(config: ProcessConfigResponse) {
26
29
  for (const suiProcessor of SuiProcessorState.INSTANCE.getValues()) {
@@ -67,6 +70,27 @@ export class SuiPlugin extends Plugin {
67
70
  }
68
71
  config.contractConfigs.push(contractConfig)
69
72
  }
73
+
74
+ for (const processor of SuiAccountProcessorState.INSTANCE.getValues()) {
75
+ const accountConfig = AccountConfig.fromPartial({
76
+ address: processor.config.address,
77
+ chainId: processor.getChainId(),
78
+ startBlock: BigInt(processor.config.startTimestamp), // TODO maybe use another field
79
+ })
80
+ for (const handler of processor.objectHandlers) {
81
+ const handlerId = this.suiObjectHandlers.push(handler.handler) - 1
82
+ accountConfig.suiIntervalConfigs.push({
83
+ intervalConfig: {
84
+ handlerId: handlerId,
85
+ minutes: 0,
86
+ minutesInterval: handler.timeIntervalInMinutes,
87
+ slot: 0,
88
+ slotInterval: handler.versionInterval,
89
+ },
90
+ })
91
+ }
92
+ config.accountConfigs.push(accountConfig)
93
+ }
70
94
  }
71
95
 
72
96
  supportedHandlers = [HandlerType.SUI_EVENT, HandlerType.SUI_CALL]
@@ -107,12 +131,34 @@ export class SuiPlugin extends Plugin {
107
131
  return mergeProcessResults(await Promise.all(promises))
108
132
  }
109
133
 
134
+ async processSuiObject(binding: DataBinding): Promise<ProcessResult> {
135
+ if (!binding.data?.suiObject) {
136
+ throw new ServerError(Status.INVALID_ARGUMENT, "Object can't be empty")
137
+ }
138
+ const object = binding.data.suiObject
139
+
140
+ const promises: Promise<ProcessResult>[] = []
141
+ for (const handlerId of binding.handlerIds) {
142
+ promises.push(
143
+ this.suiObjectHandlers[handlerId](object).catch((e) => {
144
+ throw new ServerError(
145
+ Status.INTERNAL,
146
+ 'error processing object: ' + JSON.stringify(object) + '\n' + errorString(e)
147
+ )
148
+ })
149
+ )
150
+ }
151
+ return mergeProcessResults(await Promise.all(promises))
152
+ }
153
+
110
154
  processBinding(request: DataBinding): Promise<ProcessResult> {
111
155
  switch (request.handlerType) {
112
156
  case HandlerType.SUI_EVENT:
113
157
  return this.processSuiEvent(request)
114
158
  case HandlerType.SUI_CALL:
115
159
  return this.processSuiFunctionCall(request)
160
+ case HandlerType.SUI_OBJECT:
161
+ return this.processSuiObject(request)
116
162
  default:
117
163
  throw new ServerError(Status.INVALID_ARGUMENT, 'No handle type registered ' + request.handlerType)
118
164
  }
@@ -1,9 +1,16 @@
1
- import { Data_SuiCall, Data_SuiEvent, MoveFetchConfig } from '@sentio/protos'
1
+ import {
2
+ Data_SuiCall,
3
+ Data_SuiEvent,
4
+ MoveFetchConfig,
5
+ Data_SuiObject,
6
+ ProcessResult,
7
+ HandleInterval,
8
+ } from '@sentio/protos'
2
9
  import { ListStateStorage } from '@sentio/runtime'
3
10
  import { SuiNetwork, getChainId } from './network.js'
4
11
  import { ServerError, Status } from 'nice-grpc'
5
- import { SuiContext } from './context.js'
6
- import { MoveEvent, SuiTransactionResponse, MoveCall } from '@mysten/sui.js'
12
+ import { SuiContext, SuiObjectContext } from './context.js'
13
+ import { MoveEvent, SuiTransactionResponse, MoveCall, SuiMoveObject } from '@mysten/sui.js'
7
14
  import { CallHandler, EventFilter, EventHandler, FunctionNameAndCallFilter } from '../move/index.js'
8
15
  import { getMoveCalls } from './utils.js'
9
16
  import { defaultMoveCoder } from './move-coder.js'
@@ -148,6 +155,81 @@ export class SuiBaseProcessor {
148
155
  }
149
156
  }
150
157
 
158
+ class ObjectHandler {
159
+ versionInterval?: HandleInterval
160
+ timeIntervalInMinutes?: HandleInterval
161
+ handler: (resource: Data_SuiObject) => Promise<ProcessResult>
162
+ }
163
+
164
+ export class SuiAccountProcessorState extends ListStateStorage<SuiAccountProcessor> {
165
+ static INSTANCE = new SuiAccountProcessorState()
166
+ }
167
+
168
+ export class SuiAccountProcessor {
169
+ config: IndexConfigure
170
+
171
+ objectHandlers: ObjectHandler[] = []
172
+
173
+ static bind(options: SuiBindOptions): SuiAccountProcessor {
174
+ return new SuiAccountProcessor(options)
175
+ }
176
+
177
+ protected constructor(options: SuiBindOptions) {
178
+ this.config = configure(options)
179
+ SuiAccountProcessorState.INSTANCE.addValue(this)
180
+ }
181
+
182
+ getChainId(): string {
183
+ return getChainId(this.config.network)
184
+ }
185
+
186
+ private onInterval(
187
+ handler: (resources: SuiMoveObject[], ctx: SuiObjectContext) => void,
188
+ timeInterval: HandleInterval | undefined,
189
+ versionInterval: HandleInterval | undefined
190
+ ): this {
191
+ const processor = this
192
+ this.objectHandlers.push({
193
+ handler: async function (data) {
194
+ const ctx = new SuiObjectContext(
195
+ processor.config.network,
196
+ processor.config.address,
197
+ data.slot,
198
+ data.timestamp || new Date(0)
199
+ )
200
+ await handler(data.objects as SuiMoveObject[], ctx)
201
+ return ctx.getProcessResult()
202
+ },
203
+ timeIntervalInMinutes: timeInterval,
204
+ versionInterval: versionInterval,
205
+ })
206
+ return this
207
+ }
208
+
209
+ public onTimeInterval(
210
+ handler: (objects: SuiMoveObject[], ctx: SuiObjectContext) => void,
211
+ timeIntervalInMinutes = 60,
212
+ backfillTimeIntervalInMinutes = 240
213
+ ): this {
214
+ return this.onInterval(
215
+ handler,
216
+ {
217
+ recentInterval: timeIntervalInMinutes,
218
+ backfillInterval: backfillTimeIntervalInMinutes,
219
+ },
220
+ undefined
221
+ )
222
+ }
223
+
224
+ public onSlotInterval(
225
+ handler: (objects: SuiMoveObject[], ctx: SuiObjectContext) => void,
226
+ slotInterval = 100000,
227
+ backfillSlotInterval = 400000
228
+ ): this {
229
+ return this.onInterval(handler, undefined, { recentInterval: slotInterval, backfillInterval: backfillSlotInterval })
230
+ }
231
+ }
232
+
151
233
  function configure(options: SuiBindOptions): IndexConfigure {
152
234
  return {
153
235
  startTimestamp: options.startTimestamp || 0,