@sentio/sdk 2.13.1-rc.1 → 2.13.2-rc.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,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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B,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 { 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;IA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;IAEM,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;QAC5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C,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<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,CA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,CAAA;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,OAA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G,MAAM,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,CAA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,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;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"]}
@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QAAQ,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;AAEl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../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(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"]}
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-rc.1",
4
+ "version": "2.13.2-rc.1",
5
5
  "type": "module",
6
6
  "scripts": {
7
7
  "compile": "tsc && cp src/utils/*.csv lib/utils && cp src/tsup.config.ts lib",
@@ -23,8 +23,8 @@
23
23
  "@project-serum/anchor": "^0.26.0",
24
24
  "@sentio/bigdecimal": "^9.1.1-patch.3",
25
25
  "@sentio/ethers-v6": "^1.0.28",
26
- "@sentio/protos": "^2.13.1-rc.1",
27
- "@sentio/runtime": "^2.13.1-rc.1",
26
+ "@sentio/protos": "^2.13.2-rc.1",
27
+ "@sentio/runtime": "^2.13.2-rc.1",
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": "22bf3f12b4a397091c58120cf4408c6ce9c673b0"
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> {