@sentio/sdk 2.16.0-rc.1 → 2.16.0-rc.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/core/core-plugin.js +3 -0
- package/lib/core/core-plugin.js.map +1 -1
- package/lib/eth/eth-plugin.js +0 -2
- package/lib/eth/eth-plugin.js.map +1 -1
- package/lib/sui/context.d.ts +11 -5
- package/lib/sui/context.js +20 -10
- package/lib/sui/context.js.map +1 -1
- package/lib/sui/ext/move-dex.d.ts +2 -2
- package/lib/sui/ext/move-dex.js.map +1 -1
- package/lib/sui/index.d.ts +1 -1
- package/lib/sui/index.js +1 -1
- package/lib/sui/index.js.map +1 -1
- package/lib/sui/sui-object-processor-template.d.ts +34 -0
- package/lib/sui/{sui-objects-processor-template.js → sui-object-processor-template.js} +11 -10
- package/lib/sui/sui-object-processor-template.js.map +1 -0
- package/lib/sui/sui-object-processor.d.ts +13 -13
- package/lib/sui/sui-object-processor.js +11 -11
- package/lib/sui/sui-object-processor.js.map +1 -1
- package/lib/sui/sui-plugin.js +2 -2
- package/lib/sui/sui-plugin.js.map +1 -1
- package/package.json +3 -3
- package/src/core/core-plugin.ts +4 -0
- package/src/eth/eth-plugin.ts +0 -2
- package/src/sui/context.ts +35 -10
- package/src/sui/ext/move-dex.ts +2 -2
- package/src/sui/index.ts +2 -2
- package/src/sui/{sui-objects-processor-template.ts → sui-object-processor-template.ts} +20 -19
- package/src/sui/sui-object-processor.ts +25 -25
- package/src/sui/sui-plugin.ts +6 -3
- package/lib/sui/sui-objects-processor-template.d.ts +0 -34
- package/lib/sui/sui-objects-processor-template.js.map +0 -1
@@ -1,6 +1,6 @@
|
|
1
1
|
import { MoveOwnerType } from '@sentio/protos';
|
2
2
|
import { ListStateStorage } from '@sentio/runtime';
|
3
|
-
import {
|
3
|
+
import { SuiObjectContext } from './context.js';
|
4
4
|
import { configure } from './sui-processor.js';
|
5
5
|
export const DEFAULT_FETCH_CONFIG = {
|
6
6
|
owned: true,
|
@@ -9,7 +9,7 @@ class SuiAccountProcessorState extends ListStateStorage {
|
|
9
9
|
static INSTANCE = new SuiAccountProcessorState();
|
10
10
|
}
|
11
11
|
export { SuiAccountProcessorState };
|
12
|
-
export class
|
12
|
+
export class SuiBaseObjectOrAddressProcessor {
|
13
13
|
config;
|
14
14
|
ownerType;
|
15
15
|
objectHandlers = [];
|
@@ -25,16 +25,16 @@ export class SuiBaseObjectsProcessor {
|
|
25
25
|
return this.config.network;
|
26
26
|
}
|
27
27
|
onInterval(handler, //(resources: SuiMoveObject[], ctx: SuiObjectsContext) => PromiseOrVoid,
|
28
|
-
timeInterval,
|
28
|
+
timeInterval, checkpointInterval, type, fetchConfig) {
|
29
29
|
const processor = this;
|
30
30
|
this.objectHandlers.push({
|
31
31
|
handler: async function (data) {
|
32
|
-
const ctx = new
|
32
|
+
const ctx = new SuiObjectContext(processor.config.network, processor.config.address, data.slot, data.timestamp || new Date(0), processor.config.baseLabels);
|
33
33
|
await processor.doHandle(handler, data, ctx);
|
34
34
|
return ctx.getProcessResult();
|
35
35
|
},
|
36
36
|
timeIntervalInMinutes: timeInterval,
|
37
|
-
|
37
|
+
checkPointInterval: checkpointInterval,
|
38
38
|
type,
|
39
39
|
fetchConfig: { ...DEFAULT_FETCH_CONFIG, ...fetchConfig },
|
40
40
|
});
|
@@ -46,11 +46,11 @@ export class SuiBaseObjectsProcessor {
|
|
46
46
|
backfillInterval: backfillTimeIntervalInMinutes,
|
47
47
|
}, undefined, type, fetchConfig);
|
48
48
|
}
|
49
|
-
|
50
|
-
return this.onInterval(handler, undefined, { recentInterval:
|
49
|
+
onCheckpointInterval(handler, checkpointInterval = 100000, backfillCheckpointInterval = 400000, type, fetchConfig) {
|
50
|
+
return this.onInterval(handler, undefined, { recentInterval: checkpointInterval, backfillInterval: backfillCheckpointInterval }, type, fetchConfig);
|
51
51
|
}
|
52
52
|
}
|
53
|
-
export class SuiAddressProcessor extends
|
53
|
+
export class SuiAddressProcessor extends SuiBaseObjectOrAddressProcessor {
|
54
54
|
static bind(options) {
|
55
55
|
return new SuiAddressProcessor({ ...options, ownerType: MoveOwnerType.ADDRESS });
|
56
56
|
}
|
@@ -58,7 +58,7 @@ export class SuiAddressProcessor extends SuiBaseObjectsProcessor {
|
|
58
58
|
return handler(data.objects, ctx);
|
59
59
|
}
|
60
60
|
}
|
61
|
-
export class SuiObjectProcessor extends
|
61
|
+
export class SuiObjectProcessor extends SuiBaseObjectOrAddressProcessor {
|
62
62
|
static bind(options) {
|
63
63
|
return new SuiObjectProcessor({
|
64
64
|
address: options.objectId,
|
@@ -70,13 +70,13 @@ export class SuiObjectProcessor extends SuiBaseObjectsProcessor {
|
|
70
70
|
}
|
71
71
|
doHandle(handler, data, ctx) {
|
72
72
|
if (!data.self) {
|
73
|
-
console.log(`Sui object not existed in ${ctx.
|
73
|
+
console.log(`Sui object not existed in ${ctx.checkpoint}, please specific a start time`);
|
74
74
|
return;
|
75
75
|
}
|
76
76
|
return handler(data.self, data.objects, ctx);
|
77
77
|
}
|
78
78
|
}
|
79
|
-
export class SuiWrappedObjectProcessor extends
|
79
|
+
export class SuiWrappedObjectProcessor extends SuiBaseObjectOrAddressProcessor {
|
80
80
|
static bind(options) {
|
81
81
|
return new SuiWrappedObjectProcessor({
|
82
82
|
address: options.objectId,
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"sui-object-processor.js","sourceRoot":"","sources":["../../src/sui/sui-object-processor.ts"],"names":[],"mappings":"AAAA,OAAO,EAA0D,aAAa,EAAiB,MAAM,gBAAgB,CAAA;AACrH,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAElD,OAAO,EAAE,
|
1
|
+
{"version":3,"file":"sui-object-processor.js","sourceRoot":"","sources":["../../src/sui/sui-object-processor.ts"],"names":[],"mappings":"AAAA,OAAO,EAA0D,aAAa,EAAiB,MAAM,gBAAgB,CAAA;AACrH,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,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,IAAI,kBAAkB,CAAC;YAC5B,OAAO,EAAE,OAAO,CAAC,QAAQ;YACzB,OAAO,EAAE,OAAO,CAAC,OAAO;YACxB,eAAe,EAAE,OAAO,CAAC,eAAe;YACxC,SAAS,EAAE,aAAa,CAAC,MAAM;YAC/B,UAAU,EAAE,OAAO,CAAC,UAAU;SAC/B,CAAC,CAAA;IACJ,CAAC;IAES,QAAQ,CAChB,OAA4G,EAC5G,IAAoB,EACpB,GAAqB;QAErB,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE;YACd,OAAO,CAAC,GAAG,CAAC,6BAA6B,GAAG,CAAC,UAAU,gCAAgC,CAAC,CAAA;YACxF,OAAM;SACP;QACD,OAAO,OAAO,CAAC,IAAI,CAAC,IAAqB,EAAE,IAAI,CAAC,OAA0B,EAAE,GAAG,CAAC,CAAA;IAClF,CAAC;CACF;AAED,MAAM,OAAO,yBAA0B,SAAQ,+BAE9C;IACC,MAAM,CAAC,IAAI,CAAC,OAA6B;QACvC,OAAO,IAAI,yBAAyB,CAAC;YACnC,OAAO,EAAE,OAAO,CAAC,QAAQ;YACzB,OAAO,EAAE,OAAO,CAAC,OAAO;YACxB,eAAe,EAAE,OAAO,CAAC,eAAe;YACxC,SAAS,EAAE,aAAa,CAAC,cAAc;YACvC,UAAU,EAAE,OAAO,CAAC,UAAU;SAC/B,CAAC,CAAA;IACJ,CAAC;IAES,QAAQ,CAChB,OAAuF,EACvF,IAAoB,EACpB,GAAqB;QAErB,OAAO,OAAO,CAAC,IAAI,CAAC,OAA0B,EAAE,GAAG,CAAC,CAAA;IACtD,CAAC;CACF","sourcesContent":["import { Data_SuiObject, HandleInterval, MoveAccountFetchConfig, MoveOwnerType, ProcessResult } from '@sentio/protos'\nimport { ListStateStorage } from '@sentio/runtime'\nimport { SuiNetwork } from './network.js'\nimport { SuiObjectContext } from './context.js'\nimport { SuiMoveObject } from '@mysten/sui.js'\nimport { PromiseOrVoid } from '../core/index.js'\nimport { configure, IndexConfigure, SuiBindOptions } from './sui-processor.js'\n\nexport interface SuiObjectBindOptions {\n objectId: string\n network?: SuiNetwork\n startCheckpoint?: bigint\n baseLabels?: { [key: string]: string }\n}\n\ninterface ObjectHandler {\n type?: string\n checkPointInterval?: HandleInterval\n timeIntervalInMinutes?: HandleInterval\n fetchConfig: MoveAccountFetchConfig\n handler: (resource: Data_SuiObject) => Promise<ProcessResult>\n}\n\nexport const DEFAULT_FETCH_CONFIG: MoveAccountFetchConfig = {\n owned: true,\n}\n\nexport class SuiAccountProcessorState extends ListStateStorage<SuiBaseObjectOrAddressProcessor<any>> {\n static INSTANCE = new SuiAccountProcessorState()\n}\n\nexport interface SuiInternalObjectsBindOptions extends SuiBindOptions {\n ownerType: MoveOwnerType\n}\n\nexport abstract class SuiBaseObjectOrAddressProcessor<HandlerType> {\n config: IndexConfigure\n ownerType: MoveOwnerType\n\n objectHandlers: ObjectHandler[] = []\n\n // static bind(options: SuiObjectsBindOptions): SuiBaseObjectsProcessor<any> {\n // return new SuiBaseObjectsProcessor(options)\n // }\n\n protected constructor(options: SuiInternalObjectsBindOptions) {\n this.config = configure(options)\n this.ownerType = options.ownerType\n SuiAccountProcessorState.INSTANCE.addValue(this)\n }\n\n getChainId(): string {\n return this.config.network\n }\n\n // protected abstract transformObjects(objects: SuiMoveObject[]): SuiMoveObject[]\n\n protected abstract doHandle(handler: HandlerType, data: Data_SuiObject, ctx: SuiObjectContext): PromiseOrVoid\n\n public onInterval(\n handler: HandlerType, //(resources: SuiMoveObject[], ctx: SuiObjectsContext) => PromiseOrVoid,\n timeInterval: HandleInterval | undefined,\n checkpointInterval: HandleInterval | undefined,\n type: string | undefined,\n fetchConfig: Partial<MoveAccountFetchConfig> | 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 processor.config.baseLabels\n )\n await processor.doHandle(handler, data, ctx)\n return ctx.getProcessResult()\n },\n timeIntervalInMinutes: timeInterval,\n checkPointInterval: checkpointInterval,\n type,\n fetchConfig: { ...DEFAULT_FETCH_CONFIG, ...fetchConfig },\n })\n return this\n }\n\n public onTimeInterval(\n handler: HandlerType,\n timeIntervalInMinutes = 60,\n backfillTimeIntervalInMinutes = 240,\n type?: string,\n fetchConfig?: Partial<MoveAccountFetchConfig>\n ): this {\n return this.onInterval(\n handler,\n {\n recentInterval: timeIntervalInMinutes,\n backfillInterval: backfillTimeIntervalInMinutes,\n },\n undefined,\n type,\n fetchConfig\n )\n }\n\n public onCheckpointInterval(\n handler: HandlerType,\n checkpointInterval = 100000,\n backfillCheckpointInterval = 400000,\n type?: string,\n fetchConfig?: Partial<MoveAccountFetchConfig>\n ): this {\n return this.onInterval(\n handler,\n undefined,\n { recentInterval: checkpointInterval, backfillInterval: backfillCheckpointInterval },\n type,\n fetchConfig\n )\n }\n}\n\nexport class SuiAddressProcessor extends SuiBaseObjectOrAddressProcessor<\n (objects: SuiMoveObject[], ctx: SuiObjectContext) => PromiseOrVoid\n> {\n static bind(options: SuiBindOptions): SuiAddressProcessor {\n return new SuiAddressProcessor({ ...options, ownerType: MoveOwnerType.ADDRESS })\n }\n\n protected doHandle(\n handler: (objects: SuiMoveObject[], ctx: SuiObjectContext) => PromiseOrVoid,\n data: Data_SuiObject,\n ctx: SuiObjectContext\n ): PromiseOrVoid {\n return handler(data.objects as SuiMoveObject[], ctx)\n }\n}\n\nexport class SuiObjectProcessor extends SuiBaseObjectOrAddressProcessor<\n (self: SuiMoveObject, dynamicFieldObjects: SuiMoveObject[], ctx: SuiObjectContext) => PromiseOrVoid\n> {\n static bind(options: SuiObjectBindOptions): SuiObjectProcessor {\n return new SuiObjectProcessor({\n address: options.objectId,\n network: options.network,\n startCheckpoint: options.startCheckpoint,\n ownerType: MoveOwnerType.OBJECT,\n baseLabels: options.baseLabels,\n })\n }\n\n protected doHandle(\n handler: (self: SuiMoveObject, dynamicFieldObjects: SuiMoveObject[], ctx: SuiObjectContext) => PromiseOrVoid,\n data: Data_SuiObject,\n ctx: SuiObjectContext\n ): PromiseOrVoid {\n if (!data.self) {\n console.log(`Sui object not existed in ${ctx.checkpoint}, please specific a start time`)\n return\n }\n return handler(data.self as SuiMoveObject, data.objects as SuiMoveObject[], ctx)\n }\n}\n\nexport class SuiWrappedObjectProcessor extends SuiBaseObjectOrAddressProcessor<\n (dynamicFieldObjects: SuiMoveObject[], ctx: SuiObjectContext) => PromiseOrVoid\n> {\n static bind(options: SuiObjectBindOptions): SuiWrappedObjectProcessor {\n return new SuiWrappedObjectProcessor({\n address: options.objectId,\n network: options.network,\n startCheckpoint: options.startCheckpoint,\n ownerType: MoveOwnerType.WRAPPED_OBJECT,\n baseLabels: options.baseLabels,\n })\n }\n\n protected doHandle(\n handler: (dynamicFieldObjects: SuiMoveObject[], ctx: SuiObjectContext) => PromiseOrVoid,\n data: Data_SuiObject,\n ctx: SuiObjectContext\n ): PromiseOrVoid {\n return handler(data.objects as SuiMoveObject[], ctx)\n }\n}\n"]}
|
package/lib/sui/sui-plugin.js
CHANGED
@@ -6,7 +6,7 @@ import { SuiAccountProcessorState } from './sui-object-processor.js';
|
|
6
6
|
import { validateAndNormalizeAddress } from './utils.js';
|
7
7
|
import { initCoinList } from './ext/coin.js';
|
8
8
|
import { SuiChainId } from '../core/chain.js';
|
9
|
-
import { SuiAccountProcessorTemplateState } from './sui-
|
9
|
+
import { SuiAccountProcessorTemplateState, } from './sui-object-processor-template.js';
|
10
10
|
import { SuiNetwork } from './network.js';
|
11
11
|
import { SuiContext } from './context.js';
|
12
12
|
export class SuiPlugin extends Plugin {
|
@@ -95,7 +95,7 @@ export class SuiPlugin extends Plugin {
|
|
95
95
|
minutes: 0,
|
96
96
|
minutesInterval: handler.timeIntervalInMinutes,
|
97
97
|
slot: 0,
|
98
|
-
slotInterval: handler.
|
98
|
+
slotInterval: handler.checkPointInterval,
|
99
99
|
fetchConfig: undefined,
|
100
100
|
},
|
101
101
|
type: handler.type || '',
|
@@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CAAC,CAAA;AAEhD,MAAM,WAAW,GAAG,IAAI,UAAU,CAAC,EAAE,EAAE,UAAU,CAAC,WAAW,EAAE,EAAE,EAAE,IAAI,IAAI,EAAE,EAAE,EAAE,EAAE,EAAS,EAAE,CAAC,EAAE,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 StartRequest,\n} from '@sentio/protos'\n\nimport { ServerError, Status } from 'nice-grpc'\n\nimport { SuiProcessorState } from './sui-processor.js'\nimport { SuiAccountProcessorState } from './sui-object-processor.js'\nimport { validateAndNormalizeAddress } from './utils.js'\nimport { initCoinList } from './ext/coin.js'\nimport { SuiChainId } from '../core/chain.js'\nimport { SuiAccountProcessorTemplateState, SuiBaseObjectsProcessorTemplate } from './sui-objects-processor-template.js'\nimport { SuiNetwork } from './network.js'\nimport { SuiContext } from './context.js'\n\ninterface Handlers {\n suiEventHandlers: ((event: Data_SuiEvent) => Promise<ProcessResult>)[]\n suiCallHandlers: ((func: Data_SuiCall) => Promise<ProcessResult>)[]\n suiObjectHandlers: ((object: Data_SuiObject) => Promise<ProcessResult>)[]\n}\n\nexport class SuiPlugin extends Plugin {\n name: string = 'SuiPlugin'\n handlers: Handlers = {\n suiCallHandlers: [],\n suiEventHandlers: [],\n suiObjectHandlers: [],\n }\n async start(request: StartRequest): Promise<void> {\n await initCoinList()\n\n const allowedChainIds = new Set<string>(Object.values(SuiChainId))\n for (const instance of request.templateInstances) {\n if (!allowedChainIds.has(instance.contract?.chainId || '')) {\n continue\n }\n\n const template: SuiBaseObjectsProcessorTemplate<any, any> =\n SuiAccountProcessorTemplateState.INSTANCE.getValues()[instance.templateId]\n\n template.bind(\n {\n objectId: instance.contract?.address || '',\n network: <SuiNetwork>instance.contract?.chainId || SuiNetwork.MAIN_NET,\n startCheckpoint: instance.startBlock || 0n,\n },\n NoopContext\n )\n }\n }\n\n async configure(config: ProcessConfigResponse) {\n const handlers: Handlers = {\n suiCallHandlers: [],\n suiEventHandlers: [],\n suiObjectHandlers: [],\n }\n for (const suiProcessor of SuiProcessorState.INSTANCE.getValues()) {\n const contractConfig = ContractConfig.fromPartial({\n transactionConfig: [],\n processorType: USER_PROCESSOR,\n contract: {\n name: suiProcessor.moduleName,\n chainId: suiProcessor.config.network,\n address: validateAndNormalizeAddress(suiProcessor.config.address),\n abi: '',\n },\n startBlock: suiProcessor.config.startCheckpoint,\n })\n for (const handler of suiProcessor.eventHandlers) {\n const handlerId = handlers.suiEventHandlers.push(handler.handler) - 1\n const eventHandlerConfig: MoveEventHandlerConfig = {\n filters: handler.filters.map((f) => {\n return {\n type: f.type,\n account: f.account || '',\n }\n }),\n fetchConfig: handler.fetchConfig,\n handlerId,\n }\n contractConfig.moveEventConfigs.push(eventHandlerConfig)\n }\n for (const handler of suiProcessor.callHandlers) {\n const handlerId = handlers.suiCallHandlers.push(handler.handler) - 1\n const functionHandlerConfig: MoveCallHandlerConfig = {\n filters: handler.filters.map((filter) => {\n return {\n function: filter.function,\n typeArguments: filter.typeArguments || [],\n withTypeArguments: !!filter.typeArguments,\n includeFailed: filter.includeFailed || false,\n }\n }),\n fetchConfig: handler.fetchConfig,\n handlerId,\n }\n contractConfig.moveCallConfigs.push(functionHandlerConfig)\n }\n config.contractConfigs.push(contractConfig)\n }\n\n for (const processor of SuiAccountProcessorState.INSTANCE.getValues()) {\n const accountConfig = AccountConfig.fromPartial({\n address: validateAndNormalizeAddress(processor.config.address),\n chainId: processor.getChainId(),\n startBlock: processor.config.startCheckpoint, // TODO maybe use another field\n })\n for (const handler of processor.objectHandlers) {\n const handlerId = handlers.suiObjectHandlers.push(handler.handler) - 1\n accountConfig.moveIntervalConfigs.push({\n intervalConfig: {\n handlerId: handlerId,\n minutes: 0,\n minutesInterval: handler.timeIntervalInMinutes,\n slot: 0,\n slotInterval: handler.versionInterval,\n fetchConfig: undefined,\n },\n type: handler.type || '',\n ownerType: processor.ownerType,\n fetchConfig: undefined,\n })\n }\n config.accountConfigs.push(accountConfig)\n }\n this.handlers = handlers\n }\n\n supportedHandlers = [HandlerType.SUI_EVENT, HandlerType.SUI_CALL, HandlerType.SUI_OBJECT]\n\n async processSuiEvent(binding: DataBinding): Promise<ProcessResult> {\n if (!binding.data?.suiEvent) {\n throw new ServerError(Status.INVALID_ARGUMENT, \"Event can't be empty\")\n }\n const promises: Promise<ProcessResult>[] = []\n const event = binding.data.suiEvent\n\n for (const handlerId of binding.handlerIds) {\n promises.push(\n this.handlers.suiEventHandlers[handlerId](event).catch((e) => {\n throw new ServerError(\n Status.INTERNAL,\n 'error processing event: ' + JSON.stringify(event) + '\\n' + errorString(e)\n )\n })\n )\n }\n return mergeProcessResults(await Promise.all(promises))\n }\n\n async processSuiFunctionCall(binding: DataBinding): Promise<ProcessResult> {\n if (!binding.data?.suiCall) {\n throw new ServerError(Status.INVALID_ARGUMENT, \"Call can't be empty\")\n }\n const call = binding.data.suiCall\n\n const promises: Promise<ProcessResult>[] = []\n for (const handlerId of binding.handlerIds) {\n const promise = this.handlers.suiCallHandlers[handlerId](call).catch((e) => {\n throw new ServerError(Status.INTERNAL, 'error processing call: ' + JSON.stringify(call) + '\\n' + errorString(e))\n })\n promises.push(promise)\n }\n return mergeProcessResults(await Promise.all(promises))\n }\n\n async processSuiObject(binding: DataBinding): Promise<ProcessResult> {\n if (!binding.data?.suiObject) {\n throw new ServerError(Status.INVALID_ARGUMENT, \"Object can't be empty\")\n }\n const object = binding.data.suiObject\n\n const promises: Promise<ProcessResult>[] = []\n for (const handlerId of binding.handlerIds) {\n promises.push(\n this.handlers.suiObjectHandlers[handlerId](object).catch((e) => {\n throw new ServerError(\n Status.INTERNAL,\n 'error processing object: ' + JSON.stringify(object) + '\\n' + errorString(e)\n )\n })\n )\n }\n return mergeProcessResults(await Promise.all(promises))\n }\n\n processBinding(request: DataBinding): Promise<ProcessResult> {\n switch (request.handlerType) {\n case HandlerType.SUI_EVENT:\n return this.processSuiEvent(request)\n case HandlerType.SUI_CALL:\n return this.processSuiFunctionCall(request)\n case HandlerType.SUI_OBJECT:\n return this.processSuiObject(request)\n default:\n throw new ServerError(Status.INVALID_ARGUMENT, 'No handle type registered ' + request.handlerType)\n }\n }\n}\n\nPluginManager.INSTANCE.register(new SuiPlugin())\n\nconst NoopContext = new SuiContext('', SuiChainId.SUI_MAINNET, '', new Date(), 0n, {} as any, 0, {})\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,GAMZ,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,wBAAwB,EAAE,MAAM,2BAA2B,CAAA;AACpE,OAAO,EAAE,2BAA2B,EAAE,MAAM,YAAY,CAAA;AACxD,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAA;AAC5C,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAC7C,OAAO,EACL,gCAAgC,GAEjC,MAAM,oCAAoC,CAAA;AAC3C,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AACzC,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AAQzC,MAAM,OAAO,SAAU,SAAQ,MAAM;IACnC,IAAI,GAAW,WAAW,CAAA;IAC1B,QAAQ,GAAa;QACnB,eAAe,EAAE,EAAE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,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;AAEhD,MAAM,WAAW,GAAG,IAAI,UAAU,CAAC,EAAE,EAAE,UAAU,CAAC,WAAW,EAAE,EAAE,EAAE,IAAI,IAAI,EAAE,EAAE,EAAE,EAAE,EAAS,EAAE,CAAC,EAAE,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 StartRequest,\n} from '@sentio/protos'\n\nimport { ServerError, Status } from 'nice-grpc'\n\nimport { SuiProcessorState } from './sui-processor.js'\nimport { SuiAccountProcessorState } from './sui-object-processor.js'\nimport { validateAndNormalizeAddress } from './utils.js'\nimport { initCoinList } from './ext/coin.js'\nimport { SuiChainId } from '../core/chain.js'\nimport {\n SuiAccountProcessorTemplateState,\n SuiObjectOrAddressProcessorTemplate,\n} from './sui-object-processor-template.js'\nimport { SuiNetwork } from './network.js'\nimport { SuiContext } from './context.js'\n\ninterface Handlers {\n suiEventHandlers: ((event: Data_SuiEvent) => Promise<ProcessResult>)[]\n suiCallHandlers: ((func: Data_SuiCall) => Promise<ProcessResult>)[]\n suiObjectHandlers: ((object: Data_SuiObject) => Promise<ProcessResult>)[]\n}\n\nexport class SuiPlugin extends Plugin {\n name: string = 'SuiPlugin'\n handlers: Handlers = {\n suiCallHandlers: [],\n suiEventHandlers: [],\n suiObjectHandlers: [],\n }\n async start(request: StartRequest): Promise<void> {\n await initCoinList()\n\n const allowedChainIds = new Set<string>(Object.values(SuiChainId))\n for (const instance of request.templateInstances) {\n if (!allowedChainIds.has(instance.contract?.chainId || '')) {\n continue\n }\n\n const template: SuiObjectOrAddressProcessorTemplate<any, any> =\n SuiAccountProcessorTemplateState.INSTANCE.getValues()[instance.templateId]\n\n template.bind(\n {\n objectId: instance.contract?.address || '',\n network: <SuiNetwork>instance.contract?.chainId || SuiNetwork.MAIN_NET,\n startCheckpoint: instance.startBlock || 0n,\n },\n NoopContext\n )\n }\n }\n\n async configure(config: ProcessConfigResponse) {\n const handlers: Handlers = {\n suiCallHandlers: [],\n suiEventHandlers: [],\n suiObjectHandlers: [],\n }\n for (const suiProcessor of SuiProcessorState.INSTANCE.getValues()) {\n const contractConfig = ContractConfig.fromPartial({\n transactionConfig: [],\n processorType: USER_PROCESSOR,\n contract: {\n name: suiProcessor.moduleName,\n chainId: suiProcessor.config.network,\n address: validateAndNormalizeAddress(suiProcessor.config.address),\n abi: '',\n },\n startBlock: suiProcessor.config.startCheckpoint,\n })\n for (const handler of suiProcessor.eventHandlers) {\n const handlerId = handlers.suiEventHandlers.push(handler.handler) - 1\n const eventHandlerConfig: MoveEventHandlerConfig = {\n filters: handler.filters.map((f) => {\n return {\n type: f.type,\n account: f.account || '',\n }\n }),\n fetchConfig: handler.fetchConfig,\n handlerId,\n }\n contractConfig.moveEventConfigs.push(eventHandlerConfig)\n }\n for (const handler of suiProcessor.callHandlers) {\n const handlerId = handlers.suiCallHandlers.push(handler.handler) - 1\n const functionHandlerConfig: MoveCallHandlerConfig = {\n filters: handler.filters.map((filter) => {\n return {\n function: filter.function,\n typeArguments: filter.typeArguments || [],\n withTypeArguments: !!filter.typeArguments,\n includeFailed: filter.includeFailed || false,\n }\n }),\n fetchConfig: handler.fetchConfig,\n handlerId,\n }\n contractConfig.moveCallConfigs.push(functionHandlerConfig)\n }\n config.contractConfigs.push(contractConfig)\n }\n\n for (const processor of SuiAccountProcessorState.INSTANCE.getValues()) {\n const accountConfig = AccountConfig.fromPartial({\n address: validateAndNormalizeAddress(processor.config.address),\n chainId: processor.getChainId(),\n startBlock: processor.config.startCheckpoint, // TODO maybe use another field\n })\n for (const handler of processor.objectHandlers) {\n const handlerId = handlers.suiObjectHandlers.push(handler.handler) - 1\n accountConfig.moveIntervalConfigs.push({\n intervalConfig: {\n handlerId: handlerId,\n minutes: 0,\n minutesInterval: handler.timeIntervalInMinutes,\n slot: 0,\n slotInterval: handler.checkPointInterval,\n fetchConfig: undefined,\n },\n type: handler.type || '',\n ownerType: processor.ownerType,\n fetchConfig: undefined,\n })\n }\n config.accountConfigs.push(accountConfig)\n }\n this.handlers = handlers\n }\n\n supportedHandlers = [HandlerType.SUI_EVENT, HandlerType.SUI_CALL, HandlerType.SUI_OBJECT]\n\n async processSuiEvent(binding: DataBinding): Promise<ProcessResult> {\n if (!binding.data?.suiEvent) {\n throw new ServerError(Status.INVALID_ARGUMENT, \"Event can't be empty\")\n }\n const promises: Promise<ProcessResult>[] = []\n const event = binding.data.suiEvent\n\n for (const handlerId of binding.handlerIds) {\n promises.push(\n this.handlers.suiEventHandlers[handlerId](event).catch((e) => {\n throw new ServerError(\n Status.INTERNAL,\n 'error processing event: ' + JSON.stringify(event) + '\\n' + errorString(e)\n )\n })\n )\n }\n return mergeProcessResults(await Promise.all(promises))\n }\n\n async processSuiFunctionCall(binding: DataBinding): Promise<ProcessResult> {\n if (!binding.data?.suiCall) {\n throw new ServerError(Status.INVALID_ARGUMENT, \"Call can't be empty\")\n }\n const call = binding.data.suiCall\n\n const promises: Promise<ProcessResult>[] = []\n for (const handlerId of binding.handlerIds) {\n const promise = this.handlers.suiCallHandlers[handlerId](call).catch((e) => {\n throw new ServerError(Status.INTERNAL, 'error processing call: ' + JSON.stringify(call) + '\\n' + errorString(e))\n })\n promises.push(promise)\n }\n return mergeProcessResults(await Promise.all(promises))\n }\n\n async processSuiObject(binding: DataBinding): Promise<ProcessResult> {\n if (!binding.data?.suiObject) {\n throw new ServerError(Status.INVALID_ARGUMENT, \"Object can't be empty\")\n }\n const object = binding.data.suiObject\n\n const promises: Promise<ProcessResult>[] = []\n for (const handlerId of binding.handlerIds) {\n promises.push(\n this.handlers.suiObjectHandlers[handlerId](object).catch((e) => {\n throw new ServerError(\n Status.INTERNAL,\n 'error processing object: ' + JSON.stringify(object) + '\\n' + errorString(e)\n )\n })\n )\n }\n return mergeProcessResults(await Promise.all(promises))\n }\n\n processBinding(request: DataBinding): Promise<ProcessResult> {\n switch (request.handlerType) {\n case HandlerType.SUI_EVENT:\n return this.processSuiEvent(request)\n case HandlerType.SUI_CALL:\n return this.processSuiFunctionCall(request)\n case HandlerType.SUI_OBJECT:\n return this.processSuiObject(request)\n default:\n throw new ServerError(Status.INVALID_ARGUMENT, 'No handle type registered ' + request.handlerType)\n }\n }\n}\n\nPluginManager.INSTANCE.register(new SuiPlugin())\n\nconst NoopContext = new SuiContext('', SuiChainId.SUI_MAINNET, '', new Date(), 0n, {} as any, 0, {})\n"]}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@sentio/sdk",
|
3
|
-
"version": "2.16.0-rc.
|
3
|
+
"version": "2.16.0-rc.3",
|
4
4
|
"license": "Apache-2.0",
|
5
5
|
"type": "module",
|
6
6
|
"exports": {
|
@@ -71,8 +71,8 @@
|
|
71
71
|
"typedoc": "^0.24.1",
|
72
72
|
"utility-types": "^3.10.0",
|
73
73
|
"yaml": "^2.2.1",
|
74
|
-
"@sentio/protos": "^2.16.0-rc.
|
75
|
-
"@sentio/runtime": "^2.16.0-rc.
|
74
|
+
"@sentio/protos": "^2.16.0-rc.3",
|
75
|
+
"@sentio/runtime": "^2.16.0-rc.3"
|
76
76
|
},
|
77
77
|
"peerDependencies": {
|
78
78
|
"tsup": "npm:@sentio/tsup@^6.7.0"
|
package/src/core/core-plugin.ts
CHANGED
@@ -4,11 +4,15 @@ import { ProcessConfigResponse } from '@sentio/protos'
|
|
4
4
|
import { MetricState } from './meter.js'
|
5
5
|
import { ExporterState } from './exporter.js'
|
6
6
|
import { EventTrackerState } from './event-tracker.js'
|
7
|
+
import { TemplateInstanceState } from './template.js'
|
7
8
|
|
8
9
|
export class CorePlugin extends Plugin {
|
9
10
|
name: string = 'CorePlugin'
|
10
11
|
|
11
12
|
async configure(config: ProcessConfigResponse): Promise<void> {
|
13
|
+
// This syntax is to copy values instead of using references
|
14
|
+
config.templateInstances = [...TemplateInstanceState.INSTANCE.getValues()]
|
15
|
+
|
12
16
|
for (const metric of MetricState.INSTANCE.getValues()) {
|
13
17
|
config.metricConfigs.push({
|
14
18
|
...metric.config,
|
package/src/eth/eth-plugin.ts
CHANGED
@@ -48,8 +48,6 @@ export class EthPlugin extends Plugin {
|
|
48
48
|
traceHandlers: [],
|
49
49
|
transactionHandlers: [],
|
50
50
|
}
|
51
|
-
// This syntax is to copy values instead of using references
|
52
|
-
config.templateInstances = [...TemplateInstanceState.INSTANCE.getValues()]
|
53
51
|
|
54
52
|
for (const processor of ProcessorState.INSTANCE.getValues()) {
|
55
53
|
// If server favor incremental update this need to change
|
package/src/sui/context.ts
CHANGED
@@ -14,7 +14,7 @@ import { MoveAccountContext, MoveContext } from '../move/index.js'
|
|
14
14
|
export class SuiContext extends MoveContext<SuiNetwork, SuiMoveNormalizedModule, SuiEvent | SuiMoveObject> {
|
15
15
|
moduleName: string
|
16
16
|
timestamp: Date
|
17
|
-
|
17
|
+
checkpoint: bigint
|
18
18
|
transaction: SuiTransactionBlockResponse
|
19
19
|
eventIndex: number
|
20
20
|
coder: MoveCoder
|
@@ -24,7 +24,7 @@ export class SuiContext extends MoveContext<SuiNetwork, SuiMoveNormalizedModule,
|
|
24
24
|
network: SuiNetwork,
|
25
25
|
address: string,
|
26
26
|
timestamp: Date,
|
27
|
-
|
27
|
+
checkpoint: bigint,
|
28
28
|
transaction: SuiTransactionBlockResponse,
|
29
29
|
eventIndex: number,
|
30
30
|
baseLabels: Labels | undefined
|
@@ -34,7 +34,7 @@ export class SuiContext extends MoveContext<SuiNetwork, SuiMoveNormalizedModule,
|
|
34
34
|
this.network = network
|
35
35
|
this.moduleName = moduleName
|
36
36
|
this.timestamp = timestamp
|
37
|
-
this.
|
37
|
+
this.checkpoint = checkpoint
|
38
38
|
this.eventIndex = eventIndex
|
39
39
|
this.coder = defaultMoveCoder(network)
|
40
40
|
if (transaction) {
|
@@ -54,7 +54,7 @@ export class SuiContext extends MoveContext<SuiNetwork, SuiMoveNormalizedModule,
|
|
54
54
|
return {
|
55
55
|
address: this.address,
|
56
56
|
contractName: this.moduleName,
|
57
|
-
blockNumber: this.
|
57
|
+
blockNumber: this.checkpoint,
|
58
58
|
transactionIndex: 0,
|
59
59
|
transactionHash: this.transaction?.digest || '', // TODO
|
60
60
|
logIndex: 0,
|
@@ -69,22 +69,31 @@ export class SuiContext extends MoveContext<SuiNetwork, SuiMoveNormalizedModule,
|
|
69
69
|
}
|
70
70
|
}
|
71
71
|
|
72
|
-
|
72
|
+
// TODO address handler should use this context
|
73
|
+
export class SuiAddressContext extends MoveAccountContext<
|
73
74
|
SuiNetwork,
|
74
75
|
SuiMoveNormalizedModule,
|
75
76
|
SuiEvent | SuiMoveObject
|
76
77
|
> {
|
77
78
|
address: string
|
78
79
|
network: SuiNetwork
|
79
|
-
|
80
|
+
checkpoint: bigint
|
80
81
|
timestamp: Date
|
81
82
|
coder: MoveCoder
|
82
83
|
|
83
|
-
|
84
|
+
protected contractName = 'address'
|
85
|
+
|
86
|
+
constructor(
|
87
|
+
network: SuiNetwork,
|
88
|
+
address: string,
|
89
|
+
checkpoint: bigint,
|
90
|
+
timestamp: Date,
|
91
|
+
baseLabels: Labels | undefined
|
92
|
+
) {
|
84
93
|
super(baseLabels)
|
85
94
|
this.address = address
|
86
95
|
this.network = network
|
87
|
-
this.
|
96
|
+
this.checkpoint = checkpoint
|
88
97
|
this.timestamp = timestamp
|
89
98
|
this.coder = defaultMoveCoder(network)
|
90
99
|
}
|
@@ -96,8 +105,8 @@ export class SuiObjectsContext extends MoveAccountContext<
|
|
96
105
|
getMetaDataInternal(name: string, labels: Labels): RecordMetaData {
|
97
106
|
return {
|
98
107
|
address: this.address,
|
99
|
-
contractName:
|
100
|
-
blockNumber: this.
|
108
|
+
contractName: this.contractName,
|
109
|
+
blockNumber: this.checkpoint,
|
101
110
|
transactionIndex: 0,
|
102
111
|
transactionHash: '',
|
103
112
|
logIndex: 0,
|
@@ -115,3 +124,19 @@ export class SuiObjectsContext extends MoveAccountContext<
|
|
115
124
|
return this.timestamp.getDate()
|
116
125
|
}
|
117
126
|
}
|
127
|
+
|
128
|
+
export class SuiObjectContext extends SuiAddressContext {
|
129
|
+
contractName = 'object'
|
130
|
+
objectId: string
|
131
|
+
|
132
|
+
constructor(
|
133
|
+
network: SuiNetwork,
|
134
|
+
objectId: string,
|
135
|
+
checkpoint: bigint,
|
136
|
+
timestamp: Date,
|
137
|
+
baseLabels: Labels | undefined
|
138
|
+
) {
|
139
|
+
super(network, objectId, checkpoint, timestamp, baseLabels)
|
140
|
+
this.objectId = objectId
|
141
|
+
}
|
142
|
+
}
|
package/src/sui/ext/move-dex.ts
CHANGED
@@ -3,7 +3,7 @@ import { calculateValueInUsd, getCoinInfo, whitelistCoins, whiteListed } from '.
|
|
3
3
|
import { MoveCoinList, MoveDex, moveGetPairValue, MovePoolAdaptor, SimpleCoinInfo } from '../../move/ext/index.js'
|
4
4
|
import { SuiMoveObject, SuiMovePackage } from '@mysten/sui.js'
|
5
5
|
import { SuiNetwork } from '../network.js'
|
6
|
-
import { SuiContext,
|
6
|
+
import { SuiContext, SuiObjectContext } from '../context.js'
|
7
7
|
|
8
8
|
export type PoolAdaptor<T> = MovePoolAdaptor<SuiMoveObject, T>
|
9
9
|
|
@@ -33,7 +33,7 @@ export class SuiDex<T> extends MoveDex<
|
|
33
33
|
SuiMoveObject,
|
34
34
|
Event,
|
35
35
|
SuiContext,
|
36
|
-
|
36
|
+
SuiObjectContext,
|
37
37
|
T
|
38
38
|
> {
|
39
39
|
coinList = SuiCoinList
|
package/src/sui/index.ts
CHANGED
@@ -8,9 +8,9 @@ export {
|
|
8
8
|
|
9
9
|
export {
|
10
10
|
// SuiAddressProcessorTemplate,
|
11
|
-
|
11
|
+
SuiObjectProcessorTemplate,
|
12
12
|
SuiWrappedObjectProcessorTemplate,
|
13
|
-
} from './sui-
|
13
|
+
} from './sui-object-processor-template.js'
|
14
14
|
|
15
15
|
export * from './network.js'
|
16
16
|
export * from './context.js'
|
@@ -1,11 +1,11 @@
|
|
1
1
|
import { HandleInterval, MoveAccountFetchConfig } from '@sentio/protos'
|
2
2
|
import { ListStateStorage } from '@sentio/runtime'
|
3
|
-
import { SuiContext,
|
3
|
+
import { SuiContext, SuiObjectContext } from './context.js'
|
4
4
|
import { SuiMoveObject } from '@mysten/sui.js'
|
5
5
|
import { PromiseOrVoid } from '../core/index.js'
|
6
6
|
import {
|
7
7
|
DEFAULT_FETCH_CONFIG,
|
8
|
-
|
8
|
+
SuiBaseObjectOrAddressProcessor,
|
9
9
|
SuiObjectBindOptions,
|
10
10
|
SuiObjectProcessor,
|
11
11
|
SuiWrappedObjectProcessor,
|
@@ -14,34 +14,35 @@ import { TemplateInstanceState } from '../core/template.js'
|
|
14
14
|
|
15
15
|
class ObjectHandler<HandlerType> {
|
16
16
|
type?: string
|
17
|
-
|
17
|
+
checkpointInterval?: HandleInterval
|
18
18
|
timeIntervalInMinutes?: HandleInterval
|
19
19
|
handler: HandlerType
|
20
20
|
fetchConfig: MoveAccountFetchConfig
|
21
21
|
}
|
22
22
|
|
23
|
-
export class SuiAccountProcessorTemplateState extends ListStateStorage<
|
23
|
+
export class SuiAccountProcessorTemplateState extends ListStateStorage<SuiObjectOrAddressProcessorTemplate<any, any>> {
|
24
24
|
static INSTANCE = new SuiAccountProcessorTemplateState()
|
25
25
|
}
|
26
26
|
|
27
|
-
export abstract class
|
27
|
+
export abstract class SuiObjectOrAddressProcessorTemplate<
|
28
28
|
HandlerType,
|
29
29
|
// OptionType,
|
30
|
-
ProcessorType extends
|
30
|
+
ProcessorType extends SuiBaseObjectOrAddressProcessor<HandlerType>
|
31
31
|
> {
|
32
32
|
id: number
|
33
33
|
objectHandlers: ObjectHandler<HandlerType>[] = []
|
34
34
|
binds = new Set<string>()
|
35
35
|
|
36
|
-
|
36
|
+
constructor() {
|
37
37
|
this.id = SuiAccountProcessorTemplateState.INSTANCE.getValues().length
|
38
38
|
SuiAccountProcessorTemplateState.INSTANCE.addValue(this)
|
39
39
|
}
|
40
40
|
|
41
|
-
abstract createProcessor(options: SuiObjectBindOptions): ProcessorType
|
41
|
+
protected abstract createProcessor(options: SuiObjectBindOptions): ProcessorType
|
42
42
|
|
43
43
|
bind(options: SuiObjectBindOptions, ctx: SuiContext): void {
|
44
44
|
options.network = options.network || ctx.network
|
45
|
+
options.startCheckpoint = options.startCheckpoint || ctx.checkpoint
|
45
46
|
const sig = [options.network, options.objectId].join('_')
|
46
47
|
if (this.binds.has(sig)) {
|
47
48
|
console.log(`Same object id can be bind to one template only once, ignore duplicate bind: ${sig}`)
|
@@ -51,7 +52,7 @@ export abstract class SuiBaseObjectsProcessorTemplate<
|
|
51
52
|
|
52
53
|
const processor = this.createProcessor(options)
|
53
54
|
for (const h of this.objectHandlers) {
|
54
|
-
processor.onInterval(h.handler, h.timeIntervalInMinutes, h.
|
55
|
+
processor.onInterval(h.handler, h.timeIntervalInMinutes, h.checkpointInterval, h.type, h.fetchConfig)
|
55
56
|
}
|
56
57
|
const config = processor.config
|
57
58
|
|
@@ -72,14 +73,14 @@ export abstract class SuiBaseObjectsProcessorTemplate<
|
|
72
73
|
protected onInterval(
|
73
74
|
handler: HandlerType,
|
74
75
|
timeInterval: HandleInterval | undefined,
|
75
|
-
|
76
|
+
checkpointInterval: HandleInterval | undefined,
|
76
77
|
type: string | undefined,
|
77
78
|
fetchConfig: Partial<MoveAccountFetchConfig> | undefined
|
78
79
|
): this {
|
79
80
|
this.objectHandlers.push({
|
80
81
|
handler: handler,
|
81
82
|
timeIntervalInMinutes: timeInterval,
|
82
|
-
|
83
|
+
checkpointInterval: checkpointInterval,
|
83
84
|
type,
|
84
85
|
fetchConfig: { ...DEFAULT_FETCH_CONFIG, ...fetchConfig },
|
85
86
|
})
|
@@ -105,17 +106,17 @@ export abstract class SuiBaseObjectsProcessorTemplate<
|
|
105
106
|
)
|
106
107
|
}
|
107
108
|
|
108
|
-
public
|
109
|
+
public onCheckpointInterval(
|
109
110
|
handler: HandlerType,
|
110
|
-
|
111
|
-
|
111
|
+
checkpointInterval = 100000,
|
112
|
+
backfillCheckpointInterval = 400000,
|
112
113
|
type?: string,
|
113
114
|
fetchConfig?: Partial<MoveAccountFetchConfig>
|
114
115
|
): this {
|
115
116
|
return this.onInterval(
|
116
117
|
handler,
|
117
118
|
undefined,
|
118
|
-
{ recentInterval:
|
119
|
+
{ recentInterval: checkpointInterval, backfillInterval: backfillCheckpointInterval },
|
119
120
|
type,
|
120
121
|
fetchConfig
|
121
122
|
)
|
@@ -132,8 +133,8 @@ export abstract class SuiBaseObjectsProcessorTemplate<
|
|
132
133
|
// }
|
133
134
|
// }
|
134
135
|
|
135
|
-
export class
|
136
|
-
(self: SuiMoveObject, dynamicFieldObjects: SuiMoveObject[], ctx:
|
136
|
+
export class SuiObjectProcessorTemplate extends SuiObjectOrAddressProcessorTemplate<
|
137
|
+
(self: SuiMoveObject, dynamicFieldObjects: SuiMoveObject[], ctx: SuiObjectContext) => PromiseOrVoid,
|
137
138
|
// SuiObjectBindOptions,
|
138
139
|
SuiObjectProcessor
|
139
140
|
> {
|
@@ -142,8 +143,8 @@ export class SuiObjectsProcessorTemplate extends SuiBaseObjectsProcessorTemplate
|
|
142
143
|
}
|
143
144
|
}
|
144
145
|
|
145
|
-
export class SuiWrappedObjectProcessorTemplate extends
|
146
|
-
(dynamicFieldObjects: SuiMoveObject[], ctx:
|
146
|
+
export class SuiWrappedObjectProcessorTemplate extends SuiObjectOrAddressProcessorTemplate<
|
147
|
+
(dynamicFieldObjects: SuiMoveObject[], ctx: SuiObjectContext) => PromiseOrVoid,
|
147
148
|
// SuiObjectBindOptions,
|
148
149
|
SuiWrappedObjectProcessor
|
149
150
|
> {
|