@sentio/sdk 2.15.7-rc.1 → 2.16.0-rc.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/aptos/aptos-plugin.js +3 -14
- package/lib/aptos/aptos-plugin.js.map +1 -1
- package/lib/core/template.d.ts +5 -0
- package/lib/core/template.js +6 -0
- package/lib/core/template.js.map +1 -0
- package/lib/eth/base-processor-template.d.ts +1 -4
- package/lib/eth/base-processor-template.js +2 -7
- package/lib/eth/base-processor-template.js.map +1 -1
- package/lib/eth/eth-plugin.js +6 -1
- package/lib/eth/eth-plugin.js.map +1 -1
- package/lib/move/abstract-move-coder.js +2 -2
- package/lib/move/abstract-move-coder.js.map +1 -1
- package/lib/move/ts-type.test.js.map +1 -1
- package/lib/move/types.js +4 -6
- package/lib/move/types.js.map +1 -1
- package/lib/sui/index.d.ts +3 -1
- package/lib/sui/index.js +5 -1
- package/lib/sui/index.js.map +1 -1
- package/lib/sui/move-types.js +1 -1
- package/lib/sui/move-types.js.map +1 -1
- package/lib/sui/sui-object-processor.d.ts +54 -0
- package/lib/sui/sui-object-processor.js +93 -0
- package/lib/sui/sui-object-processor.js.map +1 -0
- package/lib/sui/sui-objects-processor-template.d.ts +34 -0
- package/lib/sui/sui-objects-processor-template.js +88 -0
- package/lib/sui/sui-objects-processor-template.js.map +1 -0
- package/lib/sui/sui-plugin.d.ts +1 -1
- package/lib/sui/sui-plugin.js +21 -2
- package/lib/sui/sui-plugin.js.map +1 -1
- package/lib/sui/sui-processor.d.ts +8 -56
- package/lib/sui/sui-processor.js +9 -122
- package/lib/sui/sui-processor.js.map +1 -1
- package/package.json +4 -3
- package/src/aptos/aptos-plugin.ts +3 -15
- package/src/core/template.ts +6 -0
- package/src/eth/base-processor-template.ts +2 -7
- package/src/eth/eth-plugin.ts +8 -1
- package/src/move/abstract-move-coder.ts +2 -2
- package/src/move/types.ts +6 -6
- package/src/sui/index.ts +13 -1
- package/src/sui/move-types.ts +1 -1
- package/src/sui/sui-object-processor.ts +186 -0
- package/src/sui/sui-objects-processor-template.ts +153 -0
- package/src/sui/sui-plugin.ts +29 -2
- package/src/sui/sui-processor.ts +14 -196
package/lib/sui/index.js
CHANGED
@@ -1,4 +1,8 @@
|
|
1
|
-
export
|
1
|
+
export { SuiBaseProcessor } from './sui-processor.js';
|
2
|
+
export { SuiAddressProcessor, SuiObjectProcessor, SuiWrappedObjectProcessor, } from './sui-object-processor.js';
|
3
|
+
export {
|
4
|
+
// SuiAddressProcessorTemplate,
|
5
|
+
SuiObjectsProcessorTemplate, SuiWrappedObjectProcessorTemplate, } from './sui-objects-processor-template.js';
|
2
6
|
export * from './network.js';
|
3
7
|
export * from './context.js';
|
4
8
|
export * from './models.js';
|
package/lib/sui/index.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/sui/index.ts"],"names":[],"mappings":"AAAA,
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/sui/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAuB,MAAM,oBAAoB,CAAA;AAC1E,OAAO,EACL,mBAAmB,EACnB,kBAAkB,EAClB,yBAAyB,GAE1B,MAAM,2BAA2B,CAAA;AAElC,OAAO;AACL,+BAA+B;AAC/B,2BAA2B,EAC3B,iCAAiC,GAClC,MAAM,qCAAqC,CAAA;AAE5C,cAAc,cAAc,CAAA;AAC5B,cAAc,cAAc,CAAA;AAC5B,cAAc,aAAa,CAAA;AAG3B,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAA;AAEhD,cAAc,iBAAiB,CAAA;AAE/B,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAE3C,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AAEjD,OAAO,EAAE,2BAA2B,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAA","sourcesContent":["export { SuiBaseProcessor, type SuiBindOptions } from './sui-processor.js'\nexport {\n SuiAddressProcessor,\n SuiObjectProcessor,\n SuiWrappedObjectProcessor,\n type SuiObjectBindOptions,\n} from './sui-object-processor.js'\n\nexport {\n // SuiAddressProcessorTemplate,\n SuiObjectsProcessorTemplate,\n SuiWrappedObjectProcessorTemplate,\n} from './sui-objects-processor-template.js'\n\nexport * from './network.js'\nexport * from './context.js'\nexport * from './models.js'\n\nexport type { SuiAddress } from './move-types.js'\nexport { BUILTIN_TYPES } from '../move/types.js'\n\nexport * from './move-coder.js'\n\nexport { SuiPlugin } from './sui-plugin.js'\n\nexport { ModuleClient } from './module-client.js'\n\nexport { validateAndNormalizeAddress, isValidSuiAddress } from './utils.js'\n"]}
|
package/lib/sui/move-types.js
CHANGED
@@ -61,7 +61,7 @@ export function toTypeDescriptor(normalizedType) {
|
|
61
61
|
return new TypeDescriptor(qname, args);
|
62
62
|
}
|
63
63
|
if ('Vector' in normalizedType) {
|
64
|
-
return new TypeDescriptor('
|
64
|
+
return new TypeDescriptor('Vector', [toTypeDescriptor(normalizedType.Vector)]);
|
65
65
|
}
|
66
66
|
if ('TypeParameter' in normalizedType) {
|
67
67
|
return new TypeDescriptor('T' + normalizedType.TypeParameter);
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"move-types.js","sourceRoot":"","sources":["../../src/sui/move-types.ts"],"names":[],"mappings":"AAOA,OAAO,EAEL,8BAA8B,GAI/B,MAAM,4BAA4B,CAAA;AACnC,OAAO,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAA;AAI3D,MAAM,UAAU,gBAAgB,CAAC,MAA+B;IAC9D,OAAO;QACL,OAAO,EAAE,MAAM,CAAC,OAAO;QACvB,gBAAgB,EAAE,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,gBAAgB,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,kBAAkB,CAAC,CAAC,EAAE,CAAC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,GAAG,GAAG,gBAAgB,CAAC,cAAc,CAAC,SAAS,CAAC,CAAA;QACtD,GAAG,CAAC,SAAS,GAAG,IAAI,CAAA;QACpB,OAAO,GAAG,CAAA;KACX;IAED,IAAI,kBAAkB,IAAI,cAAc,EAAE;QACxC,MAAM,GAAG,GAAG,gBAAgB,CAAC,cAAc,CAAC,gBAAgB,CAAC,CAAA;QAC7D,GAAG,CAAC,SAAS,GAAG,IAAI,CAAA;QACpB,GAAG,CAAC,OAAO,GAAG,IAAI,CAAA;QAClB,OAAO,GAAG,CAAA;KACX;IAED,MAAM,IAAI,KAAK,CAAC,qBAAqB,CAAC,CAAA;AACxC,CAAC","sourcesContent":["import type {\n SuiMoveNormalizedField,\n SuiMoveNormalizedFunction,\n SuiMoveNormalizedModule,\n SuiMoveNormalizedStruct,\n SuiMoveNormalizedType,\n} from '@mysten/sui.js'\nimport {\n InternalMoveFunction,\n InternalMoveFunctionVisibility,\n InternalMoveModule,\n InternalMoveStruct,\n InternalMoveStructField,\n} from '../move/internal-models.js'\nimport { SPLITTER, TypeDescriptor } from '../move/index.js'\n\nexport type { SuiAddress } from '@mysten/sui.js'\n\nexport function toInternalModule(module: SuiMoveNormalizedModule): InternalMoveModule {\n return {\n address: module.address,\n exposedFunctions: Object.entries(module.exposedFunctions).map(([n, f]) => toInternalFunction(n, f)),\n name: module.name,\n structs: Object.entries(module.structs).map(([n, s]) => toInternalStruct(n, s)),\n }\n}\n\nexport function toInternalFunction(name: string, func: SuiMoveNormalizedFunction): InternalMoveFunction {\n let visibility\n switch (func.visibility) {\n case 'Private':\n visibility = InternalMoveFunctionVisibility.PRIVATE\n break\n case 'Public':\n visibility = InternalMoveFunctionVisibility.PUBLIC\n break\n case 'Friend':\n visibility = InternalMoveFunctionVisibility.FRIEND\n break\n default:\n throw Error('No visibility for function' + name)\n }\n return {\n typeParams: func.typeParameters.map((p: any) => {\n return { constraints: p.abilities }\n }),\n isEntry: func.isEntry,\n name: name,\n params: func.parameters.map(toTypeDescriptor),\n return: func.return.map(toTypeDescriptor),\n visibility: visibility,\n }\n}\n\nexport function toInternalStruct(name: string, struct: SuiMoveNormalizedStruct): InternalMoveStruct {\n return {\n abilities: struct.abilities.abilities,\n fields: struct.fields.map(toInternalField),\n typeParams: struct.typeParameters.map((p: any) => {\n return { constraints: p.constraints.abilities }\n }),\n isNative: false,\n name: name,\n }\n}\n\nexport function toInternalField(module: SuiMoveNormalizedField): InternalMoveStructField {\n return {\n name: module.name,\n type: toTypeDescriptor(module.type),\n }\n}\n\nexport function toTypeDescriptor(normalizedType: SuiMoveNormalizedType): TypeDescriptor {\n if (typeof normalizedType === 'string') {\n return new TypeDescriptor(normalizedType)\n }\n\n if ('Struct' in normalizedType) {\n const qname = [normalizedType.Struct.address, normalizedType.Struct.module, normalizedType.Struct.name].join(\n SPLITTER\n )\n\n const args = normalizedType.Struct.typeArguments.map(toTypeDescriptor)\n\n return new TypeDescriptor(qname, args)\n }\n\n if ('Vector' in normalizedType) {\n return new TypeDescriptor('
|
1
|
+
{"version":3,"file":"move-types.js","sourceRoot":"","sources":["../../src/sui/move-types.ts"],"names":[],"mappings":"AAOA,OAAO,EAEL,8BAA8B,GAI/B,MAAM,4BAA4B,CAAA;AACnC,OAAO,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAA;AAI3D,MAAM,UAAU,gBAAgB,CAAC,MAA+B;IAC9D,OAAO;QACL,OAAO,EAAE,MAAM,CAAC,OAAO;QACvB,gBAAgB,EAAE,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,gBAAgB,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,kBAAkB,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;QACnG,IAAI,EAAE,MAAM,CAAC,IAAI;QACjB,OAAO,EAAE,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAA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AAI,cAAc,EAAE;QACxC,MAAM,GAAG,GAAG,gBAAgB,CAAC,cAAc,CAAC,gBAAgB,CAAC,CAAA;QAC7D,GAAG,CAAC,SAAS,GAAG,IAAI,CAAA;QACpB,GAAG,CAAC,OAAO,GAAG,IAAI,CAAA;QAClB,OAAO,GAAG,CAAA;KACX;IAED,MAAM,IAAI,KAAK,CAAC,qBAAqB,CAAC,CAAA;AACxC,CAAC","sourcesContent":["import type {\n SuiMoveNormalizedField,\n SuiMoveNormalizedFunction,\n SuiMoveNormalizedModule,\n SuiMoveNormalizedStruct,\n SuiMoveNormalizedType,\n} from '@mysten/sui.js'\nimport {\n InternalMoveFunction,\n InternalMoveFunctionVisibility,\n InternalMoveModule,\n InternalMoveStruct,\n InternalMoveStructField,\n} from '../move/internal-models.js'\nimport { SPLITTER, TypeDescriptor } from '../move/index.js'\n\nexport type { SuiAddress } from '@mysten/sui.js'\n\nexport function toInternalModule(module: SuiMoveNormalizedModule): InternalMoveModule {\n return {\n address: module.address,\n exposedFunctions: Object.entries(module.exposedFunctions).map(([n, f]) => toInternalFunction(n, f)),\n name: module.name,\n structs: Object.entries(module.structs).map(([n, s]) => toInternalStruct(n, s)),\n }\n}\n\nexport function toInternalFunction(name: string, func: SuiMoveNormalizedFunction): InternalMoveFunction {\n let visibility\n switch (func.visibility) {\n case 'Private':\n visibility = InternalMoveFunctionVisibility.PRIVATE\n break\n case 'Public':\n visibility = InternalMoveFunctionVisibility.PUBLIC\n break\n case 'Friend':\n visibility = InternalMoveFunctionVisibility.FRIEND\n break\n default:\n throw Error('No visibility for function' + name)\n }\n return {\n typeParams: func.typeParameters.map((p: any) => {\n return { constraints: p.abilities }\n }),\n isEntry: func.isEntry,\n name: name,\n params: func.parameters.map(toTypeDescriptor),\n return: func.return.map(toTypeDescriptor),\n visibility: visibility,\n }\n}\n\nexport function toInternalStruct(name: string, struct: SuiMoveNormalizedStruct): InternalMoveStruct {\n return {\n abilities: struct.abilities.abilities,\n fields: struct.fields.map(toInternalField),\n typeParams: struct.typeParameters.map((p: any) => {\n return { constraints: p.constraints.abilities }\n }),\n isNative: false,\n name: name,\n }\n}\n\nexport function toInternalField(module: SuiMoveNormalizedField): InternalMoveStructField {\n return {\n name: module.name,\n type: toTypeDescriptor(module.type),\n }\n}\n\nexport function toTypeDescriptor(normalizedType: SuiMoveNormalizedType): TypeDescriptor {\n if (typeof normalizedType === 'string') {\n return new TypeDescriptor(normalizedType)\n }\n\n if ('Struct' in normalizedType) {\n const qname = [normalizedType.Struct.address, normalizedType.Struct.module, normalizedType.Struct.name].join(\n SPLITTER\n )\n\n const args = normalizedType.Struct.typeArguments.map(toTypeDescriptor)\n\n return new TypeDescriptor(qname, args)\n }\n\n if ('Vector' in normalizedType) {\n return new TypeDescriptor('Vector', [toTypeDescriptor(normalizedType.Vector)])\n }\n if ('TypeParameter' in normalizedType) {\n return new TypeDescriptor('T' + normalizedType.TypeParameter)\n }\n\n if ('Reference' in normalizedType) {\n const res = toTypeDescriptor(normalizedType.Reference)\n res.reference = true\n return res\n }\n\n if ('MutableReference' in normalizedType) {\n const res = toTypeDescriptor(normalizedType.MutableReference)\n res.reference = true\n res.mutable = true\n return res\n }\n\n throw new Error('Unexpected sui type')\n}\n"]}
|
@@ -0,0 +1,54 @@
|
|
1
|
+
import { Data_SuiObject, HandleInterval, MoveAccountFetchConfig, MoveOwnerType, ProcessResult } from '@sentio/protos';
|
2
|
+
import { ListStateStorage } from '@sentio/runtime';
|
3
|
+
import { SuiNetwork } from './network.js';
|
4
|
+
import { SuiObjectsContext } from './context.js';
|
5
|
+
import { SuiMoveObject } from '@mysten/sui.js';
|
6
|
+
import { PromiseOrVoid } from '../core/index.js';
|
7
|
+
import { IndexConfigure, SuiBindOptions } from './sui-processor.js';
|
8
|
+
export interface SuiObjectBindOptions {
|
9
|
+
objectId: string;
|
10
|
+
network?: SuiNetwork;
|
11
|
+
startCheckpoint?: bigint;
|
12
|
+
baseLabels?: {
|
13
|
+
[key: string]: string;
|
14
|
+
};
|
15
|
+
}
|
16
|
+
interface ObjectHandler {
|
17
|
+
type?: string;
|
18
|
+
versionInterval?: HandleInterval;
|
19
|
+
timeIntervalInMinutes?: HandleInterval;
|
20
|
+
fetchConfig: MoveAccountFetchConfig;
|
21
|
+
handler: (resource: Data_SuiObject) => Promise<ProcessResult>;
|
22
|
+
}
|
23
|
+
export declare const DEFAULT_FETCH_CONFIG: MoveAccountFetchConfig;
|
24
|
+
export declare class SuiAccountProcessorState extends ListStateStorage<SuiBaseObjectsProcessor<any>> {
|
25
|
+
static INSTANCE: SuiAccountProcessorState;
|
26
|
+
}
|
27
|
+
export interface SuiInternalObjectsBindOptions extends SuiBindOptions {
|
28
|
+
ownerType: MoveOwnerType;
|
29
|
+
}
|
30
|
+
export declare abstract class SuiBaseObjectsProcessor<HandlerType> {
|
31
|
+
config: IndexConfigure;
|
32
|
+
ownerType: MoveOwnerType;
|
33
|
+
objectHandlers: ObjectHandler[];
|
34
|
+
protected constructor(options: SuiInternalObjectsBindOptions);
|
35
|
+
getChainId(): string;
|
36
|
+
protected abstract doHandle(handler: HandlerType, data: Data_SuiObject, ctx: SuiObjectsContext): PromiseOrVoid;
|
37
|
+
onInterval(handler: HandlerType, //(resources: SuiMoveObject[], ctx: SuiObjectsContext) => PromiseOrVoid,
|
38
|
+
timeInterval: HandleInterval | undefined, versionInterval: HandleInterval | undefined, type: string | undefined, fetchConfig: Partial<MoveAccountFetchConfig> | undefined): this;
|
39
|
+
onTimeInterval(handler: HandlerType, timeIntervalInMinutes?: number, backfillTimeIntervalInMinutes?: number, type?: string, fetchConfig?: Partial<MoveAccountFetchConfig>): this;
|
40
|
+
onSlotInterval(handler: HandlerType, slotInterval?: number, backfillSlotInterval?: number, type?: string, fetchConfig?: Partial<MoveAccountFetchConfig>): this;
|
41
|
+
}
|
42
|
+
export declare class SuiAddressProcessor extends SuiBaseObjectsProcessor<(objects: SuiMoveObject[], ctx: SuiObjectsContext) => PromiseOrVoid> {
|
43
|
+
static bind(options: SuiBindOptions): SuiAddressProcessor;
|
44
|
+
protected doHandle(handler: (objects: SuiMoveObject[], ctx: SuiObjectsContext) => PromiseOrVoid, data: Data_SuiObject, ctx: SuiObjectsContext): PromiseOrVoid;
|
45
|
+
}
|
46
|
+
export declare class SuiObjectProcessor extends SuiBaseObjectsProcessor<(self: SuiMoveObject, dynamicFieldObjects: SuiMoveObject[], ctx: SuiObjectsContext) => PromiseOrVoid> {
|
47
|
+
static bind(options: SuiObjectBindOptions): SuiObjectProcessor;
|
48
|
+
protected doHandle(handler: (self: SuiMoveObject, dynamicFieldObjects: SuiMoveObject[], ctx: SuiObjectsContext) => PromiseOrVoid, data: Data_SuiObject, ctx: SuiObjectsContext): PromiseOrVoid;
|
49
|
+
}
|
50
|
+
export declare class SuiWrappedObjectProcessor extends SuiBaseObjectsProcessor<(dynamicFieldObjects: SuiMoveObject[], ctx: SuiObjectsContext) => PromiseOrVoid> {
|
51
|
+
static bind(options: SuiObjectBindOptions): SuiWrappedObjectProcessor;
|
52
|
+
protected doHandle(handler: (dynamicFieldObjects: SuiMoveObject[], ctx: SuiObjectsContext) => PromiseOrVoid, data: Data_SuiObject, ctx: SuiObjectsContext): PromiseOrVoid;
|
53
|
+
}
|
54
|
+
export {};
|
@@ -0,0 +1,93 @@
|
|
1
|
+
import { MoveOwnerType } from '@sentio/protos';
|
2
|
+
import { ListStateStorage } from '@sentio/runtime';
|
3
|
+
import { SuiObjectsContext } from './context.js';
|
4
|
+
import { configure } from './sui-processor.js';
|
5
|
+
export const DEFAULT_FETCH_CONFIG = {
|
6
|
+
owned: true,
|
7
|
+
};
|
8
|
+
class SuiAccountProcessorState extends ListStateStorage {
|
9
|
+
static INSTANCE = new SuiAccountProcessorState();
|
10
|
+
}
|
11
|
+
export { SuiAccountProcessorState };
|
12
|
+
export class SuiBaseObjectsProcessor {
|
13
|
+
config;
|
14
|
+
ownerType;
|
15
|
+
objectHandlers = [];
|
16
|
+
// static bind(options: SuiObjectsBindOptions): SuiBaseObjectsProcessor<any> {
|
17
|
+
// return new SuiBaseObjectsProcessor(options)
|
18
|
+
// }
|
19
|
+
constructor(options) {
|
20
|
+
this.config = configure(options);
|
21
|
+
this.ownerType = options.ownerType;
|
22
|
+
SuiAccountProcessorState.INSTANCE.addValue(this);
|
23
|
+
}
|
24
|
+
getChainId() {
|
25
|
+
return this.config.network;
|
26
|
+
}
|
27
|
+
onInterval(handler, //(resources: SuiMoveObject[], ctx: SuiObjectsContext) => PromiseOrVoid,
|
28
|
+
timeInterval, versionInterval, type, fetchConfig) {
|
29
|
+
const processor = this;
|
30
|
+
this.objectHandlers.push({
|
31
|
+
handler: async function (data) {
|
32
|
+
const ctx = new SuiObjectsContext(processor.config.network, processor.config.address, data.slot, data.timestamp || new Date(0), processor.config.baseLabels);
|
33
|
+
await processor.doHandle(handler, data, ctx);
|
34
|
+
return ctx.getProcessResult();
|
35
|
+
},
|
36
|
+
timeIntervalInMinutes: timeInterval,
|
37
|
+
versionInterval: versionInterval,
|
38
|
+
type,
|
39
|
+
fetchConfig: { ...DEFAULT_FETCH_CONFIG, ...fetchConfig },
|
40
|
+
});
|
41
|
+
return this;
|
42
|
+
}
|
43
|
+
onTimeInterval(handler, timeIntervalInMinutes = 60, backfillTimeIntervalInMinutes = 240, type, fetchConfig) {
|
44
|
+
return this.onInterval(handler, {
|
45
|
+
recentInterval: timeIntervalInMinutes,
|
46
|
+
backfillInterval: backfillTimeIntervalInMinutes,
|
47
|
+
}, undefined, type, fetchConfig);
|
48
|
+
}
|
49
|
+
onSlotInterval(handler, slotInterval = 100000, backfillSlotInterval = 400000, type, fetchConfig) {
|
50
|
+
return this.onInterval(handler, undefined, { recentInterval: slotInterval, backfillInterval: backfillSlotInterval }, type, fetchConfig);
|
51
|
+
}
|
52
|
+
}
|
53
|
+
export class SuiAddressProcessor extends SuiBaseObjectsProcessor {
|
54
|
+
static bind(options) {
|
55
|
+
return new SuiAddressProcessor({ ...options, ownerType: MoveOwnerType.ADDRESS });
|
56
|
+
}
|
57
|
+
doHandle(handler, data, ctx) {
|
58
|
+
return handler(data.objects, ctx);
|
59
|
+
}
|
60
|
+
}
|
61
|
+
export class SuiObjectProcessor extends SuiBaseObjectsProcessor {
|
62
|
+
static bind(options) {
|
63
|
+
return new SuiObjectProcessor({
|
64
|
+
address: options.objectId,
|
65
|
+
network: options.network,
|
66
|
+
startCheckpoint: options.startCheckpoint,
|
67
|
+
ownerType: MoveOwnerType.OBJECT,
|
68
|
+
baseLabels: options.baseLabels,
|
69
|
+
});
|
70
|
+
}
|
71
|
+
doHandle(handler, data, ctx) {
|
72
|
+
if (!data.self) {
|
73
|
+
console.log(`Sui object not existed in ${ctx.slot}, please specific a start time`);
|
74
|
+
return;
|
75
|
+
}
|
76
|
+
return handler(data.self, data.objects, ctx);
|
77
|
+
}
|
78
|
+
}
|
79
|
+
export class SuiWrappedObjectProcessor extends SuiBaseObjectsProcessor {
|
80
|
+
static bind(options) {
|
81
|
+
return new SuiWrappedObjectProcessor({
|
82
|
+
address: options.objectId,
|
83
|
+
network: options.network,
|
84
|
+
startCheckpoint: options.startCheckpoint,
|
85
|
+
ownerType: MoveOwnerType.WRAPPED_OBJECT,
|
86
|
+
baseLabels: options.baseLabels,
|
87
|
+
});
|
88
|
+
}
|
89
|
+
doHandle(handler, data, ctx) {
|
90
|
+
return handler(data.objects, ctx);
|
91
|
+
}
|
92
|
+
}
|
93
|
+
//# sourceMappingURL=sui-object-processor.js.map
|
@@ -0,0 +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,iBAAiB,EAAE,MAAM,cAAc,CAAA;AAGhD,OAAO,EAAE,SAAS,EAAkC,MAAM,oBAAoB,CAAA;AAiB9E,MAAM,CAAC,MAA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,EAAE,aAAa,CAAC,MAAM;YAC/B,UAAU,EAAE,OAAO,CAAC,UAAU;SAC/B,CAAC,CAAA;IACJ,CAAC;IAES,QAAQ,CAChB,OAA6G,EAC7G,IAAoB,EACpB,GAAsB;QAEtB,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE;YACd,OAAO,CAAC,GAAG,CAAC,6BAA6B,GAAG,CAAC,IAAI,gCAAgC,CAAC,CAAA;YAClF,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,uBAE9C;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,OAAwF,EACxF,IAAoB,EACpB,GAAsB;QAEtB,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 { SuiObjectsContext } 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 versionInterval?: 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<SuiBaseObjectsProcessor<any>> {\n static INSTANCE = new SuiAccountProcessorState()\n}\n\nexport interface SuiInternalObjectsBindOptions extends SuiBindOptions {\n ownerType: MoveOwnerType\n}\n\nexport abstract class SuiBaseObjectsProcessor<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: SuiObjectsContext): PromiseOrVoid\n\n public onInterval(\n handler: HandlerType, //(resources: SuiMoveObject[], ctx: SuiObjectsContext) => PromiseOrVoid,\n timeInterval: HandleInterval | undefined,\n versionInterval: 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 SuiObjectsContext(\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 versionInterval: versionInterval,\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 onSlotInterval(\n handler: HandlerType,\n slotInterval = 100000,\n backfillSlotInterval = 400000,\n type?: string,\n fetchConfig?: Partial<MoveAccountFetchConfig>\n ): this {\n return this.onInterval(\n handler,\n undefined,\n { recentInterval: slotInterval, backfillInterval: backfillSlotInterval },\n type,\n fetchConfig\n )\n }\n}\n\nexport class SuiAddressProcessor extends SuiBaseObjectsProcessor<\n (objects: SuiMoveObject[], ctx: SuiObjectsContext) => 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: SuiObjectsContext) => PromiseOrVoid,\n data: Data_SuiObject,\n ctx: SuiObjectsContext\n ): PromiseOrVoid {\n return handler(data.objects as SuiMoveObject[], ctx)\n }\n}\n\nexport class SuiObjectProcessor extends SuiBaseObjectsProcessor<\n (self: SuiMoveObject, dynamicFieldObjects: SuiMoveObject[], ctx: SuiObjectsContext) => 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: SuiObjectsContext) => PromiseOrVoid,\n data: Data_SuiObject,\n ctx: SuiObjectsContext\n ): PromiseOrVoid {\n if (!data.self) {\n console.log(`Sui object not existed in ${ctx.slot}, 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 SuiBaseObjectsProcessor<\n (dynamicFieldObjects: SuiMoveObject[], ctx: SuiObjectsContext) => 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: SuiObjectsContext) => PromiseOrVoid,\n data: Data_SuiObject,\n ctx: SuiObjectsContext\n ): PromiseOrVoid {\n return handler(data.objects as SuiMoveObject[], ctx)\n }\n}\n"]}
|
@@ -0,0 +1,34 @@
|
|
1
|
+
import { HandleInterval, MoveAccountFetchConfig } from '@sentio/protos';
|
2
|
+
import { ListStateStorage } from '@sentio/runtime';
|
3
|
+
import { SuiContext, SuiObjectsContext } from './context.js';
|
4
|
+
import { SuiMoveObject } from '@mysten/sui.js';
|
5
|
+
import { PromiseOrVoid } from '../core/index.js';
|
6
|
+
import { SuiBaseObjectsProcessor, SuiObjectBindOptions, SuiObjectProcessor, SuiWrappedObjectProcessor } from './sui-object-processor.js';
|
7
|
+
declare class ObjectHandler<HandlerType> {
|
8
|
+
type?: string;
|
9
|
+
versionInterval?: HandleInterval;
|
10
|
+
timeIntervalInMinutes?: HandleInterval;
|
11
|
+
handler: HandlerType;
|
12
|
+
fetchConfig: MoveAccountFetchConfig;
|
13
|
+
}
|
14
|
+
export declare class SuiAccountProcessorTemplateState extends ListStateStorage<SuiBaseObjectsProcessorTemplate<any, any>> {
|
15
|
+
static INSTANCE: SuiAccountProcessorTemplateState;
|
16
|
+
}
|
17
|
+
export declare abstract class SuiBaseObjectsProcessorTemplate<HandlerType, ProcessorType extends SuiBaseObjectsProcessor<HandlerType>> {
|
18
|
+
id: number;
|
19
|
+
objectHandlers: ObjectHandler<HandlerType>[];
|
20
|
+
binds: Set<string>;
|
21
|
+
protected constructor();
|
22
|
+
abstract createProcessor(options: SuiObjectBindOptions): ProcessorType;
|
23
|
+
bind(options: SuiObjectBindOptions, ctx: SuiContext): void;
|
24
|
+
protected onInterval(handler: HandlerType, timeInterval: HandleInterval | undefined, versionInterval: HandleInterval | undefined, type: string | undefined, fetchConfig: Partial<MoveAccountFetchConfig> | undefined): this;
|
25
|
+
onTimeInterval(handler: HandlerType, timeIntervalInMinutes?: number, backfillTimeIntervalInMinutes?: number, type?: string, fetchConfig?: Partial<MoveAccountFetchConfig>): this;
|
26
|
+
onSlotInterval(handler: HandlerType, slotInterval?: number, backfillSlotInterval?: number, type?: string, fetchConfig?: Partial<MoveAccountFetchConfig>): this;
|
27
|
+
}
|
28
|
+
export declare class SuiObjectsProcessorTemplate extends SuiBaseObjectsProcessorTemplate<(self: SuiMoveObject, dynamicFieldObjects: SuiMoveObject[], ctx: SuiObjectsContext) => PromiseOrVoid, SuiObjectProcessor> {
|
29
|
+
createProcessor(options: SuiObjectBindOptions): SuiObjectProcessor;
|
30
|
+
}
|
31
|
+
export declare class SuiWrappedObjectProcessorTemplate extends SuiBaseObjectsProcessorTemplate<(dynamicFieldObjects: SuiMoveObject[], ctx: SuiObjectsContext) => PromiseOrVoid, SuiWrappedObjectProcessor> {
|
32
|
+
createProcessor(options: SuiObjectBindOptions): SuiWrappedObjectProcessor;
|
33
|
+
}
|
34
|
+
export {};
|
@@ -0,0 +1,88 @@
|
|
1
|
+
import { ListStateStorage } from '@sentio/runtime';
|
2
|
+
import { DEFAULT_FETCH_CONFIG, SuiObjectProcessor, SuiWrappedObjectProcessor, } from './sui-object-processor.js';
|
3
|
+
import { TemplateInstanceState } from '../core/template.js';
|
4
|
+
class ObjectHandler {
|
5
|
+
type;
|
6
|
+
versionInterval;
|
7
|
+
timeIntervalInMinutes;
|
8
|
+
handler;
|
9
|
+
fetchConfig;
|
10
|
+
}
|
11
|
+
class SuiAccountProcessorTemplateState extends ListStateStorage {
|
12
|
+
static INSTANCE = new SuiAccountProcessorTemplateState();
|
13
|
+
}
|
14
|
+
export { SuiAccountProcessorTemplateState };
|
15
|
+
export class SuiBaseObjectsProcessorTemplate {
|
16
|
+
id;
|
17
|
+
objectHandlers = [];
|
18
|
+
binds = new Set();
|
19
|
+
constructor() {
|
20
|
+
this.id = SuiAccountProcessorTemplateState.INSTANCE.getValues().length;
|
21
|
+
SuiAccountProcessorTemplateState.INSTANCE.addValue(this);
|
22
|
+
}
|
23
|
+
bind(options, ctx) {
|
24
|
+
options.network = options.network || ctx.network;
|
25
|
+
const sig = [options.network, options.objectId].join('_');
|
26
|
+
if (this.binds.has(sig)) {
|
27
|
+
console.log(`Same object id can be bind to one template only once, ignore duplicate bind: ${sig}`);
|
28
|
+
return;
|
29
|
+
}
|
30
|
+
this.binds.add(sig);
|
31
|
+
const processor = this.createProcessor(options);
|
32
|
+
for (const h of this.objectHandlers) {
|
33
|
+
processor.onInterval(h.handler, h.timeIntervalInMinutes, h.versionInterval, h.type, h.fetchConfig);
|
34
|
+
}
|
35
|
+
const config = processor.config;
|
36
|
+
ctx._res.states.configUpdated = true;
|
37
|
+
TemplateInstanceState.INSTANCE.addValue({
|
38
|
+
templateId: this.id,
|
39
|
+
contract: {
|
40
|
+
name: '',
|
41
|
+
chainId: config.network,
|
42
|
+
address: config.address,
|
43
|
+
abi: '',
|
44
|
+
},
|
45
|
+
startBlock: config.startCheckpoint,
|
46
|
+
endBlock: 0n,
|
47
|
+
});
|
48
|
+
}
|
49
|
+
onInterval(handler, timeInterval, versionInterval, type, fetchConfig) {
|
50
|
+
this.objectHandlers.push({
|
51
|
+
handler: handler,
|
52
|
+
timeIntervalInMinutes: timeInterval,
|
53
|
+
versionInterval: versionInterval,
|
54
|
+
type,
|
55
|
+
fetchConfig: { ...DEFAULT_FETCH_CONFIG, ...fetchConfig },
|
56
|
+
});
|
57
|
+
return this;
|
58
|
+
}
|
59
|
+
onTimeInterval(handler, timeIntervalInMinutes = 60, backfillTimeIntervalInMinutes = 240, type, fetchConfig) {
|
60
|
+
return this.onInterval(handler, {
|
61
|
+
recentInterval: timeIntervalInMinutes,
|
62
|
+
backfillInterval: backfillTimeIntervalInMinutes,
|
63
|
+
}, undefined, type, fetchConfig);
|
64
|
+
}
|
65
|
+
onSlotInterval(handler, slotInterval = 100000, backfillSlotInterval = 400000, type, fetchConfig) {
|
66
|
+
return this.onInterval(handler, undefined, { recentInterval: slotInterval, backfillInterval: backfillSlotInterval }, type, fetchConfig);
|
67
|
+
}
|
68
|
+
}
|
69
|
+
// export class SuiAddressProcessorTemplate extends SuiBaseObjectsProcessorTemplate<
|
70
|
+
// (objects: SuiMoveObject[], ctx: SuiObjectsContext) => PromiseOrVoid,
|
71
|
+
// SuiBindOptions,
|
72
|
+
// SuiAddressProcessor
|
73
|
+
// > {
|
74
|
+
// bind(options: SuiBindOptions, ctx: SuiContext): SuiAddressProcessor {
|
75
|
+
// return this.bindInternal(SuiAddressProcessorTemplate.bind(options), ctx)
|
76
|
+
// }
|
77
|
+
// }
|
78
|
+
export class SuiObjectsProcessorTemplate extends SuiBaseObjectsProcessorTemplate {
|
79
|
+
createProcessor(options) {
|
80
|
+
return SuiObjectProcessor.bind(options);
|
81
|
+
}
|
82
|
+
}
|
83
|
+
export class SuiWrappedObjectProcessorTemplate extends SuiBaseObjectsProcessorTemplate {
|
84
|
+
createProcessor(options) {
|
85
|
+
return SuiWrappedObjectProcessor.bind(options);
|
86
|
+
}
|
87
|
+
}
|
88
|
+
//# sourceMappingURL=sui-objects-processor-template.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"sui-objects-processor-template.js","sourceRoot":"","sources":["../../src/sui/sui-objects-processor-template.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAIlD,OAAO,EACL,oBAAoB,EAGpB,kBAAkB,EAClB,yBAAyB,GAC1B,MAAM,2BAA2B,CAAA;AAClC,OAAO,EAAE,qBAAqB,EA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,EAAE,YAAY,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,EACxE,IAAI,EACJ,WAAW,CACZ,CAAA;IACH,CAAC;CACF;AAED,oFAAoF;AACpF,yEAAyE;AACzE,oBAAoB;AACpB,wBAAwB;AACxB,MAAM;AACN,0EAA0E;AAC1E,+EAA+E;AAC/E,MAAM;AACN,IAAI;AAEJ,MAAM,OAAO,2BAA4B,SAAQ,+BAIhD;IACC,eAAe,CAAC,OAA6B;QAC3C,OAAO,kBAAkB,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;IACzC,CAAC;CACF;AAED,MAAM,OAAO,iCAAkC,SAAQ,+BAItD;IACC,eAAe,CAAC,OAA6B;QAC3C,OAAO,yBAAyB,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;IAChD,CAAC;CACF","sourcesContent":["import { HandleInterval, MoveAccountFetchConfig } from '@sentio/protos'\nimport { ListStateStorage } from '@sentio/runtime'\nimport { SuiContext, SuiObjectsContext } from './context.js'\nimport { SuiMoveObject } from '@mysten/sui.js'\nimport { PromiseOrVoid } from '../core/index.js'\nimport {\n DEFAULT_FETCH_CONFIG,\n SuiBaseObjectsProcessor,\n SuiObjectBindOptions,\n SuiObjectProcessor,\n SuiWrappedObjectProcessor,\n} from './sui-object-processor.js'\nimport { TemplateInstanceState } from '../core/template.js'\n\nclass ObjectHandler<HandlerType> {\n type?: string\n versionInterval?: HandleInterval\n timeIntervalInMinutes?: HandleInterval\n handler: HandlerType\n fetchConfig: MoveAccountFetchConfig\n}\n\nexport class SuiAccountProcessorTemplateState extends ListStateStorage<SuiBaseObjectsProcessorTemplate<any, any>> {\n static INSTANCE = new SuiAccountProcessorTemplateState()\n}\n\nexport abstract class SuiBaseObjectsProcessorTemplate<\n HandlerType,\n // OptionType,\n ProcessorType extends SuiBaseObjectsProcessor<HandlerType>\n> {\n id: number\n objectHandlers: ObjectHandler<HandlerType>[] = []\n binds = new Set<string>()\n\n protected constructor() {\n this.id = SuiAccountProcessorTemplateState.INSTANCE.getValues().length\n SuiAccountProcessorTemplateState.INSTANCE.addValue(this)\n }\n\n abstract createProcessor(options: SuiObjectBindOptions): ProcessorType\n\n bind(options: SuiObjectBindOptions, ctx: SuiContext): void {\n options.network = options.network || ctx.network\n const sig = [options.network, options.objectId].join('_')\n if (this.binds.has(sig)) {\n console.log(`Same object id can be bind to one template only once, ignore duplicate bind: ${sig}`)\n return\n }\n this.binds.add(sig)\n\n const processor = this.createProcessor(options)\n for (const h of this.objectHandlers) {\n processor.onInterval(h.handler, h.timeIntervalInMinutes, h.versionInterval, h.type, h.fetchConfig)\n }\n const config = processor.config\n\n ctx._res.states.configUpdated = true\n TemplateInstanceState.INSTANCE.addValue({\n templateId: this.id,\n contract: {\n name: '',\n chainId: config.network,\n address: config.address,\n abi: '',\n },\n startBlock: config.startCheckpoint,\n endBlock: 0n,\n })\n }\n\n protected onInterval(\n handler: HandlerType,\n timeInterval: HandleInterval | undefined,\n versionInterval: HandleInterval | undefined,\n type: string | undefined,\n fetchConfig: Partial<MoveAccountFetchConfig> | undefined\n ): this {\n this.objectHandlers.push({\n handler: handler,\n timeIntervalInMinutes: timeInterval,\n versionInterval: versionInterval,\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 onSlotInterval(\n handler: HandlerType,\n slotInterval = 100000,\n backfillSlotInterval = 400000,\n type?: string,\n fetchConfig?: Partial<MoveAccountFetchConfig>\n ): this {\n return this.onInterval(\n handler,\n undefined,\n { recentInterval: slotInterval, backfillInterval: backfillSlotInterval },\n type,\n fetchConfig\n )\n }\n}\n\n// export class SuiAddressProcessorTemplate extends SuiBaseObjectsProcessorTemplate<\n// (objects: SuiMoveObject[], ctx: SuiObjectsContext) => PromiseOrVoid,\n// SuiBindOptions,\n// SuiAddressProcessor\n// > {\n// bind(options: SuiBindOptions, ctx: SuiContext): SuiAddressProcessor {\n// return this.bindInternal(SuiAddressProcessorTemplate.bind(options), ctx)\n// }\n// }\n\nexport class SuiObjectsProcessorTemplate extends SuiBaseObjectsProcessorTemplate<\n (self: SuiMoveObject, dynamicFieldObjects: SuiMoveObject[], ctx: SuiObjectsContext) => PromiseOrVoid,\n // SuiObjectBindOptions,\n SuiObjectProcessor\n> {\n createProcessor(options: SuiObjectBindOptions): SuiObjectProcessor {\n return SuiObjectProcessor.bind(options)\n }\n}\n\nexport class SuiWrappedObjectProcessorTemplate extends SuiBaseObjectsProcessorTemplate<\n (dynamicFieldObjects: SuiMoveObject[], ctx: SuiObjectsContext) => PromiseOrVoid,\n // SuiObjectBindOptions,\n SuiWrappedObjectProcessor\n> {\n createProcessor(options: SuiObjectBindOptions): SuiWrappedObjectProcessor {\n return SuiWrappedObjectProcessor.bind(options)\n }\n}\n"]}
|
package/lib/sui/sui-plugin.d.ts
CHANGED
@@ -8,7 +8,7 @@ interface Handlers {
|
|
8
8
|
export declare class SuiPlugin extends Plugin {
|
9
9
|
name: string;
|
10
10
|
handlers: Handlers;
|
11
|
-
start(
|
11
|
+
start(request: StartRequest): Promise<void>;
|
12
12
|
configure(config: ProcessConfigResponse): Promise<void>;
|
13
13
|
supportedHandlers: HandlerType[];
|
14
14
|
processSuiEvent(binding: DataBinding): Promise<ProcessResult>;
|
package/lib/sui/sui-plugin.js
CHANGED
@@ -1,9 +1,14 @@
|
|
1
1
|
import { errorString, mergeProcessResults, Plugin, PluginManager, USER_PROCESSOR } from '@sentio/runtime';
|
2
2
|
import { AccountConfig, ContractConfig, HandlerType, } from '@sentio/protos';
|
3
3
|
import { ServerError, Status } from 'nice-grpc';
|
4
|
-
import {
|
4
|
+
import { SuiProcessorState } from './sui-processor.js';
|
5
|
+
import { SuiAccountProcessorState } from './sui-object-processor.js';
|
5
6
|
import { validateAndNormalizeAddress } from './utils.js';
|
6
7
|
import { initCoinList } from './ext/coin.js';
|
8
|
+
import { SuiChainId } from '../core/chain.js';
|
9
|
+
import { SuiAccountProcessorTemplateState } from './sui-objects-processor-template.js';
|
10
|
+
import { SuiNetwork } from './network.js';
|
11
|
+
import { SuiContext } from './context.js';
|
7
12
|
export class SuiPlugin extends Plugin {
|
8
13
|
name = 'SuiPlugin';
|
9
14
|
handlers = {
|
@@ -11,8 +16,20 @@ export class SuiPlugin extends Plugin {
|
|
11
16
|
suiEventHandlers: [],
|
12
17
|
suiObjectHandlers: [],
|
13
18
|
};
|
14
|
-
async start(
|
19
|
+
async start(request) {
|
15
20
|
await initCoinList();
|
21
|
+
const allowedChainIds = new Set(Object.values(SuiChainId));
|
22
|
+
for (const instance of request.templateInstances) {
|
23
|
+
if (!allowedChainIds.has(instance.contract?.chainId || '')) {
|
24
|
+
continue;
|
25
|
+
}
|
26
|
+
const template = SuiAccountProcessorTemplateState.INSTANCE.getValues()[instance.templateId];
|
27
|
+
template.bind({
|
28
|
+
objectId: instance.contract?.address || '',
|
29
|
+
network: instance.contract?.chainId || SuiNetwork.MAIN_NET,
|
30
|
+
startCheckpoint: instance.startBlock || 0n,
|
31
|
+
}, NoopContext);
|
32
|
+
}
|
16
33
|
}
|
17
34
|
async configure(config) {
|
18
35
|
const handlers = {
|
@@ -83,6 +100,7 @@ export class SuiPlugin extends Plugin {
|
|
83
100
|
},
|
84
101
|
type: handler.type || '',
|
85
102
|
ownerType: processor.ownerType,
|
103
|
+
fetchConfig: undefined,
|
86
104
|
});
|
87
105
|
}
|
88
106
|
config.accountConfigs.push(accountConfig);
|
@@ -144,4 +162,5 @@ export class SuiPlugin extends Plugin {
|
|
144
162
|
}
|
145
163
|
}
|
146
164
|
PluginManager.INSTANCE.register(new SuiPlugin());
|
165
|
+
const NoopContext = new SuiContext('', SuiChainId.SUI_MAINNET, '', new Date(), 0n, {}, 0, {});
|
147
166
|
//# sourceMappingURL=sui-plugin.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"sui-plugin.js","sourceRoot":"","sources":["../../src/sui/sui-plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,mBAAmB,EAAE,MAAM,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAA;AACzG,OAAO,EACL,aAAa,EACb,cAAc,EAKd,WAAW,GAMZ,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,2BAA2B,EAAE,MAAM,YAAY,CAAA;AACxD,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAA;AAQ5C,MAAM,OAAO,SAAU,SAAQ,MAAM;IACnC,IAAI,GAAW,WAAW,CAAA;IAC1B,QAAQ,GAAa;QACnB,eAAe,EAAE,EAAE;QACnB,gBAAgB,EAAE,EAAE;QACpB,iBAAiB,EAAE,EAAE;KACtB,CAAA;IACD,KAAK,CAAC,KAAK,CAAC,KAAmB;QAC7B,MAAM,YAAY,EAAE,CAAA;IACtB,CAAC;IAED,KAAK,CAAC,SAAS,CAAC,MAA6B;QAC3C,MAAM,QAAQ,GAAa;YACzB,eAAe,EAAE,EAAE;YACnB,gBAAgB,EAAE,EAAE;YACpB,iBAAiB,EAAE,EAAE;SACtB,CAAA;QACD,KAAK,MAAM,YAAY,IAAI,iBAAiB,CAAC,QAAQ,CAAC,SAAS,EAAE,EAAE;YACjE,MAAM,cAAc,GAAG,cAAc,CAAC,WAAW,CAAC;gBAChD,iBAAiB,EAAE,EAAE;gBACrB,aAAa,EAAE,cAAc;gBAC7B,QAAQ,EAAE;oBACR,IAAI,EAAE,YAAY,CAAC,UAAU;oBAC7B,OA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,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 StartRequest,\n} from '@sentio/protos'\n\nimport { ServerError, Status } from 'nice-grpc'\n\nimport { SuiAccountProcessorState, SuiProcessorState } from './sui-processor.js'\nimport { validateAndNormalizeAddress } from './utils.js'\nimport { initCoinList } from './ext/coin.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(start: StartRequest): Promise<void> {\n await initCoinList()\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 })\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"]}
|
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,EAAE,gCAAgC,EAAmC,MAAM,qCAAqC,CAAA;AACvH,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;QACnB,gBAAgB,EAAE,EAAE;QACpB,iBAAiB,EAAE,EAAE;KACtB,CAAA;IACD,KAAK,CAAC,KAAK,CAAC,OAAqB;QAC/B,MAAM,YAAY,EAAE,CAAA;QAEpB,MAAM,eAAe,GAAG,IAAI,GAAG,CAAS,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,CAAA;QAClE,KAAK,MAAM,QAAQ,IAAI,OAAO,CAAC,iBAAiB,EAAE;YAChD,IAAI,CAAC,eAAe,C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AAC;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 { 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,31 +1,20 @@
|
|
1
|
-
import { Data_SuiCall, Data_SuiEvent,
|
1
|
+
import { Data_SuiCall, Data_SuiEvent, MoveFetchConfig } from '@sentio/protos';
|
2
2
|
import { ListStateStorage } from '@sentio/runtime';
|
3
3
|
import { SuiNetwork } from './network.js';
|
4
|
-
import { SuiContext
|
5
|
-
import { MoveCallSuiTransaction, SuiEvent
|
4
|
+
import { SuiContext } from './context.js';
|
5
|
+
import { MoveCallSuiTransaction, SuiEvent } from '@mysten/sui.js';
|
6
6
|
import { CallHandler, EventFilter, EventHandler, FunctionNameAndCallFilter } from '../move/index.js';
|
7
7
|
import { MoveCoder } from './move-coder.js';
|
8
|
-
import { Labels
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
baseLabels?: Labels;
|
14
|
-
}
|
15
|
-
export declare class SuiBindOptions {
|
8
|
+
import { Labels } from '../core/index.js';
|
9
|
+
import { Required } from 'utility-types';
|
10
|
+
export type IndexConfigure = Required<SuiBindOptions, 'startCheckpoint' | 'network'>;
|
11
|
+
export declare function configure(options: SuiBindOptions): IndexConfigure;
|
12
|
+
export interface SuiBindOptions {
|
16
13
|
address: string;
|
17
14
|
network?: SuiNetwork;
|
18
15
|
startCheckpoint?: bigint;
|
19
16
|
baseLabels?: Labels;
|
20
17
|
}
|
21
|
-
export declare class SuiObjectBindOptions {
|
22
|
-
objectId: string;
|
23
|
-
network?: SuiNetwork;
|
24
|
-
startCheckpoint?: bigint;
|
25
|
-
baseLabels?: {
|
26
|
-
[key: string]: string;
|
27
|
-
};
|
28
|
-
}
|
29
18
|
export declare class SuiProcessorState extends ListStateStorage<SuiBaseProcessor> {
|
30
19
|
static INSTANCE: SuiProcessorState;
|
31
20
|
}
|
@@ -40,40 +29,3 @@ export declare class SuiBaseProcessor {
|
|
40
29
|
onMoveEvent(handler: (event: SuiEvent, ctx: SuiContext) => void, filter: EventFilter | EventFilter[], fetchConfig?: Partial<MoveFetchConfig>): SuiBaseProcessor;
|
41
30
|
onEntryFunctionCall(handler: (call: MoveCallSuiTransaction, ctx: SuiContext) => void, filter: FunctionNameAndCallFilter | FunctionNameAndCallFilter[], fetchConfig?: Partial<MoveFetchConfig>): SuiBaseProcessor;
|
42
31
|
}
|
43
|
-
declare class ObjectHandler {
|
44
|
-
type?: string;
|
45
|
-
versionInterval?: HandleInterval;
|
46
|
-
timeIntervalInMinutes?: HandleInterval;
|
47
|
-
handler: (resource: Data_SuiObject) => Promise<ProcessResult>;
|
48
|
-
}
|
49
|
-
export declare class SuiAccountProcessorState extends ListStateStorage<SuiBaseObjectsProcessor<any>> {
|
50
|
-
static INSTANCE: SuiAccountProcessorState;
|
51
|
-
}
|
52
|
-
declare class SuiObjectsBindOptions extends SuiBindOptions {
|
53
|
-
ownerType: MoveOnIntervalConfig_OwnerType;
|
54
|
-
}
|
55
|
-
declare abstract class SuiBaseObjectsProcessor<HandlerType> {
|
56
|
-
config: IndexConfigure;
|
57
|
-
ownerType: MoveOnIntervalConfig_OwnerType;
|
58
|
-
objectHandlers: ObjectHandler[];
|
59
|
-
protected constructor(options: SuiObjectsBindOptions);
|
60
|
-
getChainId(): string;
|
61
|
-
protected abstract doHandle(handler: HandlerType, data: Data_SuiObject, ctx: SuiObjectsContext): PromiseOrVoid;
|
62
|
-
protected onInterval(handler: HandlerType, //(resources: SuiMoveObject[], ctx: SuiObjectsContext) => PromiseOrVoid,
|
63
|
-
timeInterval: HandleInterval | undefined, versionInterval: HandleInterval | undefined, type: string | undefined): this;
|
64
|
-
onTimeInterval(handler: HandlerType, timeIntervalInMinutes?: number, backfillTimeIntervalInMinutes?: number, type?: string): this;
|
65
|
-
onSlotInterval(handler: HandlerType, slotInterval?: number, backfillSlotInterval?: number, type?: string): this;
|
66
|
-
}
|
67
|
-
export declare class SuiAddressProcessor extends SuiBaseObjectsProcessor<(objects: SuiMoveObject[], ctx: SuiObjectsContext) => PromiseOrVoid> {
|
68
|
-
static bind(options: SuiBindOptions): SuiAddressProcessor;
|
69
|
-
protected doHandle(handler: (objects: SuiMoveObject[], ctx: SuiObjectsContext) => PromiseOrVoid, data: Data_SuiObject, ctx: SuiObjectsContext): PromiseOrVoid;
|
70
|
-
}
|
71
|
-
export declare class SuiObjectProcessor extends SuiBaseObjectsProcessor<(self: SuiMoveObject, dynamicFieldObjects: SuiMoveObject[], ctx: SuiObjectsContext) => PromiseOrVoid> {
|
72
|
-
static bind(options: SuiObjectBindOptions): SuiObjectProcessor;
|
73
|
-
protected doHandle(handler: (self: SuiMoveObject, dynamicFieldObjects: SuiMoveObject[], ctx: SuiObjectsContext) => PromiseOrVoid, data: Data_SuiObject, ctx: SuiObjectsContext): PromiseOrVoid;
|
74
|
-
}
|
75
|
-
export declare class SuiWrappedObjectProcessor extends SuiBaseObjectsProcessor<(dynamicFieldObjects: SuiMoveObject[], ctx: SuiObjectsContext) => PromiseOrVoid> {
|
76
|
-
static bind(options: SuiObjectBindOptions): SuiWrappedObjectProcessor;
|
77
|
-
protected doHandle(handler: (dynamicFieldObjects: SuiMoveObject[], ctx: SuiObjectsContext) => PromiseOrVoid, data: Data_SuiObject, ctx: SuiObjectsContext): PromiseOrVoid;
|
78
|
-
}
|
79
|
-
export {};
|