@sentio/sdk 2.13.1 → 2.13.2-rc.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,8 +1,7 @@
1
- import { MoveResource, Transaction_UserTransaction, TransactionPayload_EntryFunctionPayload } from './move-types.js';
1
+ import { Event, MoveResource, Transaction_UserTransaction, TransactionPayload_EntryFunctionPayload } from './move-types.js';
2
2
  import { MoveCoder } from './move-coder.js';
3
3
  import { AptosBindOptions, AptosNetwork } from './network.js';
4
4
  import { AptosContext, AptosResourcesContext } from './context.js';
5
- import { EventInstance } from './models.js';
6
5
  import { ListStateStorage } from '@sentio/runtime';
7
6
  import { MoveFetchConfig, Data_AptResource, HandleInterval, ProcessResult, Data_AptEvent, Data_AptCall } from '@sentio/protos';
8
7
  import { CallHandler, EventFilter, EventHandler, FunctionNameAndCallFilter } from '../move/index.js';
@@ -29,7 +28,7 @@ export declare class AptosBaseProcessor {
29
28
  coder: MoveCoder;
30
29
  constructor(moduleName: string, options: AptosBindOptions);
31
30
  onTransaction(handler: (transaction: Transaction_UserTransaction, ctx: AptosContext) => PromiseOrVoid, includedFailed?: boolean, fetchConfig?: Partial<MoveFetchConfig>): this;
32
- onMoveEvent(handler: (event: EventInstance, ctx: AptosContext) => void, filter: EventFilter | EventFilter[], fetchConfig?: Partial<MoveFetchConfig>): this;
31
+ onMoveEvent(handler: (event: Event, ctx: AptosContext) => void, filter: EventFilter | EventFilter[], fetchConfig?: Partial<MoveFetchConfig>): this;
33
32
  onEntryFunctionCall(handler: (call: TransactionPayload_EntryFunctionPayload, ctx: AptosContext) => PromiseOrVoid, filter: FunctionNameAndCallFilter | FunctionNameAndCallFilter[], fetchConfig?: Partial<MoveFetchConfig>): this;
34
33
  getChainId(): string;
35
34
  }
@@ -83,9 +83,8 @@ export class AptosBaseProcessor {
83
83
  continue;
84
84
  }
85
85
  const ctx = new AptosContext(processor.moduleName, processor.config.network, processor.config.address, BigInt(txn.version), txn, idx);
86
- const eventInstance = evt;
87
- const decoded = await processor.coder.decodeEvent(eventInstance);
88
- await handler(decoded || eventInstance, ctx);
86
+ const decoded = await processor.coder.decodeEvent(evt);
87
+ await handler(decoded || evt, ctx);
89
88
  processResults.push(ctx.getProcessResult());
90
89
  }
91
90
  return mergeProcessResults(processResults);
@@ -1 +1 @@
1
- {"version":3,"file":"aptos-processor.js","sourceRoot":"","sources":["../../src/aptos/aptos-processor.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,gBAAgB,EAAa,MAAM,iBAAiB,CAAA;AAC7D,OAAO,EAAoB,YAAY,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AACzE,OAAO,EAAE,YAAY,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAA;AAElE,OAAO,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAA;AACvE,OAAO,EACL,eAAe,GAMhB,MAAM,gBAAgB,CAAA;AACvB,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,WAAW,CAAA;AAC/C,OAAO,EAAqE,aAAa,EAAE,MAAM,kBAAkB,CAAA;AAGnH,MAAM,oBAAoB,GAAoB;IAC5C,eAAe,EAAE,KAAK;IACtB,SAAS,EAAE,IAAI;CAChB,CAAA;AASD,MAAM,gBAAgB;IACpB,IAAI,CAAS;IACb,eAAe,CAAiB;IAChC,qBAAqB,CAAiB;IACtC,OAAO,CAAwD;CAChE;AAED,MAAa,mBAAoB,SAAQ,gBAAoC;IAC3E,MAAM,CAAC,QAAQ,GAAG,IAAI,mBAAmB,EAAE,CAAA;;SADhC,mBAAmB;AAIhC,MAAM,OAAO,kBAAkB;IACpB,UAAU,CAAQ;IAC3B,MAAM,CAAgB;IACtB,aAAa,GAAkC,EAAE,CAAA;IACjD,YAAY,GAAgC,EAAE,CAAA;IAC9C,KAAK,CAAW;IAEhB,YAAY,UAAkB,EAAE,OAAyB;QACvD,IAAI,CAAC,UAAU,GAAG,UAAU,CAAA;QAC5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B,OAAiF,EACjF,eAAe,GAAG,MAAM,EACxB,uBAAuB,GAAG,MAAM,EAChC,UAAmB;QAEnB,OAAO,IAAI,CAAC,UAAU,CACpB,OAAO,EACP,SAAS,EACT,EAAE,cAAc,EAAE,eAAe,EAAE,gBAAgB,EAAE,uBAAuB,EAAE,EAC9E,UAAU,CACX,CAAA;IACH,CAAC;CACF;AAED,SAAS,SAAS,CAAC,OAAyB;IAC1C,IAAI,YAAY,GAAG,EAAE,CAAA;IACrB,IAAI,OAAO,CAAC,YAAY,KAAK,SAAS,EAAE;QACtC,IAAI,OAAO,OAAO,CAAC,YAAY,KAAK,QAAQ,EAAE;YAC5C,YAAY,GAAG,MAAM,CAAC,OAAO,CAAC,YAAY,CAAC,CAAA;SAC5C;aAAM;YACL,YAAY,GAAG,OAAO,CAAC,YAAY,CAAA;SACpC;KACF;IAED,OAAO;QACL,YAAY,EAAE,YAAY;QAC1B,OAAO,EAAE,OAAO,CAAC,OAAO;QACxB,OAAO,EAAE,OAAO,CAAC,OAAO,IAAI,YAAY,CAAC,QAAQ;KAClD,CAAA;AACH,CAAC","sourcesContent":["import { MoveResource, Transaction_UserTransaction, TransactionPayload_EntryFunctionPayload } from './move-types.js'\n\nimport { defaultMoveCoder, MoveCoder } from './move-coder.js'\nimport { AptosBindOptions, AptosNetwork, getChainId } from './network.js'\nimport { AptosContext, AptosResourcesContext } from './context.js'\nimport { EventInstance } from './models.js'\nimport { ListStateStorage, mergeProcessResults } from '@sentio/runtime'\nimport {\n MoveFetchConfig,\n Data_AptResource,\n HandleInterval,\n ProcessResult,\n Data_AptEvent,\n Data_AptCall,\n} from '@sentio/protos'\nimport { ServerError, Status } from 'nice-grpc'\nimport { CallHandler, EventFilter, EventHandler, FunctionNameAndCallFilter, parseMoveType } from '../move/index.js'\nimport { PromiseOrVoid } from '../core/index.js'\n\nconst DEFAULT_FETCH_CONFIG: MoveFetchConfig = {\n resourceChanges: false,\n allEvents: true,\n}\n\ntype IndexConfigure = {\n address: string\n network: AptosNetwork\n startVersion: bigint\n // endSeqNumber?: Long\n}\n\nclass ResourceHandlder {\n type?: string\n versionInterval?: HandleInterval\n timeIntervalInMinutes?: HandleInterval\n handler: (resource: Data_AptResource) => Promise<ProcessResult>\n}\n\nexport class AptosProcessorState extends ListStateStorage<AptosBaseProcessor> {\n static INSTANCE = new AptosProcessorState()\n}\n\nexport class AptosBaseProcessor {\n readonly moduleName: string\n config: IndexConfigure\n eventHandlers: EventHandler<Data_AptEvent>[] = []\n callHandlers: CallHandler<Data_AptCall>[] = []\n coder: MoveCoder\n\n constructor(moduleName: string, options: AptosBindOptions) {\n this.moduleName = moduleName\n this.config = configure(options)\n AptosProcessorState.INSTANCE.addValue(this)\n this.coder = defaultMoveCoder(this.config.network)\n // this.loadTypes(this.coder)\n }\n\n // getABI(): MoveModule | undefined {\n // return undefined\n // }\n\n public onTransaction(\n handler: (transaction: Transaction_UserTransaction, ctx: AptosContext) => PromiseOrVoid,\n includedFailed = false,\n fetchConfig?: Partial<MoveFetchConfig>\n ): this {\n const _fetchConfig = MoveFetchConfig.fromPartial({ ...DEFAULT_FETCH_CONFIG, ...fetchConfig })\n\n // const address = this.config.address\n // const moduleName = this.moduleName\n const processor = this\n this.callHandlers.push({\n handler: async function (data) {\n if (!data.transaction) {\n throw new ServerError(Status.INVALID_ARGUMENT, 'call is null')\n }\n const call = data.transaction as Transaction_UserTransaction\n const ctx = new AptosContext(\n processor.moduleName,\n processor.config.network,\n processor.config.address,\n BigInt(data.transaction.version),\n call,\n 0\n )\n await handler(call, ctx)\n return ctx.getProcessResult()\n },\n filters: [{ function: '', includeFailed: includedFailed }],\n fetchConfig: _fetchConfig,\n })\n return this\n }\n\n public onMoveEvent(\n handler: (event: EventInstance, ctx: AptosContext) => void,\n filter: EventFilter | EventFilter[],\n fetchConfig?: Partial<MoveFetchConfig>\n ): this {\n let _filters: EventFilter[] = []\n const _fetchConfig = MoveFetchConfig.fromPartial({ ...DEFAULT_FETCH_CONFIG, ...fetchConfig })\n\n if (Array.isArray(filter)) {\n _filters = filter\n } else {\n _filters.push(filter)\n }\n\n // const moduleName = this.moduleName\n\n const processor = this\n const allEventType = new Set(_filters.map((f) => processor.config.address + '::' + f.type))\n\n this.eventHandlers.push({\n handler: async function (data) {\n if (!data.transaction) {\n throw new ServerError(Status.INVALID_ARGUMENT, 'event is null')\n }\n const txn = data.transaction as Transaction_UserTransaction\n if (!txn.events.length) {\n throw new ServerError(Status.INVALID_ARGUMENT, 'no event in the transactions')\n }\n\n const processResults = []\n for (const [idx, evt] of txn.events.entries()) {\n const typeQname = parseMoveType(evt.type).qname\n if (!allEventType.has(typeQname)) {\n continue\n }\n\n const ctx = new AptosContext(\n processor.moduleName,\n processor.config.network,\n processor.config.address,\n BigInt(txn.version),\n txn,\n idx\n )\n const eventInstance = evt as EventInstance\n const decoded = await processor.coder.decodeEvent<any>(eventInstance)\n await handler(decoded || eventInstance, ctx)\n processResults.push(ctx.getProcessResult())\n }\n\n return mergeProcessResults(processResults)\n },\n filters: _filters,\n fetchConfig: _fetchConfig,\n })\n return this\n }\n\n public onEntryFunctionCall(\n handler: (call: TransactionPayload_EntryFunctionPayload, ctx: AptosContext) => PromiseOrVoid,\n filter: FunctionNameAndCallFilter | FunctionNameAndCallFilter[],\n fetchConfig?: Partial<MoveFetchConfig>\n ): this {\n let _filters: FunctionNameAndCallFilter[] = []\n const _fetchConfig = MoveFetchConfig.fromPartial({ ...DEFAULT_FETCH_CONFIG, ...fetchConfig })\n\n if (Array.isArray(filter)) {\n _filters = filter\n } else {\n _filters.push(filter)\n }\n\n // const address = this.config.address\n // const moduleName = this.moduleName\n const processor = this\n\n this.callHandlers.push({\n handler: async function (data) {\n if (!data.transaction) {\n throw new ServerError(Status.INVALID_ARGUMENT, 'call is null')\n }\n const tx = data.transaction as Transaction_UserTransaction\n\n const ctx = new AptosContext(\n processor.moduleName,\n processor.config.network,\n processor.config.address,\n BigInt(tx.version),\n tx,\n 0\n )\n if (tx) {\n const payload = tx.payload as TransactionPayload_EntryFunctionPayload\n const decoded = await processor.coder.decodeFunctionPayload(payload)\n await handler(decoded, ctx)\n }\n return ctx.getProcessResult()\n },\n filters: _filters,\n fetchConfig: _fetchConfig,\n })\n return this\n }\n\n getChainId(): string {\n return getChainId(this.config.network)\n }\n\n // loadTypes(registry: MoveCoder) {\n // if (registry.contains(this.config.address, this.moduleName)) {\n // return\n // }\n // this.loadTypesInternal(registry)\n // }\n //\n // protected loadTypesInternal(registry: MoveCoder) {\n // // should be override by subclass\n // console.log('')\n // }\n}\n\nexport class AptosAccountProcessorState extends ListStateStorage<AptosResourcesProcessor> {\n static INSTANCE = new AptosAccountProcessorState()\n}\n\nexport class AptosResourcesProcessor {\n config: IndexConfigure\n\n resourcesHandlers: ResourceHandlder[] = []\n\n static bind(options: AptosBindOptions): AptosResourcesProcessor {\n return new AptosResourcesProcessor(options)\n }\n\n protected constructor(options: AptosBindOptions) {\n this.config = configure(options)\n AptosAccountProcessorState.INSTANCE.addValue(this)\n }\n\n getChainId(): string {\n return getChainId(this.config.network)\n }\n\n private onInterval(\n handler: (resources: MoveResource[], ctx: AptosResourcesContext) => PromiseOrVoid,\n timeInterval: HandleInterval | undefined,\n versionInterval: HandleInterval | undefined,\n type: string | undefined\n ): this {\n const processor = this\n this.resourcesHandlers.push({\n handler: async function (data) {\n if (data.timestampMicros > Number.MAX_SAFE_INTEGER) {\n throw new ServerError(Status.INVALID_ARGUMENT, 'timestamp is too large')\n }\n const timestamp = Number(data.timestampMicros)\n\n const ctx = new AptosResourcesContext(\n processor.config.network,\n processor.config.address,\n data.version,\n timestamp\n )\n await handler(data.resources as MoveResource[], ctx)\n return ctx.getProcessResult()\n },\n timeIntervalInMinutes: timeInterval,\n versionInterval: versionInterval,\n type: type,\n })\n return this\n }\n\n public onTimeInterval(\n handler: (resources: MoveResource[], ctx: AptosResourcesContext) => PromiseOrVoid,\n timeIntervalInMinutes = 60,\n backfillTimeIntervalInMinutes = 240,\n type?: string\n ): this {\n return this.onInterval(\n handler,\n {\n recentInterval: timeIntervalInMinutes,\n backfillInterval: backfillTimeIntervalInMinutes,\n },\n undefined,\n type\n )\n }\n\n public onVersionInterval(\n handler: (resources: MoveResource[], ctx: AptosResourcesContext) => PromiseOrVoid,\n versionInterval = 100000,\n backfillVersionInterval = 400000,\n typePrefix?: string\n ): this {\n return this.onInterval(\n handler,\n undefined,\n { recentInterval: versionInterval, backfillInterval: backfillVersionInterval },\n typePrefix\n )\n }\n}\n\nfunction configure(options: AptosBindOptions): IndexConfigure {\n let startVersion = 0n\n if (options.startVersion !== undefined) {\n if (typeof options.startVersion === 'number') {\n startVersion = BigInt(options.startVersion)\n } else {\n startVersion = options.startVersion\n }\n }\n\n return {\n startVersion: startVersion,\n address: options.address,\n network: options.network || AptosNetwork.MAIN_NET,\n }\n}\n"]}
1
+ {"version":3,"file":"aptos-processor.js","sourceRoot":"","sources":["../../src/aptos/aptos-processor.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,gBAAgB,EAAa,MAAM,iBAAiB,CAAA;AAC7D,OAAO,EAAoB,YAAY,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AACzE,OAAO,EAAE,YAAY,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAA;AAClE,OAAO,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAA;AACvE,OAAO,EACL,eAAe,GAMhB,MAAM,gBAAgB,CAAA;AACvB,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,WAAW,CAAA;AAC/C,OAAO,EAAqE,aAAa,EAAE,MAAM,kBAAkB,CAAA;AAGnH,MAAM,oBAAoB,GAAoB;IAC5C,eAAe,EAAE,KAAK;IACtB,SAAS,EAAE,IAAI;CAChB,CAAA;AASD,MAAM,gBAAgB;IACpB,IAAI,CAAS;IACb,eAAe,CAAiB;IAChC,qBAAqB,CAAiB;IACtC,OAAO,CAAwD;CAChE;AAED,MAAa,mBAAoB,SAAQ,gBAAoC;IAC3E,M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,cAAc,CACnB,OAAiF,EACjF,qBAAqB,GAAG,EAAE,EAC1B,6BAA6B,GAAG,GAAG,EACnC,IAAa;QAEb,OAAO,IAAI,CAAC,UAAU,CACpB,OAAO,EACP;YACE,cAAc,EAAE,qBAAqB;YACrC,gBAAgB,EAAE,6BAA6B;SAChD,EACD,SAAS,EACT,IAAI,CACL,CAAA;IACH,CAAC;IAEM,iBAAiB,CACtB,OAAiF,EACjF,eAAe,GAAG,MAAM,EACxB,uBAAuB,GAAG,MAAM,EAChC,UAAmB;QAEnB,OAAO,IAAI,CAAC,UAAU,CACpB,OAAO,EACP,SAAS,EACT,EAAE,cAAc,EAAE,eAAe,EAAE,gBAAgB,EAAE,uBAAuB,EAAE,EAC9E,UAAU,CACX,CAAA;IACH,CAAC;CACF;AAED,SAAS,SAAS,CAAC,OAAyB;IAC1C,IAAI,YAAY,GAAG,EAAE,CAAA;IACrB,IAAI,OAAO,CAAC,YAAY,KAAK,SAAS,EAAE;QACtC,IAAI,OAAO,OAAO,CAAC,YAAY,KAAK,QAAQ,EAAE;YAC5C,YAAY,GAAG,MAAM,CAAC,OAAO,CAAC,YAAY,CAAC,CAAA;SAC5C;aAAM;YACL,YAAY,GAAG,OAAO,CAAC,YAAY,CAAA;SACpC;KACF;IAED,OAAO;QACL,YAAY,EAAE,YAAY;QAC1B,OAAO,EAAE,OAAO,CAAC,OAAO;QACxB,OAAO,EAAE,OAAO,CAAC,OAAO,IAAI,YAAY,CAAC,QAAQ;KAClD,CAAA;AACH,CAAC","sourcesContent":["import {\n Event,\n MoveResource,\n Transaction_UserTransaction,\n TransactionPayload_EntryFunctionPayload,\n} from './move-types.js'\n\nimport { defaultMoveCoder, MoveCoder } from './move-coder.js'\nimport { AptosBindOptions, AptosNetwork, getChainId } from './network.js'\nimport { AptosContext, AptosResourcesContext } from './context.js'\nimport { ListStateStorage, mergeProcessResults } from '@sentio/runtime'\nimport {\n MoveFetchConfig,\n Data_AptResource,\n HandleInterval,\n ProcessResult,\n Data_AptEvent,\n Data_AptCall,\n} from '@sentio/protos'\nimport { ServerError, Status } from 'nice-grpc'\nimport { CallHandler, EventFilter, EventHandler, FunctionNameAndCallFilter, parseMoveType } from '../move/index.js'\nimport { PromiseOrVoid } from '../core/index.js'\n\nconst DEFAULT_FETCH_CONFIG: MoveFetchConfig = {\n resourceChanges: false,\n allEvents: true,\n}\n\ntype IndexConfigure = {\n address: string\n network: AptosNetwork\n startVersion: bigint\n // endSeqNumber?: Long\n}\n\nclass ResourceHandlder {\n type?: string\n versionInterval?: HandleInterval\n timeIntervalInMinutes?: HandleInterval\n handler: (resource: Data_AptResource) => Promise<ProcessResult>\n}\n\nexport class AptosProcessorState extends ListStateStorage<AptosBaseProcessor> {\n static INSTANCE = new AptosProcessorState()\n}\n\nexport class AptosBaseProcessor {\n readonly moduleName: string\n config: IndexConfigure\n eventHandlers: EventHandler<Data_AptEvent>[] = []\n callHandlers: CallHandler<Data_AptCall>[] = []\n coder: MoveCoder\n\n constructor(moduleName: string, options: AptosBindOptions) {\n this.moduleName = moduleName\n this.config = configure(options)\n AptosProcessorState.INSTANCE.addValue(this)\n this.coder = defaultMoveCoder(this.config.network)\n // this.loadTypes(this.coder)\n }\n\n // getABI(): MoveModule | undefined {\n // return undefined\n // }\n\n public onTransaction(\n handler: (transaction: Transaction_UserTransaction, ctx: AptosContext) => PromiseOrVoid,\n includedFailed = false,\n fetchConfig?: Partial<MoveFetchConfig>\n ): this {\n const _fetchConfig = MoveFetchConfig.fromPartial({ ...DEFAULT_FETCH_CONFIG, ...fetchConfig })\n\n // const address = this.config.address\n // const moduleName = this.moduleName\n const processor = this\n this.callHandlers.push({\n handler: async function (data) {\n if (!data.transaction) {\n throw new ServerError(Status.INVALID_ARGUMENT, 'call is null')\n }\n const call = data.transaction as Transaction_UserTransaction\n const ctx = new AptosContext(\n processor.moduleName,\n processor.config.network,\n processor.config.address,\n BigInt(data.transaction.version),\n call,\n 0\n )\n await handler(call, ctx)\n return ctx.getProcessResult()\n },\n filters: [{ function: '', includeFailed: includedFailed }],\n fetchConfig: _fetchConfig,\n })\n return this\n }\n\n public onMoveEvent(\n handler: (event: Event, ctx: AptosContext) => void,\n filter: EventFilter | EventFilter[],\n fetchConfig?: Partial<MoveFetchConfig>\n ): this {\n let _filters: EventFilter[] = []\n const _fetchConfig = MoveFetchConfig.fromPartial({ ...DEFAULT_FETCH_CONFIG, ...fetchConfig })\n\n if (Array.isArray(filter)) {\n _filters = filter\n } else {\n _filters.push(filter)\n }\n\n // const moduleName = this.moduleName\n\n const processor = this\n const allEventType = new Set(_filters.map((f) => processor.config.address + '::' + f.type))\n\n this.eventHandlers.push({\n handler: async function (data) {\n if (!data.transaction) {\n throw new ServerError(Status.INVALID_ARGUMENT, 'event is null')\n }\n const txn = data.transaction as Transaction_UserTransaction\n if (!txn.events.length) {\n throw new ServerError(Status.INVALID_ARGUMENT, 'no event in the transactions')\n }\n\n const processResults = []\n for (const [idx, evt] of txn.events.entries()) {\n const typeQname = parseMoveType(evt.type).qname\n if (!allEventType.has(typeQname)) {\n continue\n }\n\n const ctx = new AptosContext(\n processor.moduleName,\n processor.config.network,\n processor.config.address,\n BigInt(txn.version),\n txn,\n idx\n )\n\n const decoded = await processor.coder.decodeEvent<any>(evt)\n await handler(decoded || evt, ctx)\n processResults.push(ctx.getProcessResult())\n }\n\n return mergeProcessResults(processResults)\n },\n filters: _filters,\n fetchConfig: _fetchConfig,\n })\n return this\n }\n\n public onEntryFunctionCall(\n handler: (call: TransactionPayload_EntryFunctionPayload, ctx: AptosContext) => PromiseOrVoid,\n filter: FunctionNameAndCallFilter | FunctionNameAndCallFilter[],\n fetchConfig?: Partial<MoveFetchConfig>\n ): this {\n let _filters: FunctionNameAndCallFilter[] = []\n const _fetchConfig = MoveFetchConfig.fromPartial({ ...DEFAULT_FETCH_CONFIG, ...fetchConfig })\n\n if (Array.isArray(filter)) {\n _filters = filter\n } else {\n _filters.push(filter)\n }\n\n // const address = this.config.address\n // const moduleName = this.moduleName\n const processor = this\n\n this.callHandlers.push({\n handler: async function (data) {\n if (!data.transaction) {\n throw new ServerError(Status.INVALID_ARGUMENT, 'call is null')\n }\n const tx = data.transaction as Transaction_UserTransaction\n\n const ctx = new AptosContext(\n processor.moduleName,\n processor.config.network,\n processor.config.address,\n BigInt(tx.version),\n tx,\n 0\n )\n if (tx) {\n const payload = tx.payload as TransactionPayload_EntryFunctionPayload\n const decoded = await processor.coder.decodeFunctionPayload(payload)\n await handler(decoded, ctx)\n }\n return ctx.getProcessResult()\n },\n filters: _filters,\n fetchConfig: _fetchConfig,\n })\n return this\n }\n\n getChainId(): string {\n return getChainId(this.config.network)\n }\n\n // loadTypes(registry: MoveCoder) {\n // if (registry.contains(this.config.address, this.moduleName)) {\n // return\n // }\n // this.loadTypesInternal(registry)\n // }\n //\n // protected loadTypesInternal(registry: MoveCoder) {\n // // should be override by subclass\n // console.log('')\n // }\n}\n\nexport class AptosAccountProcessorState extends ListStateStorage<AptosResourcesProcessor> {\n static INSTANCE = new AptosAccountProcessorState()\n}\n\nexport class AptosResourcesProcessor {\n config: IndexConfigure\n\n resourcesHandlers: ResourceHandlder[] = []\n\n static bind(options: AptosBindOptions): AptosResourcesProcessor {\n return new AptosResourcesProcessor(options)\n }\n\n protected constructor(options: AptosBindOptions) {\n this.config = configure(options)\n AptosAccountProcessorState.INSTANCE.addValue(this)\n }\n\n getChainId(): string {\n return getChainId(this.config.network)\n }\n\n private onInterval(\n handler: (resources: MoveResource[], ctx: AptosResourcesContext) => PromiseOrVoid,\n timeInterval: HandleInterval | undefined,\n versionInterval: HandleInterval | undefined,\n type: string | undefined\n ): this {\n const processor = this\n this.resourcesHandlers.push({\n handler: async function (data) {\n if (data.timestampMicros > Number.MAX_SAFE_INTEGER) {\n throw new ServerError(Status.INVALID_ARGUMENT, 'timestamp is too large')\n }\n const timestamp = Number(data.timestampMicros)\n\n const ctx = new AptosResourcesContext(\n processor.config.network,\n processor.config.address,\n data.version,\n timestamp\n )\n await handler(data.resources as MoveResource[], ctx)\n return ctx.getProcessResult()\n },\n timeIntervalInMinutes: timeInterval,\n versionInterval: versionInterval,\n type: type,\n })\n return this\n }\n\n public onTimeInterval(\n handler: (resources: MoveResource[], ctx: AptosResourcesContext) => PromiseOrVoid,\n timeIntervalInMinutes = 60,\n backfillTimeIntervalInMinutes = 240,\n type?: string\n ): this {\n return this.onInterval(\n handler,\n {\n recentInterval: timeIntervalInMinutes,\n backfillInterval: backfillTimeIntervalInMinutes,\n },\n undefined,\n type\n )\n }\n\n public onVersionInterval(\n handler: (resources: MoveResource[], ctx: AptosResourcesContext) => PromiseOrVoid,\n versionInterval = 100000,\n backfillVersionInterval = 400000,\n typePrefix?: string\n ): this {\n return this.onInterval(\n handler,\n undefined,\n { recentInterval: versionInterval, backfillInterval: backfillVersionInterval },\n typePrefix\n )\n }\n}\n\nfunction configure(options: AptosBindOptions): IndexConfigure {\n let startVersion = 0n\n if (options.startVersion !== undefined) {\n if (typeof options.startVersion === 'number') {\n startVersion = BigInt(options.startVersion)\n } else {\n startVersion = options.startVersion\n }\n }\n\n return {\n startVersion: startVersion,\n address: options.address,\n network: options.network || AptosNetwork.MAIN_NET,\n }\n}\n"]}
@@ -1,5 +1,5 @@
1
1
  export * from './move-types.js';
2
- export type { EventInstance, TypedEventInstance, TypedFunctionPayload, TypedMoveResource } from './models.js';
2
+ export type { TypedEventInstance, TypedFunctionPayload, TypedMoveResource } from './models.js';
3
3
  export { defaultMoveCoder, MoveCoder } from './move-coder.js';
4
4
  export { AptosBaseProcessor, AptosResourcesProcessor } from './aptos-processor.js';
5
5
  export { AptosContext, AptosResourcesContext } from './context.js';
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/aptos/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAA;AAE/B,OAAO,EAAE,gBAAgB,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAC7D,OAAO,EAAE,kBAAkB,EAAE,uBAAuB,EAAE,MAAM,sBAAsB,CAAA;AAClF,OAAO,EAAE,YAAY,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAA;AAClE,OAAO,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA;AAC7D,cAAc,UAAU,CAAA;AACxB,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AAEjD,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAE/C,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAA;AAEhD,cAAc,YAAY,CAAA","sourcesContent":["export * from './move-types.js'\nexport type { EventInstance, TypedEventInstance, TypedFunctionPayload, TypedMoveResource } from './models.js'\nexport { defaultMoveCoder, MoveCoder } from './move-coder.js'\nexport { AptosBaseProcessor, AptosResourcesProcessor } from './aptos-processor.js'\nexport { AptosContext, AptosResourcesContext } from './context.js'\nexport { AptosBindOptions, AptosNetwork } from './network.js'\nexport * from './api.js'\nexport { ModuleClient } from './module-client.js'\n\nexport { AptosPlugin } from './aptos-plugin.js'\n\nexport { BUILTIN_TYPES } from '../move/types.js'\n\nexport * from './utils.js'\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/aptos/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAA;AAE/B,OAAO,EAAE,gBAAgB,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAC7D,OAAO,EAAE,kBAAkB,EAAE,uBAAuB,EAAE,MAAM,sBAAsB,CAAA;AAClF,OAAO,EAAE,YAAY,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAA;AAClE,OAAO,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA;AAC7D,cAAc,UAAU,CAAA;AACxB,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AAEjD,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAE/C,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAA;AAEhD,cAAc,YAAY,CAAA","sourcesContent":["export * from './move-types.js'\nexport type { TypedEventInstance, TypedFunctionPayload, TypedMoveResource } from './models.js'\nexport { defaultMoveCoder, MoveCoder } from './move-coder.js'\nexport { AptosBaseProcessor, AptosResourcesProcessor } from './aptos-processor.js'\nexport { AptosContext, AptosResourcesContext } from './context.js'\nexport { AptosBindOptions, AptosNetwork } from './network.js'\nexport * from './api.js'\nexport { ModuleClient } from './module-client.js'\n\nexport { AptosPlugin } from './aptos-plugin.js'\n\nexport { BUILTIN_TYPES } from '../move/types.js'\n\nexport * from './utils.js'\n"]}
@@ -1,9 +1,6 @@
1
1
  import { Event, MoveResource, TransactionPayload_EntryFunctionPayload } from './move-types.js';
2
2
  import { DecodedStruct } from '../move/types.js';
3
- export type EventInstance = Event & {
4
- version: string;
5
- };
6
- export type TypedEventInstance<T> = DecodedStruct<EventInstance, T>;
3
+ export type TypedEventInstance<T> = DecodedStruct<Event, T>;
7
4
  export type TypedMoveResource<T> = DecodedStruct<MoveResource, T>;
8
5
  export type TypedFunctionPayload<T extends Array<any>> = TransactionPayload_EntryFunctionPayload & {
9
6
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"models.js","sourceRoot":"","sources":["../../src/aptos/models.ts"],"names":[],"mappings":"","sourcesContent":["import { Event, MoveResource, TransactionPayload_EntryFunctionPayload } from './move-types.js'\nimport { DecodedStruct } from '../move/types.js'\n\nexport type EventInstance = Event & {\n version: string\n}\n\nexport type TypedEventInstance<T> = DecodedStruct<EventInstance, T>\nexport type TypedMoveResource<T> = DecodedStruct<MoveResource, T>\n\n// Don't use intermediate type to make IDE happier\nexport type TypedFunctionPayload<T extends Array<any>> = TransactionPayload_EntryFunctionPayload & {\n /**\n * decoded argument data using ABI, undefined if there is decoding error, usually because the ABI/data mismatch\n */\n arguments_decoded: T\n}\n"]}
1
+ {"version":3,"file":"models.js","sourceRoot":"","sources":["../../src/aptos/models.ts"],"names":[],"mappings":"","sourcesContent":["import { Event, MoveResource, TransactionPayload_EntryFunctionPayload } from './move-types.js'\nimport { DecodedStruct } from '../move/types.js'\n\nexport type TypedEventInstance<T> = DecodedStruct<Event, T>\nexport type TypedMoveResource<T> = DecodedStruct<MoveResource, T>\n\n// Don't use intermediate type to make IDE happier\nexport type TypedFunctionPayload<T extends Array<any>> = TransactionPayload_EntryFunctionPayload & {\n /**\n * decoded argument data using ABI, undefined if there is decoding error, usually because the ABI/data mismatch\n */\n arguments_decoded: T\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"move-coder.js","sourceRoot":"","sources":["../../src/aptos/move-coder.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,gBAAgB,GAEjB,MAAM,iBAAiB,CAAA;AAGxB,OAAO,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAA;AAClE,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA;AAC3C,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAA;AAC5D,OAAO,EAAE,aAAa,EAAkB,MAAM,kBAAkB,CAAA;AAEhE,MAAM,OAAO,SAAU,SAAQ,iBAAyE;IACtG,YAAY,OAAqB;QAC/B,KAAK,CAAC,OAAO,CAAC,CAAA;QACd,IAAI,CAAC,OAAO,GAAG,IAAI,iBAAiB,EAAE,CAAA;IACxC,CAAC;IAED,IAAI,CAAC,MAA0B;QAC7B,IAAI,CAAC,MAAM,CAAC,GAAG,EAAE;YACf,MAAM,KAAK,CAAC,oBAAoB,CAAC,CAAA;SAClC;QACD,IAAI,CAAC,GAAG,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,OAAO,GAAG,IAAI,GAAG,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,CAAA;QAC3E,4DAA4D;QAC5D,WAAW;QACX,IAAI;QACJ,IAAI,CAAC,EAAE;YACL,OAAO,CAAC,CAAA;SACT;QACD,CAAC,GAAG,gBAAgB,CAAC,MAAM,CAAC,CAAA;QAC5B,IAA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Q,CAAC,CAAA;AAE/D,MAAM,UAAU,gBAAgB,CAAC,UAAwB,YAAY,CAAC,QAAQ;IAC5E,IAAI,OAAO,IAAI,YAAY,CAAC,QAAQ,EAAE;QACpC,OAAO,UAAU,CAAA;KAClB;IACD,OAAO,kBAAkB,CAAA;AAC3B,CAAC","sourcesContent":["import {\n Event,\n MoveModuleBytecode,\n MoveResource,\n toInternalModule,\n TransactionPayload_EntryFunctionPayload,\n} from './move-types.js'\n\nimport { TypedEventInstance, TypedFunctionPayload, TypedMoveResource } from './models.js'\nimport { AbstractMoveCoder } from '../move/abstract-move-coder.js'\nimport { AptosNetwork } from './network.js'\nimport { AptosChainAdapter } from './aptos-chain-adapter.js'\nimport { parseMoveType, TypeDescriptor } from '../move/index.js'\n\nexport class MoveCoder extends AbstractMoveCoder<AptosNetwork, MoveModuleBytecode, Event | MoveResource> {\n constructor(network: AptosNetwork) {\n super(network)\n this.adapter = new AptosChainAdapter()\n }\n\n load(module: MoveModuleBytecode) {\n if (!module.abi) {\n throw Error('Module without abi')\n }\n let m = this.moduleMapping.get(module.abi.address + '::' + module.abi.name)\n // if (this.contains(module.abi.address, module.abi.name)) {\n // return\n // }\n if (m) {\n return m\n }\n m = toInternalModule(module)\n this.loadInternal(m)\n return m\n }\n\n decodeEvent<T>(event: Event): Promise<TypedEventInstance<T> | undefined> {\n return this.decodedStruct<T>(event) as any\n }\n filterAndDecodeEvents<T>(type: string | TypeDescriptor<T>, resources: Event[]): Promise<TypedEventInstance<T>[]> {\n if (typeof type === 'string') {\n type = parseMoveType(type)\n }\n return this.filterAndDecodeStruct(type, resources) as any\n }\n decodeResource<T>(res: MoveResource): Promise<TypedMoveResource<T> | undefined> {\n return this.decodedStruct<T>(res)\n }\n filterAndDecodeResources<T>(\n type: string | TypeDescriptor<T>,\n resources: MoveResource[]\n ): Promise<TypedMoveResource<T>[]> {\n if (typeof type === 'string') {\n type = parseMoveType(type)\n }\n return this.filterAndDecodeStruct(type, resources)\n }\n\n async decodeFunctionPayload(\n payload: TransactionPayload_EntryFunctionPayload\n ): Promise<TransactionPayload_EntryFunctionPayload> {\n const func = await this.getMoveFunction(payload.function)\n const params = this.adapter.getMeaningfulFunctionParams(func.params)\n const argumentsDecoded = await this.decodeArray(payload.arguments, params)\n\n return {\n ...payload,\n arguments_decoded: argumentsDecoded,\n } as TypedFunctionPayload<any>\n }\n}\n\nconst MOVE_CODER = new MoveCoder(AptosNetwork.MAIN_NET)\nconst TESTNET_MOVE_CODER = new MoveCoder(AptosNetwork.TEST_NET)\n\nexport function defaultMoveCoder(network: AptosNetwork = AptosNetwork.MAIN_NET): MoveCoder {\n if (network == AptosNetwork.MAIN_NET) {\n return MOVE_CODER\n }\n return TESTNET_MOVE_CODER\n}\n"]}
1
+ {"version":3,"file":"move-coder.js","sourceRoot":"","sources":["../../src/aptos/move-coder.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,gBAAgB,GAEjB,MAAM,iBAAiB,CAAA;AAGxB,OAAO,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAA;AAClE,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA;AAC3C,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAA;AAC5D,OAAO,EAAE,aAAa,EAAkB,MAAM,kBAAkB,CAAA;AAEhE,MAAM,OAAO,SAAU,SAAQ,iBAAyE;IACtG,YAAY,OAAqB;QAC/B,KAAK,CAAC,OAAO,CAAC,CAAA;QACd,IAAI,CAAC,OAAO,GAAG,IAAI,iBAAiB,EAAE,CAAA;IACxC,CAAC;IAED,IAAI,CAAC,MAA0B;QAC7B,IAAI,CAAC,MAAM,CAAC,GAAG,EAAE;YACf,MAAM,KAAK,CAAC,oBAAoB,CAAC,CAAA;SAClC;QACD,IAAI,CAAC,GAAG,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,OAAO,GAAG,IAAI,GAAG,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,CA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;IAChC,CAAC;CACF;AAED,MAAM,UAAU,GAAG,IAAI,SAAS,CAAC,YAAY,CAAC,QAAQ,CAAC,CAAA;AACvD,MAAM,kBAAkB,GAAG,IAAI,SAAS,CAAC,YAAY,CAAC,QAAQ,CAAC,CAAA;AAE/D,MAAM,UAAU,gBAAgB,CAAC,UAAwB,YAAY,CAAC,QAAQ;IAC5E,IAAI,OAAO,IAAI,YAAY,CAAC,QAAQ,EAAE;QACpC,OAAO,UAAU,CAAA;KAClB;IACD,OAAO,kBAAkB,CAAA;AAC3B,CAAC","sourcesContent":["import {\n Event,\n MoveModuleBytecode,\n MoveResource,\n toInternalModule,\n TransactionPayload_EntryFunctionPayload,\n} from './move-types.js'\n\nimport { TypedEventInstance, TypedFunctionPayload, TypedMoveResource } from './models.js'\nimport { AbstractMoveCoder } from '../move/abstract-move-coder.js'\nimport { AptosNetwork } from './network.js'\nimport { AptosChainAdapter } from './aptos-chain-adapter.js'\nimport { parseMoveType, TypeDescriptor } from '../move/index.js'\n\nexport class MoveCoder extends AbstractMoveCoder<AptosNetwork, MoveModuleBytecode, Event | MoveResource> {\n constructor(network: AptosNetwork) {\n super(network)\n this.adapter = new AptosChainAdapter()\n }\n\n load(module: MoveModuleBytecode) {\n if (!module.abi) {\n throw Error('Module without abi')\n }\n let m = this.moduleMapping.get(module.abi.address + '::' + module.abi.name)\n // if (this.contains(module.abi.address, module.abi.name)) {\n // return\n // }\n if (m) {\n return m\n }\n m = toInternalModule(module)\n this.loadInternal(m)\n return m\n }\n\n decodeEvent<T>(event: Event): Promise<TypedEventInstance<T> | undefined> {\n return this.decodedStruct(event)\n }\n filterAndDecodeEvents<T>(type: string | TypeDescriptor<T>, resources: Event[]): Promise<TypedEventInstance<T>[]> {\n if (typeof type === 'string') {\n type = parseMoveType(type)\n }\n return this.filterAndDecodeStruct(type, resources)\n }\n decodeResource<T>(res: MoveResource): Promise<TypedMoveResource<T> | undefined> {\n return this.decodedStruct(res)\n }\n filterAndDecodeResources<T>(\n type: string | TypeDescriptor<T>,\n resources: MoveResource[]\n ): Promise<TypedMoveResource<T>[]> {\n if (typeof type === 'string') {\n type = parseMoveType(type)\n }\n return this.filterAndDecodeStruct(type, resources)\n }\n\n async decodeFunctionPayload(\n payload: TransactionPayload_EntryFunctionPayload\n ): Promise<TransactionPayload_EntryFunctionPayload> {\n const func = await this.getMoveFunction(payload.function)\n const params = this.adapter.getMeaningfulFunctionParams(func.params)\n const argumentsDecoded = await this.decodeArray(payload.arguments, params)\n\n return {\n ...payload,\n arguments_decoded: argumentsDecoded,\n } as TypedFunctionPayload<any>\n }\n}\n\nconst MOVE_CODER = new MoveCoder(AptosNetwork.MAIN_NET)\nconst TESTNET_MOVE_CODER = new MoveCoder(AptosNetwork.TEST_NET)\n\nexport function defaultMoveCoder(network: AptosNetwork = AptosNetwork.MAIN_NET): MoveCoder {\n if (network == AptosNetwork.MAIN_NET) {\n return MOVE_CODER\n }\n return TESTNET_MOVE_CODER\n}\n"]}
@@ -22,6 +22,6 @@ export declare abstract class AbstractMoveCoder<Network, ModuleType, StructType>
22
22
  encodeArray(entriesDecoded: any[], types: TypeDescriptor[]): Promise<any[]>;
23
23
  encodeCallArgs(args: any[], func: string): Promise<any[]>;
24
24
  decodeCallResult(res: any[], func: string): Promise<any[]>;
25
- protected filterAndDecodeStruct<T>(typeMatcher: TypeDescriptor<T>, structsWithTags: StructType[]): Promise<DecodedStruct<StructType, T>[]>;
26
- protected decodedStruct<T>(typeStruct: StructType): Promise<DecodedStruct<StructType, T> | undefined>;
25
+ protected filterAndDecodeStruct<T, ST extends StructType>(typeMatcher: TypeDescriptor<T>, structsWithTags: ST[]): Promise<DecodedStruct<ST, T>[]>;
26
+ protected decodedStruct<T, ST extends StructType>(typeStruct: ST): Promise<DecodedStruct<ST, T> | undefined>;
27
27
  }
@@ -1 +1 @@
1
- {"version":3,"file":"abstract-move-coder.js","sourceRoot":"","sources":["../../src/move/abstract-move-coder.ts"],"names":[],"mappings":"AAAA,OAAO,EAA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M,IAAI,CAAC,aAAa,CAAI,QAAQ,CAAC,CAAA;YACpD,IAAI,MAAM,EAAE;gBACV,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;aACrB;iBAAM;gBACL,OAAO,CAAC,KAAK,CAAC,gBAAgB,CAAC,CAAA;aAChC;SACF;QACD,OAAO,OAAO,CAAA;IAChB,CAAC;IAES,KAAK,CAAC,aAAa,CAAI,UAAsB;QACrD,MAAM,cAAc,GAAG,aAAa,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,CAAA;QACtE,MAAM,aAAa,GAAG,cAAc,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,YAAY,EAAE,CAAC,CAAA;QAE1E,IAAI,SAAS,GAAG,SAAS,CAAA;QACzB,IAAI;YACF,SAAS,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,UAAU,EAAE,cAAc,CAAC,CAAA;SAC1D;QAAC,OAAO,CAAC,EAAE;YACV,OAAO,CAAC,KAAK,CAAC,qBAAqB,EAAE,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC,CAAA;YACnE,OAAO,SAAS,CAAA;SACjB;QACD,OAAO;YACL,GAAG,UAAU;YACb,YAAY,EAAE,SAAS;YACvB,cAAc,EAAE,aAAa;SACE,CAAA;IACnC,CAAC;CACF","sourcesContent":["import { moduleQname, SPLITTER, VECTOR_STR } from './utils.js'\nimport { DecodedStruct, matchType, parseMoveType, TypeDescriptor } from './types.js'\nimport { InternalMoveFunction, InternalMoveModule, InternalMoveStruct } from './internal-models.js'\nimport { bytesToBigInt } from '../utils/index.js'\nimport { ChainAdapter } from './chain-adapter.js'\n\nexport abstract class AbstractMoveCoder<Network, ModuleType, StructType> {\n protected moduleMapping = new Map<string, InternalMoveModule>()\n private typeMapping = new Map<string, InternalMoveStruct>()\n private funcMapping = new Map<string, InternalMoveFunction>()\n network: Network\n adapter: ChainAdapter<Network, ModuleType, StructType>\n\n protected constructor(network: Network) {\n this.network = network\n }\n\n contains(account: string, name: string) {\n return this.moduleMapping.has(account + '::' + name)\n }\n\n abstract load(module: ModuleType): InternalMoveModule\n\n protected loadInternal(module: InternalMoveModule) {\n if (this.contains(module.address, module.name)) {\n return\n }\n this.moduleMapping.set(moduleQname(module), module)\n\n for (const struct of module.structs) {\n // TODO move to util\n const key = [module.address, module.name, struct.name].join(SPLITTER)\n this.typeMapping.set(key, struct)\n }\n\n for (const func of module.exposedFunctions) {\n // if (!func.isEntry) {\n // continue\n // }\n const key = [module.address, module.name, func.name].join(SPLITTER)\n this.funcMapping.set(key, func)\n }\n }\n\n protected decodeBigInt(data: any): bigint {\n if (Array.isArray(data)) {\n // Only sui function need this, strange\n const bytes = data as number[]\n return bytesToBigInt(new Uint8Array(bytes.slice().reverse()))\n } else {\n return BigInt(data)\n }\n }\n\n protected encodeBigInt(data: bigint): any {\n return '0x' + data.toString(16)\n }\n\n private requestMap = new Map<string, Promise<InternalMoveModule>>()\n\n async getMoveStruct(type: string): Promise<InternalMoveStruct> {\n let struct = this.typeMapping.get(type)\n if (struct) {\n return struct\n }\n const [account, module, typeName] = type.split(SPLITTER)\n const key = account + SPLITTER + module\n let resp = this.requestMap.get(account + SPLITTER + module)\n if (!resp) {\n resp = this.adapter.fetchModule(account, module, this.network).then((m) => {\n return this.load(m)\n })\n this.requestMap.set(key, resp)\n }\n await resp\n struct = this.typeMapping.get(type)\n if (struct) {\n return struct\n }\n throw new Error('Failed to load function ' + type + ' type are not imported anywhere')\n }\n\n async getMoveFunction(type: string): Promise<InternalMoveFunction> {\n let func = this.funcMapping.get(type)\n if (func) {\n return func\n }\n const [account, module, typeName] = type.split(SPLITTER)\n const key = account + SPLITTER + module\n let resp = this.requestMap.get(account + SPLITTER + module)\n if (!resp) {\n resp = this.adapter.fetchModule(account, module, this.network).then((m) => {\n return this.load(m)\n })\n this.requestMap.set(key, resp)\n }\n await resp\n func = this.funcMapping.get(type)\n if (func) {\n return func\n }\n throw new Error('Failed to load function ' + type + ' type are not imported anywhere')\n }\n\n async decode(data: any, type: TypeDescriptor): Promise<any> {\n // process simple type\n if (type.reference) {\n return data\n }\n switch (type.qname) {\n case 'signer': // TODO check this, aptos only\n case 'address':\n case 'Address':\n case '0x1::string::String':\n case 'bool':\n case 'Bool':\n case 'u8':\n case 'U8':\n case 'u16':\n case 'U16':\n case 'u32':\n case 'U32':\n return data\n case 'u64':\n case 'U64':\n case 'u128':\n case 'U128':\n return this.decodeBigInt(data)\n }\n\n // process vector\n if (type.qname === VECTOR_STR) {\n // vector<u8> as hex string\n if (type.typeArgs[0].qname === 'u8' || type.typeArgs[0].qname === 'U8') {\n return data\n }\n\n const res = []\n for (const entry of data) {\n res.push(await this.decode(entry, type.typeArgs[0]))\n }\n return res\n }\n\n // Process complex type\n const struct = await this.getMoveStruct(type.qname)\n\n const typeCtx = new Map<string, TypeDescriptor>()\n for (const [idx, typeArg] of type.typeArgs.entries()) {\n typeCtx.set('T' + idx, typeArg)\n }\n\n const typedData: any = {}\n\n for (const field of struct.fields) {\n let filedType = field.type\n filedType = filedType.applyTypeArgs(typeCtx)\n const fieldValue = this.adapter.getData(data)[field.name]\n const value = await this.decode(fieldValue, filedType)\n typedData[field.name] = value\n }\n return typedData\n }\n\n async encode(data: any, type: TypeDescriptor): Promise<any> {\n // process simple type\n if (type.reference) {\n return data\n }\n switch (type.qname) {\n case 'signer': // TODO check this, aptos only\n case 'address':\n case 'Address':\n case '0x2::object::ID':\n case '0x2::coin::Coin':\n case '0x1::string::String':\n case 'bool':\n case 'Bool':\n case 'u8':\n case 'U8':\n case 'u16':\n case 'U16':\n case 'u32':\n case 'U32':\n return data\n case 'u64':\n case 'U64':\n case 'u128':\n case 'U128':\n case 'u256':\n case 'U256':\n return this.encodeBigInt(data)\n }\n\n // process vector\n if (type.qname === VECTOR_STR) {\n // vector<u8> as hex string\n if (type.typeArgs[0].qname === 'u8' || type.typeArgs[0].qname === 'U8') {\n return data\n }\n\n const res = []\n for (const entry of data) {\n res.push(this.encode(entry, type.typeArgs[0]))\n }\n return res\n }\n\n // Process complex type\n const struct = await this.getMoveStruct(type.qname)\n\n const typeCtx = new Map<string, TypeDescriptor>()\n for (const [idx, typeArg] of type.typeArgs.entries()) {\n typeCtx.set('T' + idx, typeArg)\n }\n\n const typedData: any = {}\n\n for (const field of struct.fields) {\n let filedType = field.type\n filedType = filedType.applyTypeArgs(typeCtx)\n const value = await this.encode(data[field.name], filedType)\n typedData[field.name] = value\n }\n return typedData\n }\n\n async decodeArray(entries: any[], types: TypeDescriptor[]): Promise<any[]> {\n const entriesDecoded: any[] = []\n for (const [idx, arg] of entries.entries()) {\n // TODO consider apply payload.type_arguments, but this might be hard since we don't code gen for them\n const argType = types[idx]\n try {\n entriesDecoded.push(await this.decode(arg, argType))\n } catch (e) {\n console.error(e, 'Decoding error for ', JSON.stringify(arg), 'using type', argType)\n return entries\n }\n }\n return entriesDecoded\n }\n\n async encodeArray(entriesDecoded: any[], types: TypeDescriptor[]): Promise<any[]> {\n const entries: any[] = []\n for (const [idx, arg] of entriesDecoded.entries()) {\n // TODO consider apply payload.type_arguments, but this might be hard since we don't code gen for them\n const argType = types[idx]\n try {\n entries.push(await this.encode(arg, argType))\n } catch (e) {\n throw Error('Decoding error for ' + JSON.stringify(arg) + 'using type' + argType + e.toString())\n }\n }\n return entries\n }\n\n async encodeCallArgs(args: any[], func: string): Promise<any[]> {\n const f = await this.getMoveFunction(func)\n return this.encodeArray(args, this.adapter.getMeaningfulFunctionParams(f.params))\n }\n\n async decodeCallResult(res: any[], func: string): Promise<any[]> {\n const f = await this.getMoveFunction(func)\n return this.decodeArray(res, f.return)\n }\n\n protected async filterAndDecodeStruct<T>(\n typeMatcher: TypeDescriptor<T>,\n structsWithTags: StructType[]\n ): Promise<DecodedStruct<StructType, T>[]> {\n if (!structsWithTags) {\n return [] as any\n }\n // const typeMatcherDescriptor = parseMoveType(typeMatcher)\n const results: DecodedStruct<StructType, T>[] = []\n for (const resource of structsWithTags) {\n const resourceType = this.adapter.getType(resource)\n const resourceTypeDescriptor = parseMoveType(resourceType)\n if (!matchType(typeMatcher, resourceTypeDescriptor)) {\n continue\n }\n\n const result = await this.decodedStruct<T>(resource)\n if (result) {\n results.push(result)\n } else {\n console.error('decoding error')\n }\n }\n return results\n }\n\n protected async decodedStruct<T>(typeStruct: StructType): Promise<DecodedStruct<StructType, T> | undefined> {\n const typeDescriptor = parseMoveType(this.adapter.getType(typeStruct))\n const typeArguments = typeDescriptor.typeArgs.map((t) => t.getSignature())\n\n let dataTyped = undefined\n try {\n dataTyped = await this.decode(typeStruct, typeDescriptor)\n } catch (e) {\n console.error('Decoding error for ', JSON.stringify(typeStruct), e)\n return undefined\n }\n return {\n ...typeStruct,\n data_decoded: dataTyped,\n type_arguments: typeArguments,\n } as DecodedStruct<StructType, T>\n }\n}\n"]}
1
+ {"version":3,"file":"abstract-move-coder.js","sourceRoot":"","sources":["../../src/move/abstract-move-coder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AAC9D,OAAO,EAAiB,SAAS,EAAE,aAAa,EAAkB,MAAM,YAAY,CAAA;AAEpF,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;AAGjD,MAAM,OAAgB,iBAAiB;IAC3B,aAAa,GAAG,IAAI,GAAG,EAA8B,CAAA;IACvD,WAAW,GAAG,IAAI,GAAG,EAA8B,CAAA;IACnD,WAAW,GAAG,IAAI,GAAG,EAAgC,CAAA;IAC7D,OAAO,CAAS;IAChB,OAAO,CAA+C;IAEtD,YAAsB,OAAgB;QACpC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;IACxB,CAAC;IAED,QAAQ,CAAC,OAAe,EAAE,IAAY;QACpC,OAAO,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,OAAO,GAAG,IAAI,GAAG,IAAI,CAAC,CAA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,MAAM,CAAC,UAAU,EAAE,cAAc,CAAC,CAAA;SAC1D;QAAC,OAAO,CAAC,EAAE;YACV,OAAO,CAAC,KAAK,CAAC,qBAAqB,EAAE,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC,CAAA;YACnE,OAAO,SAAS,CAAA;SACjB;QACD,OAAO;YACL,GAAG,UAAU;YACb,YAAY,EAAE,SAAS;YACvB,cAAc,EAAE,aAAa;SAC9B,CAAA;IACH,CAAC;CACF","sourcesContent":["import { moduleQname, SPLITTER, VECTOR_STR } from './utils.js'\nimport { DecodedStruct, matchType, parseMoveType, TypeDescriptor } from './types.js'\nimport { InternalMoveFunction, InternalMoveModule, InternalMoveStruct } from './internal-models.js'\nimport { bytesToBigInt } from '../utils/index.js'\nimport { ChainAdapter } from './chain-adapter.js'\n\nexport abstract class AbstractMoveCoder<Network, ModuleType, StructType> {\n protected moduleMapping = new Map<string, InternalMoveModule>()\n private typeMapping = new Map<string, InternalMoveStruct>()\n private funcMapping = new Map<string, InternalMoveFunction>()\n network: Network\n adapter: ChainAdapter<Network, ModuleType, StructType>\n\n protected constructor(network: Network) {\n this.network = network\n }\n\n contains(account: string, name: string) {\n return this.moduleMapping.has(account + '::' + name)\n }\n\n abstract load(module: ModuleType): InternalMoveModule\n\n protected loadInternal(module: InternalMoveModule) {\n if (this.contains(module.address, module.name)) {\n return\n }\n this.moduleMapping.set(moduleQname(module), module)\n\n for (const struct of module.structs) {\n // TODO move to util\n const key = [module.address, module.name, struct.name].join(SPLITTER)\n this.typeMapping.set(key, struct)\n }\n\n for (const func of module.exposedFunctions) {\n // if (!func.isEntry) {\n // continue\n // }\n const key = [module.address, module.name, func.name].join(SPLITTER)\n this.funcMapping.set(key, func)\n }\n }\n\n protected decodeBigInt(data: any): bigint {\n if (Array.isArray(data)) {\n // Only sui function need this, strange\n const bytes = data as number[]\n return bytesToBigInt(new Uint8Array(bytes.slice().reverse()))\n } else {\n return BigInt(data)\n }\n }\n\n protected encodeBigInt(data: bigint): any {\n return '0x' + data.toString(16)\n }\n\n private requestMap = new Map<string, Promise<InternalMoveModule>>()\n\n async getMoveStruct(type: string): Promise<InternalMoveStruct> {\n let struct = this.typeMapping.get(type)\n if (struct) {\n return struct\n }\n const [account, module, typeName] = type.split(SPLITTER)\n const key = account + SPLITTER + module\n let resp = this.requestMap.get(account + SPLITTER + module)\n if (!resp) {\n resp = this.adapter.fetchModule(account, module, this.network).then((m) => {\n return this.load(m)\n })\n this.requestMap.set(key, resp)\n }\n await resp\n struct = this.typeMapping.get(type)\n if (struct) {\n return struct\n }\n throw new Error('Failed to load function ' + type + ' type are not imported anywhere')\n }\n\n async getMoveFunction(type: string): Promise<InternalMoveFunction> {\n let func = this.funcMapping.get(type)\n if (func) {\n return func\n }\n const [account, module, typeName] = type.split(SPLITTER)\n const key = account + SPLITTER + module\n let resp = this.requestMap.get(account + SPLITTER + module)\n if (!resp) {\n resp = this.adapter.fetchModule(account, module, this.network).then((m) => {\n return this.load(m)\n })\n this.requestMap.set(key, resp)\n }\n await resp\n func = this.funcMapping.get(type)\n if (func) {\n return func\n }\n throw new Error('Failed to load function ' + type + ' type are not imported anywhere')\n }\n\n async decode(data: any, type: TypeDescriptor): Promise<any> {\n // process simple type\n if (type.reference) {\n return data\n }\n switch (type.qname) {\n case 'signer': // TODO check this, aptos only\n case 'address':\n case 'Address':\n case '0x1::string::String':\n case 'bool':\n case 'Bool':\n case 'u8':\n case 'U8':\n case 'u16':\n case 'U16':\n case 'u32':\n case 'U32':\n return data\n case 'u64':\n case 'U64':\n case 'u128':\n case 'U128':\n return this.decodeBigInt(data)\n }\n\n // process vector\n if (type.qname === VECTOR_STR) {\n // vector<u8> as hex string\n if (type.typeArgs[0].qname === 'u8' || type.typeArgs[0].qname === 'U8') {\n return data\n }\n\n const res = []\n for (const entry of data) {\n res.push(await this.decode(entry, type.typeArgs[0]))\n }\n return res\n }\n\n // Process complex type\n const struct = await this.getMoveStruct(type.qname)\n\n const typeCtx = new Map<string, TypeDescriptor>()\n for (const [idx, typeArg] of type.typeArgs.entries()) {\n typeCtx.set('T' + idx, typeArg)\n }\n\n const typedData: any = {}\n\n for (const field of struct.fields) {\n let filedType = field.type\n filedType = filedType.applyTypeArgs(typeCtx)\n const fieldValue = this.adapter.getData(data)[field.name]\n const value = await this.decode(fieldValue, filedType)\n typedData[field.name] = value\n }\n return typedData\n }\n\n async encode(data: any, type: TypeDescriptor): Promise<any> {\n // process simple type\n if (type.reference) {\n return data\n }\n switch (type.qname) {\n case 'signer': // TODO check this, aptos only\n case 'address':\n case 'Address':\n case '0x2::object::ID':\n case '0x2::coin::Coin':\n case '0x1::string::String':\n case 'bool':\n case 'Bool':\n case 'u8':\n case 'U8':\n case 'u16':\n case 'U16':\n case 'u32':\n case 'U32':\n return data\n case 'u64':\n case 'U64':\n case 'u128':\n case 'U128':\n case 'u256':\n case 'U256':\n return this.encodeBigInt(data)\n }\n\n // process vector\n if (type.qname === VECTOR_STR) {\n // vector<u8> as hex string\n if (type.typeArgs[0].qname === 'u8' || type.typeArgs[0].qname === 'U8') {\n return data\n }\n\n const res = []\n for (const entry of data) {\n res.push(this.encode(entry, type.typeArgs[0]))\n }\n return res\n }\n\n // Process complex type\n const struct = await this.getMoveStruct(type.qname)\n\n const typeCtx = new Map<string, TypeDescriptor>()\n for (const [idx, typeArg] of type.typeArgs.entries()) {\n typeCtx.set('T' + idx, typeArg)\n }\n\n const typedData: any = {}\n\n for (const field of struct.fields) {\n let filedType = field.type\n filedType = filedType.applyTypeArgs(typeCtx)\n const value = await this.encode(data[field.name], filedType)\n typedData[field.name] = value\n }\n return typedData\n }\n\n async decodeArray(entries: any[], types: TypeDescriptor[]): Promise<any[]> {\n const entriesDecoded: any[] = []\n for (const [idx, arg] of entries.entries()) {\n // TODO consider apply payload.type_arguments, but this might be hard since we don't code gen for them\n const argType = types[idx]\n try {\n entriesDecoded.push(await this.decode(arg, argType))\n } catch (e) {\n console.error(e, 'Decoding error for ', JSON.stringify(arg), 'using type', argType)\n return entries\n }\n }\n return entriesDecoded\n }\n\n async encodeArray(entriesDecoded: any[], types: TypeDescriptor[]): Promise<any[]> {\n const entries: any[] = []\n for (const [idx, arg] of entriesDecoded.entries()) {\n // TODO consider apply payload.type_arguments, but this might be hard since we don't code gen for them\n const argType = types[idx]\n try {\n entries.push(await this.encode(arg, argType))\n } catch (e) {\n throw Error('Decoding error for ' + JSON.stringify(arg) + 'using type' + argType + e.toString())\n }\n }\n return entries\n }\n\n async encodeCallArgs(args: any[], func: string): Promise<any[]> {\n const f = await this.getMoveFunction(func)\n return this.encodeArray(args, this.adapter.getMeaningfulFunctionParams(f.params))\n }\n\n async decodeCallResult(res: any[], func: string): Promise<any[]> {\n const f = await this.getMoveFunction(func)\n return this.decodeArray(res, f.return)\n }\n\n protected async filterAndDecodeStruct<T, ST extends StructType>(\n typeMatcher: TypeDescriptor<T>,\n structsWithTags: ST[]\n ): Promise<DecodedStruct<ST, T>[]> {\n if (!structsWithTags) {\n return [] as any\n }\n // const typeMatcherDescriptor = parseMoveType(typeMatcher)\n const results: DecodedStruct<ST, T>[] = []\n for (const resource of structsWithTags) {\n const resourceType = this.adapter.getType(resource)\n const resourceTypeDescriptor = parseMoveType(resourceType)\n if (!matchType(typeMatcher, resourceTypeDescriptor)) {\n continue\n }\n\n const result = await this.decodedStruct<T, ST>(resource)\n if (result) {\n results.push(result)\n } else {\n console.error('decoding error')\n }\n }\n return results\n }\n\n protected async decodedStruct<T, ST extends StructType>(typeStruct: ST): Promise<DecodedStruct<ST, T> | undefined> {\n const typeDescriptor = parseMoveType(this.adapter.getType(typeStruct))\n const typeArguments = typeDescriptor.typeArgs.map((t) => t.getSignature())\n\n let dataTyped = undefined\n try {\n dataTyped = await this.decode(typeStruct, typeDescriptor)\n } catch (e) {\n console.error('Decoding error for ', JSON.stringify(typeStruct), e)\n return undefined\n }\n return {\n ...typeStruct,\n data_decoded: dataTyped,\n type_arguments: typeArguments,\n }\n }\n}\n"]}
@@ -1 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,EAAE;QAClC,OAAO,UAAU,CAAA;KAClB;IACD,OAAO,kBAAkB,CAAA;AAC3B,CAAC","sourcesContent":["import { TypedEventInstance, TypedFunctionPayload } from './models.js'\nimport { AbstractMoveCoder } from '../move/abstract-move-coder.js'\nimport { MoveCallSuiTransaction, SuiCallArg, SuiEvent, SuiMoveNormalizedModule, SuiMoveObject } from '@mysten/sui.js'\nimport { toInternalModule } from './move-types.js'\nimport { ANY_TYPE, DecodedStruct, parseMoveType, SPLITTER, TypeDescriptor } from '../move/index.js'\nimport { SuiNetwork } from './network.js'\nimport { SuiChainAdapter } from './sui-chain-adapter.js'\nimport { InternalMoveModule } from '../move/internal-models.js'\nimport { dynamic_field } from './builtin/0x2.js'\n\nexport class MoveCoder extends AbstractMoveCoder<SuiNetwork, SuiMoveNormalizedModule, SuiEvent | SuiMoveObject> {\n constructor(network: SuiNetwork) {\n super(network)\n this.adapter = new SuiChainAdapter()\n }\n\n load(module: SuiMoveNormalizedModule): InternalMoveModule {\n let m = this.moduleMapping.get(module.address + '::' + module.name)\n if (m) {\n return m\n }\n m = toInternalModule(module)\n this.loadInternal(m)\n return m\n }\n\n decode(data: any, type: TypeDescriptor): any {\n switch (type.qname) {\n case '0x2::object::ID':\n case '0x2::coin::Coin':\n case '0x2::balance::Balance':\n return data\n case '0x1::option::Option':\n if (data === null) {\n return data\n }\n return this.decode(data, type.typeArgs[0])\n default:\n return super.decode(data, type)\n }\n }\n\n decodeEvent<T>(event: SuiEvent): Promise<TypedEventInstance<T> | undefined> {\n return this.decodedStruct<T>(event) as any\n }\n filterAndDecodeEvents<T>(type: TypeDescriptor<T> | string, resources: SuiEvent[]): Promise<TypedEventInstance<T>[]> {\n if (typeof type === 'string') {\n type = parseMoveType(type)\n }\n return this.filterAndDecodeStruct(type, resources) as any\n }\n\n async getDynamicFields<T1, T2>(\n objects: SuiMoveObject[],\n keyType: TypeDescriptor<T1> = ANY_TYPE,\n valueType: TypeDescriptor<T2> = ANY_TYPE\n ): Promise<dynamic_field.Field<T1, T2>[]> {\n // const type = dynamic_field.Field.TYPE\n // Not using the code above to avoid cycle initialize failed\n const type = new TypeDescriptor<dynamic_field.Field<T1, T2>>('0x2::dynamic_field::Field')\n type.typeArgs = [keyType, valueType]\n const res = await this.filterAndDecodeObjects(type, objects)\n return res.map((o) => o.data_decoded)\n }\n\n filterAndDecodeObjects<T>(\n type: TypeDescriptor<T>,\n objects: SuiMoveObject[]\n ): Promise<DecodedStruct<SuiMoveObject, T>[]> {\n return this.filterAndDecodeStruct(type, objects) as any\n }\n\n async decodeFunctionPayload(payload: MoveCallSuiTransaction, inputs: SuiCallArg[]): Promise<MoveCallSuiTransaction> {\n const functionType = [payload.package, payload.module, payload.function].join(SPLITTER)\n const func = await this.getMoveFunction(functionType)\n const params = this.adapter.getMeaningfulFunctionParams(func.params)\n const args = []\n for (const value of payload.arguments || []) {\n const argValue = value as any\n if ('Input' in (argValue as any)) {\n const idx = argValue.Input\n const arg = inputs[idx]\n if (arg.type === 'pure') {\n args.push(arg.value)\n } else if (arg.type === 'object') {\n args.push(arg.objectId)\n } else {\n console.error('unexpected function arg value')\n args.push(undefined)\n }\n // args.push(arg) // TODO check why ts not work using arg.push(arg)\n } else {\n args.push(undefined)\n }\n }\n\n const argumentsTyped = await this.decodeArray(args, params)\n return {\n ...payload,\n arguments_decoded: argumentsTyped,\n } as TypedFunctionPayload<any>\n }\n}\n\nconst MOVE_CODER = new MoveCoder(SuiNetwork.MAIN_NET)\nconst TESTNET_MOVE_CODER = new MoveCoder(SuiNetwork.TEST_NET)\n\nexport function defaultMoveCoder(network: SuiNetwork = SuiNetwork.MAIN_NET): MoveCoder {\n if (network == SuiNetwork.MAIN_NET) {\n return MOVE_CODER\n }\n return TESTNET_MOVE_CODER\n}\n"]}
1
+ {"version":3,"file":"move-coder.js","sourceRoot":"","sources":["../../src/sui/move-coder.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAA;AAElE,OAA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ract-move-coder.js'\nimport { MoveCallSuiTransaction, SuiCallArg, SuiEvent, SuiMoveNormalizedModule, SuiMoveObject } from '@mysten/sui.js'\nimport { toInternalModule } from './move-types.js'\nimport { ANY_TYPE, DecodedStruct, parseMoveType, SPLITTER, TypeDescriptor } from '../move/index.js'\nimport { SuiNetwork } from './network.js'\nimport { SuiChainAdapter } from './sui-chain-adapter.js'\nimport { InternalMoveModule } from '../move/internal-models.js'\nimport { dynamic_field } from './builtin/0x2.js'\n\nexport class MoveCoder extends AbstractMoveCoder<SuiNetwork, SuiMoveNormalizedModule, SuiEvent | SuiMoveObject> {\n constructor(network: SuiNetwork) {\n super(network)\n this.adapter = new SuiChainAdapter()\n }\n\n load(module: SuiMoveNormalizedModule): InternalMoveModule {\n let m = this.moduleMapping.get(module.address + '::' + module.name)\n if (m) {\n return m\n }\n m = toInternalModule(module)\n this.loadInternal(m)\n return m\n }\n\n decode(data: any, type: TypeDescriptor): any {\n switch (type.qname) {\n case '0x2::object::ID':\n case '0x2::coin::Coin':\n case '0x2::balance::Balance':\n return data\n case '0x1::option::Option':\n if (data === null) {\n return data\n }\n return this.decode(data, type.typeArgs[0])\n default:\n return super.decode(data, type)\n }\n }\n\n decodeEvent<T>(event: SuiEvent): Promise<TypedEventInstance<T> | undefined> {\n return this.decodedStruct(event)\n }\n filterAndDecodeEvents<T>(type: TypeDescriptor<T> | string, resources: SuiEvent[]): Promise<TypedEventInstance<T>[]> {\n if (typeof type === 'string') {\n type = parseMoveType(type)\n }\n return this.filterAndDecodeStruct(type, resources)\n }\n\n async getDynamicFields<T1, T2>(\n objects: SuiMoveObject[],\n keyType: TypeDescriptor<T1> = ANY_TYPE,\n valueType: TypeDescriptor<T2> = ANY_TYPE\n ): Promise<dynamic_field.Field<T1, T2>[]> {\n // const type = dynamic_field.Field.TYPE\n // Not using the code above to avoid cycle initialize failed\n const type = new TypeDescriptor<dynamic_field.Field<T1, T2>>('0x2::dynamic_field::Field')\n type.typeArgs = [keyType, valueType]\n const res = await this.filterAndDecodeObjects(type, objects)\n return res.map((o) => o.data_decoded)\n }\n\n filterAndDecodeObjects<T>(\n type: TypeDescriptor<T>,\n objects: SuiMoveObject[]\n ): Promise<DecodedStruct<SuiMoveObject, T>[]> {\n return this.filterAndDecodeStruct(type, objects)\n }\n\n async decodeFunctionPayload(payload: MoveCallSuiTransaction, inputs: SuiCallArg[]): Promise<MoveCallSuiTransaction> {\n const functionType = [payload.package, payload.module, payload.function].join(SPLITTER)\n const func = await this.getMoveFunction(functionType)\n const params = this.adapter.getMeaningfulFunctionParams(func.params)\n const args = []\n for (const value of payload.arguments || []) {\n const argValue = value as any\n if ('Input' in (argValue as any)) {\n const idx = argValue.Input\n const arg = inputs[idx]\n if (arg.type === 'pure') {\n args.push(arg.value)\n } else if (arg.type === 'object') {\n args.push(arg.objectId)\n } else {\n console.error('unexpected function arg value')\n args.push(undefined)\n }\n // args.push(arg) // TODO check why ts not work using arg.push(arg)\n } else {\n args.push(undefined)\n }\n }\n\n const argumentsTyped = await this.decodeArray(args, params)\n return {\n ...payload,\n arguments_decoded: argumentsTyped,\n } as TypedFunctionPayload<any>\n }\n}\n\nconst MOVE_CODER = new MoveCoder(SuiNetwork.MAIN_NET)\nconst TESTNET_MOVE_CODER = new MoveCoder(SuiNetwork.TEST_NET)\n\nexport function defaultMoveCoder(network: SuiNetwork = SuiNetwork.MAIN_NET): MoveCoder {\n if (network == SuiNetwork.MAIN_NET) {\n return MOVE_CODER\n }\n return TESTNET_MOVE_CODER\n}\n"]}
@@ -20,7 +20,7 @@ export class SuiPlugin extends Plugin {
20
20
  address: validateAndNormalizeAddress(suiProcessor.config.address),
21
21
  abi: '',
22
22
  },
23
- startBlock: BigInt(suiProcessor.config.startTimestamp),
23
+ startBlock: suiProcessor.config.startCheckpoint,
24
24
  });
25
25
  for (const handler of suiProcessor.eventHandlers) {
26
26
  const handlerId = this.suiEventHandlers.push(handler.handler) - 1;
@@ -58,7 +58,7 @@ export class SuiPlugin extends Plugin {
58
58
  const accountConfig = AccountConfig.fromPartial({
59
59
  address: validateAndNormalizeAddress(processor.config.address),
60
60
  chainId: processor.getChainId(),
61
- startBlock: BigInt(processor.config.startTimestamp), // TODO maybe use another field
61
+ startBlock: processor.config.startCheckpoint, // TODO maybe use another field
62
62
  });
63
63
  for (const handler of processor.objectHandlers) {
64
64
  const handlerId = this.suiObjectHandlers.push(handler.handler) - 1;
@@ -1 +1 @@
1
- {"version":3,"file":"sui-plugin.js","sourceRoot":"","sources":["../../src/sui/sui-plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,mBAAmB,EAAE,MAAM,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAA;AACzG,OAAO,EACL,aAAa,EACb,cAAc,EAKd,WAAW,GAKZ,MAAM,gBAAgB,CAAA;AAEvB,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,WAAW,CAAA;AAE/C,OAAO,EAAE,wBAAwB,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAA;AAChF,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AACzC,OAAO,EAAE,2BAA2B,EAAE,MAAM,YAAY,CAAA;AAExD,MAAM,OAAO,SAAU,SAAQ,MAAM;IACnC,IAAI,GAAW,WAAW,CAAA;IAElB,gBAAgB,GAAyD,EAAE,CAAA;IAC3E,eAAe,GAAuD,EAAE,CAAA;IACxE,iBAAiB,GAA2D,EAAE,CAAA;IAEtF,KAAK,CAAC,SAAS,CAAC,MAA6B;QAC3C,KAAK,MAAM,YAAY,IAAI,iBAAiB,CAAC,QAAQ,CAAC,SAAS,EAAE,EAAE;YACjE,MAAM,cAAc,GAAG,cAAc,CAAC,WAAW,CAAC;gBAChD,iBAAiB,EAAE,EAAE;gBACrB,aAAa,EAAE,cAAc;gBAC7B,QAAQ,EAAE;oBACR,IAAI,EAAE,YAAY,CAAC,UAAU;oBAC7B,OAAO,EAAE,UAAU,CAAC,YAAY,CAAC,MA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AAQ;gBACvB,OAAO,IAAI,CAAC,sBAAsB,CAAC,OAAO,CAAC,CAAA;YAC7C,KAAK,WAAW,CAAC,UAAU;gBACzB,OAAO,IAAI,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAA;YACvC;gBACE,MAAM,IAAI,WAAW,CAAC,MAAM,CAAC,gBAAgB,EAAE,4BAA4B,GAAG,OAAO,CAAC,WAAW,CAAC,CAAA;SACrG;IACH,CAAC;CACF;AAED,aAAa,CAAC,QAAQ,CAAC,QAAQ,CAAC,IAAI,SAAS,EAAE,CAAC,CAAA","sourcesContent":["import { errorString, mergeProcessResults, Plugin, PluginManager, USER_PROCESSOR } from '@sentio/runtime'\nimport {\n AccountConfig,\n ContractConfig,\n Data_SuiCall,\n Data_SuiEvent,\n Data_SuiObject,\n DataBinding,\n HandlerType,\n MoveCallHandlerConfig,\n MoveEventHandlerConfig,\n ProcessConfigResponse,\n ProcessResult,\n} from '@sentio/protos'\n\nimport { ServerError, Status } from 'nice-grpc'\n\nimport { SuiAccountProcessorState, SuiProcessorState } from './sui-processor.js'\nimport { getChainId } from './network.js'\nimport { validateAndNormalizeAddress } from './utils.js'\n\nexport class SuiPlugin extends Plugin {\n name: string = 'SuiPlugin'\n\n private suiEventHandlers: ((event: Data_SuiEvent) => Promise<ProcessResult>)[] = []\n private suiCallHandlers: ((func: Data_SuiCall) => Promise<ProcessResult>)[] = []\n private suiObjectHandlers: ((object: Data_SuiObject) => Promise<ProcessResult>)[] = []\n\n async configure(config: ProcessConfigResponse) {\n for (const suiProcessor of SuiProcessorState.INSTANCE.getValues()) {\n const contractConfig = ContractConfig.fromPartial({\n transactionConfig: [],\n processorType: USER_PROCESSOR,\n contract: {\n name: suiProcessor.moduleName,\n chainId: getChainId(suiProcessor.config.network),\n address: validateAndNormalizeAddress(suiProcessor.config.address),\n abi: '',\n },\n startBlock: BigInt(suiProcessor.config.startTimestamp),\n })\n for (const handler of suiProcessor.eventHandlers) {\n const handlerId = this.suiEventHandlers.push(handler.handler) - 1\n const eventHandlerConfig: MoveEventHandlerConfig = {\n filters: handler.filters.map((f) => {\n return {\n type: f.type,\n account: f.account || '',\n }\n }),\n fetchConfig: handler.fetchConfig,\n handlerId,\n }\n contractConfig.moveEventConfigs.push(eventHandlerConfig)\n }\n for (const handler of suiProcessor.callHandlers) {\n const handlerId = this.suiCallHandlers.push(handler.handler) - 1\n const functionHandlerConfig: MoveCallHandlerConfig = {\n filters: handler.filters.map((filter) => {\n return {\n function: filter.function,\n typeArguments: filter.typeArguments || [],\n withTypeArguments: !!filter.typeArguments,\n includeFailed: filter.includeFailed || false,\n }\n }),\n fetchConfig: handler.fetchConfig,\n handlerId,\n }\n contractConfig.moveCallConfigs.push(functionHandlerConfig)\n }\n config.contractConfigs.push(contractConfig)\n }\n\n for (const processor of SuiAccountProcessorState.INSTANCE.getValues()) {\n const accountConfig = AccountConfig.fromPartial({\n address: validateAndNormalizeAddress(processor.config.address),\n chainId: processor.getChainId(),\n startBlock: BigInt(processor.config.startTimestamp), // TODO maybe use another field\n })\n for (const handler of processor.objectHandlers) {\n const handlerId = this.suiObjectHandlers.push(handler.handler) - 1\n accountConfig.moveIntervalConfigs.push({\n intervalConfig: {\n handlerId: handlerId,\n minutes: 0,\n minutesInterval: handler.timeIntervalInMinutes,\n slot: 0,\n slotInterval: handler.versionInterval,\n fetchConfig: undefined,\n },\n type: handler.type || '',\n ownerType: processor.ownerType,\n })\n }\n config.accountConfigs.push(accountConfig)\n }\n }\n\n supportedHandlers = [HandlerType.SUI_EVENT, HandlerType.SUI_CALL, HandlerType.SUI_OBJECT]\n\n async processSuiEvent(binding: DataBinding): Promise<ProcessResult> {\n if (!binding.data?.suiEvent) {\n throw new ServerError(Status.INVALID_ARGUMENT, \"Event can't be empty\")\n }\n const promises: Promise<ProcessResult>[] = []\n const event = binding.data.suiEvent\n\n for (const handlerId of binding.handlerIds) {\n promises.push(\n this.suiEventHandlers[handlerId](event).catch((e) => {\n throw new ServerError(\n Status.INTERNAL,\n 'error processing event: ' + JSON.stringify(event) + '\\n' + errorString(e)\n )\n })\n )\n }\n return mergeProcessResults(await Promise.all(promises))\n }\n\n async processSuiFunctionCall(binding: DataBinding): Promise<ProcessResult> {\n if (!binding.data?.suiCall) {\n throw new ServerError(Status.INVALID_ARGUMENT, \"Call can't be empty\")\n }\n const call = binding.data.suiCall\n\n const promises: Promise<ProcessResult>[] = []\n for (const handlerId of binding.handlerIds) {\n const promise = this.suiCallHandlers[handlerId](call).catch((e) => {\n throw new ServerError(Status.INTERNAL, 'error processing call: ' + JSON.stringify(call) + '\\n' + errorString(e))\n })\n promises.push(promise)\n }\n return mergeProcessResults(await Promise.all(promises))\n }\n\n async processSuiObject(binding: DataBinding): Promise<ProcessResult> {\n if (!binding.data?.suiObject) {\n throw new ServerError(Status.INVALID_ARGUMENT, \"Object can't be empty\")\n }\n const object = binding.data.suiObject\n\n const promises: Promise<ProcessResult>[] = []\n for (const handlerId of binding.handlerIds) {\n promises.push(\n this.suiObjectHandlers[handlerId](object).catch((e) => {\n throw new ServerError(\n Status.INTERNAL,\n 'error processing object: ' + JSON.stringify(object) + '\\n' + errorString(e)\n )\n })\n )\n }\n return mergeProcessResults(await Promise.all(promises))\n }\n\n processBinding(request: DataBinding): Promise<ProcessResult> {\n switch (request.handlerType) {\n case HandlerType.SUI_EVENT:\n return this.processSuiEvent(request)\n case HandlerType.SUI_CALL:\n return this.processSuiFunctionCall(request)\n case HandlerType.SUI_OBJECT:\n return this.processSuiObject(request)\n default:\n throw new ServerError(Status.INVALID_ARGUMENT, 'No handle type registered ' + request.handlerType)\n }\n }\n}\n\nPluginManager.INSTANCE.register(new SuiPlugin())\n"]}
1
+ {"version":3,"file":"sui-plugin.js","sourceRoot":"","sources":["../../src/sui/sui-plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,mBAAmB,EAAE,MAAM,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAA;AACzG,OAAO,EACL,aAAa,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,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,SAAS,CAAA;QAErC,MAAM,QAAQ,GAA6B,EAAE,CAAA;QAC7C,KAAK,MAAM,SAAS,IAAI,OAAO,CAAC,UAAU,EAAE;YAC1C,QAAQ,CAAC,IAAI,CACX,IAAI,CAAC,iBAAiB,CAAC,SAAS,CAAC,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE;gBACpD,MAAM,IAAI,WAAW,CACnB,MAAM,CAAC,QAAQ,EACf,2BAA2B,GAAG,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,GAAG,IAAI,GAAG,WAAW,CAAC,CAAC,CAAC,CAC7E,CAAA;YACH,CAAC,CAAC,CACH,CAAA;SACF;QACD,OAAO,mBAAmB,CAAC,MAAM,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAA;IACzD,CAAC;IAED,cAAc,CAAC,OAAoB;QACjC,QAAQ,OAAO,CAAC,WAAW,EAAE;YAC3B,KAAK,WAAW,CAAC,SAAS;gBACxB,OAAO,IAAI,CAAC,eAAe,CAAC,OAAO,CAAC,CAAA;YACtC,KAAK,WAAW,CAAC,QAAQ;gBACvB,OAAO,IAAI,CAAC,sBAAsB,CAAC,OAAO,CAAC,CAAA;YAC7C,KAAK,WAAW,CAAC,UAAU;gBACzB,OAAO,IAAI,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAA;YACvC;gBACE,MAAM,IAAI,WAAW,CAAC,MAAM,CAAC,gBAAgB,EAAE,4BAA4B,GAAG,OAAO,CAAC,WAAW,CAAC,CAAA;SACrG;IACH,CAAC;CACF;AAED,aAAa,CAAC,QAAQ,CAAC,QAAQ,CAAC,IAAI,SAAS,EAAE,CAAC,CAAA","sourcesContent":["import { errorString, mergeProcessResults, Plugin, PluginManager, USER_PROCESSOR } from '@sentio/runtime'\nimport {\n AccountConfig,\n ContractConfig,\n Data_SuiCall,\n Data_SuiEvent,\n Data_SuiObject,\n DataBinding,\n HandlerType,\n MoveCallHandlerConfig,\n MoveEventHandlerConfig,\n ProcessConfigResponse,\n ProcessResult,\n} from '@sentio/protos'\n\nimport { ServerError, Status } from 'nice-grpc'\n\nimport { SuiAccountProcessorState, SuiProcessorState } from './sui-processor.js'\nimport { getChainId } from './network.js'\nimport { validateAndNormalizeAddress } from './utils.js'\n\nexport class SuiPlugin extends Plugin {\n name: string = 'SuiPlugin'\n\n private suiEventHandlers: ((event: Data_SuiEvent) => Promise<ProcessResult>)[] = []\n private suiCallHandlers: ((func: Data_SuiCall) => Promise<ProcessResult>)[] = []\n private suiObjectHandlers: ((object: Data_SuiObject) => Promise<ProcessResult>)[] = []\n\n async configure(config: ProcessConfigResponse) {\n for (const suiProcessor of SuiProcessorState.INSTANCE.getValues()) {\n const contractConfig = ContractConfig.fromPartial({\n transactionConfig: [],\n processorType: USER_PROCESSOR,\n contract: {\n name: suiProcessor.moduleName,\n chainId: getChainId(suiProcessor.config.network),\n address: validateAndNormalizeAddress(suiProcessor.config.address),\n abi: '',\n },\n startBlock: suiProcessor.config.startCheckpoint,\n })\n for (const handler of suiProcessor.eventHandlers) {\n const handlerId = this.suiEventHandlers.push(handler.handler) - 1\n const eventHandlerConfig: MoveEventHandlerConfig = {\n filters: handler.filters.map((f) => {\n return {\n type: f.type,\n account: f.account || '',\n }\n }),\n fetchConfig: handler.fetchConfig,\n handlerId,\n }\n contractConfig.moveEventConfigs.push(eventHandlerConfig)\n }\n for (const handler of suiProcessor.callHandlers) {\n const handlerId = this.suiCallHandlers.push(handler.handler) - 1\n const functionHandlerConfig: MoveCallHandlerConfig = {\n filters: handler.filters.map((filter) => {\n return {\n function: filter.function,\n typeArguments: filter.typeArguments || [],\n withTypeArguments: !!filter.typeArguments,\n includeFailed: filter.includeFailed || false,\n }\n }),\n fetchConfig: handler.fetchConfig,\n handlerId,\n }\n contractConfig.moveCallConfigs.push(functionHandlerConfig)\n }\n config.contractConfigs.push(contractConfig)\n }\n\n for (const processor of SuiAccountProcessorState.INSTANCE.getValues()) {\n const accountConfig = AccountConfig.fromPartial({\n address: validateAndNormalizeAddress(processor.config.address),\n chainId: processor.getChainId(),\n startBlock: processor.config.startCheckpoint, // TODO maybe use another field\n })\n for (const handler of processor.objectHandlers) {\n const handlerId = this.suiObjectHandlers.push(handler.handler) - 1\n accountConfig.moveIntervalConfigs.push({\n intervalConfig: {\n handlerId: handlerId,\n minutes: 0,\n minutesInterval: handler.timeIntervalInMinutes,\n slot: 0,\n slotInterval: handler.versionInterval,\n fetchConfig: undefined,\n },\n type: handler.type || '',\n ownerType: processor.ownerType,\n })\n }\n config.accountConfigs.push(accountConfig)\n }\n }\n\n supportedHandlers = [HandlerType.SUI_EVENT, HandlerType.SUI_CALL, HandlerType.SUI_OBJECT]\n\n async processSuiEvent(binding: DataBinding): Promise<ProcessResult> {\n if (!binding.data?.suiEvent) {\n throw new ServerError(Status.INVALID_ARGUMENT, \"Event can't be empty\")\n }\n const promises: Promise<ProcessResult>[] = []\n const event = binding.data.suiEvent\n\n for (const handlerId of binding.handlerIds) {\n promises.push(\n this.suiEventHandlers[handlerId](event).catch((e) => {\n throw new ServerError(\n Status.INTERNAL,\n 'error processing event: ' + JSON.stringify(event) + '\\n' + errorString(e)\n )\n })\n )\n }\n return mergeProcessResults(await Promise.all(promises))\n }\n\n async processSuiFunctionCall(binding: DataBinding): Promise<ProcessResult> {\n if (!binding.data?.suiCall) {\n throw new ServerError(Status.INVALID_ARGUMENT, \"Call can't be empty\")\n }\n const call = binding.data.suiCall\n\n const promises: Promise<ProcessResult>[] = []\n for (const handlerId of binding.handlerIds) {\n const promise = this.suiCallHandlers[handlerId](call).catch((e) => {\n throw new ServerError(Status.INTERNAL, 'error processing call: ' + JSON.stringify(call) + '\\n' + errorString(e))\n })\n promises.push(promise)\n }\n return mergeProcessResults(await Promise.all(promises))\n }\n\n async processSuiObject(binding: DataBinding): Promise<ProcessResult> {\n if (!binding.data?.suiObject) {\n throw new ServerError(Status.INVALID_ARGUMENT, \"Object can't be empty\")\n }\n const object = binding.data.suiObject\n\n const promises: Promise<ProcessResult>[] = []\n for (const handlerId of binding.handlerIds) {\n promises.push(\n this.suiObjectHandlers[handlerId](object).catch((e) => {\n throw new ServerError(\n Status.INTERNAL,\n 'error processing object: ' + JSON.stringify(object) + '\\n' + errorString(e)\n )\n })\n )\n }\n return mergeProcessResults(await Promise.all(promises))\n }\n\n processBinding(request: DataBinding): Promise<ProcessResult> {\n switch (request.handlerType) {\n case HandlerType.SUI_EVENT:\n return this.processSuiEvent(request)\n case HandlerType.SUI_CALL:\n return this.processSuiFunctionCall(request)\n case HandlerType.SUI_OBJECT:\n return this.processSuiObject(request)\n default:\n throw new ServerError(Status.INVALID_ARGUMENT, 'No handle type registered ' + request.handlerType)\n }\n }\n}\n\nPluginManager.INSTANCE.register(new SuiPlugin())\n"]}
@@ -9,17 +9,17 @@ import { PromiseOrVoid } from '../core/index.js';
9
9
  declare class IndexConfigure {
10
10
  address: string;
11
11
  network: SuiNetwork;
12
- startTimestamp: number;
12
+ startCheckpoint: bigint;
13
13
  }
14
14
  export declare class SuiBindOptions {
15
15
  address: string;
16
16
  network?: SuiNetwork;
17
- startTimestamp?: number;
17
+ startCheckpoint?: bigint;
18
18
  }
19
19
  export declare class SuiObjectBindOptions {
20
20
  objectId: string;
21
21
  network?: SuiNetwork;
22
- startTimestamp?: number;
22
+ startCheckpoint?: bigint;
23
23
  }
24
24
  export declare class SuiProcessorState extends ListStateStorage<SuiBaseProcessor> {
25
25
  static INSTANCE: SuiProcessorState;
@@ -15,17 +15,17 @@ const DEFAULT_FETCH_CONFIG = {
15
15
  class IndexConfigure {
16
16
  address;
17
17
  network;
18
- startTimestamp;
18
+ startCheckpoint;
19
19
  }
20
20
  export class SuiBindOptions {
21
21
  address;
22
22
  network;
23
- startTimestamp;
23
+ startCheckpoint;
24
24
  }
25
25
  export class SuiObjectBindOptions {
26
26
  objectId;
27
27
  network;
28
- startTimestamp;
28
+ startCheckpoint;
29
29
  }
30
30
  class SuiProcessorState extends ListStateStorage {
31
31
  static INSTANCE = new SuiProcessorState();
@@ -181,7 +181,7 @@ class SuiBaseObjectsProcessor {
181
181
  }
182
182
  function configure(options) {
183
183
  return {
184
- startTimestamp: options.startTimestamp || 0,
184
+ startCheckpoint: options.startCheckpoint || 0n,
185
185
  address: options.address,
186
186
  network: options.network || SuiNetwork.MAIN_NET,
187
187
  };
@@ -200,7 +200,7 @@ export class SuiDynamicFieldObjectsProcessor extends SuiBaseObjectsProcessor {
200
200
  return new SuiDynamicFieldObjectsProcessor({
201
201
  address: options.objectId,
202
202
  network: options.network,
203
- startTimestamp: options.startTimestamp,
203
+ startCheckpoint: options.startCheckpoint,
204
204
  ownerType: MoveOnIntervalConfig_OwnerType.OBJECT,
205
205
  });
206
206
  }
@@ -1 +1 @@
1
- {"version":3,"file":"sui-processor.js","sourceRoot":"","sources":["../../src/sui/sui-processor.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,eAAe,EACf,8BAA8B,GAE/B,MAAM,gBAAgB,CAAA;AACvB,OAAO,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAA;AACvE,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AACrD,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,WAAW,CAAA;AAC/C,OAAO,EAAE,UAAU,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAA;AAC5D,OAAO,EACL,0BAA0B,EAC1B,kBAAkB,GAKnB,MAAM,gBAAgB,CAAA;AACvB,OAAO,EAAqE,aAAa,EAAE,MAAM,kBAAkB,CAAA;AACnH,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;AACzC,OAAO,EAAE,gBAAgB,EAAa,MAAM,iBAAiB,CAAA;AAE7D,mDAAmD;AAEnD,MAAM,oBAAoB,GAAoB;IAC5C,eAAe,EAAE,KAAK;IACtB,SAAS,EAAE,IAAI;CAChB,CAAA;AAED,MAAM,c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iCall,\n Data_SuiEvent,\n Data_SuiObject,\n HandleInterval,\n MoveFetchConfig,\n MoveOnIntervalConfig_OwnerType,\n ProcessResult,\n} from '@sentio/protos'\nimport { ListStateStorage, mergeProcessResults } from '@sentio/runtime'\nimport { getChainId, SuiNetwork } from './network.js'\nimport { ServerError, Status } from 'nice-grpc'\nimport { SuiContext, SuiObjectsContext } from './context.js'\nimport {\n getProgrammableTransaction,\n getTransactionKind,\n MoveCallSuiTransaction,\n SuiEvent,\n SuiMoveObject,\n SuiTransactionBlockResponse,\n} from '@mysten/sui.js'\nimport { CallHandler, EventFilter, EventHandler, FunctionNameAndCallFilter, parseMoveType } from '../move/index.js'\nimport { getMoveCalls } from './utils.js'\nimport { defaultMoveCoder, MoveCoder } from './move-coder.js'\nimport { PromiseOrVoid } from '../core/index.js'\n// import { dynamic_field } from './builtin/0x2.js'\n\nconst DEFAULT_FETCH_CONFIG: MoveFetchConfig = {\n resourceChanges: false,\n allEvents: true,\n}\n\nclass IndexConfigure {\n address: string\n network: SuiNetwork\n startTimestamp: number\n}\n\nexport class SuiBindOptions {\n address: string\n network?: SuiNetwork\n startTimestamp?: number\n}\n\nexport class SuiObjectBindOptions {\n objectId: string\n network?: SuiNetwork\n startTimestamp?: number\n}\n\nexport class SuiProcessorState extends ListStateStorage<SuiBaseProcessor> {\n static INSTANCE = new SuiProcessorState()\n}\n\nexport class SuiBaseProcessor {\n readonly moduleName: string\n config: IndexConfigure\n\n eventHandlers: EventHandler<Data_SuiEvent>[] = []\n callHandlers: CallHandler<Data_SuiCall>[] = []\n coder: MoveCoder\n\n constructor(name: string, options: SuiBindOptions) {\n this.moduleName = name\n this.config = configure(options)\n SuiProcessorState.INSTANCE.addValue(this)\n this.coder = defaultMoveCoder(this.config.network)\n }\n\n getChainId(): string {\n return getChainId(this.config.network)\n }\n\n public onMoveEvent(\n handler: (event: SuiEvent, ctx: SuiContext) => void,\n filter: EventFilter | EventFilter[],\n fetchConfig?: Partial<MoveFetchConfig>\n ): SuiBaseProcessor {\n let _filters: EventFilter[] = []\n const _fetchConfig = MoveFetchConfig.fromPartial({ ...DEFAULT_FETCH_CONFIG, ...fetchConfig })\n\n if (Array.isArray(filter)) {\n _filters = filter\n } else {\n _filters.push(filter)\n }\n\n // const address = this.config.address\n // const moduleName = this.moduleName\n\n const processor = this\n const allEventType = new Set(_filters.map((f) => processor.config.address + '::' + f.type))\n\n this.eventHandlers.push({\n handler: async function (data) {\n if (!data.transaction) {\n throw new ServerError(Status.INVALID_ARGUMENT, 'event is null')\n }\n const txn = data.transaction as SuiTransactionBlockResponse\n if (!txn.events || !txn.events.length) {\n throw new ServerError(Status.INVALID_ARGUMENT, 'no event in the transactions')\n }\n\n const processResults = []\n for (const [idx, evt] of (txn.events as SuiEvent[]).entries()) {\n const typeQname = parseMoveType(evt.type).qname\n if (!allEventType.has(typeQname)) {\n continue\n }\n\n const ctx = new SuiContext(\n processor.moduleName,\n processor.config.network,\n processor.config.address,\n data.timestamp || new Date(0),\n data.slot,\n txn,\n idx\n )\n\n const decoded = await processor.coder.decodeEvent<any>(evt)\n await handler(decoded || evt, ctx)\n processResults.push(ctx.getProcessResult())\n }\n\n return mergeProcessResults(processResults)\n },\n filters: _filters,\n fetchConfig: _fetchConfig,\n })\n return this\n }\n\n public onEntryFunctionCall(\n handler: (call: MoveCallSuiTransaction, ctx: SuiContext) => void,\n filter: FunctionNameAndCallFilter | FunctionNameAndCallFilter[],\n fetchConfig?: Partial<MoveFetchConfig>\n ): SuiBaseProcessor {\n let _filters: FunctionNameAndCallFilter[] = []\n const _fetchConfig = MoveFetchConfig.fromPartial({ ...DEFAULT_FETCH_CONFIG, ...fetchConfig })\n\n if (Array.isArray(filter)) {\n _filters = filter\n } else {\n _filters.push(filter)\n }\n\n // const address = this.config.address\n // const moduleName = this.moduleName\n const processor = this\n\n this.callHandlers.push({\n handler: async function (data) {\n if (!data.transaction) {\n throw new ServerError(Status.INVALID_ARGUMENT, 'call is null')\n }\n const tx = data.transaction as SuiTransactionBlockResponse\n\n const ctx = new SuiContext(\n processor.moduleName,\n processor.config.network,\n processor.config.address,\n data.timestamp || new Date(0),\n data.slot,\n tx,\n 0\n )\n if (tx) {\n const calls: MoveCallSuiTransaction[] = getMoveCalls(tx)\n if (calls.length !== 1) {\n throw new ServerError(Status.INVALID_ARGUMENT, 'Unexpected number of call transactions ' + calls.length)\n }\n const txKind = getTransactionKind(tx)\n if (!txKind) {\n throw new ServerError(Status.INVALID_ARGUMENT, 'Unexpected getTransactionKind get empty')\n }\n const programmableTx = getProgrammableTransaction(txKind)\n\n const payload = calls[0]\n const decoded = await processor.coder.decodeFunctionPayload(payload, programmableTx?.inputs || [])\n await handler(decoded, ctx)\n }\n return ctx.getProcessResult()\n },\n filters: _filters,\n fetchConfig: _fetchConfig,\n })\n return this\n }\n}\n\nclass ObjectHandler {\n type?: string\n versionInterval?: HandleInterval\n timeIntervalInMinutes?: HandleInterval\n handler: (resource: Data_SuiObject) => Promise<ProcessResult>\n}\n\nexport class SuiAccountProcessorState extends ListStateStorage<SuiBaseObjectsProcessor<any>> {\n static INSTANCE = new SuiAccountProcessorState()\n}\n\nclass SuiObjectsBindOptions extends SuiBindOptions {\n ownerType: MoveOnIntervalConfig_OwnerType\n}\n\nabstract class SuiBaseObjectsProcessor<HandlerType> {\n config: IndexConfigure\n ownerType: MoveOnIntervalConfig_OwnerType\n\n objectHandlers: ObjectHandler[] = []\n\n // static bind(options: SuiObjectsBindOptions): SuiBaseObjectsProcessor<any> {\n // return new SuiBaseObjectsProcessor(options)\n // }\n\n protected constructor(options: SuiObjectsBindOptions) {\n this.config = configure(options)\n this.ownerType = options.ownerType\n SuiAccountProcessorState.INSTANCE.addValue(this)\n }\n\n getChainId(): string {\n return getChainId(this.config.network)\n }\n\n protected abstract transformObjects(objects: SuiMoveObject[]): HandlerType[]\n\n protected onInterval(\n handler: (resources: HandlerType[], ctx: SuiObjectsContext) => PromiseOrVoid,\n timeInterval: HandleInterval | undefined,\n versionInterval: HandleInterval | undefined,\n type: string | 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 )\n await handler(processor.transformObjects(data.objects as SuiMoveObject[]), ctx)\n return ctx.getProcessResult()\n },\n timeIntervalInMinutes: timeInterval,\n versionInterval: versionInterval,\n type,\n })\n return this\n }\n\n public onTimeInterval(\n handler: (objects: HandlerType[], ctx: SuiObjectsContext) => PromiseOrVoid,\n timeIntervalInMinutes = 60,\n backfillTimeIntervalInMinutes = 240,\n type?: string\n ): this {\n return this.onInterval(\n handler,\n {\n recentInterval: timeIntervalInMinutes,\n backfillInterval: backfillTimeIntervalInMinutes,\n },\n undefined,\n type\n )\n }\n\n public onSlotInterval(\n handler: (objects: HandlerType[], ctx: SuiObjectsContext) => PromiseOrVoid,\n slotInterval = 100000,\n backfillSlotInterval = 400000,\n type?: string\n ): this {\n return this.onInterval(\n handler,\n undefined,\n { recentInterval: slotInterval, backfillInterval: backfillSlotInterval },\n type\n )\n }\n}\n\nfunction configure(options: SuiBindOptions): IndexConfigure {\n return {\n startTimestamp: options.startTimestamp || 0,\n address: options.address,\n network: options.network || SuiNetwork.MAIN_NET,\n }\n}\n\nexport class SuiAddressObjectsProcessor extends SuiBaseObjectsProcessor<SuiMoveObject> {\n static bind(options: SuiBindOptions): SuiAddressObjectsProcessor {\n return new SuiAddressObjectsProcessor({ ...options, ownerType: MoveOnIntervalConfig_OwnerType.ADDRESS })\n }\n\n protected transformObjects(objects: SuiMoveObject[]): SuiMoveObject[] {\n return objects\n }\n}\n// export class SuiDynamicFieldObjectsProcessor extends SuiBaseObjectsProcessor<dynamic_field.Field<any, any>> {\nexport class SuiDynamicFieldObjectsProcessor extends SuiBaseObjectsProcessor<SuiMoveObject> {\n static bind(options: SuiObjectBindOptions): SuiDynamicFieldObjectsProcessor {\n return new SuiDynamicFieldObjectsProcessor({\n address: options.objectId,\n network: options.network,\n startTimestamp: options.startTimestamp,\n ownerType: MoveOnIntervalConfig_OwnerType.OBJECT,\n })\n }\n\n protected transformObjects(objects: SuiMoveObject[]) {\n return objects\n // return defaultMoveCoder().getObjectsFromDynamicFields(objects)\n }\n}\n"]}
1
+ {"version":3,"file":"sui-processor.js","sourceRoot":"","sources":["../../src/sui/sui-processor.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,eAAe,EACf,8BAA8B,GAE/B,MAAM,gBAAgB,CAAA;AACvB,OAAO,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAA;AACvE,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AACrD,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,WAAW,CAAA;AAC/C,OAAO,EAAE,UAAU,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAA;AAC5D,OAAO,EACL,0BAA0B,EAC1B,kBAAkB,GAKnB,MAAM,gBAAgB,CAAA;AACvB,OAAO,EAAqE,aAAa,EAAE,MAAM,kBAAkB,CAAA;AACnH,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;AACzC,OAAO,EAAE,gBAAgB,EAAa,MAAM,iBAAiB,CAAA;AAE7D,mDAAmD;AAEnD,MAAM,oBAAoB,GAAoB;IAC5C,eAAe,EAAE,KAAK;IACtB,SAAS,EAAE,IAAI;CAChB,CAAA;AAED,MAAM,cAAc;IAClB,OAAO,CAAQ;IACf,OAAO,CAAY;IACnB,eAAe,CAAQ;CACxB;AAED,MAAM,OAAO,cAAc;IACzB,OAAO,CAAQ;IACf,OAAO,CAAa;IACpB,eAAe,CAAS;CACzB;AAED,MAAM,OAAO,oBAAoB;IAC/B,QAAQ,CAAQ;IAChB,OAAO,CAAa;IACpB,eAAe,CAAS;CACzB;AAED,MAAa,iBAAkB,SAAQ,gBAAkC;IACvE,MAAM,CAAC,QAAQ,GAAG,IAAI,iBAAiB,EAAE,CAAA;;SAD9B,iBAAiB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CACF;AAED,SAAS,SAAS,CAAC,OAAuB;IACxC,OAAO;QACL,eAAe,EAAE,OAAO,CAAC,eAAe,IAAI,EAAE;QAC9C,OAAO,EAAE,OAAO,CAAC,OAAO;QACxB,OAAO,EAAE,OAAO,CAAC,OAAO,IAAI,UAAU,CAAC,QAAQ;KAChD,CAAA;AACH,CAAC;AAED,MAAM,OAAO,0BAA2B,SAAQ,uBAAsC;IACpF,MAAM,CAAC,IAAI,CAAC,OAAuB;QACjC,OAAO,IAAI,0BAA0B,CAAC,EAAE,GAAG,OAAO,EAAE,SAAS,EAAE,8BAA8B,CAAC,OAAO,EAAE,CAAC,CAAA;IAC1G,CAAC;IAES,gBAAgB,CAAC,OAAwB;QACjD,OAAO,OAAO,CAAA;IAChB,CAAC;CACF;AACD,gHAAgH;AAChH,MAAM,OAAO,+BAAgC,SAAQ,uBAAsC;IACzF,MAAM,CAAC,IAAI,CAAC,OAA6B;QACvC,OAAO,IAAI,+BAA+B,CAAC;YACzC,OAAO,EAAE,OAAO,CAAC,QAAQ;YACzB,OAAO,EAAE,OAAO,CAAC,OAAO;YACxB,eAAe,EAAE,OAAO,CAAC,eAAe;YACxC,SAAS,EAAE,8BAA8B,CAAC,MAAM;SACjD,CAAC,CAAA;IACJ,CAAC;IAES,gBAAgB,CAAC,OAAwB;QACjD,OAAO,OAAO,CAAA;QACd,iEAAiE;IACnE,CAAC;CACF","sourcesContent":["import {\n Data_SuiCall,\n Data_SuiEvent,\n Data_SuiObject,\n HandleInterval,\n MoveFetchConfig,\n MoveOnIntervalConfig_OwnerType,\n ProcessResult,\n} from '@sentio/protos'\nimport { ListStateStorage, mergeProcessResults } from '@sentio/runtime'\nimport { getChainId, SuiNetwork } from './network.js'\nimport { ServerError, Status } from 'nice-grpc'\nimport { SuiContext, SuiObjectsContext } from './context.js'\nimport {\n getProgrammableTransaction,\n getTransactionKind,\n MoveCallSuiTransaction,\n SuiEvent,\n SuiMoveObject,\n SuiTransactionBlockResponse,\n} from '@mysten/sui.js'\nimport { CallHandler, EventFilter, EventHandler, FunctionNameAndCallFilter, parseMoveType } from '../move/index.js'\nimport { getMoveCalls } from './utils.js'\nimport { defaultMoveCoder, MoveCoder } from './move-coder.js'\nimport { PromiseOrVoid } from '../core/index.js'\n// import { dynamic_field } from './builtin/0x2.js'\n\nconst DEFAULT_FETCH_CONFIG: MoveFetchConfig = {\n resourceChanges: false,\n allEvents: true,\n}\n\nclass IndexConfigure {\n address: string\n network: SuiNetwork\n startCheckpoint: bigint\n}\n\nexport class SuiBindOptions {\n address: string\n network?: SuiNetwork\n startCheckpoint?: bigint\n}\n\nexport class SuiObjectBindOptions {\n objectId: string\n network?: SuiNetwork\n startCheckpoint?: bigint\n}\n\nexport class SuiProcessorState extends ListStateStorage<SuiBaseProcessor> {\n static INSTANCE = new SuiProcessorState()\n}\n\nexport class SuiBaseProcessor {\n readonly moduleName: string\n config: IndexConfigure\n\n eventHandlers: EventHandler<Data_SuiEvent>[] = []\n callHandlers: CallHandler<Data_SuiCall>[] = []\n coder: MoveCoder\n\n constructor(name: string, options: SuiBindOptions) {\n this.moduleName = name\n this.config = configure(options)\n SuiProcessorState.INSTANCE.addValue(this)\n this.coder = defaultMoveCoder(this.config.network)\n }\n\n getChainId(): string {\n return getChainId(this.config.network)\n }\n\n public onMoveEvent(\n handler: (event: SuiEvent, ctx: SuiContext) => void,\n filter: EventFilter | EventFilter[],\n fetchConfig?: Partial<MoveFetchConfig>\n ): SuiBaseProcessor {\n let _filters: EventFilter[] = []\n const _fetchConfig = MoveFetchConfig.fromPartial({ ...DEFAULT_FETCH_CONFIG, ...fetchConfig })\n\n if (Array.isArray(filter)) {\n _filters = filter\n } else {\n _filters.push(filter)\n }\n\n // const address = this.config.address\n // const moduleName = this.moduleName\n\n const processor = this\n const allEventType = new Set(_filters.map((f) => processor.config.address + '::' + f.type))\n\n this.eventHandlers.push({\n handler: async function (data) {\n if (!data.transaction) {\n throw new ServerError(Status.INVALID_ARGUMENT, 'event is null')\n }\n const txn = data.transaction as SuiTransactionBlockResponse\n if (!txn.events || !txn.events.length) {\n throw new ServerError(Status.INVALID_ARGUMENT, 'no event in the transactions')\n }\n\n const processResults = []\n for (const [idx, evt] of (txn.events as SuiEvent[]).entries()) {\n const typeQname = parseMoveType(evt.type).qname\n if (!allEventType.has(typeQname)) {\n continue\n }\n\n const ctx = new SuiContext(\n processor.moduleName,\n processor.config.network,\n processor.config.address,\n data.timestamp || new Date(0),\n data.slot,\n txn,\n idx\n )\n\n const decoded = await processor.coder.decodeEvent<any>(evt)\n await handler(decoded || evt, ctx)\n processResults.push(ctx.getProcessResult())\n }\n\n return mergeProcessResults(processResults)\n },\n filters: _filters,\n fetchConfig: _fetchConfig,\n })\n return this\n }\n\n public onEntryFunctionCall(\n handler: (call: MoveCallSuiTransaction, ctx: SuiContext) => void,\n filter: FunctionNameAndCallFilter | FunctionNameAndCallFilter[],\n fetchConfig?: Partial<MoveFetchConfig>\n ): SuiBaseProcessor {\n let _filters: FunctionNameAndCallFilter[] = []\n const _fetchConfig = MoveFetchConfig.fromPartial({ ...DEFAULT_FETCH_CONFIG, ...fetchConfig })\n\n if (Array.isArray(filter)) {\n _filters = filter\n } else {\n _filters.push(filter)\n }\n\n // const address = this.config.address\n // const moduleName = this.moduleName\n const processor = this\n\n this.callHandlers.push({\n handler: async function (data) {\n if (!data.transaction) {\n throw new ServerError(Status.INVALID_ARGUMENT, 'call is null')\n }\n const tx = data.transaction as SuiTransactionBlockResponse\n\n const ctx = new SuiContext(\n processor.moduleName,\n processor.config.network,\n processor.config.address,\n data.timestamp || new Date(0),\n data.slot,\n tx,\n 0\n )\n if (tx) {\n const calls: MoveCallSuiTransaction[] = getMoveCalls(tx)\n if (calls.length !== 1) {\n throw new ServerError(Status.INVALID_ARGUMENT, 'Unexpected number of call transactions ' + calls.length)\n }\n const txKind = getTransactionKind(tx)\n if (!txKind) {\n throw new ServerError(Status.INVALID_ARGUMENT, 'Unexpected getTransactionKind get empty')\n }\n const programmableTx = getProgrammableTransaction(txKind)\n\n const payload = calls[0]\n const decoded = await processor.coder.decodeFunctionPayload(payload, programmableTx?.inputs || [])\n await handler(decoded, ctx)\n }\n return ctx.getProcessResult()\n },\n filters: _filters,\n fetchConfig: _fetchConfig,\n })\n return this\n }\n}\n\nclass ObjectHandler {\n type?: string\n versionInterval?: HandleInterval\n timeIntervalInMinutes?: HandleInterval\n handler: (resource: Data_SuiObject) => Promise<ProcessResult>\n}\n\nexport class SuiAccountProcessorState extends ListStateStorage<SuiBaseObjectsProcessor<any>> {\n static INSTANCE = new SuiAccountProcessorState()\n}\n\nclass SuiObjectsBindOptions extends SuiBindOptions {\n ownerType: MoveOnIntervalConfig_OwnerType\n}\n\nabstract class SuiBaseObjectsProcessor<HandlerType> {\n config: IndexConfigure\n ownerType: MoveOnIntervalConfig_OwnerType\n\n objectHandlers: ObjectHandler[] = []\n\n // static bind(options: SuiObjectsBindOptions): SuiBaseObjectsProcessor<any> {\n // return new SuiBaseObjectsProcessor(options)\n // }\n\n protected constructor(options: SuiObjectsBindOptions) {\n this.config = configure(options)\n this.ownerType = options.ownerType\n SuiAccountProcessorState.INSTANCE.addValue(this)\n }\n\n getChainId(): string {\n return getChainId(this.config.network)\n }\n\n protected abstract transformObjects(objects: SuiMoveObject[]): HandlerType[]\n\n protected onInterval(\n handler: (resources: HandlerType[], ctx: SuiObjectsContext) => PromiseOrVoid,\n timeInterval: HandleInterval | undefined,\n versionInterval: HandleInterval | undefined,\n type: string | 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 )\n await handler(processor.transformObjects(data.objects as SuiMoveObject[]), ctx)\n return ctx.getProcessResult()\n },\n timeIntervalInMinutes: timeInterval,\n versionInterval: versionInterval,\n type,\n })\n return this\n }\n\n public onTimeInterval(\n handler: (objects: HandlerType[], ctx: SuiObjectsContext) => PromiseOrVoid,\n timeIntervalInMinutes = 60,\n backfillTimeIntervalInMinutes = 240,\n type?: string\n ): this {\n return this.onInterval(\n handler,\n {\n recentInterval: timeIntervalInMinutes,\n backfillInterval: backfillTimeIntervalInMinutes,\n },\n undefined,\n type\n )\n }\n\n public onSlotInterval(\n handler: (objects: HandlerType[], ctx: SuiObjectsContext) => PromiseOrVoid,\n slotInterval = 100000,\n backfillSlotInterval = 400000,\n type?: string\n ): this {\n return this.onInterval(\n handler,\n undefined,\n { recentInterval: slotInterval, backfillInterval: backfillSlotInterval },\n type\n )\n }\n}\n\nfunction configure(options: SuiBindOptions): IndexConfigure {\n return {\n startCheckpoint: options.startCheckpoint || 0n,\n address: options.address,\n network: options.network || SuiNetwork.MAIN_NET,\n }\n}\n\nexport class SuiAddressObjectsProcessor extends SuiBaseObjectsProcessor<SuiMoveObject> {\n static bind(options: SuiBindOptions): SuiAddressObjectsProcessor {\n return new SuiAddressObjectsProcessor({ ...options, ownerType: MoveOnIntervalConfig_OwnerType.ADDRESS })\n }\n\n protected transformObjects(objects: SuiMoveObject[]): SuiMoveObject[] {\n return objects\n }\n}\n// export class SuiDynamicFieldObjectsProcessor extends SuiBaseObjectsProcessor<dynamic_field.Field<any, any>> {\nexport class SuiDynamicFieldObjectsProcessor extends SuiBaseObjectsProcessor<SuiMoveObject> {\n static bind(options: SuiObjectBindOptions): SuiDynamicFieldObjectsProcessor {\n return new SuiDynamicFieldObjectsProcessor({\n address: options.objectId,\n network: options.network,\n startCheckpoint: options.startCheckpoint,\n ownerType: MoveOnIntervalConfig_OwnerType.OBJECT,\n })\n }\n\n protected transformObjects(objects: SuiMoveObject[]) {\n return objects\n // return defaultMoveCoder().getObjectsFromDynamicFields(objects)\n }\n}\n"]}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@sentio/sdk",
3
3
  "license": "Apache-2.0",
4
- "version": "2.13.1",
4
+ "version": "2.13.2-rc.2",
5
5
  "type": "module",
6
6
  "scripts": {
7
7
  "compile": "tsc && cp src/utils/*.csv lib/utils && cp src/tsup.config.ts lib",
@@ -23,8 +23,8 @@
23
23
  "@project-serum/anchor": "^0.26.0",
24
24
  "@sentio/bigdecimal": "^9.1.1-patch.3",
25
25
  "@sentio/ethers-v6": "^1.0.28",
26
- "@sentio/protos": "^2.13.1",
27
- "@sentio/runtime": "^2.13.1",
26
+ "@sentio/protos": "^2.13.2-rc.2",
27
+ "@sentio/runtime": "^2.13.2-rc.2",
28
28
  "@solana/web3.js": "^1.74.0",
29
29
  "@types/prettier": "^2.7.2",
30
30
  "aptos-sdk": "npm:aptos@^1.8.3",
@@ -88,5 +88,5 @@
88
88
  "engines": {
89
89
  "node": ">=16"
90
90
  },
91
- "gitHead": "f66df76c254f9b665990cf84200b29ccc11aa0e6"
91
+ "gitHead": "3d612c2c0329322f5fa4f962c39bb6a3a881a861"
92
92
  }
@@ -1,9 +1,13 @@
1
- import { MoveResource, Transaction_UserTransaction, TransactionPayload_EntryFunctionPayload } from './move-types.js'
1
+ import {
2
+ Event,
3
+ MoveResource,
4
+ Transaction_UserTransaction,
5
+ TransactionPayload_EntryFunctionPayload,
6
+ } from './move-types.js'
2
7
 
3
8
  import { defaultMoveCoder, MoveCoder } from './move-coder.js'
4
9
  import { AptosBindOptions, AptosNetwork, getChainId } from './network.js'
5
10
  import { AptosContext, AptosResourcesContext } from './context.js'
6
- import { EventInstance } from './models.js'
7
11
  import { ListStateStorage, mergeProcessResults } from '@sentio/runtime'
8
12
  import {
9
13
  MoveFetchConfig,
@@ -93,7 +97,7 @@ export class AptosBaseProcessor {
93
97
  }
94
98
 
95
99
  public onMoveEvent(
96
- handler: (event: EventInstance, ctx: AptosContext) => void,
100
+ handler: (event: Event, ctx: AptosContext) => void,
97
101
  filter: EventFilter | EventFilter[],
98
102
  fetchConfig?: Partial<MoveFetchConfig>
99
103
  ): this {
@@ -136,9 +140,9 @@ export class AptosBaseProcessor {
136
140
  txn,
137
141
  idx
138
142
  )
139
- const eventInstance = evt as EventInstance
140
- const decoded = await processor.coder.decodeEvent<any>(eventInstance)
141
- await handler(decoded || eventInstance, ctx)
143
+
144
+ const decoded = await processor.coder.decodeEvent<any>(evt)
145
+ await handler(decoded || evt, ctx)
142
146
  processResults.push(ctx.getProcessResult())
143
147
  }
144
148
 
@@ -1,5 +1,5 @@
1
1
  export * from './move-types.js'
2
- export type { EventInstance, TypedEventInstance, TypedFunctionPayload, TypedMoveResource } from './models.js'
2
+ export type { TypedEventInstance, TypedFunctionPayload, TypedMoveResource } from './models.js'
3
3
  export { defaultMoveCoder, MoveCoder } from './move-coder.js'
4
4
  export { AptosBaseProcessor, AptosResourcesProcessor } from './aptos-processor.js'
5
5
  export { AptosContext, AptosResourcesContext } from './context.js'
@@ -1,11 +1,7 @@
1
1
  import { Event, MoveResource, TransactionPayload_EntryFunctionPayload } from './move-types.js'
2
2
  import { DecodedStruct } from '../move/types.js'
3
3
 
4
- export type EventInstance = Event & {
5
- version: string
6
- }
7
-
8
- export type TypedEventInstance<T> = DecodedStruct<EventInstance, T>
4
+ export type TypedEventInstance<T> = DecodedStruct<Event, T>
9
5
  export type TypedMoveResource<T> = DecodedStruct<MoveResource, T>
10
6
 
11
7
  // Don't use intermediate type to make IDE happier
@@ -35,16 +35,16 @@ export class MoveCoder extends AbstractMoveCoder<AptosNetwork, MoveModuleBytecod
35
35
  }
36
36
 
37
37
  decodeEvent<T>(event: Event): Promise<TypedEventInstance<T> | undefined> {
38
- return this.decodedStruct<T>(event) as any
38
+ return this.decodedStruct(event)
39
39
  }
40
40
  filterAndDecodeEvents<T>(type: string | TypeDescriptor<T>, resources: Event[]): Promise<TypedEventInstance<T>[]> {
41
41
  if (typeof type === 'string') {
42
42
  type = parseMoveType(type)
43
43
  }
44
- return this.filterAndDecodeStruct(type, resources) as any
44
+ return this.filterAndDecodeStruct(type, resources)
45
45
  }
46
46
  decodeResource<T>(res: MoveResource): Promise<TypedMoveResource<T> | undefined> {
47
- return this.decodedStruct<T>(res)
47
+ return this.decodedStruct(res)
48
48
  }
49
49
  filterAndDecodeResources<T>(
50
50
  type: string | TypeDescriptor<T>,
@@ -264,15 +264,15 @@ export abstract class AbstractMoveCoder<Network, ModuleType, StructType> {
264
264
  return this.decodeArray(res, f.return)
265
265
  }
266
266
 
267
- protected async filterAndDecodeStruct<T>(
267
+ protected async filterAndDecodeStruct<T, ST extends StructType>(
268
268
  typeMatcher: TypeDescriptor<T>,
269
- structsWithTags: StructType[]
270
- ): Promise<DecodedStruct<StructType, T>[]> {
269
+ structsWithTags: ST[]
270
+ ): Promise<DecodedStruct<ST, T>[]> {
271
271
  if (!structsWithTags) {
272
272
  return [] as any
273
273
  }
274
274
  // const typeMatcherDescriptor = parseMoveType(typeMatcher)
275
- const results: DecodedStruct<StructType, T>[] = []
275
+ const results: DecodedStruct<ST, T>[] = []
276
276
  for (const resource of structsWithTags) {
277
277
  const resourceType = this.adapter.getType(resource)
278
278
  const resourceTypeDescriptor = parseMoveType(resourceType)
@@ -280,7 +280,7 @@ export abstract class AbstractMoveCoder<Network, ModuleType, StructType> {
280
280
  continue
281
281
  }
282
282
 
283
- const result = await this.decodedStruct<T>(resource)
283
+ const result = await this.decodedStruct<T, ST>(resource)
284
284
  if (result) {
285
285
  results.push(result)
286
286
  } else {
@@ -290,7 +290,7 @@ export abstract class AbstractMoveCoder<Network, ModuleType, StructType> {
290
290
  return results
291
291
  }
292
292
 
293
- protected async decodedStruct<T>(typeStruct: StructType): Promise<DecodedStruct<StructType, T> | undefined> {
293
+ protected async decodedStruct<T, ST extends StructType>(typeStruct: ST): Promise<DecodedStruct<ST, T> | undefined> {
294
294
  const typeDescriptor = parseMoveType(this.adapter.getType(typeStruct))
295
295
  const typeArguments = typeDescriptor.typeArgs.map((t) => t.getSignature())
296
296
 
@@ -305,6 +305,6 @@ export abstract class AbstractMoveCoder<Network, ModuleType, StructType> {
305
305
  ...typeStruct,
306
306
  data_decoded: dataTyped,
307
307
  type_arguments: typeArguments,
308
- } as DecodedStruct<StructType, T>
308
+ }
309
309
  }
310
310
  }
@@ -41,13 +41,13 @@ export class MoveCoder extends AbstractMoveCoder<SuiNetwork, SuiMoveNormalizedMo
41
41
  }
42
42
 
43
43
  decodeEvent<T>(event: SuiEvent): Promise<TypedEventInstance<T> | undefined> {
44
- return this.decodedStruct<T>(event) as any
44
+ return this.decodedStruct(event)
45
45
  }
46
46
  filterAndDecodeEvents<T>(type: TypeDescriptor<T> | string, resources: SuiEvent[]): Promise<TypedEventInstance<T>[]> {
47
47
  if (typeof type === 'string') {
48
48
  type = parseMoveType(type)
49
49
  }
50
- return this.filterAndDecodeStruct(type, resources) as any
50
+ return this.filterAndDecodeStruct(type, resources)
51
51
  }
52
52
 
53
53
  async getDynamicFields<T1, T2>(
@@ -67,7 +67,7 @@ export class MoveCoder extends AbstractMoveCoder<SuiNetwork, SuiMoveNormalizedMo
67
67
  type: TypeDescriptor<T>,
68
68
  objects: SuiMoveObject[]
69
69
  ): Promise<DecodedStruct<SuiMoveObject, T>[]> {
70
- return this.filterAndDecodeStruct(type, objects) as any
70
+ return this.filterAndDecodeStruct(type, objects)
71
71
  }
72
72
 
73
73
  async decodeFunctionPayload(payload: MoveCallSuiTransaction, inputs: SuiCallArg[]): Promise<MoveCallSuiTransaction> {
@@ -37,7 +37,7 @@ export class SuiPlugin extends Plugin {
37
37
  address: validateAndNormalizeAddress(suiProcessor.config.address),
38
38
  abi: '',
39
39
  },
40
- startBlock: BigInt(suiProcessor.config.startTimestamp),
40
+ startBlock: suiProcessor.config.startCheckpoint,
41
41
  })
42
42
  for (const handler of suiProcessor.eventHandlers) {
43
43
  const handlerId = this.suiEventHandlers.push(handler.handler) - 1
@@ -76,7 +76,7 @@ export class SuiPlugin extends Plugin {
76
76
  const accountConfig = AccountConfig.fromPartial({
77
77
  address: validateAndNormalizeAddress(processor.config.address),
78
78
  chainId: processor.getChainId(),
79
- startBlock: BigInt(processor.config.startTimestamp), // TODO maybe use another field
79
+ startBlock: processor.config.startCheckpoint, // TODO maybe use another field
80
80
  })
81
81
  for (const handler of processor.objectHandlers) {
82
82
  const handlerId = this.suiObjectHandlers.push(handler.handler) - 1
@@ -33,19 +33,19 @@ const DEFAULT_FETCH_CONFIG: MoveFetchConfig = {
33
33
  class IndexConfigure {
34
34
  address: string
35
35
  network: SuiNetwork
36
- startTimestamp: number
36
+ startCheckpoint: bigint
37
37
  }
38
38
 
39
39
  export class SuiBindOptions {
40
40
  address: string
41
41
  network?: SuiNetwork
42
- startTimestamp?: number
42
+ startCheckpoint?: bigint
43
43
  }
44
44
 
45
45
  export class SuiObjectBindOptions {
46
46
  objectId: string
47
47
  network?: SuiNetwork
48
- startTimestamp?: number
48
+ startCheckpoint?: bigint
49
49
  }
50
50
 
51
51
  export class SuiProcessorState extends ListStateStorage<SuiBaseProcessor> {
@@ -285,7 +285,7 @@ abstract class SuiBaseObjectsProcessor<HandlerType> {
285
285
 
286
286
  function configure(options: SuiBindOptions): IndexConfigure {
287
287
  return {
288
- startTimestamp: options.startTimestamp || 0,
288
+ startCheckpoint: options.startCheckpoint || 0n,
289
289
  address: options.address,
290
290
  network: options.network || SuiNetwork.MAIN_NET,
291
291
  }
@@ -306,7 +306,7 @@ export class SuiDynamicFieldObjectsProcessor extends SuiBaseObjectsProcessor<Sui
306
306
  return new SuiDynamicFieldObjectsProcessor({
307
307
  address: options.objectId,
308
308
  network: options.network,
309
- startTimestamp: options.startTimestamp,
309
+ startCheckpoint: options.startCheckpoint,
310
310
  ownerType: MoveOnIntervalConfig_OwnerType.OBJECT,
311
311
  })
312
312
  }