@sentio/sdk 2.13.2-rc.4 → 2.13.2-rc.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/move/abstract-codegen.d.ts +1 -1
- package/lib/move/abstract-codegen.js +25 -21
- package/lib/move/abstract-codegen.js.map +1 -1
- package/lib/move/abstract-move-coder.d.ts +3 -2
- package/lib/move/abstract-move-coder.js +14 -0
- package/lib/move/abstract-move-coder.js.map +1 -1
- package/lib/sui/builtin/0x1.d.ts +12 -0
- package/lib/sui/builtin/0x1.js +34 -1
- package/lib/sui/builtin/0x1.js.map +1 -1
- package/lib/sui/builtin/0x2.d.ts +12 -0
- package/lib/sui/builtin/0x2.js +27 -0
- package/lib/sui/builtin/0x2.js.map +1 -1
- package/lib/sui/codegen/codegen.js +10 -5
- package/lib/sui/codegen/codegen.js.map +1 -1
- package/lib/sui/move-coder.d.ts +1 -1
- package/lib/sui/move-coder.js.map +1 -1
- package/package.json +4 -4
- package/src/move/abstract-codegen.ts +27 -23
- package/src/move/abstract-move-coder.ts +19 -4
- package/src/sui/builtin/0x1.ts +30 -0
- package/src/sui/builtin/0x2.ts +31 -0
- package/src/sui/codegen/codegen.ts +10 -5
- package/src/sui/move-coder.ts +1 -1
@@ -33,20 +33,25 @@ class SuiCodegen extends AbstractCodegen {
|
|
33
33
|
return res;
|
34
34
|
}
|
35
35
|
generateStructs(module, struct, events) {
|
36
|
+
let content = '';
|
36
37
|
switch (structQname(module, struct)) {
|
37
38
|
// TODO they should still have module code generated
|
38
39
|
case '0x1::ascii::Char':
|
39
40
|
case '0x1::ascii::String':
|
40
41
|
case '0x2::object::ID':
|
41
|
-
|
42
|
+
content += `export type ${struct.name} = string`;
|
43
|
+
break;
|
42
44
|
case '0x2::coin::Coin':
|
43
|
-
|
45
|
+
content += `export type ${struct.name}<T> = string`;
|
46
|
+
break;
|
44
47
|
case '0x2::balance::Balance':
|
45
|
-
|
48
|
+
content += `export type ${struct.name}<T> = bigint`;
|
49
|
+
break;
|
46
50
|
case '0x1::option::Option':
|
47
|
-
|
51
|
+
content += `export type Option<T> = T | undefined`;
|
52
|
+
break;
|
48
53
|
}
|
49
|
-
return super.generateStructs(module, struct, events);
|
54
|
+
return content + super.generateStructs(module, struct, events, content !== '');
|
50
55
|
}
|
51
56
|
generateOnEvents(module, struct) {
|
52
57
|
switch (structQname(module, struct)) {
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"codegen.js","sourceRoot":"","sources":["../../../src/sui/codegen/codegen.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAA;AAC1C,OAAO,KAAK,EAAE,MAAM,IAAI,CAAA;AACxB,OAAO,KAAK,MAAM,OAAO,CAAA;AAEzB,OAAO,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAA;AAChE,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAA;AACjD,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAA;AAC3B,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAA;AAEzD,MAAM,CAAC,KAAK,UAAU,OAAO,CAC3B,OAAe,EACf,MAAM,GAAG,IAAI,CAAC,KAAK,EAAE,OAAO,EAAE,KAAK,CAAC,EACpC,UAAU,GAAG,KAAK,EAClB,OAAO,GAAG,KAAK;IAEf,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,OAAO,CAAC,EAAE;QAC3B,OAAM;KACP;IACD,MAAM,GAAG,GAAG,IAAI,UAAU,EAAE,CAAA;IAC5B,MAAM,QAAQ,GAAG,MAAM,GAAG,CAAC,QAAQ,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,CAAA;IAC7D,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,aAAa,QAAQ,UAAU,CAAC,CAAC,CAAA;AAC3D,CAAC;AAED,MAAM,UAAW,SAAQ,eAA8E;IACrG,YAAY,GAAG,YAAY,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K;YACP,KAAK,iBAAiB;gBACpB,OAAO,IAAI,eAAe,MAAM,CAAC,IAAI,cAAc,CAAA;gBACnD,MAAK;YACP,KAAK,uBAAuB;gBAC1B,OAAO,IAAI,eAAe,MAAM,CAAC,IAAI,cAAc,CAAA;gBACnD,MAAK;YACP,KAAK,qBAAqB;gBACxB,OAAO,IAAI,uCAAuC,CAAA;gBAClD,MAAK;SACR;QACD,OAAO,OAAO,GAAG,KAAK,CAAC,eAAe,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,KAAK,EAAE,CAAC,CAAA;IAChF,CAAC;IAED,gBAAgB,CAAC,MAA0B,EAAE,MAA0B;QACrE,QAAQ,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE;YACnC,KAAK,kBAAkB,CAAC;YACxB,KAAK,oBAAoB,CAAC;YAC1B,KAAK,iBAAiB,CAAC;YACvB,KAAK,iBAAiB,CAAC;YACvB,KAAK,qBAAqB,CAAC;YAC3B,KAAK,uBAAuB;gBAC1B,OAAO,EAAE,CAAA;SACZ;QACD,OAAO,KAAK,CAAC,gBAAgB,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAC/C,CAAC;CACF","sourcesContent":["import { SuiMoveNormalizedModule, SuiEvent, SuiMoveObject } from '@mysten/sui.js'\n\nimport { SuiNetwork } from '../network.js'\nimport * as fs from 'fs'\nimport chalk from 'chalk'\nimport { InternalMoveModule, InternalMoveStruct } from '../../move/internal-models.js'\nimport { AbstractCodegen } from '../../move/abstract-codegen.js'\nimport { structQname } from '../../move/index.js'\nimport { join } from 'path'\nimport { SuiChainAdapter } from '../sui-chain-adapter.js'\n\nexport async function codegen(\n abisDir: string,\n outDir = join('src', 'types', 'sui'),\n genExample = false,\n builtin = false\n) {\n if (!fs.existsSync(abisDir)) {\n return\n }\n const gen = new SuiCodegen()\n const numFiles = await gen.generate(abisDir, outDir, builtin)\n console.log(chalk.green(`Generated ${numFiles} for Sui`))\n}\n\nclass SuiCodegen extends AbstractCodegen<SuiNetwork, SuiMoveNormalizedModule, SuiEvent | SuiMoveObject> {\n ADDRESS_TYPE = 'SuiAddress'\n // ADDRESS_TYPE = 'string'\n MAIN_NET = SuiNetwork.MAIN_NET\n TEST_NET = SuiNetwork.TEST_NET\n PREFIX = 'Sui'\n // STRUCT_FIELD_NAME = 'fields'\n // GENERATE_ON_ENTRY = true\n PAYLOAD_OPTIONAL = true\n\n constructor() {\n super(new SuiChainAdapter())\n }\n\n readModulesFile(fullPath: string) {\n const res = super.readModulesFile(fullPath)\n if (res.result) {\n return res.result\n }\n return res\n }\n\n generateStructs(module: InternalMoveModule, struct: InternalMoveStruct, events: Set<string>): string {\n let content = ''\n switch (structQname(module, struct)) {\n // TODO they should still have module code generated\n case '0x1::ascii::Char':\n case '0x1::ascii::String':\n case '0x2::object::ID':\n content += `export type ${struct.name} = string`\n break\n case '0x2::coin::Coin':\n content += `export type ${struct.name}<T> = string`\n break\n case '0x2::balance::Balance':\n content += `export type ${struct.name}<T> = bigint`\n break\n case '0x1::option::Option':\n content += `export type Option<T> = T | undefined`\n break\n }\n return content + super.generateStructs(module, struct, events, content !== '')\n }\n\n generateOnEvents(module: InternalMoveModule, struct: InternalMoveStruct): string {\n switch (structQname(module, struct)) {\n case '0x1::ascii::Char':\n case '0x1::ascii::String':\n case '0x2::object::ID':\n case '0x2::coin::Coin':\n case '0x1::option::Option':\n case '0x2::balance::Balance':\n return ''\n }\n return super.generateOnEvents(module, struct)\n }\n}\n"]}
|
package/lib/sui/move-coder.d.ts
CHANGED
@@ -8,7 +8,7 @@ import { dynamic_field } from './builtin/0x2.js';
|
|
8
8
|
export declare class MoveCoder extends AbstractMoveCoder<SuiNetwork, SuiMoveNormalizedModule, SuiEvent | SuiMoveObject> {
|
9
9
|
constructor(network: SuiNetwork);
|
10
10
|
load(module: SuiMoveNormalizedModule): InternalMoveModule;
|
11
|
-
decode(data: any, type: TypeDescriptor): any;
|
11
|
+
protected decode(data: any, type: TypeDescriptor): any;
|
12
12
|
decodeEvent<T>(event: SuiEvent): Promise<TypedEventInstance<T> | undefined>;
|
13
13
|
filterAndDecodeEvents<T>(type: TypeDescriptor<T> | string, resources: SuiEvent[]): Promise<TypedEventInstance<T>[]>;
|
14
14
|
getDynamicFields<T1, T2>(objects: SuiMoveObject[], keyType?: TypeDescriptor<T1>, valueType?: TypeDescriptor<T2>): Promise<dynamic_field.Field<T1, T2>[]>;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"move-coder.js","sourceRoot":"","sources":["../../src/sui/move-coder.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAA;AAElE,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAClD,OAAO,EAAE,QAAQ,EAAiB,aAAa,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAA;AACnG,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AACzC,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAA;AAIxD,MAAM,OAAO,SAAU,SAAQ,iBAAgF;IAC7G,YAAY,OAAmB;QAC7B,KAAK,CAAC,OAAO,CAAC,CAAA;QACd,IAAI,CAAC,OAAO,GAAG,IAAI,eAAe,EAAE,CAAA;IACtC,CAAC;IAED,IAAI,CAAC,MAA+B;QAClC,IAAI,CAAC,GAAG,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,MAAM,CAAC,OAAO,GAAG,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,CAAA;QACnE,IAAI,CAAC,EAAE;YACL,OAAO,CAAC,CAAA;SACT;QACD,CAAC,GAAG,gBAAgB,CAAC,MAAM,CAAC,CAAA;QAC5B,IAAI,CAAC,YAAY,CAAC,CAAC,CAAC,CAAA;QACpB,OAAO,CAAC,CAAA;IACV,CAAC;
|
1
|
+
{"version":3,"file":"move-coder.js","sourceRoot":"","sources":["../../src/sui/move-coder.ts"],"names":[],"mappings":"AAC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AAQ,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 protected decode(data: any, type: TypeDescriptor): any {\n switch (type.qname) {\n case '0x1::ascii::Char':\n case '0x1::ascii::String':\n case '0x2::object::ID':\n case '0x2::coin::Coin':\n return data\n case '0x2::balance::Balance':\n return BigInt(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.2-rc.
|
4
|
+
"version": "2.13.2-rc.6",
|
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.2-rc.
|
27
|
-
"@sentio/runtime": "^2.13.2-rc.
|
26
|
+
"@sentio/protos": "^2.13.2-rc.6",
|
27
|
+
"@sentio/runtime": "^2.13.2-rc.6",
|
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": "
|
91
|
+
"gitHead": "a727b9170f464d1f2449f1c21cb93c279989f2b6"
|
92
92
|
}
|
@@ -220,7 +220,7 @@ export abstract class AbstractCodegen<NetworkType, ModuleTypes, StructType> {
|
|
220
220
|
`
|
221
221
|
}
|
222
222
|
|
223
|
-
generateStructs(module: InternalMoveModule, struct: InternalMoveStruct, events: Set<string
|
223
|
+
generateStructs(module: InternalMoveModule, struct: InternalMoveStruct, events: Set<string>, typeOnly = false) {
|
224
224
|
const typeParams = struct.typeParams || []
|
225
225
|
const genericString = this.generateStructTypeParameters(struct)
|
226
226
|
const genericStringAny = this.generateStructTypeParameters(struct, true)
|
@@ -232,17 +232,6 @@ export abstract class AbstractCodegen<NetworkType, ModuleTypes, StructType> {
|
|
232
232
|
return `${field.name}: ${type}`
|
233
233
|
})
|
234
234
|
|
235
|
-
let eventPayload = ''
|
236
|
-
if (events.has(moduleQname(module) + SPLITTER + struct.name)) {
|
237
|
-
eventPayload = `
|
238
|
-
export interface ${structName}Instance extends
|
239
|
-
TypedEventInstance<${structName}${genericStringAny}> {
|
240
|
-
${this.STRUCT_FIELD_NAME}_decoded: ${structName}${genericStringAny}
|
241
|
-
type_arguments: [${struct.typeParams.map((_) => 'string').join(', ')}]
|
242
|
-
}
|
243
|
-
`
|
244
|
-
}
|
245
|
-
|
246
235
|
const typeParamApplyArg = typeParams
|
247
236
|
.map((v, idx) => {
|
248
237
|
return `arg${idx}: TypeDescriptor<T${idx}> = ANY_TYPE`
|
@@ -254,23 +243,38 @@ export abstract class AbstractCodegen<NetworkType, ModuleTypes, StructType> {
|
|
254
243
|
})
|
255
244
|
.join(',')
|
256
245
|
|
257
|
-
const
|
258
|
-
export function type${genericString}(${typeParamApplyArg}): TypeDescriptor<${structName}${genericString}> {
|
259
|
-
return TYPE.apply(${typeParamApply})
|
260
|
-
}`
|
261
|
-
|
262
|
-
return `
|
263
|
-
export interface ${structName}${genericString} {
|
264
|
-
${fields.join('\n')}
|
265
|
-
}
|
266
|
-
|
246
|
+
const typeDescriptor = `
|
267
247
|
export namespace ${structName}{
|
268
248
|
export const TYPE_QNAME = '${module.address}::${module.name}::${struct.name}'
|
269
249
|
|
270
250
|
const TYPE = new TypeDescriptor<${structName}${genericStringAny}>(${structName}.TYPE_QNAME)
|
271
251
|
|
272
|
-
${
|
252
|
+
export function type${genericString}(${typeParamApplyArg}): TypeDescriptor<${structName}${genericString}> {
|
253
|
+
return TYPE.apply(${typeParamApply})
|
254
|
+
}
|
255
|
+
}
|
256
|
+
`
|
257
|
+
if (typeOnly) {
|
258
|
+
return typeDescriptor
|
259
|
+
}
|
260
|
+
|
261
|
+
let eventPayload = ''
|
262
|
+
if (events.has(moduleQname(module) + SPLITTER + struct.name)) {
|
263
|
+
eventPayload = `
|
264
|
+
export interface ${structName}Instance extends
|
265
|
+
TypedEventInstance<${structName}${genericStringAny}> {
|
266
|
+
${this.STRUCT_FIELD_NAME}_decoded: ${structName}${genericStringAny}
|
267
|
+
type_arguments: [${struct.typeParams.map((_) => 'string').join(', ')}]
|
268
|
+
}
|
269
|
+
`
|
270
|
+
}
|
271
|
+
|
272
|
+
return `
|
273
|
+
export interface ${structName}${genericString} {
|
274
|
+
${fields.join('\n')}
|
273
275
|
}
|
276
|
+
|
277
|
+
${typeDescriptor}
|
274
278
|
|
275
279
|
${eventPayload}
|
276
280
|
`
|
@@ -102,7 +102,7 @@ export abstract class AbstractMoveCoder<Network, ModuleType, StructType> {
|
|
102
102
|
throw new Error('Failed to load function ' + type + ' type are not imported anywhere')
|
103
103
|
}
|
104
104
|
|
105
|
-
async decode(data: any, type: TypeDescriptor): Promise<
|
105
|
+
protected async decode<T>(data: any, type: TypeDescriptor<T>): Promise<T> {
|
106
106
|
// process simple type
|
107
107
|
if (type.reference) {
|
108
108
|
return data
|
@@ -125,7 +125,7 @@ export abstract class AbstractMoveCoder<Network, ModuleType, StructType> {
|
|
125
125
|
case 'U64':
|
126
126
|
case 'u128':
|
127
127
|
case 'U128':
|
128
|
-
return this.decodeBigInt(data)
|
128
|
+
return this.decodeBigInt(data) as any
|
129
129
|
}
|
130
130
|
|
131
131
|
// process vector
|
@@ -139,7 +139,7 @@ export abstract class AbstractMoveCoder<Network, ModuleType, StructType> {
|
|
139
139
|
for (const entry of data) {
|
140
140
|
res.push(await this.decode(entry, type.typeArgs[0]))
|
141
141
|
}
|
142
|
-
return res
|
142
|
+
return res as any
|
143
143
|
}
|
144
144
|
|
145
145
|
// Process complex type
|
@@ -162,7 +162,7 @@ export abstract class AbstractMoveCoder<Network, ModuleType, StructType> {
|
|
162
162
|
return typedData
|
163
163
|
}
|
164
164
|
|
165
|
-
async encode(data: any, type: TypeDescriptor): Promise<any> {
|
165
|
+
protected async encode(data: any, type: TypeDescriptor): Promise<any> {
|
166
166
|
// process simple type
|
167
167
|
if (type.reference) {
|
168
168
|
return data
|
@@ -307,4 +307,19 @@ export abstract class AbstractMoveCoder<Network, ModuleType, StructType> {
|
|
307
307
|
type_arguments: typeArguments,
|
308
308
|
}
|
309
309
|
}
|
310
|
+
async decodedType<T, ST>(typeStruct: ST, type: TypeDescriptor<T>): Promise<T | undefined> {
|
311
|
+
if (typeStruct === null || typeStruct == undefined) {
|
312
|
+
return typeStruct as any
|
313
|
+
}
|
314
|
+
if (typeof typeStruct === 'object') {
|
315
|
+
if ('type' in typeStruct) {
|
316
|
+
const typeInStruct = parseMoveType((typeStruct.type as any).toString() || '')
|
317
|
+
if (!matchType(type, typeInStruct)) {
|
318
|
+
return undefined
|
319
|
+
}
|
320
|
+
}
|
321
|
+
}
|
322
|
+
|
323
|
+
return await this.decode(typeStruct, type)
|
324
|
+
}
|
310
325
|
}
|
package/src/sui/builtin/0x1.ts
CHANGED
@@ -22,7 +22,26 @@ export namespace address {}
|
|
22
22
|
|
23
23
|
export namespace ascii {
|
24
24
|
export type Char = string;
|
25
|
+
export namespace Char {
|
26
|
+
export const TYPE_QNAME = "0x1::ascii::Char";
|
27
|
+
|
28
|
+
const TYPE = new TypeDescriptor<Char>(Char.TYPE_QNAME);
|
29
|
+
|
30
|
+
export function type(): TypeDescriptor<Char> {
|
31
|
+
return TYPE.apply();
|
32
|
+
}
|
33
|
+
}
|
34
|
+
|
25
35
|
export type String = string;
|
36
|
+
export namespace String {
|
37
|
+
export const TYPE_QNAME = "0x1::ascii::String";
|
38
|
+
|
39
|
+
const TYPE = new TypeDescriptor<String>(String.TYPE_QNAME);
|
40
|
+
|
41
|
+
export function type(): TypeDescriptor<String> {
|
42
|
+
return TYPE.apply();
|
43
|
+
}
|
44
|
+
}
|
26
45
|
}
|
27
46
|
|
28
47
|
export namespace bcs {}
|
@@ -133,6 +152,17 @@ export namespace hash {}
|
|
133
152
|
|
134
153
|
export namespace option {
|
135
154
|
export type Option<T> = T | undefined;
|
155
|
+
export namespace Option {
|
156
|
+
export const TYPE_QNAME = "0x1::option::Option";
|
157
|
+
|
158
|
+
const TYPE = new TypeDescriptor<Option<any>>(Option.TYPE_QNAME);
|
159
|
+
|
160
|
+
export function type<T0>(
|
161
|
+
arg0: TypeDescriptor<T0> = ANY_TYPE
|
162
|
+
): TypeDescriptor<Option<T0>> {
|
163
|
+
return TYPE.apply(arg0);
|
164
|
+
}
|
165
|
+
}
|
136
166
|
}
|
137
167
|
|
138
168
|
export class string_ extends SuiBaseProcessor {
|
package/src/sui/builtin/0x2.ts
CHANGED
@@ -41,6 +41,17 @@ export namespace bag {
|
|
41
41
|
|
42
42
|
export namespace balance {
|
43
43
|
export type Balance<T> = bigint;
|
44
|
+
export namespace Balance {
|
45
|
+
export const TYPE_QNAME = "0x2::balance::Balance";
|
46
|
+
|
47
|
+
const TYPE = new TypeDescriptor<Balance<any>>(Balance.TYPE_QNAME);
|
48
|
+
|
49
|
+
export function type<T0>(
|
50
|
+
arg0: TypeDescriptor<T0> = ANY_TYPE
|
51
|
+
): TypeDescriptor<Balance<T0>> {
|
52
|
+
return TYPE.apply(arg0);
|
53
|
+
}
|
54
|
+
}
|
44
55
|
|
45
56
|
export interface Supply<T0> {
|
46
57
|
value: bigint;
|
@@ -303,6 +314,17 @@ export class coin extends SuiBaseProcessor {
|
|
303
314
|
|
304
315
|
export namespace coin {
|
305
316
|
export type Coin<T> = string;
|
317
|
+
export namespace Coin {
|
318
|
+
export const TYPE_QNAME = "0x2::coin::Coin";
|
319
|
+
|
320
|
+
const TYPE = new TypeDescriptor<Coin<any>>(Coin.TYPE_QNAME);
|
321
|
+
|
322
|
+
export function type<T0>(
|
323
|
+
arg0: TypeDescriptor<T0> = ANY_TYPE
|
324
|
+
): TypeDescriptor<Coin<T0>> {
|
325
|
+
return TYPE.apply(arg0);
|
326
|
+
}
|
327
|
+
}
|
306
328
|
|
307
329
|
export interface CoinMetadata<T0> {
|
308
330
|
id: object_.UID;
|
@@ -1176,6 +1198,15 @@ export namespace math {}
|
|
1176
1198
|
|
1177
1199
|
export namespace object_ {
|
1178
1200
|
export type ID = string;
|
1201
|
+
export namespace ID {
|
1202
|
+
export const TYPE_QNAME = "0x2::object::ID";
|
1203
|
+
|
1204
|
+
const TYPE = new TypeDescriptor<ID>(ID.TYPE_QNAME);
|
1205
|
+
|
1206
|
+
export function type(): TypeDescriptor<ID> {
|
1207
|
+
return TYPE.apply();
|
1208
|
+
}
|
1209
|
+
}
|
1179
1210
|
|
1180
1211
|
export interface UID {
|
1181
1212
|
id: object_.ID;
|
@@ -46,20 +46,25 @@ class SuiCodegen extends AbstractCodegen<SuiNetwork, SuiMoveNormalizedModule, Su
|
|
46
46
|
}
|
47
47
|
|
48
48
|
generateStructs(module: InternalMoveModule, struct: InternalMoveStruct, events: Set<string>): string {
|
49
|
+
let content = ''
|
49
50
|
switch (structQname(module, struct)) {
|
50
51
|
// TODO they should still have module code generated
|
51
52
|
case '0x1::ascii::Char':
|
52
53
|
case '0x1::ascii::String':
|
53
54
|
case '0x2::object::ID':
|
54
|
-
|
55
|
+
content += `export type ${struct.name} = string`
|
56
|
+
break
|
55
57
|
case '0x2::coin::Coin':
|
56
|
-
|
58
|
+
content += `export type ${struct.name}<T> = string`
|
59
|
+
break
|
57
60
|
case '0x2::balance::Balance':
|
58
|
-
|
61
|
+
content += `export type ${struct.name}<T> = bigint`
|
62
|
+
break
|
59
63
|
case '0x1::option::Option':
|
60
|
-
|
64
|
+
content += `export type Option<T> = T | undefined`
|
65
|
+
break
|
61
66
|
}
|
62
|
-
return super.generateStructs(module, struct, events)
|
67
|
+
return content + super.generateStructs(module, struct, events, content !== '')
|
63
68
|
}
|
64
69
|
|
65
70
|
generateOnEvents(module: InternalMoveModule, struct: InternalMoveStruct): string {
|
package/src/sui/move-coder.ts
CHANGED
@@ -24,7 +24,7 @@ export class MoveCoder extends AbstractMoveCoder<SuiNetwork, SuiMoveNormalizedMo
|
|
24
24
|
return m
|
25
25
|
}
|
26
26
|
|
27
|
-
decode(data: any, type: TypeDescriptor): any {
|
27
|
+
protected decode(data: any, type: TypeDescriptor): any {
|
28
28
|
switch (type.qname) {
|
29
29
|
case '0x1::ascii::Char':
|
30
30
|
case '0x1::ascii::String':
|