@sentio/sdk 2.13.6 → 2.13.7-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.
@@ -11,4 +11,5 @@ export declare class AptosChainAdapter extends ChainAdapter<AptosNetwork, MoveMo
11
11
  getEventStructs(module: InternalMoveModule): Map<string, InternalMoveStruct>;
12
12
  getType(data: Event | MoveResource): string;
13
13
  getData(data: Event | MoveResource): any;
14
+ validateAndNormalizeAddress(address: string): string;
14
15
  }
@@ -2,6 +2,7 @@ import { ChainAdapter, moduleQname, SPLITTER } from '../move/index.js';
2
2
  import { toInternalModule } from './move-types.js';
3
3
  import { AptosNetwork } from './network.js';
4
4
  import { AptosClient } from 'aptos-sdk';
5
+ import { validateAndNormalizeAddress } from './utils.js';
5
6
  class AptosChainAdapter extends ChainAdapter {
6
7
  static INSTANCE = new AptosChainAdapter();
7
8
  async fetchModules(account, network) {
@@ -54,6 +55,9 @@ class AptosChainAdapter extends ChainAdapter {
54
55
  }
55
56
  return data;
56
57
  }
58
+ validateAndNormalizeAddress(address) {
59
+ return validateAndNormalizeAddress(address);
60
+ }
57
61
  }
58
62
  export { AptosChainAdapter };
59
63
  function getRpcClient(network) {
@@ -1 +1 @@
1
- {"version":3,"file":"aptos-chain-adapter.js","sourceRoot":"","sources":["../../src/aptos/aptos-chain-adapter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,QAAQ,EAAkB,MAAM,kBAAkB,CAAA;AACtF,OAAO,EAA2C,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAC3F,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA;AAE3C,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAA;AAEvC,MAAa,iBAAkB,SAAQ,YAAoE;IACzG,MAAM,CAAC,QAAQ,GAAG,IAAI,iBAAiB,EAAE,CAAA;IAEzC,KAAK,CAAC,YAAY,CAAC,OAAe,EAAE,OAAq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IAAI,MAAM,CAAC,OAAO,EAAE;YACnC,KAAK,MAAM,KAAK,IAAI,MAAM,CAAC,MAAM,EAAE;gBACjC,MAAM,CAAC,GAAG,KAAK,CAAC,IAAI,CAAA;gBACpB,IAAI,CAAC,CAAC,KAAK,KAAK,yBAAyB,EAAE;oBACzC,MAAM,KAAK,GAAG,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,KAAK,CAAA;oBACjC,MAAM,WAAW,GAAG,SAAS,CAAC,GAAG,CAAC,KAAK,CAAC,CAAA;oBACxC,IAAI,WAAW,EAAE;wBACf,QAAQ,CAAC,GAAG,CAAC,KAAK,EAAE,WAAW,CAAC,CAAA;qBACjC;iBACF;aACF;SACF;QAED,OAAO,QAAQ,CAAA;IACjB,CAAC;IAED,OAAO,CAAC,IAA0B;QAChC,OAAO,IAAI,CAAC,IAAI,CAAA;IAClB,CAAC;IAED,OAAO,CAAC,IAA0B;QAChC,IAAI,MAAM,IAAI,IAAI,IAAI,MAAM,IAAI,IAAI,EAAE;YACpC,OAAO,IAAI,CAAC,IAAI,CAAA;SACjB;QACD,OAAO,IAAI,CAAA;IACb,CAAC;;SA7DU,iBAAiB;AAgE9B,SAAS,YAAY,CAAC,OAAqB;IACzC,OAAO,IAAI,WAAW,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC,CAAA;AACjD,CAAC;AAED,SAAS,cAAc,CAAC,OAAqB;IAC3C,QAAQ,OAAO,EAAE;QACf,KAAK,YAAY,CAAC,QAAQ;YACxB,OAAO,gCAAgC,CAAA;KAC1C;IACD,OAAO,gCAAgC,CAAA;AACzC,CAAC","sourcesContent":["import { ChainAdapter, moduleQname, SPLITTER, TypeDescriptor } from '../move/index.js'\nimport { Event, MoveModuleBytecode, MoveResource, toInternalModule } from './move-types.js'\nimport { AptosNetwork } from './network.js'\nimport { InternalMoveModule, InternalMoveStruct } from '../move/internal-models.js'\nimport { AptosClient } from 'aptos-sdk'\n\nexport class AptosChainAdapter extends ChainAdapter<AptosNetwork, MoveModuleBytecode, Event | MoveResource> {\n static INSTANCE = new AptosChainAdapter()\n\n async fetchModules(account: string, network: AptosNetwork): Promise<MoveModuleBytecode[]> {\n const client = getRpcClient(network)\n return await client.getAccountModules(account)\n }\n\n async fetchModule(account: string, module: string, network: AptosNetwork): Promise<MoveModuleBytecode> {\n const client = getRpcClient(network)\n return await client.getAccountModule(account, module)\n }\n\n toInternalModules(modules: MoveModuleBytecode[]): InternalMoveModule[] {\n return modules.flatMap((m) => (m.abi ? [toInternalModule(m)] : []))\n }\n\n getMeaningfulFunctionParams(params: TypeDescriptor[]): TypeDescriptor[] {\n if (params.length === 0) {\n return params\n }\n if (params[0].qname === 'signer' && params[0].reference) {\n params = params.slice(1)\n }\n return params\n }\n\n getEventStructs(module: InternalMoveModule) {\n const qname = moduleQname(module)\n const structMap = new Map<string, InternalMoveStruct>()\n const eventMap = new Map<string, InternalMoveStruct>()\n\n for (const struct of module.structs) {\n structMap.set(qname + SPLITTER + struct.name, struct)\n }\n\n for (const struct of module.structs) {\n for (const field of struct.fields) {\n const t = field.type\n if (t.qname === '0x1::event::EventHandle') {\n const event = t.typeArgs[0].qname\n const eventStruct = structMap.get(event)\n if (eventStruct) {\n eventMap.set(event, eventStruct)\n }\n }\n }\n }\n\n return eventMap\n }\n\n getType(data: Event | MoveResource): string {\n return data.type\n }\n\n getData(data: Event | MoveResource) {\n if ('data' in data && 'type' in data) {\n return data.data\n }\n return data\n }\n}\n\nfunction getRpcClient(network: AptosNetwork): AptosClient {\n return new AptosClient(getRpcEndpoint(network))\n}\n\nfunction getRpcEndpoint(network: AptosNetwork): string {\n switch (network) {\n case AptosNetwork.TEST_NET:\n return 'https://testnet.aptoslabs.com/'\n }\n return 'https://mainnet.aptoslabs.com/'\n}\n"]}
1
+ {"version":3,"file":"aptos-chain-adapter.js","sourceRoot":"","sources":["../../src/aptos/aptos-chain-adapter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,QAA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IAAI,WAAW,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC,CAAA;AACjD,CAAC;AAED,SAAS,cAAc,CAAC,OAAqB;IAC3C,QAAQ,OAAO,EAAE;QACf,KAAK,YAAY,CAAC,QAAQ;YACxB,OAAO,gCAAgC,CAAA;KAC1C;IACD,OAAO,gCAAgC,CAAA;AACzC,CAAC","sourcesContent":["import { ChainAdapter, moduleQname, SPLITTER, TypeDescriptor } from '../move/index.js'\nimport { Event, MoveModuleBytecode, MoveResource, toInternalModule } from './move-types.js'\nimport { AptosNetwork } from './network.js'\nimport { InternalMoveModule, InternalMoveStruct } from '../move/internal-models.js'\nimport { AptosClient } from 'aptos-sdk'\nimport { validateAndNormalizeAddress } from './utils.js'\n\nexport class AptosChainAdapter extends ChainAdapter<AptosNetwork, MoveModuleBytecode, Event | MoveResource> {\n static INSTANCE = new AptosChainAdapter()\n\n async fetchModules(account: string, network: AptosNetwork): Promise<MoveModuleBytecode[]> {\n const client = getRpcClient(network)\n return await client.getAccountModules(account)\n }\n\n async fetchModule(account: string, module: string, network: AptosNetwork): Promise<MoveModuleBytecode> {\n const client = getRpcClient(network)\n return await client.getAccountModule(account, module)\n }\n\n toInternalModules(modules: MoveModuleBytecode[]): InternalMoveModule[] {\n return modules.flatMap((m) => (m.abi ? [toInternalModule(m)] : []))\n }\n\n getMeaningfulFunctionParams(params: TypeDescriptor[]): TypeDescriptor[] {\n if (params.length === 0) {\n return params\n }\n if (params[0].qname === 'signer' && params[0].reference) {\n params = params.slice(1)\n }\n return params\n }\n\n getEventStructs(module: InternalMoveModule) {\n const qname = moduleQname(module)\n const structMap = new Map<string, InternalMoveStruct>()\n const eventMap = new Map<string, InternalMoveStruct>()\n\n for (const struct of module.structs) {\n structMap.set(qname + SPLITTER + struct.name, struct)\n }\n\n for (const struct of module.structs) {\n for (const field of struct.fields) {\n const t = field.type\n if (t.qname === '0x1::event::EventHandle') {\n const event = t.typeArgs[0].qname\n const eventStruct = structMap.get(event)\n if (eventStruct) {\n eventMap.set(event, eventStruct)\n }\n }\n }\n }\n\n return eventMap\n }\n\n getType(data: Event | MoveResource): string {\n return data.type\n }\n\n getData(data: Event | MoveResource) {\n if ('data' in data && 'type' in data) {\n return data.data\n }\n return data\n }\n validateAndNormalizeAddress(address: string): string {\n return validateAndNormalizeAddress(address)\n }\n}\n\nfunction getRpcClient(network: AptosNetwork): AptosClient {\n return new AptosClient(getRpcEndpoint(network))\n}\n\nfunction getRpcEndpoint(network: AptosNetwork): string {\n switch (network) {\n case AptosNetwork.TEST_NET:\n return 'https://testnet.aptoslabs.com/'\n }\n return 'https://mainnet.aptoslabs.com/'\n}\n"]}
@@ -14,20 +14,21 @@ export class AbstractMoveCoder {
14
14
  return this.moduleMapping.has(account + '::' + name);
15
15
  }
16
16
  loadInternal(module) {
17
- if (this.contains(module.address, module.name)) {
17
+ const account = this.adapter.validateAndNormalizeAddress(module.address);
18
+ if (this.contains(account, module.name)) {
18
19
  return;
19
20
  }
20
- this.moduleMapping.set(moduleQname(module), module);
21
+ this.moduleMapping.set(moduleQname({ address: account, name: module.name }), module);
21
22
  for (const struct of module.structs) {
22
23
  // TODO move to util
23
- const key = [module.address, module.name, struct.name].join(SPLITTER);
24
+ const key = [account, module.name, struct.name].join(SPLITTER);
24
25
  this.typeMapping.set(key, struct);
25
26
  }
26
27
  for (const func of module.exposedFunctions) {
27
28
  // if (!func.isEntry) {
28
29
  // continue
29
30
  // }
30
- const key = [module.address, module.name, func.name].join(SPLITTER);
31
+ const key = [account, module.name, func.name].join(SPLITTER);
31
32
  this.funcMapping.set(key, func);
32
33
  }
33
34
  }
@@ -46,11 +47,13 @@ export class AbstractMoveCoder {
46
47
  }
47
48
  requestMap = new Map();
48
49
  async getMoveStruct(type) {
50
+ const [account_, module, typeName] = type.split(SPLITTER);
51
+ const account = this.adapter.validateAndNormalizeAddress(account_);
52
+ type = [account, module, typeName].join(SPLITTER);
49
53
  let struct = this.typeMapping.get(type);
50
54
  if (struct) {
51
55
  return struct;
52
56
  }
53
- const [account, module, typeName] = type.split(SPLITTER);
54
57
  const key = account + SPLITTER + module;
55
58
  let resp = this.requestMap.get(account + SPLITTER + module);
56
59
  if (!resp) {
@@ -67,11 +70,13 @@ export class AbstractMoveCoder {
67
70
  throw new Error('Failed to load function ' + type + ' type are not imported anywhere');
68
71
  }
69
72
  async getMoveFunction(type) {
73
+ const [account_, module, typeName] = type.split(SPLITTER);
74
+ const account = this.adapter.validateAndNormalizeAddress(account_);
75
+ type = [account, module, typeName].join(SPLITTER);
70
76
  let func = this.funcMapping.get(type);
71
77
  if (func) {
72
78
  return func;
73
79
  }
74
- const [account, module, typeName] = type.split(SPLITTER);
75
80
  const key = account + SPLITTER + module;
76
81
  let resp = this.requestMap.get(account + SPLITTER + module);
77
82
  if (!resp) {
@@ -1 +1 @@
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,CAAA;IACtD,CAAC;IAIS,YAAY,CAAC,MAA0B;QAC/C,IAAI,IAAI,C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AAE;YACV,MAAM,KAAK,CAAC,2BAA2B,GAAG,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAA;YACpF,mBAAmB;SACpB;QACD,OAAO;YACL,GAAG,UAAU;YACb,YAAY,EAAE,SAAS;YACvB,cAAc,EAAE,aAAa;SAC9B,CAAA;IACH,CAAC;IACD,KAAK,CAAC,WAAW,CAAQ,UAAc,EAAE,IAAuB;QAC9D,IAAI,UAAU,KAAK,IAAI,IAAI,UAAU,IAAI,SAAS,EAAE;YAClD,OAAO,UAAiB,CAAA;SACzB;QACD,IAAI,OAAO,UAAU,KAAK,QAAQ,EAAE;YAClC,IAAI,MAAM,IAAI,UAAU,EAAE;gBACxB,MAAM,YAAY,GAAG,aAAa,CAAE,UAAU,CAAC,IAAY,CAAC,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAA;gBAC7E,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,YAAY,CAAC,EAAE;oBAClC,OAAO,SAAS,CAAA;iBACjB;aACF;SACF;QAED,OAAO,MAAM,IAAI,CAAC,MAAM,CAAC,UAAU,EAAE,IAAI,CAAC,CAAA;IAC5C,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 protected async decode<T>(data: any, type: TypeDescriptor<T>): Promise<T> {\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) as any\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 as any\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 protected 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 throw Error('Decoding error for ' + JSON.stringify(arg) + 'using type' + argType + e.toString())\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 throw Error('Decoding error for struct' + JSON.stringify(typeStruct) + e.toString())\n // return undefined\n }\n return {\n ...typeStruct,\n data_decoded: dataTyped,\n type_arguments: typeArguments,\n }\n }\n async decodedType<T, ST>(typeStruct: ST, type: TypeDescriptor<T>): Promise<T | undefined> {\n if (typeStruct === null || typeStruct == undefined) {\n return typeStruct as any\n }\n if (typeof typeStruct === 'object') {\n if ('type' in typeStruct) {\n const typeInStruct = parseMoveType((typeStruct.type as any).toString() || '')\n if (!matchType(type, typeInStruct)) {\n return undefined\n }\n }\n }\n\n return await this.decode(typeStruct, type)\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,O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EAAE,CAAC,CAAA;gBAC7E,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,YAAY,CAAC,EAAE;oBAClC,OAAO,SAAS,CAAA;iBACjB;aACF;SACF;QAED,OAAO,MAAM,IAAI,CAAC,MAAM,CAAC,UAAU,EAAE,IAAI,CAAC,CAAA;IAC5C,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 const account = this.adapter.validateAndNormalizeAddress(module.address)\n if (this.contains(account, module.name)) {\n return\n }\n this.moduleMapping.set(moduleQname({ address: account, name: module.name }), module)\n\n for (const struct of module.structs) {\n // TODO move to util\n const key = [account, 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 = [account, 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 const [account_, module, typeName] = type.split(SPLITTER)\n const account = this.adapter.validateAndNormalizeAddress(account_)\n type = [account, module, typeName].join(SPLITTER)\n\n let struct = this.typeMapping.get(type)\n if (struct) {\n return struct\n }\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 const [account_, module, typeName] = type.split(SPLITTER)\n const account = this.adapter.validateAndNormalizeAddress(account_)\n type = [account, module, typeName].join(SPLITTER)\n\n let func = this.funcMapping.get(type)\n if (func) {\n return func\n }\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 protected async decode<T>(data: any, type: TypeDescriptor<T>): Promise<T> {\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) as any\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 as any\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 protected 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 throw Error('Decoding error for ' + JSON.stringify(arg) + 'using type' + argType + e.toString())\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 throw Error('Decoding error for struct' + JSON.stringify(typeStruct) + e.toString())\n // return undefined\n }\n return {\n ...typeStruct,\n data_decoded: dataTyped,\n type_arguments: typeArguments,\n }\n }\n async decodedType<T, ST>(typeStruct: ST, type: TypeDescriptor<T>): Promise<T | undefined> {\n if (typeStruct === null || typeStruct == undefined) {\n return typeStruct as any\n }\n if (typeof typeStruct === 'object') {\n if ('type' in typeStruct) {\n const typeInStruct = parseMoveType((typeStruct.type as any).toString() || '')\n if (!matchType(type, typeInStruct)) {\n return undefined\n }\n }\n }\n\n return await this.decode(typeStruct, type)\n }\n}\n"]}
@@ -8,4 +8,5 @@ export declare abstract class ChainAdapter<NetworkType, ModuleType, StructType>
8
8
  abstract getMeaningfulFunctionParams(params: TypeDescriptor[]): TypeDescriptor[];
9
9
  abstract getType(base: StructType): string;
10
10
  abstract getData<T>(base: StructType): any;
11
+ abstract validateAndNormalizeAddress(address: string): string;
11
12
  }
@@ -1 +1 @@
1
- {"version":3,"file":"chain-adapter.js","sourceRoot":"","sources":["../../src/move/chain-adapter.ts"],"names":[],"mappings":"AAGA,MAAM,OAAgB,YAAY;CAajC","sourcesContent":["import { InternalMoveModule, InternalMoveStruct } from './internal-models.js'\nimport { TypeDescriptor } from './types.js'\n\nexport abstract class ChainAdapter<NetworkType, ModuleType, StructType> {\n abstract fetchModule(account: string, module: string, network: NetworkType): Promise<ModuleType>\n\n abstract fetchModules(account: string, network: NetworkType): Promise<ModuleType[]>\n abstract toInternalModules(modules: ModuleType[]): InternalMoveModule[]\n // Get the structs that represent Events\n abstract getEventStructs(module: InternalMoveModule): Map<string, InternalMoveStruct>\n // Get the parameters that actually have arguments in runtime\n // Aptos first signer and Sui's last TxContext are no use\n abstract getMeaningfulFunctionParams(params: TypeDescriptor[]): TypeDescriptor[]\n\n abstract getType(base: StructType): string\n abstract getData<T>(base: StructType): any\n}\n"]}
1
+ {"version":3,"file":"chain-adapter.js","sourceRoot":"","sources":["../../src/move/chain-adapter.ts"],"names":[],"mappings":"AAGA,MAAM,OAAgB,YAAY;CAcjC","sourcesContent":["import { InternalMoveModule, InternalMoveStruct } from './internal-models.js'\nimport { TypeDescriptor } from './types.js'\n\nexport abstract class ChainAdapter<NetworkType, ModuleType, StructType> {\n abstract fetchModule(account: string, module: string, network: NetworkType): Promise<ModuleType>\n\n abstract fetchModules(account: string, network: NetworkType): Promise<ModuleType[]>\n abstract toInternalModules(modules: ModuleType[]): InternalMoveModule[]\n // Get the structs that represent Events\n abstract getEventStructs(module: InternalMoveModule): Map<string, InternalMoveStruct>\n // Get the parameters that actually have arguments in runtime\n // Aptos first signer and Sui's last TxContext are no use\n abstract getMeaningfulFunctionParams(params: TypeDescriptor[]): TypeDescriptor[]\n\n abstract getType(base: StructType): string\n abstract getData<T>(base: StructType): any\n abstract validateAndNormalizeAddress(address: string): string\n}\n"]}
package/lib/move/utils.js CHANGED
@@ -1,4 +1,3 @@
1
- import { parseInt } from 'lodash-es';
2
1
  export const SPLITTER = '::';
3
2
  export const VECTOR_STR = 'vector';
4
3
  export function isFrameworkAccount(account) {
@@ -1 +1 @@
1
- {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/move/utils.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAA;AAEpC,MAAM,CAAC,MAAM,QAAQ,GAAG,IAAI,CAAA;AAE5B,MAAM,CAAC,MAAM,UAAU,GAAG,QAAQ,CAAA;AAElC,MAAM,UAAU,kBAAkB,CAAC,OAAe;IAChD,MAAM,CAAC,GAAG,QAAQ,CAAC,OAAO,EAAE,EAAE,CAAC,CAAA;IAC/B,IAAI,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE;QACnB,OAAO,KAAK,CAAA;KACb;IACD,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,CAAA;AACzB,CAAC;AAED,MAAM,QAAQ,GAAG,IAAI,GAAG,CAAC,CAAC,SAAS,EAAE,WAAW,EAAE,UAAU,EAAE,QAAQ,EAAE,QAAQ,EAAE,QAAQ,EAAE,QAAQ,EAAE,KAAK,CAAC,CAAC,CAAA;AAE7G,MAAM,UAAU,iBAAiB,CAAC,IAAY;IAC5C,IAAI,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE;QACtB,OAAO,IAAI,GAAG,GAAG,CAAA;KAClB;IACD,OAAO,IAAI,CAAA;AACb,CAAC;AAED,MAAM,UAAU,kBAAkB,CAAC,IAAY;IAC7C,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAA;IAC9C,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,CAAA;AAC7B,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,MAAyC;IACnE,OAAO,MAAM,CAAC,OAAO,CAAC,WAAW,EAAE,GAAG,QAAQ,GAAG,MAAM,CAAC,IAAI,CAAA;AAC9D,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,MAA0B,EAAE,MAA0B;IAChF,OAAO,CAAC,MAAM,CAAC,OAAO,EAAE,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;AAClE,CAAC","sourcesContent":["import { InternalMoveModule, InternalMoveStruct } from './internal-models.js'\nimport { parseInt } from 'lodash-es'\n\nexport const SPLITTER = '::'\n\nexport const VECTOR_STR = 'vector'\n\nexport function isFrameworkAccount(account: string) {\n const n = parseInt(account, 16)\n if (Number.isNaN(n)) {\n return false\n }\n return n >= 0 && n < 16\n}\n\nconst KEYWORDS = new Set(['package', 'namespace', 'volatile', 'object', 'string', 'number', 'bigint', 'any'])\n\nexport function normalizeToJSName(name: string) {\n if (KEYWORDS.has(name)) {\n return name + '_'\n }\n return name\n}\n\nexport function moduleQnameForType(type: string): [string, string] {\n const parts = type.split(SPLITTER).slice(0, 2)\n return [parts[0], parts[1]]\n}\n\nexport function moduleQname(module: { address: string; name: string }): string {\n return module.address.toLowerCase() + SPLITTER + module.name\n}\n\nexport function structQname(module: InternalMoveModule, struct: InternalMoveStruct): string {\n return [module.address, module.name, struct.name].join(SPLITTER)\n}\n"]}
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/move/utils.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,QAAQ,GAAG,IAAI,CAAA;AAE5B,MAAM,CAAC,MAAM,UAAU,GAAG,QAAQ,CAAA;AAElC,MAAM,UAAU,kBAAkB,CAAC,OAAe;IAChD,MAAM,CAAC,GAAG,QAAQ,CAAC,OAAO,EAAE,EAAE,CAAC,CAAA;IAC/B,IAAI,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE;QACnB,OAAO,KAAK,CAAA;KACb;IACD,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,CAAA;AACzB,CAAC;AAED,MAAM,QAAQ,GAAG,IAAI,GAAG,CAAC,CAAC,SAAS,EAAE,WAAW,EAAE,UAAU,EAAE,QAAQ,EAAE,QAAQ,EAAE,QAAQ,EAAE,QAAQ,EAAE,KAAK,CAAC,CAAC,CAAA;AAE7G,MAAM,UAAU,iBAAiB,CAAC,IAAY;IAC5C,IAAI,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE;QACtB,OAAO,IAAI,GAAG,GAAG,CAAA;KAClB;IACD,OAAO,IAAI,CAAA;AACb,CAAC;AAED,MAAM,UAAU,kBAAkB,CAAC,IAAY;IAC7C,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAA;IAC9C,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,CAAA;AAC7B,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,MAAyC;IACnE,OAAO,MAAM,CAAC,OAAO,CAAC,WAAW,EAAE,GAAG,QAAQ,GAAG,MAAM,CAAC,IAAI,CAAA;AAC9D,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,MAA0B,EAAE,MAA0B;IAChF,OAAO,CAAC,MAAM,CAAC,OAAO,EAAE,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;AAClE,CAAC","sourcesContent":["import { InternalMoveModule, InternalMoveStruct } from './internal-models.js'\n\nexport const SPLITTER = '::'\n\nexport const VECTOR_STR = 'vector'\n\nexport function isFrameworkAccount(account: string) {\n const n = parseInt(account, 16)\n if (Number.isNaN(n)) {\n return false\n }\n return n >= 0 && n < 16\n}\n\nconst KEYWORDS = new Set(['package', 'namespace', 'volatile', 'object', 'string', 'number', 'bigint', 'any'])\n\nexport function normalizeToJSName(name: string) {\n if (KEYWORDS.has(name)) {\n return name + '_'\n }\n return name\n}\n\nexport function moduleQnameForType(type: string): [string, string] {\n const parts = type.split(SPLITTER).slice(0, 2)\n return [parts[0], parts[1]]\n}\n\nexport function moduleQname(module: { address: string; name: string }): string {\n return module.address.toLowerCase() + SPLITTER + module.name\n}\n\nexport function structQname(module: InternalMoveModule, struct: InternalMoveStruct): string {\n return [module.address, module.name, struct.name].join(SPLITTER)\n}\n"]}
@@ -11,4 +11,5 @@ export declare class SuiChainAdapter extends ChainAdapter<SuiNetwork, SuiMoveNor
11
11
  getEventStructs(module: InternalMoveModule): Map<string, InternalMoveStruct>;
12
12
  getType(base: SuiEvent | SuiMoveObject): string;
13
13
  getData(val: SuiEvent | SuiMoveObject): any;
14
+ validateAndNormalizeAddress(address: string): string;
14
15
  }
@@ -2,6 +2,7 @@ import { ChainAdapter, moduleQname, SPLITTER } from '../move/index.js';
2
2
  import { toInternalModule } from './move-types.js';
3
3
  import { SuiNetwork } from './network.js';
4
4
  import { Connection, JsonRpcProvider, SuiEvent, SuiParsedData, } from '@mysten/sui.js';
5
+ import { validateAndNormalizeAddress } from './utils.js';
5
6
  class SuiChainAdapter extends ChainAdapter {
6
7
  static INSTANCE = new SuiChainAdapter();
7
8
  async fetchModule(account, module, network) {
@@ -55,6 +56,9 @@ class SuiChainAdapter extends ChainAdapter {
55
56
  }
56
57
  return val;
57
58
  }
59
+ validateAndNormalizeAddress(address) {
60
+ return validateAndNormalizeAddress(address);
61
+ }
58
62
  }
59
63
  export { SuiChainAdapter };
60
64
  function getRpcEndpoint(network) {
@@ -1 +1 @@
1
- {"version":3,"file":"sui-chain-adapter.js","sourceRoot":"","sources":["../../src/sui/sui-chain-adapter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,QAAQ,EAAkB,MAAM,kBAAkB,CAAA;AACtF,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAClD,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AAEzC,OAAO,EACL,UAAU,EACV,eAAe,EAEf,QAAQ,EAER,aAAa,GACd,MAAM,gBAAgB,CAAA;AAEvB,MAAa,eAAgB,SAAQ,YAA2E;IAC9G,MAAM,CAAC,QAAQ,GAAG,IAAI,eAAe,EAAE,CAAA;IAEvC,KAAK,CAAC,WAAW,CAAC,OAAe,EAAE,MAAc,EAAE,OAAmB;QACpE,MAAM,MAAM,GAAG,YAAY,CAAC,OAAO,CAAC,CAAA;QACpC,OAAO,MAAM,MAAM,CAAC,uBAAuB,CAAC,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC,CAAA;IAC3E,CAAC;IAED,KAAK,CAAC,YAAY,CAAC,OAAe,EAAE,OAAmB;QACrD,MAAM,MAAM,GAAG,YAAY,CAAC,OAAO,CAAC,CAAA;QACpC,MAAM,OAAO,GAAG,MAAM,MAAM,CAAC,iCAAiC,CAAC,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC,CAAA;QACpF,OAAO,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAA;IAC/B,CAAC;IAED,2BAA2B,CAAC,MAAw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,MAAa,CAAA;aACzB;SACF;QACD,OAAO,GAAU,CAAA;IACnB,CAAC;;SA5DU,eAAe;AA+D5B,SAAS,cAAc,CAAC,OAAmB;IACzC,QAAQ,OAAO,EAAE;QACf,KAAK,UAAU,CAAC,QAAQ;YACtB,OAAO,kCAAkC,CAAA;KAC5C;IACD,OAAO,kCAAkC,CAAA;AAC3C,CAAC;AAED,SAAS,YAAY,CAAC,OAAmB;IACvC,OAAO,IAAI,eAAe,CAAC,IAAI,UAAU,CAAC,EAAE,QAAQ,EAAE,cAAc,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,CAAA;AACnF,CAAC","sourcesContent":["import { ChainAdapter, moduleQname, SPLITTER, TypeDescriptor } from '../move/index.js'\nimport { toInternalModule } from './move-types.js'\nimport { SuiNetwork } from './network.js'\nimport { InternalMoveModule, InternalMoveStruct } from '../move/internal-models.js'\nimport {\n Connection,\n JsonRpcProvider,\n SuiMoveNormalizedModule,\n SuiEvent,\n SuiMoveObject,\n SuiParsedData,\n} from '@mysten/sui.js'\n\nexport class SuiChainAdapter extends ChainAdapter<SuiNetwork, SuiMoveNormalizedModule, SuiEvent | SuiMoveObject> {\n static INSTANCE = new SuiChainAdapter()\n\n async fetchModule(account: string, module: string, network: SuiNetwork): Promise<SuiMoveNormalizedModule> {\n const client = getRpcClient(network)\n return await client.getNormalizedMoveModule({ package: account, module })\n }\n\n async fetchModules(account: string, network: SuiNetwork): Promise<SuiMoveNormalizedModule[]> {\n const client = getRpcClient(network)\n const modules = await client.getNormalizedMoveModulesByPackage({ package: account })\n return Object.values(modules)\n }\n\n getMeaningfulFunctionParams(params: TypeDescriptor[]): TypeDescriptor[] {\n return params\n // if (params.length === 0) {\n // return params\n // }\n // return params.slice(0, params.length - 1)\n }\n\n toInternalModules(modules: SuiMoveNormalizedModule[]): InternalMoveModule[] {\n return Object.values(modules).map(toInternalModule)\n }\n\n getEventStructs(module: InternalMoveModule) {\n const qname = moduleQname(module)\n const eventMap = new Map<string, InternalMoveStruct>()\n\n for (const struct of module.structs) {\n const abilities = new Set(struct.abilities)\n if (abilities.has('Drop') && abilities.has('Copy')) {\n eventMap.set(qname + SPLITTER + struct.name, struct)\n }\n }\n return eventMap\n }\n\n getType(base: SuiEvent | SuiMoveObject): string {\n return base.type\n }\n\n getData(val: SuiEvent | SuiMoveObject) {\n if (SuiEvent.is(val)) {\n return val.parsedJson as any\n }\n if (SuiParsedData.is(val)) {\n return val.fields as any\n }\n // if (SuiMoveObject.is(val)) {\n // return val.fields as any\n // }\n // This may not be perfect, just think everything has\n if ('fields' in val) {\n if ('type' in val && Object.keys(val).length === 2) {\n return val.fields as any\n }\n }\n return val as any\n }\n}\n\nfunction getRpcEndpoint(network: SuiNetwork): string {\n switch (network) {\n case SuiNetwork.TEST_NET:\n return 'https://fullnode.testnet.sui.io/'\n }\n return 'https://fullnode.mainnet.sui.io/'\n}\n\nfunction getRpcClient(network: SuiNetwork): JsonRpcProvider {\n return new JsonRpcProvider(new Connection({ fullnode: getRpcEndpoint(network) }))\n}\n"]}
1
+ {"version":3,"file":"sui-chain-adapter.js","sourceRoot":"","sources":["../../src/sui/sui-chain-adapter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,QAAQ,EAAkB,MAAM,kBAAkB,CAAA;AACtF,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAClD,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AAEzC,OAAO,EACL,UAAU,EACV,eAAe,EAEf,QAAQ,EAER,aAAa,GACd,MAAM,gBAAgB,CAAA;AACvB,OAAO,EAAE,2BAA2B,EAAE,MAAM,YAAY,CAAA;AAExD,MAAa,eAAgB,SAAQ,YAA2E;IAC9G,MAAM,CAAC,QAAQ,GAAG,IAAI,eAAe,EAAE,CAAA;IAEvC,KAAK,CAAC,WAAW,CAAC,OAAe,EAAE,MAAc,EAAE,OAAmB;QACpE,MAAM,MAAM,GAAG,YAAY,CAAC,O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AA6B;QACnC,IAAI,QAAQ,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE;YACpB,OAAO,GAAG,CAAC,UAAiB,CAAA;SAC7B;QACD,IAAI,aAAa,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE;YACzB,OAAO,GAAG,CAAC,MAAa,CAAA;SACzB;QACD,+BAA+B;QAC/B,6BAA6B;QAC7B,IAAI;QACJ,qDAAqD;QACrD,IAAI,QAAQ,IAAI,GAAG,EAAE;YACnB,IAAI,MAAM,IAAI,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,MAAM,KAAK,CAAC,EAAE;gBAClD,OAAO,GAAG,CAAC,MAAa,CAAA;aACzB;SACF;QACD,OAAO,GAAU,CAAA;IACnB,CAAC;IACD,2BAA2B,CAAC,OAAe;QACzC,OAAO,2BAA2B,CAAC,OAAO,CAAC,CAAA;IAC7C,CAAC;;SA/DU,eAAe;AAkE5B,SAAS,cAAc,CAAC,OAAmB;IACzC,QAAQ,OAAO,EAAE;QACf,KAAK,UAAU,CAAC,QAAQ;YACtB,OAAO,kCAAkC,CAAA;KAC5C;IACD,OAAO,kCAAkC,CAAA;AAC3C,CAAC;AAED,SAAS,YAAY,CAAC,OAAmB;IACvC,OAAO,IAAI,eAAe,CAAC,IAAI,UAAU,CAAC,EAAE,QAAQ,EAAE,cAAc,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,CAAA;AACnF,CAAC","sourcesContent":["import { ChainAdapter, moduleQname, SPLITTER, TypeDescriptor } from '../move/index.js'\nimport { toInternalModule } from './move-types.js'\nimport { SuiNetwork } from './network.js'\nimport { InternalMoveModule, InternalMoveStruct } from '../move/internal-models.js'\nimport {\n Connection,\n JsonRpcProvider,\n SuiMoveNormalizedModule,\n SuiEvent,\n SuiMoveObject,\n SuiParsedData,\n} from '@mysten/sui.js'\nimport { validateAndNormalizeAddress } from './utils.js'\n\nexport class SuiChainAdapter extends ChainAdapter<SuiNetwork, SuiMoveNormalizedModule, SuiEvent | SuiMoveObject> {\n static INSTANCE = new SuiChainAdapter()\n\n async fetchModule(account: string, module: string, network: SuiNetwork): Promise<SuiMoveNormalizedModule> {\n const client = getRpcClient(network)\n return await client.getNormalizedMoveModule({ package: account, module })\n }\n\n async fetchModules(account: string, network: SuiNetwork): Promise<SuiMoveNormalizedModule[]> {\n const client = getRpcClient(network)\n const modules = await client.getNormalizedMoveModulesByPackage({ package: account })\n return Object.values(modules)\n }\n\n getMeaningfulFunctionParams(params: TypeDescriptor[]): TypeDescriptor[] {\n return params\n // if (params.length === 0) {\n // return params\n // }\n // return params.slice(0, params.length - 1)\n }\n\n toInternalModules(modules: SuiMoveNormalizedModule[]): InternalMoveModule[] {\n return Object.values(modules).map(toInternalModule)\n }\n\n getEventStructs(module: InternalMoveModule) {\n const qname = moduleQname(module)\n const eventMap = new Map<string, InternalMoveStruct>()\n\n for (const struct of module.structs) {\n const abilities = new Set(struct.abilities)\n if (abilities.has('Drop') && abilities.has('Copy')) {\n eventMap.set(qname + SPLITTER + struct.name, struct)\n }\n }\n return eventMap\n }\n\n getType(base: SuiEvent | SuiMoveObject): string {\n return base.type\n }\n\n getData(val: SuiEvent | SuiMoveObject) {\n if (SuiEvent.is(val)) {\n return val.parsedJson as any\n }\n if (SuiParsedData.is(val)) {\n return val.fields as any\n }\n // if (SuiMoveObject.is(val)) {\n // return val.fields as any\n // }\n // This may not be perfect, just think everything has\n if ('fields' in val) {\n if ('type' in val && Object.keys(val).length === 2) {\n return val.fields as any\n }\n }\n return val as any\n }\n validateAndNormalizeAddress(address: string) {\n return validateAndNormalizeAddress(address)\n }\n}\n\nfunction getRpcEndpoint(network: SuiNetwork): string {\n switch (network) {\n case SuiNetwork.TEST_NET:\n return 'https://fullnode.testnet.sui.io/'\n }\n return 'https://fullnode.mainnet.sui.io/'\n}\n\nfunction getRpcClient(network: SuiNetwork): JsonRpcProvider {\n return new JsonRpcProvider(new Connection({ fullnode: getRpcEndpoint(network) }))\n}\n"]}
package/lib/sui/utils.js CHANGED
@@ -1,6 +1,5 @@
1
1
  import { getTransactionKind, getProgrammableTransaction, normalizeSuiAddress, SUI_ADDRESS_LENGTH, } from '@mysten/sui.js';
2
2
  import { isFrameworkAccount } from '../move/index.js';
3
- import { parseInt } from 'lodash-es';
4
3
  export function getMoveCalls(txBlock) {
5
4
  const txKind = getTransactionKind(txBlock);
6
5
  if (!txKind) {
@@ -1 +1 @@
1
- {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/sui/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,kBAAkB,EAClB,0BAA0B,EAG1B,mBAAmB,EACnB,kBAAkB,GAEnB,MAAM,gBAAgB,CAAA;AACvB,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAA;AACrD,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAA;AAEpC,MAAM,UAAU,YAAY,CAAC,OAAoC;IAC/D,MAAM,MAAM,GAAG,kBAAkB,CAAC,OAAO,CAAC,CAAA;IAC1C,IAAI,CAAC,MAAM,EAAE;QACX,OAAO,EAAE,CAAA;KACV;IACD,MAAM,cAAc,GAAwC,0BAA0B,CAAC,MAAM,CAAC,CAAA;IAC9F,IAAI,CAAC,cAAc,EAAE;QACnB,OAAO,EAAE,CAAA;KACV;IAED,OAAO,cAAc,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC,EAAkB,EAAE,EAAE;QAChE,IAAI,UAAU,IAAI,EAAE,EAAE;YACpB,MAAM,IAAI,GAAG,EAAE,CAAC,QAAkC,CAAA;YAElD,IAAI,GAAG,GAAW,IAAI,CAAC,OAAO,CAAA;YAC9B,IAAI,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,mEAAmE,CAAC,EAAE;gBAChG,GAAG,GAAG,IAAI,GAAG,GAAG,CAAC,GAAG,CAAC,MAAM,GAAG,CAAC,CAAC,CAAA;aACjC;YACD,IAAI,CAAC,OAAO,GAAG,GAAG,CAAA;YAElB,OAAO,CAAC,IAAI,CAAC,CAAA;SACd;QACD,OAAO,EAAE,CAAA;IACX,CAAC,CAAC,CAAA;AACJ,CAAC;AAED,SAAS,KAAK,CAAC,KAAa;IAC1B,OAAO,wBAAwB,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;AAC7C,CAAC;AAED,SAAS,gBAAgB,CAAC,KAAa;IACrC,OAAO,UAAU,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAA;AAC3E,CAAC;AAED,MAAM,UAAU,iBAAiB,CAAC,KAAa;IAC7C,OAAO,KAAK,CAAC,KAAK,CAAC,IAAI,gBAAgB,CAAC,KAAK,CAAC,IAAI,kBAAkB,CAAA;AACtE,CAAC;AAED,MAAM,UAAU,2BAA2B,CAAC,OAAe;IACzD,IAAI,kBAAkB,CAAC,OAAO,CAAC,EAAE;QAC/B,MAAM,CAAC,GAAG,QAAQ,CAAC,OAAO,EAAE,EAAE,CAAC,CAAA;QAC/B,OAAO,KAAK,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,EAAE,CAAA;KAC7B;IACD,IAAI,CAAC,iBAAiB,CAAC,OAAO,CAAC,EAAE;QAC/B,MAAM,KAAK,CAAC,mBAAmB,CAAC,CAAA;KACjC;IACD,OAAO,mBAAmB,CAAC,OAAO,CAAC,CAAA;AACrC,CAAC","sourcesContent":["import {\n SuiTransactionBlockResponse,\n MoveCallSuiTransaction,\n getTransactionKind,\n getProgrammableTransaction,\n ProgrammableTransaction,\n SuiTransaction,\n normalizeSuiAddress,\n SUI_ADDRESS_LENGTH,\n SuiAddress,\n} from '@mysten/sui.js'\nimport { isFrameworkAccount } from '../move/index.js'\nimport { parseInt } from 'lodash-es'\n\nexport function getMoveCalls(txBlock: SuiTransactionBlockResponse) {\n const txKind = getTransactionKind(txBlock)\n if (!txKind) {\n return []\n }\n const programmableTx: ProgrammableTransaction | undefined = getProgrammableTransaction(txKind)\n if (!programmableTx) {\n return []\n }\n\n return programmableTx.transactions.flatMap((tx: SuiTransaction) => {\n if ('MoveCall' in tx) {\n const call = tx.MoveCall as MoveCallSuiTransaction\n\n let pkg: string = call.package\n if (call.package.startsWith('0x000000000000000000000000000000000000000000000000000000000000000')) {\n pkg = '0x' + pkg[pkg.length - 1]\n }\n call.package = pkg\n\n return [call]\n }\n return []\n })\n}\n\nfunction isHex(value: string): boolean {\n return /^(0x|0X)?[a-fA-F0-9]+$/.test(value)\n}\n\nfunction getHexByteLength(value: string): number {\n return /^(0x|0X)/.test(value) ? (value.length - 2) / 2 : value.length / 2\n}\n\nexport function isValidSuiAddress(value: string): value is SuiAddress {\n return isHex(value) && getHexByteLength(value) <= SUI_ADDRESS_LENGTH\n}\n\nexport function validateAndNormalizeAddress(address: string): string {\n if (isFrameworkAccount(address)) {\n const n = parseInt(address, 16)\n return `0x${n.toString(16)}`\n }\n if (!isValidSuiAddress(address)) {\n throw Error('Not valid Address')\n }\n return normalizeSuiAddress(address)\n}\n"]}
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/sui/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,kBAAkB,EAClB,0BAA0B,EAG1B,mBAAmB,EACnB,kBAAkB,GAEnB,MAAM,gBAAgB,CAAA;AACvB,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAA;AAErD,MAAM,UAAU,YAAY,CAAC,OAAoC;IAC/D,MAAM,MAAM,GAAG,kBAAkB,CAAC,OAAO,CAAC,CAAA;IAC1C,IAAI,CAAC,MAAM,EAAE;QACX,OAAO,EAAE,CAAA;KACV;IACD,MAAM,cAAc,GAAwC,0BAA0B,CAAC,MAAM,CAAC,CAAA;IAC9F,IAAI,CAAC,cAAc,EAAE;QACnB,OAAO,EAAE,CAAA;KACV;IAED,OAAO,cAAc,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC,EAAkB,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IACD,OAAO,mBAAmB,CAAC,OAAO,CAAC,CAAA;AACrC,CAAC","sourcesContent":["import {\n SuiTransactionBlockResponse,\n MoveCallSuiTransaction,\n getTransactionKind,\n getProgrammableTransaction,\n ProgrammableTransaction,\n SuiTransaction,\n normalizeSuiAddress,\n SUI_ADDRESS_LENGTH,\n SuiAddress,\n} from '@mysten/sui.js'\nimport { isFrameworkAccount } from '../move/index.js'\n\nexport function getMoveCalls(txBlock: SuiTransactionBlockResponse) {\n const txKind = getTransactionKind(txBlock)\n if (!txKind) {\n return []\n }\n const programmableTx: ProgrammableTransaction | undefined = getProgrammableTransaction(txKind)\n if (!programmableTx) {\n return []\n }\n\n return programmableTx.transactions.flatMap((tx: SuiTransaction) => {\n if ('MoveCall' in tx) {\n const call = tx.MoveCall as MoveCallSuiTransaction\n\n let pkg: string = call.package\n if (call.package.startsWith('0x000000000000000000000000000000000000000000000000000000000000000')) {\n pkg = '0x' + pkg[pkg.length - 1]\n }\n call.package = pkg\n\n return [call]\n }\n return []\n })\n}\n\nfunction isHex(value: string): boolean {\n return /^(0x|0X)?[a-fA-F0-9]+$/.test(value)\n}\n\nfunction getHexByteLength(value: string): number {\n return /^(0x|0X)/.test(value) ? (value.length - 2) / 2 : value.length / 2\n}\n\nexport function isValidSuiAddress(value: string): value is SuiAddress {\n return isHex(value) && getHexByteLength(value) <= SUI_ADDRESS_LENGTH\n}\n\nexport function validateAndNormalizeAddress(address: string): string {\n if (isFrameworkAccount(address)) {\n const n = parseInt(address, 16)\n return `0x${n.toString(16)}`\n }\n if (!isValidSuiAddress(address)) {\n throw Error('Not valid Address')\n }\n return normalizeSuiAddress(address)\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.6",
4
+ "version": "2.13.7-rc.2",
5
5
  "type": "module",
6
6
  "dependencies": {
7
7
  "@mysten/sui.js": "npm:@sentio/sui.js@^0.32.0-patch.1",
@@ -30,8 +30,8 @@
30
30
  "nice-grpc-common": "^2.0.2",
31
31
  "@coral-xyz/borsh": "^0.27.0",
32
32
  "typedoc": "^0.24.1",
33
- "@sentio/protos": "^2.13.6",
34
- "@sentio/runtime": "^2.13.6"
33
+ "@sentio/protos": "^2.13.7-rc.2",
34
+ "@sentio/runtime": "^2.13.7-rc.2"
35
35
  },
36
36
  "devDependencies": {
37
37
  "@certusone/wormhole-sdk": "^0.9.10",
@@ -3,6 +3,7 @@ import { Event, MoveModuleBytecode, MoveResource, toInternalModule } from './mov
3
3
  import { AptosNetwork } from './network.js'
4
4
  import { InternalMoveModule, InternalMoveStruct } from '../move/internal-models.js'
5
5
  import { AptosClient } from 'aptos-sdk'
6
+ import { validateAndNormalizeAddress } from './utils.js'
6
7
 
7
8
  export class AptosChainAdapter extends ChainAdapter<AptosNetwork, MoveModuleBytecode, Event | MoveResource> {
8
9
  static INSTANCE = new AptosChainAdapter()
@@ -66,6 +67,9 @@ export class AptosChainAdapter extends ChainAdapter<AptosNetwork, MoveModuleByte
66
67
  }
67
68
  return data
68
69
  }
70
+ validateAndNormalizeAddress(address: string): string {
71
+ return validateAndNormalizeAddress(address)
72
+ }
69
73
  }
70
74
 
71
75
  function getRpcClient(network: AptosNetwork): AptosClient {
@@ -22,14 +22,15 @@ export abstract class AbstractMoveCoder<Network, ModuleType, StructType> {
22
22
  abstract load(module: ModuleType): InternalMoveModule
23
23
 
24
24
  protected loadInternal(module: InternalMoveModule) {
25
- if (this.contains(module.address, module.name)) {
25
+ const account = this.adapter.validateAndNormalizeAddress(module.address)
26
+ if (this.contains(account, module.name)) {
26
27
  return
27
28
  }
28
- this.moduleMapping.set(moduleQname(module), module)
29
+ this.moduleMapping.set(moduleQname({ address: account, name: module.name }), module)
29
30
 
30
31
  for (const struct of module.structs) {
31
32
  // TODO move to util
32
- const key = [module.address, module.name, struct.name].join(SPLITTER)
33
+ const key = [account, module.name, struct.name].join(SPLITTER)
33
34
  this.typeMapping.set(key, struct)
34
35
  }
35
36
 
@@ -37,7 +38,7 @@ export abstract class AbstractMoveCoder<Network, ModuleType, StructType> {
37
38
  // if (!func.isEntry) {
38
39
  // continue
39
40
  // }
40
- const key = [module.address, module.name, func.name].join(SPLITTER)
41
+ const key = [account, module.name, func.name].join(SPLITTER)
41
42
  this.funcMapping.set(key, func)
42
43
  }
43
44
  }
@@ -59,11 +60,14 @@ export abstract class AbstractMoveCoder<Network, ModuleType, StructType> {
59
60
  private requestMap = new Map<string, Promise<InternalMoveModule>>()
60
61
 
61
62
  async getMoveStruct(type: string): Promise<InternalMoveStruct> {
63
+ const [account_, module, typeName] = type.split(SPLITTER)
64
+ const account = this.adapter.validateAndNormalizeAddress(account_)
65
+ type = [account, module, typeName].join(SPLITTER)
66
+
62
67
  let struct = this.typeMapping.get(type)
63
68
  if (struct) {
64
69
  return struct
65
70
  }
66
- const [account, module, typeName] = type.split(SPLITTER)
67
71
  const key = account + SPLITTER + module
68
72
  let resp = this.requestMap.get(account + SPLITTER + module)
69
73
  if (!resp) {
@@ -81,11 +85,14 @@ export abstract class AbstractMoveCoder<Network, ModuleType, StructType> {
81
85
  }
82
86
 
83
87
  async getMoveFunction(type: string): Promise<InternalMoveFunction> {
88
+ const [account_, module, typeName] = type.split(SPLITTER)
89
+ const account = this.adapter.validateAndNormalizeAddress(account_)
90
+ type = [account, module, typeName].join(SPLITTER)
91
+
84
92
  let func = this.funcMapping.get(type)
85
93
  if (func) {
86
94
  return func
87
95
  }
88
- const [account, module, typeName] = type.split(SPLITTER)
89
96
  const key = account + SPLITTER + module
90
97
  let resp = this.requestMap.get(account + SPLITTER + module)
91
98
  if (!resp) {
@@ -14,4 +14,5 @@ export abstract class ChainAdapter<NetworkType, ModuleType, StructType> {
14
14
 
15
15
  abstract getType(base: StructType): string
16
16
  abstract getData<T>(base: StructType): any
17
+ abstract validateAndNormalizeAddress(address: string): string
17
18
  }
package/src/move/utils.ts CHANGED
@@ -1,5 +1,4 @@
1
1
  import { InternalMoveModule, InternalMoveStruct } from './internal-models.js'
2
- import { parseInt } from 'lodash-es'
3
2
 
4
3
  export const SPLITTER = '::'
5
4
 
@@ -10,6 +10,7 @@ import {
10
10
  SuiMoveObject,
11
11
  SuiParsedData,
12
12
  } from '@mysten/sui.js'
13
+ import { validateAndNormalizeAddress } from './utils.js'
13
14
 
14
15
  export class SuiChainAdapter extends ChainAdapter<SuiNetwork, SuiMoveNormalizedModule, SuiEvent | SuiMoveObject> {
15
16
  static INSTANCE = new SuiChainAdapter()
@@ -72,6 +73,9 @@ export class SuiChainAdapter extends ChainAdapter<SuiNetwork, SuiMoveNormalizedM
72
73
  }
73
74
  return val as any
74
75
  }
76
+ validateAndNormalizeAddress(address: string) {
77
+ return validateAndNormalizeAddress(address)
78
+ }
75
79
  }
76
80
 
77
81
  function getRpcEndpoint(network: SuiNetwork): string {
package/src/sui/utils.ts CHANGED
@@ -10,7 +10,6 @@ import {
10
10
  SuiAddress,
11
11
  } from '@mysten/sui.js'
12
12
  import { isFrameworkAccount } from '../move/index.js'
13
- import { parseInt } from 'lodash-es'
14
13
 
15
14
  export function getMoveCalls(txBlock: SuiTransactionBlockResponse) {
16
15
  const txKind = getTransactionKind(txBlock)