@sentio/sdk 2.16.0-rc.2 → 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/sui/context.d.ts +5 -5
- package/lib/sui/context.js +10 -10
- package/lib/sui/context.js.map +1 -1
- package/lib/sui/sui-object-processor-template.d.ts +3 -3
- package/lib/sui/sui-object-processor-template.js +7 -6
- package/lib/sui/sui-object-processor-template.js.map +1 -1
- package/lib/sui/sui-object-processor.d.ts +3 -3
- package/lib/sui/sui-object-processor.js +5 -5
- package/lib/sui/sui-object-processor.js.map +1 -1
- package/lib/sui/sui-plugin.js +1 -1
- package/lib/sui/sui-plugin.js.map +1 -1
- package/package.json +3 -3
- package/src/sui/context.ts +22 -10
- package/src/sui/sui-object-processor-template.ts +9 -8
- package/src/sui/sui-object-processor.ts +8 -8
- package/src/sui/sui-plugin.ts +1 -1
package/lib/sui/context.d.ts
CHANGED
@@ -7,11 +7,11 @@ import { MoveAccountContext, MoveContext } from '../move/index.js';
|
|
7
7
|
export declare class SuiContext extends MoveContext<SuiNetwork, SuiMoveNormalizedModule, SuiEvent | SuiMoveObject> {
|
8
8
|
moduleName: string;
|
9
9
|
timestamp: Date;
|
10
|
-
|
10
|
+
checkpoint: bigint;
|
11
11
|
transaction: SuiTransactionBlockResponse;
|
12
12
|
eventIndex: number;
|
13
13
|
coder: MoveCoder;
|
14
|
-
constructor(moduleName: string, network: SuiNetwork, address: string, timestamp: Date,
|
14
|
+
constructor(moduleName: string, network: SuiNetwork, address: string, timestamp: Date, checkpoint: bigint, transaction: SuiTransactionBlockResponse, eventIndex: number, baseLabels: Labels | undefined);
|
15
15
|
getChainId(): import("../index.js").SuiChainId;
|
16
16
|
getTimestamp(): number;
|
17
17
|
getMetaDataInternal(name: string, labels: Labels): RecordMetaData;
|
@@ -20,11 +20,11 @@ export declare class SuiContext extends MoveContext<SuiNetwork, SuiMoveNormalize
|
|
20
20
|
export declare class SuiAddressContext extends MoveAccountContext<SuiNetwork, SuiMoveNormalizedModule, SuiEvent | SuiMoveObject> {
|
21
21
|
address: string;
|
22
22
|
network: SuiNetwork;
|
23
|
-
|
23
|
+
checkpoint: bigint;
|
24
24
|
timestamp: Date;
|
25
25
|
coder: MoveCoder;
|
26
26
|
protected contractName: string;
|
27
|
-
constructor(network: SuiNetwork, address: string,
|
27
|
+
constructor(network: SuiNetwork, address: string, checkpoint: bigint, timestamp: Date, baseLabels: Labels | undefined);
|
28
28
|
getChainId(): import("../index.js").SuiChainId;
|
29
29
|
getMetaDataInternal(name: string, labels: Labels): RecordMetaData;
|
30
30
|
get client(): JsonRpcProvider;
|
@@ -33,5 +33,5 @@ export declare class SuiAddressContext extends MoveAccountContext<SuiNetwork, Su
|
|
33
33
|
export declare class SuiObjectContext extends SuiAddressContext {
|
34
34
|
contractName: string;
|
35
35
|
objectId: string;
|
36
|
-
constructor(network: SuiNetwork, objectId: string,
|
36
|
+
constructor(network: SuiNetwork, objectId: string, checkpoint: bigint, timestamp: Date, baseLabels: Labels | undefined);
|
37
37
|
}
|
package/lib/sui/context.js
CHANGED
@@ -5,17 +5,17 @@ import { MoveAccountContext, MoveContext } from '../move/index.js';
|
|
5
5
|
export class SuiContext extends MoveContext {
|
6
6
|
moduleName;
|
7
7
|
timestamp;
|
8
|
-
|
8
|
+
checkpoint;
|
9
9
|
transaction;
|
10
10
|
eventIndex;
|
11
11
|
coder;
|
12
|
-
constructor(moduleName, network, address, timestamp,
|
12
|
+
constructor(moduleName, network, address, timestamp, checkpoint, transaction, eventIndex, baseLabels) {
|
13
13
|
super(baseLabels);
|
14
14
|
this.address = address.toLowerCase();
|
15
15
|
this.network = network;
|
16
16
|
this.moduleName = moduleName;
|
17
17
|
this.timestamp = timestamp;
|
18
|
-
this.
|
18
|
+
this.checkpoint = checkpoint;
|
19
19
|
this.eventIndex = eventIndex;
|
20
20
|
this.coder = defaultMoveCoder(network);
|
21
21
|
if (transaction) {
|
@@ -32,7 +32,7 @@ export class SuiContext extends MoveContext {
|
|
32
32
|
return {
|
33
33
|
address: this.address,
|
34
34
|
contractName: this.moduleName,
|
35
|
-
blockNumber: this.
|
35
|
+
blockNumber: this.checkpoint,
|
36
36
|
transactionIndex: 0,
|
37
37
|
transactionHash: this.transaction?.digest || '',
|
38
38
|
logIndex: 0,
|
@@ -49,15 +49,15 @@ export class SuiContext extends MoveContext {
|
|
49
49
|
export class SuiAddressContext extends MoveAccountContext {
|
50
50
|
address;
|
51
51
|
network;
|
52
|
-
|
52
|
+
checkpoint;
|
53
53
|
timestamp;
|
54
54
|
coder;
|
55
55
|
contractName = 'address';
|
56
|
-
constructor(network, address,
|
56
|
+
constructor(network, address, checkpoint, timestamp, baseLabels) {
|
57
57
|
super(baseLabels);
|
58
58
|
this.address = address;
|
59
59
|
this.network = network;
|
60
|
-
this.
|
60
|
+
this.checkpoint = checkpoint;
|
61
61
|
this.timestamp = timestamp;
|
62
62
|
this.coder = defaultMoveCoder(network);
|
63
63
|
}
|
@@ -68,7 +68,7 @@ export class SuiAddressContext extends MoveAccountContext {
|
|
68
68
|
return {
|
69
69
|
address: this.address,
|
70
70
|
contractName: this.contractName,
|
71
|
-
blockNumber: this.
|
71
|
+
blockNumber: this.checkpoint,
|
72
72
|
transactionIndex: 0,
|
73
73
|
transactionHash: '',
|
74
74
|
logIndex: 0,
|
@@ -87,8 +87,8 @@ export class SuiAddressContext extends MoveAccountContext {
|
|
87
87
|
export class SuiObjectContext extends SuiAddressContext {
|
88
88
|
contractName = 'object';
|
89
89
|
objectId;
|
90
|
-
constructor(network, objectId,
|
91
|
-
super(network, objectId,
|
90
|
+
constructor(network, objectId, checkpoint, timestamp, baseLabels) {
|
91
|
+
super(network, objectId, checkpoint, timestamp, baseLabels);
|
92
92
|
this.objectId = objectId;
|
93
93
|
}
|
94
94
|
}
|
package/lib/sui/context.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"context.js","sourceRoot":"","sources":["../../src/sui/context.ts"],"names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UAAU;QACR,OAAO,IAAI,CAAC,OAAO,CAAA;IACrB,CAAC;IAED,mBAAmB,CAAC,IAAY,EAAE,MAAc;QAC9C,OAAO;YACL,OAAO,EAAE,IAAI,CAAC,OAAO;YACrB,YAAY,EAAE,IAAI,CAAC,YAAY;YAC/B,WAAW,EAAE,IAAI,CAAC,UAAU;YAC5B,gBAAgB,EAAE,CAAC;YACnB,eAAe,EAAE,EAAE;YACnB,QAAQ,EAAE,CAAC;YACX,OAAO,EAAE,IAAI,CAAC,UAAU,EAAE;YAC1B,IAAI,EAAE,IAAI;YACV,MAAM,EAAE,eAAe,CAAC,MAAM,CAAC;SAChC,CAAA;IACH,CAAC;IAED,IAAI,MAAM;QACR,OAAO,SAAS,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;IAChC,CAAC;IAED,YAAY;QACV,OAAO,IAAI,CAAC,SAAS,CAAC,OAAO,EAAE,CAAA;IACjC,CAAC;CACF;AAED,MAAM,OAAO,gBAAiB,SAAQ,iBAAiB;IACrD,YAAY,GAAG,QAAQ,CAAA;IACvB,QAAQ,CAAQ;IAEhB,YACE,OAAmB,EACnB,QAAgB,EAChB,UAAkB,EAClB,SAAe,EACf,UAA8B;QAE9B,KAAK,CAAC,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,SAAS,EAAE,UAAU,CAAC,CAAA;QAC3D,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAA;IAC1B,CAAC;CACF","sourcesContent":["import { RecordMetaData } from '@sentio/protos'\nimport { type Labels, normalizeLabels } from '../index.js'\nimport { getClient, SuiNetwork } from './network.js'\nimport {\n SuiTransactionBlockResponse,\n JsonRpcProvider,\n SuiEvent,\n SuiMoveNormalizedModule,\n SuiMoveObject,\n} from '@mysten/sui.js'\nimport { MoveCoder, defaultMoveCoder } from './move-coder.js'\nimport { MoveAccountContext, MoveContext } from '../move/index.js'\n\nexport class SuiContext extends MoveContext<SuiNetwork, SuiMoveNormalizedModule, SuiEvent | SuiMoveObject> {\n moduleName: string\n timestamp: Date\n checkpoint: bigint\n transaction: SuiTransactionBlockResponse\n eventIndex: number\n coder: MoveCoder\n\n constructor(\n moduleName: string,\n network: SuiNetwork,\n address: string,\n timestamp: Date,\n checkpoint: bigint,\n transaction: SuiTransactionBlockResponse,\n eventIndex: number,\n baseLabels: Labels | undefined\n ) {\n super(baseLabels)\n this.address = address.toLowerCase()\n this.network = network\n this.moduleName = moduleName\n this.timestamp = timestamp\n this.checkpoint = checkpoint\n this.eventIndex = eventIndex\n this.coder = defaultMoveCoder(network)\n if (transaction) {\n this.transaction = transaction\n }\n }\n\n getChainId() {\n return this.network\n }\n\n getTimestamp(): number {\n return this.timestamp.getDate()\n }\n\n getMetaDataInternal(name: string, labels: Labels): RecordMetaData {\n return {\n address: this.address,\n contractName: this.moduleName,\n blockNumber: this.checkpoint,\n transactionIndex: 0,\n transactionHash: this.transaction?.digest || '', // TODO\n logIndex: 0,\n chainId: this.getChainId(),\n name: name,\n labels: normalizeLabels(labels),\n }\n }\n\n get client(): JsonRpcProvider {\n return getClient(this.network)\n }\n}\n\n// TODO address handler should use this context\nexport class SuiAddressContext extends MoveAccountContext<\n SuiNetwork,\n SuiMoveNormalizedModule,\n SuiEvent | SuiMoveObject\n> {\n address: string\n network: SuiNetwork\n checkpoint: bigint\n timestamp: Date\n coder: MoveCoder\n\n protected contractName = 'address'\n\n constructor(\n network: SuiNetwork,\n address: string,\n checkpoint: bigint,\n timestamp: Date,\n baseLabels: Labels | undefined\n ) {\n super(baseLabels)\n this.address = address\n this.network = network\n this.checkpoint = checkpoint\n this.timestamp = timestamp\n this.coder = defaultMoveCoder(network)\n }\n\n getChainId() {\n return this.network\n }\n\n getMetaDataInternal(name: string, labels: Labels): RecordMetaData {\n return {\n address: this.address,\n contractName: this.contractName,\n blockNumber: this.checkpoint,\n transactionIndex: 0,\n transactionHash: '',\n logIndex: 0,\n chainId: this.getChainId(),\n name: name,\n labels: normalizeLabels(labels),\n }\n }\n\n get client(): JsonRpcProvider {\n return getClient(this.network)\n }\n\n getTimestamp(): number {\n return this.timestamp.getDate()\n }\n}\n\nexport class SuiObjectContext extends SuiAddressContext {\n contractName = 'object'\n objectId: string\n\n constructor(\n network: SuiNetwork,\n objectId: string,\n checkpoint: bigint,\n timestamp: Date,\n baseLabels: Labels | undefined\n ) {\n super(network, objectId, checkpoint, timestamp, baseLabels)\n this.objectId = objectId\n }\n}\n"]}
|
@@ -6,7 +6,7 @@ import { PromiseOrVoid } from '../core/index.js';
|
|
6
6
|
import { SuiBaseObjectOrAddressProcessor, SuiObjectBindOptions, SuiObjectProcessor, SuiWrappedObjectProcessor } from './sui-object-processor.js';
|
7
7
|
declare class ObjectHandler<HandlerType> {
|
8
8
|
type?: string;
|
9
|
-
|
9
|
+
checkpointInterval?: HandleInterval;
|
10
10
|
timeIntervalInMinutes?: HandleInterval;
|
11
11
|
handler: HandlerType;
|
12
12
|
fetchConfig: MoveAccountFetchConfig;
|
@@ -21,9 +21,9 @@ export declare abstract class SuiObjectOrAddressProcessorTemplate<HandlerType, P
|
|
21
21
|
constructor();
|
22
22
|
protected abstract createProcessor(options: SuiObjectBindOptions): ProcessorType;
|
23
23
|
bind(options: SuiObjectBindOptions, ctx: SuiContext): void;
|
24
|
-
protected onInterval(handler: HandlerType, timeInterval: HandleInterval | undefined,
|
24
|
+
protected onInterval(handler: HandlerType, timeInterval: HandleInterval | undefined, checkpointInterval: HandleInterval | undefined, type: string | undefined, fetchConfig: Partial<MoveAccountFetchConfig> | undefined): this;
|
25
25
|
onTimeInterval(handler: HandlerType, timeIntervalInMinutes?: number, backfillTimeIntervalInMinutes?: number, type?: string, fetchConfig?: Partial<MoveAccountFetchConfig>): this;
|
26
|
-
|
26
|
+
onCheckpointInterval(handler: HandlerType, checkpointInterval?: number, backfillCheckpointInterval?: number, type?: string, fetchConfig?: Partial<MoveAccountFetchConfig>): this;
|
27
27
|
}
|
28
28
|
export declare class SuiObjectProcessorTemplate extends SuiObjectOrAddressProcessorTemplate<(self: SuiMoveObject, dynamicFieldObjects: SuiMoveObject[], ctx: SuiObjectContext) => PromiseOrVoid, SuiObjectProcessor> {
|
29
29
|
createProcessor(options: SuiObjectBindOptions): SuiObjectProcessor;
|
@@ -3,7 +3,7 @@ import { DEFAULT_FETCH_CONFIG, SuiObjectProcessor, SuiWrappedObjectProcessor, }
|
|
3
3
|
import { TemplateInstanceState } from '../core/template.js';
|
4
4
|
class ObjectHandler {
|
5
5
|
type;
|
6
|
-
|
6
|
+
checkpointInterval;
|
7
7
|
timeIntervalInMinutes;
|
8
8
|
handler;
|
9
9
|
fetchConfig;
|
@@ -22,6 +22,7 @@ export class SuiObjectOrAddressProcessorTemplate {
|
|
22
22
|
}
|
23
23
|
bind(options, ctx) {
|
24
24
|
options.network = options.network || ctx.network;
|
25
|
+
options.startCheckpoint = options.startCheckpoint || ctx.checkpoint;
|
25
26
|
const sig = [options.network, options.objectId].join('_');
|
26
27
|
if (this.binds.has(sig)) {
|
27
28
|
console.log(`Same object id can be bind to one template only once, ignore duplicate bind: ${sig}`);
|
@@ -30,7 +31,7 @@ export class SuiObjectOrAddressProcessorTemplate {
|
|
30
31
|
this.binds.add(sig);
|
31
32
|
const processor = this.createProcessor(options);
|
32
33
|
for (const h of this.objectHandlers) {
|
33
|
-
processor.onInterval(h.handler, h.timeIntervalInMinutes, h.
|
34
|
+
processor.onInterval(h.handler, h.timeIntervalInMinutes, h.checkpointInterval, h.type, h.fetchConfig);
|
34
35
|
}
|
35
36
|
const config = processor.config;
|
36
37
|
ctx._res.states.configUpdated = true;
|
@@ -46,11 +47,11 @@ export class SuiObjectOrAddressProcessorTemplate {
|
|
46
47
|
endBlock: 0n,
|
47
48
|
});
|
48
49
|
}
|
49
|
-
onInterval(handler, timeInterval,
|
50
|
+
onInterval(handler, timeInterval, checkpointInterval, type, fetchConfig) {
|
50
51
|
this.objectHandlers.push({
|
51
52
|
handler: handler,
|
52
53
|
timeIntervalInMinutes: timeInterval,
|
53
|
-
|
54
|
+
checkpointInterval: checkpointInterval,
|
54
55
|
type,
|
55
56
|
fetchConfig: { ...DEFAULT_FETCH_CONFIG, ...fetchConfig },
|
56
57
|
});
|
@@ -62,8 +63,8 @@ export class SuiObjectOrAddressProcessorTemplate {
|
|
62
63
|
backfillInterval: backfillTimeIntervalInMinutes,
|
63
64
|
}, undefined, type, fetchConfig);
|
64
65
|
}
|
65
|
-
|
66
|
-
return this.onInterval(handler, undefined, { recentInterval:
|
66
|
+
onCheckpointInterval(handler, checkpointInterval = 100000, backfillCheckpointInterval = 400000, type, fetchConfig) {
|
67
|
+
return this.onInterval(handler, undefined, { recentInterval: checkpointInterval, backfillInterval: backfillCheckpointInterval }, type, fetchConfig);
|
67
68
|
}
|
68
69
|
}
|
69
70
|
// export class SuiAddressProcessorTemplate extends SuiBaseObjectsProcessorTemplate<
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"sui-object-processor-template.js","sourceRoot":"","sources":["../../src/sui/sui-object-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,EAAE,MAAM,qBAAqB,CAAA;AAE3D,MAAM,aAAa;IACjB,IAAI,CAAS;IACb,
|
1
|
+
{"version":3,"file":"sui-object-processor-template.js","sourceRoot":"","sources":["../../src/sui/sui-object-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,EAAE,MAAM,qBAAqB,CAAA;AAE3D,MAAM,aAAa;IACjB,IAAI,CAAS;IACb,kBAAkB,CAAiB;IACnC,qBAAqB,CAAiB;IACtC,OAAO,CAAa;IACpB,WA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BAA0B,EAAE,EACpF,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,0BAA2B,SAAQ,mCAI/C;IACC,eAAe,CAAC,OAA6B;QAC3C,OAAO,kBAAkB,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;IACzC,CAAC;CACF;AAED,MAAM,OAAO,iCAAkC,SAAQ,mCAItD;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, SuiObjectContext } from './context.js'\nimport { SuiMoveObject } from '@mysten/sui.js'\nimport { PromiseOrVoid } from '../core/index.js'\nimport {\n DEFAULT_FETCH_CONFIG,\n SuiBaseObjectOrAddressProcessor,\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 checkpointInterval?: HandleInterval\n timeIntervalInMinutes?: HandleInterval\n handler: HandlerType\n fetchConfig: MoveAccountFetchConfig\n}\n\nexport class SuiAccountProcessorTemplateState extends ListStateStorage<SuiObjectOrAddressProcessorTemplate<any, any>> {\n static INSTANCE = new SuiAccountProcessorTemplateState()\n}\n\nexport abstract class SuiObjectOrAddressProcessorTemplate<\n HandlerType,\n // OptionType,\n ProcessorType extends SuiBaseObjectOrAddressProcessor<HandlerType>\n> {\n id: number\n objectHandlers: ObjectHandler<HandlerType>[] = []\n binds = new Set<string>()\n\n constructor() {\n this.id = SuiAccountProcessorTemplateState.INSTANCE.getValues().length\n SuiAccountProcessorTemplateState.INSTANCE.addValue(this)\n }\n\n protected abstract createProcessor(options: SuiObjectBindOptions): ProcessorType\n\n bind(options: SuiObjectBindOptions, ctx: SuiContext): void {\n options.network = options.network || ctx.network\n options.startCheckpoint = options.startCheckpoint || ctx.checkpoint\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.checkpointInterval, 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 checkpointInterval: HandleInterval | undefined,\n type: string | undefined,\n fetchConfig: Partial<MoveAccountFetchConfig> | undefined\n ): this {\n this.objectHandlers.push({\n handler: handler,\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\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 SuiObjectProcessorTemplate extends SuiObjectOrAddressProcessorTemplate<\n (self: SuiMoveObject, dynamicFieldObjects: SuiMoveObject[], ctx: SuiObjectContext) => PromiseOrVoid,\n // SuiObjectBindOptions,\n SuiObjectProcessor\n> {\n createProcessor(options: SuiObjectBindOptions): SuiObjectProcessor {\n return SuiObjectProcessor.bind(options)\n }\n}\n\nexport class SuiWrappedObjectProcessorTemplate extends SuiObjectOrAddressProcessorTemplate<\n (dynamicFieldObjects: SuiMoveObject[], ctx: SuiObjectContext) => PromiseOrVoid,\n // SuiObjectBindOptions,\n SuiWrappedObjectProcessor\n> {\n createProcessor(options: SuiObjectBindOptions): SuiWrappedObjectProcessor {\n return SuiWrappedObjectProcessor.bind(options)\n }\n}\n"]}
|
@@ -15,7 +15,7 @@ export interface SuiObjectBindOptions {
|
|
15
15
|
}
|
16
16
|
interface ObjectHandler {
|
17
17
|
type?: string;
|
18
|
-
|
18
|
+
checkPointInterval?: HandleInterval;
|
19
19
|
timeIntervalInMinutes?: HandleInterval;
|
20
20
|
fetchConfig: MoveAccountFetchConfig;
|
21
21
|
handler: (resource: Data_SuiObject) => Promise<ProcessResult>;
|
@@ -35,9 +35,9 @@ export declare abstract class SuiBaseObjectOrAddressProcessor<HandlerType> {
|
|
35
35
|
getChainId(): string;
|
36
36
|
protected abstract doHandle(handler: HandlerType, data: Data_SuiObject, ctx: SuiObjectContext): PromiseOrVoid;
|
37
37
|
onInterval(handler: HandlerType, //(resources: SuiMoveObject[], ctx: SuiObjectsContext) => PromiseOrVoid,
|
38
|
-
timeInterval: HandleInterval | undefined,
|
38
|
+
timeInterval: HandleInterval | undefined, checkpointInterval: HandleInterval | undefined, type: string | undefined, fetchConfig: Partial<MoveAccountFetchConfig> | undefined): this;
|
39
39
|
onTimeInterval(handler: HandlerType, timeIntervalInMinutes?: number, backfillTimeIntervalInMinutes?: number, type?: string, fetchConfig?: Partial<MoveAccountFetchConfig>): this;
|
40
|
-
|
40
|
+
onCheckpointInterval(handler: HandlerType, checkpointInterval?: number, backfillCheckpointInterval?: number, type?: string, fetchConfig?: Partial<MoveAccountFetchConfig>): this;
|
41
41
|
}
|
42
42
|
export declare class SuiAddressProcessor extends SuiBaseObjectOrAddressProcessor<(objects: SuiMoveObject[], ctx: SuiObjectContext) => PromiseOrVoid> {
|
43
43
|
static bind(options: SuiBindOptions): SuiAddressProcessor;
|
@@ -25,7 +25,7 @@ export class SuiBaseObjectOrAddressProcessor {
|
|
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) {
|
@@ -34,7 +34,7 @@ export class SuiBaseObjectOrAddressProcessor {
|
|
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,8 +46,8 @@ export class SuiBaseObjectOrAddressProcessor {
|
|
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
53
|
export class SuiAddressProcessor extends SuiBaseObjectOrAddressProcessor {
|
@@ -70,7 +70,7 @@ export class SuiObjectProcessor extends SuiBaseObjectOrAddressProcessor {
|
|
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);
|
@@ -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,gBAAgB,EAAE,MAAM,cAAc,CAAA;AAG/C,OAAO,EAAE,SAAS,EAAkC,MAAM,oBAAoB,CAAA;AAiB9E,MAAM,CAAC,MAAM,oBAAoB,GAA2B;IAC1D,KAAK,EAAE,IAAI;CACZ,CAAA;AAED,MAAa,wBAAyB,SAAQ,gBAAsD;IAClG,MAAM,CAAC,QAAQ,GAAG,IAAI,wBAAwB,EAAE,CAAA;;SADrC,wBAAwB;AAQrC,MAAM,OAAgB,+BAA+B;IACnD,MAAM,CAAgB;IACtB,SAAS,CAAe;IAExB,cAAc,GAAoB,EAAE,CAAA;IAEpC,8EAA8E;IAC9E,gDAAgD;IAChD,IAAI;IAEJ,YAAsB,OAAsC;QAC1D,IAAI,CAAC,MAAM,GAAG,SAAS,CAAC,OAAO,CAAC,CAAA;QAChC,IAAI,CAAC,SAAS,GAAG,OAAO,CAAC,SAAS,CA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C,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
@@ -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 || '',
|
@@ -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,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;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,CAAC,GAAG,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AED,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.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;IACn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3B,KAAK,WAAW,CAAC,SAAS;gBACxB,OAAO,IAAI,CAAC,eAAe,CAAC,OAAO,CAAC,CAAA;YACtC,KAAK,WAAW,CAAC,QAAQ;gBACvB,OAAO,IAAI,CAAC,sBAAsB,CAAC,OAAO,CAAC,CAAA;YAC7C,KAAK,WAAW,CAAC,UAAU;gBACzB,OAAO,IAAI,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAA;YACvC;gBACE,MAAM,IAAI,WAAW,CAAC,MAAM,CAAC,gBAAgB,EAAE,4BAA4B,GAAG,OAAO,CAAC,WAAW,CAAC,CAAA;SACrG;IACH,CAAC;CACF;AAED,aAAa,CAAC,QAAQ,CAAC,QAAQ,CAAC,IAAI,SAAS,EAAE,CAAC,CAAA;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/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,
|
@@ -77,17 +77,23 @@ export class SuiAddressContext extends MoveAccountContext<
|
|
77
77
|
> {
|
78
78
|
address: string
|
79
79
|
network: SuiNetwork
|
80
|
-
|
80
|
+
checkpoint: bigint
|
81
81
|
timestamp: Date
|
82
82
|
coder: MoveCoder
|
83
83
|
|
84
84
|
protected contractName = 'address'
|
85
85
|
|
86
|
-
constructor(
|
86
|
+
constructor(
|
87
|
+
network: SuiNetwork,
|
88
|
+
address: string,
|
89
|
+
checkpoint: bigint,
|
90
|
+
timestamp: Date,
|
91
|
+
baseLabels: Labels | undefined
|
92
|
+
) {
|
87
93
|
super(baseLabels)
|
88
94
|
this.address = address
|
89
95
|
this.network = network
|
90
|
-
this.
|
96
|
+
this.checkpoint = checkpoint
|
91
97
|
this.timestamp = timestamp
|
92
98
|
this.coder = defaultMoveCoder(network)
|
93
99
|
}
|
@@ -100,7 +106,7 @@ export class SuiAddressContext extends MoveAccountContext<
|
|
100
106
|
return {
|
101
107
|
address: this.address,
|
102
108
|
contractName: this.contractName,
|
103
|
-
blockNumber: this.
|
109
|
+
blockNumber: this.checkpoint,
|
104
110
|
transactionIndex: 0,
|
105
111
|
transactionHash: '',
|
106
112
|
logIndex: 0,
|
@@ -123,8 +129,14 @@ export class SuiObjectContext extends SuiAddressContext {
|
|
123
129
|
contractName = 'object'
|
124
130
|
objectId: string
|
125
131
|
|
126
|
-
constructor(
|
127
|
-
|
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)
|
128
140
|
this.objectId = objectId
|
129
141
|
}
|
130
142
|
}
|
@@ -14,7 +14,7 @@ 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
|
@@ -42,6 +42,7 @@ export abstract class SuiObjectOrAddressProcessorTemplate<
|
|
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 SuiObjectOrAddressProcessorTemplate<
|
|
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 SuiObjectOrAddressProcessorTemplate<
|
|
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 SuiObjectOrAddressProcessorTemplate<
|
|
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
|
)
|
@@ -15,7 +15,7 @@ export interface SuiObjectBindOptions {
|
|
15
15
|
|
16
16
|
interface ObjectHandler {
|
17
17
|
type?: string
|
18
|
-
|
18
|
+
checkPointInterval?: HandleInterval
|
19
19
|
timeIntervalInMinutes?: HandleInterval
|
20
20
|
fetchConfig: MoveAccountFetchConfig
|
21
21
|
handler: (resource: Data_SuiObject) => Promise<ProcessResult>
|
@@ -60,7 +60,7 @@ export abstract class SuiBaseObjectOrAddressProcessor<HandlerType> {
|
|
60
60
|
public onInterval(
|
61
61
|
handler: HandlerType, //(resources: SuiMoveObject[], ctx: SuiObjectsContext) => PromiseOrVoid,
|
62
62
|
timeInterval: HandleInterval | undefined,
|
63
|
-
|
63
|
+
checkpointInterval: HandleInterval | undefined,
|
64
64
|
type: string | undefined,
|
65
65
|
fetchConfig: Partial<MoveAccountFetchConfig> | undefined
|
66
66
|
): this {
|
@@ -78,7 +78,7 @@ export abstract class SuiBaseObjectOrAddressProcessor<HandlerType> {
|
|
78
78
|
return ctx.getProcessResult()
|
79
79
|
},
|
80
80
|
timeIntervalInMinutes: timeInterval,
|
81
|
-
|
81
|
+
checkPointInterval: checkpointInterval,
|
82
82
|
type,
|
83
83
|
fetchConfig: { ...DEFAULT_FETCH_CONFIG, ...fetchConfig },
|
84
84
|
})
|
@@ -104,17 +104,17 @@ export abstract class SuiBaseObjectOrAddressProcessor<HandlerType> {
|
|
104
104
|
)
|
105
105
|
}
|
106
106
|
|
107
|
-
public
|
107
|
+
public onCheckpointInterval(
|
108
108
|
handler: HandlerType,
|
109
|
-
|
110
|
-
|
109
|
+
checkpointInterval = 100000,
|
110
|
+
backfillCheckpointInterval = 400000,
|
111
111
|
type?: string,
|
112
112
|
fetchConfig?: Partial<MoveAccountFetchConfig>
|
113
113
|
): this {
|
114
114
|
return this.onInterval(
|
115
115
|
handler,
|
116
116
|
undefined,
|
117
|
-
{ recentInterval:
|
117
|
+
{ recentInterval: checkpointInterval, backfillInterval: backfillCheckpointInterval },
|
118
118
|
type,
|
119
119
|
fetchConfig
|
120
120
|
)
|
@@ -156,7 +156,7 @@ export class SuiObjectProcessor extends SuiBaseObjectOrAddressProcessor<
|
|
156
156
|
ctx: SuiObjectContext
|
157
157
|
): PromiseOrVoid {
|
158
158
|
if (!data.self) {
|
159
|
-
console.log(`Sui object not existed in ${ctx.
|
159
|
+
console.log(`Sui object not existed in ${ctx.checkpoint}, please specific a start time`)
|
160
160
|
return
|
161
161
|
}
|
162
162
|
return handler(data.self as SuiMoveObject, data.objects as SuiMoveObject[], ctx)
|
package/src/sui/sui-plugin.ts
CHANGED
@@ -129,7 +129,7 @@ export class SuiPlugin extends Plugin {
|
|
129
129
|
minutes: 0,
|
130
130
|
minutesInterval: handler.timeIntervalInMinutes,
|
131
131
|
slot: 0,
|
132
|
-
slotInterval: handler.
|
132
|
+
slotInterval: handler.checkPointInterval,
|
133
133
|
fetchConfig: undefined,
|
134
134
|
},
|
135
135
|
type: handler.type || '',
|