@sentio/sdk 2.5.4-rc.1 → 2.5.5-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.
- package/lib/aptos/builtin/0x1.d.ts +70 -76
- package/lib/aptos/builtin/0x1.js +4 -4
- package/lib/aptos/builtin/0x1.js.map +1 -1
- package/lib/aptos/builtin/0x3.d.ts +14 -32
- package/lib/aptos/builtin/0x3.js.map +1 -1
- package/lib/aptos/codegen/codegen.js +1 -0
- package/lib/aptos/codegen/codegen.js.map +1 -1
- package/lib/aptos/codegen/types.test.js.map +1 -1
- package/lib/aptos/index.d.ts +2 -1
- package/lib/aptos/index.js +1 -0
- package/lib/aptos/index.js.map +1 -1
- package/lib/aptos/models.d.ts +1 -1
- package/lib/aptos/models.js.map +1 -1
- package/lib/aptos/module-client.d.ts +6 -0
- package/lib/aptos/module-client.js +25 -0
- package/lib/aptos/module-client.js.map +1 -0
- package/lib/aptos/module-client.test.d.ts +1 -0
- package/lib/aptos/module-client.test.js.map +1 -0
- package/lib/aptos/move-coder.d.ts +2 -0
- package/lib/aptos/move-coder.js +7 -15
- package/lib/aptos/move-coder.js.map +1 -1
- package/lib/aptos/network.d.ts +2 -0
- package/lib/aptos/network.js +1 -0
- package/lib/aptos/network.js.map +1 -1
- package/lib/move/abstract-codegen.d.ts +2 -0
- package/lib/move/abstract-codegen.js +44 -7
- package/lib/move/abstract-codegen.js.map +1 -1
- package/lib/move/abstract-move-coder.d.ts +12 -5
- package/lib/move/abstract-move-coder.js +100 -6
- package/lib/move/abstract-move-coder.js.map +1 -1
- package/lib/move/ts-type.js +1 -1
- package/lib/move/ts-type.js.map +1 -1
- package/lib/move/utils.js +1 -1
- package/lib/move/utils.js.map +1 -1
- package/lib/sui/builtin/0x1.js.map +1 -1
- package/lib/sui/builtin/0x2.d.ts +49 -49
- package/lib/sui/builtin/0x2.js.map +1 -1
- package/lib/sui/codegen/codegen.js +2 -4
- package/lib/sui/codegen/codegen.js.map +1 -1
- package/lib/sui/index.d.ts +1 -0
- package/lib/sui/index.js +1 -0
- package/lib/sui/index.js.map +1 -1
- package/lib/sui/models.d.ts +1 -1
- package/lib/sui/models.js.map +1 -1
- package/lib/sui/module-client.d.ts +3 -0
- package/lib/sui/module-client.js +7 -0
- package/lib/sui/module-client.js.map +1 -0
- package/lib/sui/move-coder.d.ts +2 -0
- package/lib/sui/move-coder.js +8 -17
- package/lib/sui/move-coder.js.map +1 -1
- package/lib/sui/utils.d.ts +2 -0
- package/lib/sui/utils.js +6 -0
- package/lib/sui/utils.js.map +1 -1
- package/package.json +4 -4
- package/src/aptos/builtin/0x1.ts +71 -81
- package/src/aptos/builtin/0x3.ts +15 -21
- package/src/aptos/codegen/codegen.ts +1 -0
- package/src/aptos/index.ts +2 -1
- package/src/aptos/models.ts +1 -1
- package/src/aptos/module-client.ts +30 -0
- package/src/aptos/move-coder.ts +11 -17
- package/src/aptos/network.ts +2 -0
- package/src/move/abstract-codegen.ts +55 -9
- package/src/move/abstract-move-coder.ts +116 -10
- package/src/move/ts-type.ts +1 -1
- package/src/move/utils.ts +1 -1
- package/src/sui/builtin/0x1.ts +2 -2
- package/src/sui/builtin/0x2.ts +50 -51
- package/src/sui/codegen/codegen.ts +2 -4
- package/src/sui/index.ts +2 -0
- package/src/sui/models.ts +1 -1
- package/src/sui/module-client.ts +7 -0
- package/src/sui/move-coder.ts +11 -21
- package/src/sui/utils.ts +8 -0
package/lib/aptos/index.js
CHANGED
|
@@ -4,5 +4,6 @@ export { AptosBaseProcessor, AptosAccountProcessor } from './aptos-processor.js'
|
|
|
4
4
|
export { AptosContext, AptosResourceContext } from './context.js';
|
|
5
5
|
export { AptosBindOptions, AptosNetwork } from './network.js';
|
|
6
6
|
export * from './api.js';
|
|
7
|
+
export { ModuleClient } from './module-client.js';
|
|
7
8
|
export { AptosPlugin } from './aptos-plugin.js';
|
|
8
9
|
//# sourceMappingURL=index.js.map
|
package/lib/aptos/index.js.map
CHANGED
|
@@ -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,qBAAqB,EAAE,MAAM,sBAAsB,CAAA;AAChF,OAAO,EAAE,YAAY,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAA;AACjE,OAAO,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA;AAC7D,cAAc,UAAU,CAAA;
|
|
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,qBAAqB,EAAE,MAAM,sBAAsB,CAAA;AAChF,OAAO,EAAE,YAAY,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAA;AACjE,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","sourcesContent":["export * from './move-types.js'\nexport type { EventInstance, TypedEventInstance, TypedFunctionPayload, TypedMoveResource } from './models.js'\nexport { defaultMoveCoder, MoveCoder } from './move-coder.js'\nexport { AptosBaseProcessor, AptosAccountProcessor } from './aptos-processor.js'\nexport { AptosContext, AptosResourceContext } 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"]}
|
package/lib/aptos/models.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ export type TypedEventInstance<T> = EventInstance & {
|
|
|
9
9
|
data_decoded: T;
|
|
10
10
|
type_arguments: string[];
|
|
11
11
|
};
|
|
12
|
-
export type
|
|
12
|
+
export type TypedFunctionPayload<T extends Array<any>> = TransactionPayload_EntryFunctionPayload & {
|
|
13
13
|
/**
|
|
14
14
|
* decoded argument data using ABI, undefined if there is decoding error, usually because the ABI/data mismatch
|
|
15
15
|
*/
|
package/lib/aptos/models.js.map
CHANGED
|
@@ -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'\n\nexport type EventInstance = Event & {\n version: string\n}\n\nexport type TypedEventInstance<T> = EventInstance & {\n /**\n * decoded data using ABI, undefined if there is decoding error, usually because the ABI/data mismatch\n */\n data_decoded: T\n\n type_arguments: string[]\n}\n\n// Don't use intermediate type to make IDE happier\nexport type
|
|
1
|
+
{"version":3,"file":"models.js","sourceRoot":"","sources":["../../src/aptos/models.ts"],"names":[],"mappings":"","sourcesContent":["import { Event, MoveResource, TransactionPayload_EntryFunctionPayload } from './move-types.js'\n\nexport type EventInstance = Event & {\n version: string\n}\n\nexport type TypedEventInstance<T> = EventInstance & {\n /**\n * decoded data using ABI, undefined if there is decoding error, usually because the ABI/data mismatch\n */\n data_decoded: T\n\n type_arguments: string[]\n}\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\nexport type TypedMoveResource<T> = MoveResource & {\n data_decoded: T\n type_arguments: string[]\n}\n"]}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { defaultMoveCoder } from './index.js';
|
|
2
|
+
import { AptosClient } from 'aptos-sdk';
|
|
3
|
+
export class ModuleClient {
|
|
4
|
+
client;
|
|
5
|
+
constructor(client) {
|
|
6
|
+
if (typeof client === 'string') {
|
|
7
|
+
this.client = new AptosClient(client);
|
|
8
|
+
}
|
|
9
|
+
else {
|
|
10
|
+
this.client = client;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
async viewDecoded(func, typeArguments, args, ledger_version) {
|
|
14
|
+
const coder = defaultMoveCoder();
|
|
15
|
+
const encodedArgs = coder.encodeCallArgs(args, func);
|
|
16
|
+
const request = {
|
|
17
|
+
function: func,
|
|
18
|
+
type_arguments: typeArguments,
|
|
19
|
+
arguments: encodedArgs,
|
|
20
|
+
};
|
|
21
|
+
const res = await this.client.view(request, ledger_version?.toString());
|
|
22
|
+
return coder.decodeCallResult(res, func);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=module-client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"module-client.js","sourceRoot":"","sources":["../../src/aptos/module-client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAA;AAC7C,OAAO,EAAE,WAAW,EAAS,MAAM,WAAW,CAAA;AAE9C,MAAM,OAAO,YAAY;IACvB,MAAM,CAAa;IACnB,YAAY,MAA4B;QACtC,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE;YAC9B,IAAI,CAAC,MAAM,GAAG,IAAI,WAAW,CAAC,MAAM,CAAC,CAAA;SACtC;aAAM;YACL,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;SACrB;IACH,CAAC;IACM,KAAK,CAAC,WAAW,CACtB,IAAY,EACZ,aAAuB,EACvB,IAAW,EACX,cAAuB;QAEvB,MAAM,KAAK,GAAG,gBAAgB,EAAE,CAAA;QAChC,MAAM,WAAW,GAAG,KAAK,CAAC,cAAc,CAAC,IAAI,EAAE,IAAI,CAAC,CAAA;QAEpD,MAAM,OAAO,GAAsB;YACjC,QAAQ,EAAE,IAAI;YACd,cAAc,EAAE,aAAa;YAC7B,SAAS,EAAE,WAAW;SACvB,CAAA;QACD,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,cAAc,EAAE,QAAQ,EAAE,CAAC,CAAA;QACvE,OAAO,KAAK,CAAC,gBAAgB,CAAC,GAAG,EAAE,IAAI,CAAC,CAAA;IAC1C,CAAC;CACF","sourcesContent":["import { defaultMoveCoder } from './index.js'\nimport { AptosClient, Types } from 'aptos-sdk'\n\nexport class ModuleClient {\n client: AptosClient\n constructor(client: AptosClient | string) {\n if (typeof client === 'string') {\n this.client = new AptosClient(client)\n } else {\n this.client = client\n }\n }\n public async viewDecoded(\n func: string,\n typeArguments: string[],\n args: any[],\n ledger_version?: bigint\n ): Promise<any[]> {\n const coder = defaultMoveCoder()\n const encodedArgs = coder.encodeCallArgs(args, func)\n\n const request: Types.ViewRequest = {\n function: func,\n type_arguments: typeArguments,\n arguments: encodedArgs,\n }\n const res = await this.client.view(request, ledger_version?.toString())\n return coder.decodeCallResult(res, func)\n }\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"module-client.test.js","sourceRoot":"","sources":["../../src/aptos/module-client.test.ts"],"names":[],"mappings":"AAAA,gFAAgF;AAChF,sDAAsD;AACtD,qDAAqD;AACrD,2CAA2C;AAC3C,iCAAiC;AACjC,EAAE;AACF,QAAQ,CAAC,iBAAiB,EAAE,GAAG,EAAE;IAC/B,IAAI,CAAC,OAAO,EAAE,GAAG,EAAE,GAAE,CAAC,CAAC,CAAA;IACvB,qCAAqC;IACrC,oEAAoE;IACpE,EAAE;IACF,mCAAmC;IACnC,0CAA0C;IAC1C,4CAA4C;IAC5C,gCAAgC;IAChC,0CAA0C;IAC1C,iFAAiF;IACjF,QAAQ;IACR,wCAAwC;IACxC,OAAO;IACP,EAAE;IACF,oCAAoC;IACpC,yCAAyC;IACzC,yEAAyE;IACzE,iFAAiF;IACjF,YAAY;IACZ,QAAQ;IACR,wCAAwC;IACxC,OAAO;IACP,EAAE;IACF,wCAAwC;IACxC,SAAS;IACT,4CAA4C;IAC5C,2CAA2C;IAC3C,+EAA+E;IAC/E,UAAU;IACV,QAAQ;IACR,2BAA2B;IAC3B,OAAO;IACP,EAAE;IACF,uCAAuC;IACvC,yCAAyC;IACzC,wEAAwE;IACxE,YAAY;IACZ,QAAQ;IACR,8BAA8B;IAC9B,OAAO;AACT,CAAC,CAAC,CAAA","sourcesContent":["// import { coin_client, loadAllTypes, string__client } from \"./builtin/0x1.js\";\n// import { defaultMoveCoder } from \"./move-coder.js\";\n// import { ModuleClient } from \"./module-client.js\";\n// import { AptosClient } from \"aptos-sdk\";\n// import { expect } from \"chai\";\n//\ndescribe('type view calls', () => {\n test('empty', () => {})\n // loadAllTypes(defaultMoveCoder())\n // const client = new AptosClient(\"https://testnet.aptoslabs.com\")\n //\n // test(\"raw call\", async () => {\n // const mc = new ModuleClient(client)\n // const decoded = await mc.viewDecoded(\n // \"0x1::coin::balance\",\n // [\"0x1::aptos_coin::AptosCoin\"],\n // [\"0xc0cbc38f05f1aed5467b889ef704135bc01f0a492d6fd28ef499d19e7bb58108\"]\n // )\n // expect(decoded).eql([191195941n])\n // })\n //\n // test(\"coin call\", async () => {\n // const mc = new coin_client(client)\n // const decoded = await mc.balance([\"0x1::aptos_coin::AptosCoin\"], [\n // \"0xc0cbc38f05f1aed5467b889ef704135bc01f0a492d6fd28ef499d19e7bb58108\"\n // ]\n // )\n // expect(decoded).eql([191195941n])\n // })\n //\n // test(\"gen code call\", async () => {\n // //\n // const mc = new string__client(client)\n // const decoded = await mc.bytes([], [\n // \"0xc0cbc38f05f1aed5467b889ef704135bc01f0a492d6fd28ef499d19e7bb58108\"\n // ]\n // )\n // console.log(decoded)\n // })\n //\n // test(\"coin decimal\", async () => {\n // const mc = new coin_client(client)\n // const decoded = await mc.supply([\"0x1::aptos_coin::AptosCoin\"], [\n // ]\n // )\n // expect(decoded).eql(18)\n // })\n})\n"]}
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import { Event, MoveModuleBytecode, MoveResource, TransactionPayload_EntryFunctionPayload } from './move-types.js';
|
|
2
2
|
import { TypedEventInstance, TypedMoveResource } from './models.js';
|
|
3
3
|
import { AbstractMoveCoder } from '../move/abstract-move-coder.js';
|
|
4
|
+
import { TypeDescriptor } from '../move/index.js';
|
|
4
5
|
export declare class MoveCoder extends AbstractMoveCoder<Event | MoveResource> {
|
|
5
6
|
load(module: MoveModuleBytecode): void;
|
|
6
7
|
decodeEvent<T>(event: Event): TypedEventInstance<T> | undefined;
|
|
7
8
|
filterAndDecodeEvents<T>(typeQname: string, resources: Event[]): TypedEventInstance<T>[];
|
|
8
9
|
decodeResource<T>(res: MoveResource): TypedMoveResource<T> | undefined;
|
|
9
10
|
filterAndDecodeResources<T>(typeQname: string, resources: MoveResource[]): TypedMoveResource<T>[];
|
|
11
|
+
getMeaningfulFunctionParams(params: TypeDescriptor[]): TypeDescriptor[];
|
|
10
12
|
decodeFunctionPayload(payload: TransactionPayload_EntryFunctionPayload): TransactionPayload_EntryFunctionPayload;
|
|
11
13
|
}
|
|
12
14
|
export declare const MOVE_CODER: MoveCoder;
|
package/lib/aptos/move-coder.js
CHANGED
|
@@ -23,24 +23,16 @@ export class MoveCoder extends AbstractMoveCoder {
|
|
|
23
23
|
filterAndDecodeResources(typeQname, resources) {
|
|
24
24
|
return this.filterAndDecodeInternal(typeQname, resources);
|
|
25
25
|
}
|
|
26
|
+
getMeaningfulFunctionParams(params) {
|
|
27
|
+
return getMeaningfulFunctionParams(params);
|
|
28
|
+
}
|
|
26
29
|
decodeFunctionPayload(payload) {
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
const params = getMeaningfulFunctionParams(func.params);
|
|
31
|
-
for (const [idx, arg] of payload.arguments.entries()) {
|
|
32
|
-
// TODO consider apply payload.type_arguments, but this might be hard since we don't code gen for them
|
|
33
|
-
const argType = params[idx];
|
|
34
|
-
argumentsTyped.push(this.decode(arg, argType));
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
catch (e) {
|
|
38
|
-
console.error('Decoding error for ', JSON.stringify(payload), e);
|
|
39
|
-
return payload;
|
|
40
|
-
}
|
|
30
|
+
const func = this.getMoveFunction(payload.function);
|
|
31
|
+
const params = getMeaningfulFunctionParams(func.params);
|
|
32
|
+
const argumentsDecoded = this.decodeArray(payload.arguments, params);
|
|
41
33
|
return {
|
|
42
34
|
...payload,
|
|
43
|
-
arguments_decoded:
|
|
35
|
+
arguments_decoded: argumentsDecoded,
|
|
44
36
|
};
|
|
45
37
|
}
|
|
46
38
|
}
|
|
@@ -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,2BAA2B,EAAE,MAAM,YAAY,CAAA;AACxD,OAAO,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAA;
|
|
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,2BAA2B,EAAE,MAAM,YAAY,CAAA;AACxD,OAAO,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAA;AAGlE,MAAM,OAAO,SAAU,SAAQ,iBAAuC;IACpE,IAAI,CAAC,MAA0B;QAC7B,IAAI,CAAC,MAAM,CAAC,GAAG,EAAE;YACf,MAAM,KAAK,CAAC,oBAAoB,CAAC,CAAA;SAClC;QACD,IAAI,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,GAAG,CAAC,OAAO,EAAE,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE;YACtD,OAAM;SACP;QACD,IAAI,CAAC,YAAY,CAAC,gBAAgB,CAAC,MAAM,CAAC,CAAC,CAAA;IAC7C,CAAC;IAED,WAAW,CAAI,KAAY;QACzB,OAAO,IAAI,CAAC,eAAe,CAAI,KAAK,CAA0B,CAAA;IAChE,CAAC;IACD,qBAAqB,CAAI,SAAiB,EAAE,SAAkB;QAC5D,OAAO,IAAI,CAAC,uBAAuB,CAAC,SAAS,EAAE,SAAS,CAA4B,CAAA;IACtF,CAAC;IACD,cAAc,CAAI,GAAiB;QACjC,OAAO,IAAI,CAAC,eAAe,CAAI,GAAG,CAAC,CAAA;IACrC,CAAC;IACD,wBAAwB,CAAI,SAAiB,EAAE,SAAyB;QACtE,OAAO,IAAI,CAAC,uBAAuB,CAAC,SAAS,EAAE,SAAS,CAAC,CAAA;IAC3D,CAAC;IAED,2BAA2B,CAAC,MAAwB;QAClD,OAAO,2BAA2B,CAAC,MAAM,CAAC,CAAA;IAC5C,CAAC;IAED,qBAAqB,CAAC,OAAgD;QACpE,MAAM,IAAI,GAAG,IAAI,CAAC,eAAe,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAA;QACnD,MAAM,MAAM,GAAG,2BAA2B,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;QACvD,MAAM,gBAAgB,GAAG,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,SAAS,EAAE,MAAM,CAAC,CAAA;QAEpE,OAAO;YACL,GAAG,OAAO;YACV,iBAAiB,EAAE,gBAAgB;SACP,CAAA;IAChC,CAAC;CACF;AAED,MAAM,CAAC,MAAM,UAAU,GAAG,IAAI,SAAS,EAAE,CAAA;AAEzC,MAAM,UAAU,gBAAgB;IAC9B,OAAO,UAAU,CAAA;AACnB,CAAC","sourcesContent":["import {\n Event,\n MoveModuleBytecode,\n MoveResource,\n toInternalModule,\n TransactionPayload_EntryFunctionPayload,\n} from './move-types.js'\n\nimport { TypedEventInstance, TypedMoveResource, TypedFunctionPayload } from './models.js'\nimport { getMeaningfulFunctionParams } from './utils.js'\nimport { AbstractMoveCoder } from '../move/abstract-move-coder.js'\nimport { TypeDescriptor } from '../move/index.js'\n\nexport class MoveCoder extends AbstractMoveCoder<Event | MoveResource> {\n load(module: MoveModuleBytecode) {\n if (!module.abi) {\n throw Error('Module without abi')\n }\n if (this.contains(module.abi.address, module.abi.name)) {\n return\n }\n this.loadInternal(toInternalModule(module))\n }\n\n decodeEvent<T>(event: Event): TypedEventInstance<T> | undefined {\n return this.decodedInternal<T>(event) as TypedEventInstance<T>\n }\n filterAndDecodeEvents<T>(typeQname: string, resources: Event[]): TypedEventInstance<T>[] {\n return this.filterAndDecodeInternal(typeQname, resources) as TypedEventInstance<T>[]\n }\n decodeResource<T>(res: MoveResource): TypedMoveResource<T> | undefined {\n return this.decodedInternal<T>(res)\n }\n filterAndDecodeResources<T>(typeQname: string, resources: MoveResource[]): TypedMoveResource<T>[] {\n return this.filterAndDecodeInternal(typeQname, resources)\n }\n\n getMeaningfulFunctionParams(params: TypeDescriptor[]): TypeDescriptor[] {\n return getMeaningfulFunctionParams(params)\n }\n\n decodeFunctionPayload(payload: TransactionPayload_EntryFunctionPayload): TransactionPayload_EntryFunctionPayload {\n const func = this.getMoveFunction(payload.function)\n const params = getMeaningfulFunctionParams(func.params)\n const argumentsDecoded = this.decodeArray(payload.arguments, params)\n\n return {\n ...payload,\n arguments_decoded: argumentsDecoded,\n } as TypedFunctionPayload<any>\n }\n}\n\nexport const MOVE_CODER = new MoveCoder()\n\nexport function defaultMoveCoder(): MoveCoder {\n return MOVE_CODER\n}\n"]}
|
package/lib/aptos/network.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { AptosClient } from 'aptos-sdk';
|
|
1
2
|
export declare enum AptosNetwork {
|
|
2
3
|
MAIN_NET = 1,
|
|
3
4
|
TEST_NET = 2
|
|
@@ -7,5 +8,6 @@ export declare function getAptosChainName(network: AptosNetwork): string;
|
|
|
7
8
|
export declare class AptosBindOptions {
|
|
8
9
|
address: string;
|
|
9
10
|
network?: AptosNetwork;
|
|
11
|
+
client?: AptosClient;
|
|
10
12
|
startVersion?: bigint | number;
|
|
11
13
|
}
|
package/lib/aptos/network.js
CHANGED
package/lib/aptos/network.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"network.js","sourceRoot":"","sources":["../../src/aptos/network.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAA;
|
|
1
|
+
{"version":3,"file":"network.js","sourceRoot":"","sources":["../../src/aptos/network.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAA;AAG1D,MAAM,CAAN,IAAY,YAIX;AAJD,WAAY,YAAY;IACtB,uDAAY,CAAA;IACZ,uDAAY,CAAA;IACZ,WAAW;AACb,CAAC,EAJW,YAAY,KAAZ,YAAY,QAIvB;AAED,MAAM,UAAU,UAAU,CAAC,OAAqB;IAC9C,QAAQ,OAAO,EAAE;QACf,KAAK,YAAY,CAAC,QAAQ;YACxB,OAAO,SAAS,CAAC,aAAa,CAAA;KACjC;IACD,OAAO,SAAS,CAAC,aAAa,CAAA;AAChC,CAAC;AAED,MAAM,UAAU,iBAAiB,CAAC,OAAqB;IACrD,QAAQ,OAAO,EAAE;QACf,KAAK,YAAY,CAAC,QAAQ;YACxB,OAAO,YAAY,CAAC,SAAS,CAAC,aAAa,CAAC,CAAA;KAC/C;IACD,OAAO,YAAY,CAAC,SAAS,CAAC,aAAa,CAAC,CAAA;AAC9C,CAAC;AAED,MAAM,OAAO,gBAAgB;IAC3B,OAAO,CAAQ;IACf,OAAO,GAAkB,YAAY,CAAC,QAAQ,CAAA;IAC9C,MAAM,CAAc;IACpB,YAAY,CAAkB;CAC/B","sourcesContent":["import { CHAIN_IDS, getChainName } from '../core/chain.js'\nimport { AptosClient } from 'aptos-sdk'\n\nexport enum AptosNetwork {\n MAIN_NET = 1,\n TEST_NET = 2,\n // DEV_NET,\n}\n\nexport function getChainId(network: AptosNetwork): string {\n switch (network) {\n case AptosNetwork.TEST_NET:\n return CHAIN_IDS.APTOS_TESTNET\n }\n return CHAIN_IDS.APTOS_MAINNET\n}\n\nexport function getAptosChainName(network: AptosNetwork): string {\n switch (network) {\n case AptosNetwork.TEST_NET:\n return getChainName(CHAIN_IDS.APTOS_TESTNET)\n }\n return getChainName(CHAIN_IDS.APTOS_MAINNET)\n}\n\nexport class AptosBindOptions {\n address: string\n network?: AptosNetwork = AptosNetwork.MAIN_NET\n client?: AptosClient\n startVersion?: bigint | number\n}\n"]}
|
|
@@ -16,6 +16,7 @@ export declare abstract class AbstractCodegen<ModuleTypes, NetworkType> {
|
|
|
16
16
|
ADDRESS_TYPE: string;
|
|
17
17
|
PREFIX: string;
|
|
18
18
|
STRUCT_FIELD_NAME: string;
|
|
19
|
+
GENERATED_CLIENT: boolean;
|
|
19
20
|
abstract fetchModules(account: string, network: NetworkType): Promise<ModuleTypes>;
|
|
20
21
|
abstract toInternalModules(modules: ModuleTypes): InternalMoveModule[];
|
|
21
22
|
abstract getEventStructs(module: InternalMoveModule): Map<string, InternalMoveStruct>;
|
|
@@ -29,6 +30,7 @@ export declare abstract class AbstractCodegen<ModuleTypes, NetworkType> {
|
|
|
29
30
|
generateFunctionTypeParameters(func: InternalMoveFunction): string;
|
|
30
31
|
generateStructTypeParameters(struct: InternalMoveStruct, useAny?: boolean): string;
|
|
31
32
|
generateCallArgsStructs(module: InternalMoveModule, func: InternalMoveFunction): string | undefined;
|
|
33
|
+
generateClientFunctions(module: InternalMoveModule, func: InternalMoveFunction): string;
|
|
32
34
|
generateOnEntryFunctions(module: InternalMoveModule, func: InternalMoveFunction): string;
|
|
33
35
|
generateOnEvents(module: InternalMoveModule, struct: InternalMoveStruct): string;
|
|
34
36
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { InternalMoveFunctionVisibility, } from './internal-models.js';
|
|
1
2
|
import path from 'path';
|
|
2
3
|
import fs from 'fs';
|
|
3
4
|
import { AccountModulesImportInfo, AccountRegister } from './account.js';
|
|
@@ -12,6 +13,7 @@ export class AbstractCodegen {
|
|
|
12
13
|
ADDRESS_TYPE;
|
|
13
14
|
PREFIX;
|
|
14
15
|
STRUCT_FIELD_NAME = 'data';
|
|
16
|
+
GENERATED_CLIENT = false;
|
|
15
17
|
readModulesFile(fullPath) {
|
|
16
18
|
return JSON.parse(fs.readFileSync(fullPath, 'utf-8'));
|
|
17
19
|
}
|
|
@@ -23,9 +25,6 @@ export class AbstractCodegen {
|
|
|
23
25
|
if (!fs.existsSync(srcDir)) {
|
|
24
26
|
return;
|
|
25
27
|
}
|
|
26
|
-
if (network === this.TEST_NET) {
|
|
27
|
-
console.log('Found testnet directory, generate code for testnet modules');
|
|
28
|
-
}
|
|
29
28
|
const files = fs.readdirSync(srcDir);
|
|
30
29
|
outputDir = path.resolve(outputDir);
|
|
31
30
|
const outputs = [];
|
|
@@ -78,6 +77,7 @@ export class AbstractCodegen {
|
|
|
78
77
|
}
|
|
79
78
|
}
|
|
80
79
|
for (const output of outputs) {
|
|
80
|
+
// const content = output.fileContent
|
|
81
81
|
const content = format(output.fileContent, { parser: 'typescript' });
|
|
82
82
|
fs.writeFileSync(path.join(outputDir, output.fileName), content);
|
|
83
83
|
}
|
|
@@ -88,7 +88,7 @@ export class AbstractCodegen {
|
|
|
88
88
|
`);
|
|
89
89
|
for (const output of outputs) {
|
|
90
90
|
const parsed = path.parse(output.fileName);
|
|
91
|
-
const content = `export * as _${parsed.name} from './${parsed.name}.js'\n`;
|
|
91
|
+
const content = `export * as _${parsed.name.replaceAll('-', '_')} from './${parsed.name}.js'\n`;
|
|
92
92
|
fs.appendFileSync(rootFile, content);
|
|
93
93
|
}
|
|
94
94
|
}
|
|
@@ -103,6 +103,9 @@ export class AbstractCodegen {
|
|
|
103
103
|
const functions = module.exposedFunctions
|
|
104
104
|
.map((f) => this.generateOnEntryFunctions(module, f))
|
|
105
105
|
.filter((s) => s !== '');
|
|
106
|
+
const clientFunctions = module.exposedFunctions
|
|
107
|
+
.map((f) => this.generateClientFunctions(module, f))
|
|
108
|
+
.filter((s) => s !== '');
|
|
106
109
|
const eventStructs = this.getEventStructs(module);
|
|
107
110
|
const eventTypes = new Set(eventStructs.keys());
|
|
108
111
|
const events = Array.from(eventStructs.values())
|
|
@@ -112,6 +115,14 @@ export class AbstractCodegen {
|
|
|
112
115
|
const callArgs = module.exposedFunctions.map((f) => this.generateCallArgsStructs(module, f));
|
|
113
116
|
const moduleName = normalizeToJSName(module.name);
|
|
114
117
|
let processor = '';
|
|
118
|
+
let client = '';
|
|
119
|
+
if (this.GENERATED_CLIENT && clientFunctions.length > 0) {
|
|
120
|
+
client = `
|
|
121
|
+
export class ${moduleName}_client extends ModuleClient {
|
|
122
|
+
${clientFunctions.join('\n')}
|
|
123
|
+
}
|
|
124
|
+
`;
|
|
125
|
+
}
|
|
115
126
|
if (functions.length > 0 || events.length > 0) {
|
|
116
127
|
processor = `export class ${moduleName} extends ${this.PREFIX}BaseProcessor {
|
|
117
128
|
|
|
@@ -134,6 +145,8 @@ export class AbstractCodegen {
|
|
|
134
145
|
`;
|
|
135
146
|
}
|
|
136
147
|
return `
|
|
148
|
+
${client}
|
|
149
|
+
|
|
137
150
|
${processor}
|
|
138
151
|
|
|
139
152
|
export namespace ${moduleName} {
|
|
@@ -205,12 +218,36 @@ export class AbstractCodegen {
|
|
|
205
218
|
const genericString = this.generateFunctionTypeParameters(func);
|
|
206
219
|
return `
|
|
207
220
|
export interface ${camelFuncName}Payload${genericString}
|
|
208
|
-
extends
|
|
221
|
+
extends TypedFunctionPayload<[${fields.join(',')}]> {
|
|
209
222
|
arguments_decoded: [${fields.join(',')}],
|
|
210
223
|
type_arguments: [${func.typeParams.map((_) => 'string').join(', ')}]
|
|
211
224
|
}
|
|
212
225
|
`;
|
|
213
226
|
}
|
|
227
|
+
generateClientFunctions(module, func) {
|
|
228
|
+
if (func.visibility === InternalMoveFunctionVisibility.PRIVATE) {
|
|
229
|
+
return '';
|
|
230
|
+
}
|
|
231
|
+
if (func.isEntry) {
|
|
232
|
+
return '';
|
|
233
|
+
}
|
|
234
|
+
// const moduleName = normalizeToJSName(module.name)
|
|
235
|
+
const funcName = camelCase(func.name);
|
|
236
|
+
const fields = this.getMeaningfulFunctionParams(func.params).map((param) => {
|
|
237
|
+
return generateTypeForDescriptor(param, module.address, this.ADDRESS_TYPE);
|
|
238
|
+
});
|
|
239
|
+
const genericString = this.generateFunctionTypeParameters(func);
|
|
240
|
+
const returns = func.return.map((param) => {
|
|
241
|
+
return generateTypeForDescriptor(param, module.address, this.ADDRESS_TYPE);
|
|
242
|
+
});
|
|
243
|
+
const source = `
|
|
244
|
+
${funcName}${genericString}(type_arguments: [${func.typeParams
|
|
245
|
+
.map((_) => 'string')
|
|
246
|
+
.join(', ')}], args: [${fields.join(',')}], version?: bigint): Promise<[${returns.join(',')}]> {
|
|
247
|
+
return this.viewDecoded('${module.address}::${module.name}::${func.name}', type_arguments, args, version) as any
|
|
248
|
+
}`;
|
|
249
|
+
return source;
|
|
250
|
+
}
|
|
214
251
|
generateOnEntryFunctions(module, func) {
|
|
215
252
|
if (!func.isEntry) {
|
|
216
253
|
return '';
|
|
@@ -278,10 +315,10 @@ export class AccountCodegen {
|
|
|
278
315
|
import { CallFilter } from "@sentio/sdk/move"
|
|
279
316
|
import {
|
|
280
317
|
MoveCoder, defaultMoveCoder, ${this.moduleGen.PREFIX}BindOptions, ${this.moduleGen.PREFIX}BaseProcessor,
|
|
281
|
-
TypedEventInstance, ${this.moduleGen.PREFIX}Network,
|
|
318
|
+
TypedEventInstance, ${this.moduleGen.PREFIX}Network, TypedFunctionPayload,
|
|
282
319
|
${this.moduleGen.PREFIX}Context } from "@sentio/sdk/${this.moduleGen.PREFIX.toLowerCase()}"
|
|
283
320
|
import { MoveFetchConfig } from "@sentio/protos"
|
|
284
|
-
import { ${this.moduleGen.ADDRESS_TYPE} } from "@sentio/sdk/${this.moduleGen.PREFIX.toLowerCase()}"
|
|
321
|
+
import { ${this.moduleGen.ADDRESS_TYPE}, ModuleClient } from "@sentio/sdk/${this.moduleGen.PREFIX.toLowerCase()}"
|
|
285
322
|
`;
|
|
286
323
|
const dependedAccounts = [];
|
|
287
324
|
const moduleImports = [];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"abstract-codegen.js","sourceRoot":"","sources":["../../src/move/abstract-codegen.ts"],"names":[],"mappings":"AACA,OAAO,IAAI,MAAM,MAAM,CAAA;AACvB,OAAO,EAAE,MAAM,IAAI,CAAA;AACnB,OAAO,EAAE,wBAAwB,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AACxE,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAA;AACjC,OAAO,EAAE,kBAAkB,EAAE,WAAW,EAAE,iBAAiB,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AACzF,OAAO,EAAE,yBAAyB,EAAE,MAAM,cAAc,CAAA;AACxD,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,WAAW,CAAA;AAcjD,MAAM,OAAgB,eAAe;IACnC,QAAQ,CAAa;IACrB,QAAQ,CAAa;IACrB,YAAY,CAAQ;IACpB,MAAM,CAAQ;IACd,iBAAiB,GAAW,MAAM,CAAA;IAUlC,eAAe,CAAC,QAAgB;QAC9B,OAAO,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,YAAY,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC,CAAA;IACvD,CAAC;IAED,KAAK,CAAC,QAAQ,CAAC,MAAc,EAAE,SAAiB;QAC9C,MAAM,IAAI,CAAC,kBAAkB,CAAC,MAAM,EAAE,SAAS,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAA;QAC/D,MAAM,IAAI,CAAC,kBAAkB,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,SAAS,CAAC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B;SACF;QAED,MAAM,MAAM,GAAG;;;;;uCAKoB,OAAO;;MAExC,OAAO;;MAEP,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC;;MAExB,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,cAAc,CAAC,CAAC,EAAE,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC;;kCAE7D,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,GAAG,CAAC;;;QAGlD,gBAAgB,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,sBAAsB,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC;;;;;;;KAOtE,CAAA,CAAC,SAAS;QAEX,OAAO;YACL;gBACE,QAAQ,EAAE,IAAI,CAAC,MAAM,CAAC,QAAQ,GAAG,KAAK;gBACtC,WAAW,EAAE,MAAM;aACpB;SACF,CAAA;IACH,CAAC;CACF","sourcesContent":["import { InternalMoveFunction, InternalMoveModule, InternalMoveStruct } from './internal-models.js'\nimport path from 'path'\nimport fs from 'fs'\nimport { AccountModulesImportInfo, AccountRegister } from './account.js'\nimport chalk from 'chalk'\nimport { format } from 'prettier'\nimport { isFrameworkAccount, moduleQname, normalizeToJSName, SPLITTER } from './utils.js'\nimport { generateTypeForDescriptor } from './ts-type.js'\nimport { camelCase, upperFirst } from 'lodash-es'\nimport { TypeDescriptor } from './types.js'\n\ninterface OutputFile {\n fileName: string\n fileContent: string\n}\n\ninterface Config<NetworkType> {\n fileName: string\n outputDir: string\n network: NetworkType\n}\n\nexport abstract class AbstractCodegen<ModuleTypes, NetworkType> {\n TEST_NET: NetworkType\n MAIN_NET: NetworkType\n ADDRESS_TYPE: string\n PREFIX: string\n STRUCT_FIELD_NAME: string = 'data'\n\n abstract fetchModules(account: string, network: NetworkType): Promise<ModuleTypes>\n abstract toInternalModules(modules: ModuleTypes): 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 readModulesFile(fullPath: string) {\n return JSON.parse(fs.readFileSync(fullPath, 'utf-8'))\n }\n\n async generate(srcDir: string, outputDir: string) {\n await this.generateForNetwork(srcDir, outputDir, this.MAIN_NET)\n await this.generateForNetwork(path.join(srcDir, 'testnet'), path.join(outputDir, 'testnet'), this.TEST_NET)\n }\n\n async generateForNetwork(srcDir: string, outputDir: string, network: NetworkType) {\n if (!fs.existsSync(srcDir)) {\n return\n }\n if (network === this.TEST_NET) {\n console.log('Found testnet directory, generate code for testnet modules')\n }\n const files = fs.readdirSync(srcDir)\n outputDir = path.resolve(outputDir)\n const outputs: OutputFile[] = []\n\n fs.mkdirSync(outputDir, { recursive: true })\n\n const loader = new AccountRegister()\n\n // when generating user code, don't need to generate framework account\n loader.accountImports.set('0x1', new AccountModulesImportInfo('0x1', '0x1'))\n loader.accountImports.set('0x2', new AccountModulesImportInfo('0x2', '0x2'))\n loader.accountImports.set('0x3', new AccountModulesImportInfo('0x3', '0x3'))\n // const client = getRpcClient(network)\n\n for (const file of files) {\n if (!file.endsWith('.json')) {\n continue\n }\n const fullPath = path.resolve(srcDir, file)\n const abi = this.readModulesFile(fullPath)\n const modules = this.toInternalModules(abi)\n\n for (const module of modules) {\n loader.register(module, path.basename(file, '.json'))\n }\n const codeGen = new AccountCodegen(this, loader, abi, modules, {\n fileName: path.basename(file, '.json'),\n outputDir: outputDir,\n network,\n })\n\n outputs.push(...codeGen.generate())\n }\n\n while (loader.pendingAccounts.size > 0) {\n for (const account of loader.pendingAccounts) {\n console.log(`download dependent module for account ${account} at ${network}`)\n\n try {\n const rawModules = await this.fetchModules(account, network)\n const modules = this.toInternalModules(rawModules)\n\n fs.writeFileSync(path.resolve(srcDir, account + '.json'), JSON.stringify(rawModules, null, '\\t'))\n\n for (const module of modules) {\n loader.register(module, account)\n }\n const codeGen = new AccountCodegen(this, loader, rawModules, modules, {\n fileName: account,\n outputDir: outputDir,\n network,\n })\n\n outputs.push(...codeGen.generate())\n } catch (e) {\n console.error(\n chalk.red(\n 'Error downloading account module, check if you choose the right network,or download account modules manually into your director'\n )\n )\n console.error(e)\n process.exit(1)\n }\n }\n }\n\n for (const output of outputs) {\n const content = format(output.fileContent, { parser: 'typescript' })\n fs.writeFileSync(path.join(outputDir, output.fileName), content)\n }\n\n const rootFile = path.join(outputDir, 'index.ts')\n fs.writeFileSync(\n rootFile,\n `/* Autogenerated file. Do not edit manually. */\n/* tslint:disable */\n/* eslint-disable */\n`\n )\n for (const output of outputs) {\n const parsed = path.parse(output.fileName)\n const content = `export * as _${parsed.name} from './${parsed.name}.js'\\n`\n fs.appendFileSync(rootFile, content)\n }\n }\n\n generateNetworkOption(network: NetworkType) {\n switch (network) {\n case this.TEST_NET:\n return 'TEST_NET'\n }\n return 'MAIN_NET'\n }\n\n generateModule(module: InternalMoveModule, network: NetworkType) {\n const functions = module.exposedFunctions\n .map((f) => this.generateOnEntryFunctions(module, f))\n .filter((s) => s !== '')\n\n const eventStructs = this.getEventStructs(module)\n const eventTypes = new Set(eventStructs.keys())\n const events = Array.from(eventStructs.values())\n .map((e) => this.generateOnEvents(module, e))\n .filter((s) => s !== '')\n const structs = module.structs.map((s) => this.generateStructs(module, s, eventTypes))\n const callArgs = module.exposedFunctions.map((f) => this.generateCallArgsStructs(module, f))\n\n const moduleName = normalizeToJSName(module.name)\n let processor = ''\n if (functions.length > 0 || events.length > 0) {\n processor = `export class ${moduleName} extends ${this.PREFIX}BaseProcessor {\n\n constructor(options: ${this.PREFIX}BindOptions) {\n super(\"${module.name}\", options)\n }\n static DEFAULT_OPTIONS: ${this.PREFIX}BindOptions = {\n address: \"${module.address}\",\n network: ${this.PREFIX}Network.${this.generateNetworkOption(network)}\n }\n\n static bind(options: Partial<${this.PREFIX}BindOptions> = {}): ${moduleName} {\n return new ${moduleName}({ ...${moduleName}.DEFAULT_OPTIONS, ...options })\n }\n\n ${functions.join('\\n')}\n\n ${events.join('\\n')}\n }\n `\n }\n\n return `\n ${processor}\n\n export namespace ${moduleName} {\n ${structs.join('\\n')}\n\n ${callArgs.join('\\n')}\n }\n `\n }\n\n generateStructs(module: InternalMoveModule, struct: InternalMoveStruct, events: Set<string>) {\n const genericString = this.generateStructTypeParameters(struct)\n const genericStringAny = this.generateStructTypeParameters(struct, true)\n\n const structName = normalizeToJSName(struct.name)\n\n const fields = struct.fields.map((field) => {\n const type = generateTypeForDescriptor(field.type, module.address, this.ADDRESS_TYPE)\n return `${field.name}: ${type}`\n })\n\n let eventPayload = ''\n if (events.has(moduleQname(module) + SPLITTER + struct.name)) {\n eventPayload = `\n export interface ${structName}Instance extends\n TypedEventInstance<${structName}${genericStringAny}> {\n ${this.STRUCT_FIELD_NAME}_decoded: ${structName}${genericStringAny}\n type_arguments: [${struct.typeParams.map((_) => 'string').join(', ')}]\n }\n `\n }\n\n return `\n export class ${structName}${genericString} {\n static TYPE_QNAME = '${module.address}::${module.name}::${struct.name}'\n ${fields.join('\\n')}\n }\n\n ${eventPayload}\n `\n }\n\n generateFunctionTypeParameters(func: InternalMoveFunction) {\n let genericString = ''\n if (func.typeParams && func.typeParams.length > 0) {\n const params = func.typeParams\n .map((v, idx) => {\n return `T${idx}=any`\n })\n .join(',')\n genericString = `<${params}>`\n }\n return genericString\n }\n\n generateStructTypeParameters(struct: InternalMoveStruct, useAny = false) {\n let genericString = ''\n\n if (struct.typeParams && struct.typeParams.length > 0) {\n const params = struct.typeParams\n .map((v, idx) => {\n return useAny ? 'any' : 'T' + idx\n })\n .join(',')\n genericString = `<${params}>`\n }\n return genericString\n }\n\n generateCallArgsStructs(module: InternalMoveModule, func: InternalMoveFunction) {\n if (!func.isEntry) {\n return\n }\n\n const fields = this.getMeaningfulFunctionParams(func.params).map((param) => {\n return generateTypeForDescriptor(param, module.address, this.ADDRESS_TYPE)\n })\n\n const camelFuncName = upperFirst(camelCase(func.name))\n\n const genericString = this.generateFunctionTypeParameters(func)\n return `\n export interface ${camelFuncName}Payload${genericString}\n extends TypedEntryFunctionPayload<[${fields.join(',')}]> {\n arguments_decoded: [${fields.join(',')}],\n type_arguments: [${func.typeParams.map((_) => 'string').join(', ')}]\n }\n `\n }\n\n generateOnEntryFunctions(module: InternalMoveModule, func: InternalMoveFunction) {\n if (!func.isEntry) {\n return ''\n }\n\n // const genericString = generateFunctionTypeParameters(func)\n const moduleName = normalizeToJSName(module.name)\n\n const camelFuncName = upperFirst(camelCase(func.name))\n const source = `\n onEntry${camelFuncName}(func: (call: ${moduleName}.${camelFuncName}Payload, ctx: ${this.PREFIX}Context) => void, filter?: CallFilter, fetchConfig?: MoveFetchConfig): ${moduleName} {\n this.onEntryFunctionCall(func, {\n ...filter,\n function: '${module.name}::${func.name}'\n },\n fetchConfig)\n return this\n }`\n\n return source\n }\n\n generateOnEvents(module: InternalMoveModule, struct: InternalMoveStruct): string {\n // for struct that has drop + store\n // if (!isEvent(struct, module)) {\n // return ''\n // }\n\n // const genericString = generateStructTypeParameters(struct)\n\n const moduleName = normalizeToJSName(module.name)\n const source = `\n onEvent${struct.name}(func: (event: ${moduleName}.${normalizeToJSName(struct.name)}Instance, ctx: ${\n this.PREFIX\n }Context) => void, fetchConfig?: MoveFetchConfig): ${moduleName} {\n this.onMoveEvent(func, {\n type: '${module.name}::${struct.name}'\n },\n fetchConfig)\n return this\n }\n `\n return source\n }\n}\n\nexport class AccountCodegen<ModuleType, NetworkType> {\n modules: InternalMoveModule[]\n config: Config<NetworkType>\n abi: ModuleType\n loader: AccountRegister\n moduleGen: AbstractCodegen<ModuleType, NetworkType>\n\n constructor(\n moduleGen: AbstractCodegen<ModuleType, NetworkType>,\n loader: AccountRegister,\n abi: ModuleType,\n modules: InternalMoveModule[],\n config: Config<NetworkType>\n ) {\n // const json = fs.readFileSync(config.srcFile, 'utf-8')\n this.moduleGen = moduleGen\n this.abi = abi\n this.modules = modules\n this.config = config\n this.loader = loader\n }\n\n generate(): OutputFile[] {\n if (!this.modules) {\n return []\n }\n // const baseName = path.basename(this.config.fileName, '.json')\n\n let address: string | undefined\n for (const module of this.modules) {\n address = module.address\n }\n if (!address) {\n return []\n }\n\n const imports = `\n import { CallFilter } from \"@sentio/sdk/move\"\n import {\n MoveCoder, defaultMoveCoder, ${this.moduleGen.PREFIX}BindOptions, ${this.moduleGen.PREFIX}BaseProcessor,\n TypedEventInstance, ${this.moduleGen.PREFIX}Network, TypedEntryFunctionPayload,\n ${this.moduleGen.PREFIX}Context } from \"@sentio/sdk/${this.moduleGen.PREFIX.toLowerCase()}\"\n import { MoveFetchConfig } from \"@sentio/protos\"\n import { ${this.moduleGen.ADDRESS_TYPE} } from \"@sentio/sdk/${this.moduleGen.PREFIX.toLowerCase()}\"\n `\n\n const dependedAccounts: string[] = []\n\n const moduleImports: string[] = []\n\n const info = this.loader.accountImports.get(address)\n\n if (info) {\n for (const [account] of info.imports.entries()) {\n // Remap to user's filename if possible, TODO codepath not well tested\n const tsAccountModule = './' + (this.loader.accountImports.get(account)?.moduleName || account)\n if (isFrameworkAccount(account) && !isFrameworkAccount(address)) {\n // Decide where to find runtime library\n moduleImports.push(`import { _${account} } from \"@sentio/sdk/${this.moduleGen.PREFIX.toLowerCase()}/builtin\"`)\n } else {\n moduleImports.push(`import * as _${account} from \"${tsAccountModule}.js\"`)\n }\n\n dependedAccounts.push(account)\n }\n }\n\n const source = `\n /* Autogenerated file. Do not edit manually. */\n /* tslint:disable */\n /* eslint-disable */\n\n /* Generated modules for account ${address} */\n\n ${imports}\n\n ${moduleImports.join('\\n')}\n\n ${this.modules.map((m) => this.moduleGen.generateModule(m, this.config.network)).join('\\n')}\n\n const MODULES = JSON.parse('${JSON.stringify(this.abi)}')\n\n export function loadAllTypes(coder: MoveCoder) {\n ${dependedAccounts.map((a) => `_${a}.loadAllTypes(coder)`).join('\\n')}\n for (const m of Object.values(MODULES)) {\n coder.load(m as any)\n }\n }\n\n loadAllTypes(defaultMoveCoder())\n ` // source\n\n return [\n {\n fileName: this.config.fileName + '.ts',\n fileContent: source,\n },\n ]\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"abstract-codegen.js","sourceRoot":"","sources":["../../src/move/abstract-codegen.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,8BAA8B,GAG/B,MAAM,sBAAsB,CAAA;AAC7B,OAAO,IAAI,MAAM,MAAM,CAAA;AACvB,OAAO,EAAE,MAAM,IAAI,CAAA;AACnB,OAAO,EAAE,wBAAwB,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AACxE,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAA;AACjC,OAAO,EAAE,kBAAkB,EAAE,WAAW,EAAE,iBAAiB,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AACzF,OAAO,EAAE,yBAAyB,EAAE,MAAM,cAAc,CAAA;AACxD,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,WAAW,CAAA;AAcjD,MAAM,OAAgB,eAAe;IACnC,QAAQ,CAAa;IACrB,QAAQ,CAAa;IACrB,YAAY,CAAQ;IACpB,MAAM,CAAQ;IACd,iBAAiB,GAAW,MAAM,CAAA;IAClC,gBAAgB,GAAG,KAAK,CAAA;IAUxB,eAAe,CAAC,QAAgB;QAC9B,OAAO,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,YAAY,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC,CAAA;IACvD,CAAC;IAED,KAAK,CAAC,QAAQ,CAAC,MAAc,EAAE,SAAiB;QAC9C,MAAM,IAAI,CAAC,kBAAkB,CAAC,MAAM,EAAE,SAAS,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAA;QAC/D,MAAM,IAAI,CAAC,kBAAkB,CAAC,IAAI,CAAC,IAAI,CAAC,M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O,CAAC,IAAI,CAAC,kBAAkB,CAAC,OAAO,CAAC,EAAE;oBAC/D,uCAAuC;oBACvC,aAAa,CAAC,IAAI,CAAC,aAAa,OAAO,wBAAwB,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,WAAW,EAAE,WAAW,CAAC,CAAA;iBAC/G;qBAAM;oBACL,aAAa,CAAC,IAAI,CAAC,gBAAgB,OAAO,UAAU,eAAe,MAAM,CAAC,CAAA;iBAC3E;gBAED,gBAAgB,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;aAC/B;SACF;QAED,MAAM,MAAM,GAAG;;;;;uCAKoB,OAAO;;MAExC,OAAO;;MAEP,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC;;MAExB,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,cAAc,CAAC,CAAC,EAAE,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC;;kCAE7D,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,GAAG,CAAC;;;QAGlD,gBAAgB,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,sBAAsB,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC;;;;;;;KAOtE,CAAA,CAAC,SAAS;QAEX,OAAO;YACL;gBACE,QAAQ,EAAE,IAAI,CAAC,MAAM,CAAC,QAAQ,GAAG,KAAK;gBACtC,WAAW,EAAE,MAAM;aACpB;SACF,CAAA;IACH,CAAC;CACF","sourcesContent":["import {\n InternalMoveFunction,\n InternalMoveFunctionVisibility,\n InternalMoveModule,\n InternalMoveStruct,\n} from './internal-models.js'\nimport path from 'path'\nimport fs from 'fs'\nimport { AccountModulesImportInfo, AccountRegister } from './account.js'\nimport chalk from 'chalk'\nimport { format } from 'prettier'\nimport { isFrameworkAccount, moduleQname, normalizeToJSName, SPLITTER } from './utils.js'\nimport { generateTypeForDescriptor } from './ts-type.js'\nimport { camelCase, upperFirst } from 'lodash-es'\nimport { TypeDescriptor } from './types.js'\n\ninterface OutputFile {\n fileName: string\n fileContent: string\n}\n\ninterface Config<NetworkType> {\n fileName: string\n outputDir: string\n network: NetworkType\n}\n\nexport abstract class AbstractCodegen<ModuleTypes, NetworkType> {\n TEST_NET: NetworkType\n MAIN_NET: NetworkType\n ADDRESS_TYPE: string\n PREFIX: string\n STRUCT_FIELD_NAME: string = 'data'\n GENERATED_CLIENT = false\n\n abstract fetchModules(account: string, network: NetworkType): Promise<ModuleTypes>\n abstract toInternalModules(modules: ModuleTypes): 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 readModulesFile(fullPath: string) {\n return JSON.parse(fs.readFileSync(fullPath, 'utf-8'))\n }\n\n async generate(srcDir: string, outputDir: string) {\n await this.generateForNetwork(srcDir, outputDir, this.MAIN_NET)\n await this.generateForNetwork(path.join(srcDir, 'testnet'), path.join(outputDir, 'testnet'), this.TEST_NET)\n }\n\n async generateForNetwork(srcDir: string, outputDir: string, network: NetworkType) {\n if (!fs.existsSync(srcDir)) {\n return\n }\n\n const files = fs.readdirSync(srcDir)\n outputDir = path.resolve(outputDir)\n const outputs: OutputFile[] = []\n\n fs.mkdirSync(outputDir, { recursive: true })\n\n const loader = new AccountRegister()\n\n // when generating user code, don't need to generate framework account\n loader.accountImports.set('0x1', new AccountModulesImportInfo('0x1', '0x1'))\n loader.accountImports.set('0x2', new AccountModulesImportInfo('0x2', '0x2'))\n loader.accountImports.set('0x3', new AccountModulesImportInfo('0x3', '0x3'))\n // const client = getRpcClient(network)\n\n for (const file of files) {\n if (!file.endsWith('.json')) {\n continue\n }\n const fullPath = path.resolve(srcDir, file)\n const abi = this.readModulesFile(fullPath)\n const modules = this.toInternalModules(abi)\n\n for (const module of modules) {\n loader.register(module, path.basename(file, '.json'))\n }\n const codeGen = new AccountCodegen(this, loader, abi, modules, {\n fileName: path.basename(file, '.json'),\n outputDir: outputDir,\n network,\n })\n\n outputs.push(...codeGen.generate())\n }\n\n while (loader.pendingAccounts.size > 0) {\n for (const account of loader.pendingAccounts) {\n console.log(`download dependent module for account ${account} at ${network}`)\n\n try {\n const rawModules = await this.fetchModules(account, network)\n const modules = this.toInternalModules(rawModules)\n\n fs.writeFileSync(path.resolve(srcDir, account + '.json'), JSON.stringify(rawModules, null, '\\t'))\n\n for (const module of modules) {\n loader.register(module, account)\n }\n const codeGen = new AccountCodegen(this, loader, rawModules, modules, {\n fileName: account,\n outputDir: outputDir,\n network,\n })\n\n outputs.push(...codeGen.generate())\n } catch (e) {\n console.error(\n chalk.red(\n 'Error downloading account module, check if you choose the right network,or download account modules manually into your director'\n )\n )\n console.error(e)\n process.exit(1)\n }\n }\n }\n\n for (const output of outputs) {\n // const content = output.fileContent\n const content = format(output.fileContent, { parser: 'typescript' })\n fs.writeFileSync(path.join(outputDir, output.fileName), content)\n }\n\n const rootFile = path.join(outputDir, 'index.ts')\n fs.writeFileSync(\n rootFile,\n `/* Autogenerated file. Do not edit manually. */\n/* tslint:disable */\n/* eslint-disable */\n`\n )\n for (const output of outputs) {\n const parsed = path.parse(output.fileName)\n const content = `export * as _${parsed.name.replaceAll('-', '_')} from './${parsed.name}.js'\\n`\n fs.appendFileSync(rootFile, content)\n }\n }\n\n generateNetworkOption(network: NetworkType) {\n switch (network) {\n case this.TEST_NET:\n return 'TEST_NET'\n }\n return 'MAIN_NET'\n }\n\n generateModule(module: InternalMoveModule, network: NetworkType) {\n const functions = module.exposedFunctions\n .map((f) => this.generateOnEntryFunctions(module, f))\n .filter((s) => s !== '')\n const clientFunctions = module.exposedFunctions\n .map((f) => this.generateClientFunctions(module, f))\n .filter((s) => s !== '')\n const eventStructs = this.getEventStructs(module)\n const eventTypes = new Set(eventStructs.keys())\n const events = Array.from(eventStructs.values())\n .map((e) => this.generateOnEvents(module, e))\n .filter((s) => s !== '')\n const structs = module.structs.map((s) => this.generateStructs(module, s, eventTypes))\n const callArgs = module.exposedFunctions.map((f) => this.generateCallArgsStructs(module, f))\n\n const moduleName = normalizeToJSName(module.name)\n let processor = ''\n let client = ''\n\n if (this.GENERATED_CLIENT && clientFunctions.length > 0) {\n client = `\n export class ${moduleName}_client extends ModuleClient {\n ${clientFunctions.join('\\n')}\n }\n `\n }\n\n if (functions.length > 0 || events.length > 0) {\n processor = `export class ${moduleName} extends ${this.PREFIX}BaseProcessor {\n\n constructor(options: ${this.PREFIX}BindOptions) {\n super(\"${module.name}\", options)\n }\n static DEFAULT_OPTIONS: ${this.PREFIX}BindOptions = {\n address: \"${module.address}\",\n network: ${this.PREFIX}Network.${this.generateNetworkOption(network)}\n }\n\n static bind(options: Partial<${this.PREFIX}BindOptions> = {}): ${moduleName} {\n return new ${moduleName}({ ...${moduleName}.DEFAULT_OPTIONS, ...options })\n }\n\n ${functions.join('\\n')}\n\n ${events.join('\\n')}\n }\n `\n }\n\n return `\n ${client}\n\n ${processor}\n\n export namespace ${moduleName} {\n ${structs.join('\\n')}\n\n ${callArgs.join('\\n')}\n }\n `\n }\n\n generateStructs(module: InternalMoveModule, struct: InternalMoveStruct, events: Set<string>) {\n const genericString = this.generateStructTypeParameters(struct)\n const genericStringAny = this.generateStructTypeParameters(struct, true)\n\n const structName = normalizeToJSName(struct.name)\n\n const fields = struct.fields.map((field) => {\n const type = generateTypeForDescriptor(field.type, module.address, this.ADDRESS_TYPE)\n return `${field.name}: ${type}`\n })\n\n let eventPayload = ''\n if (events.has(moduleQname(module) + SPLITTER + struct.name)) {\n eventPayload = `\n export interface ${structName}Instance extends\n TypedEventInstance<${structName}${genericStringAny}> {\n ${this.STRUCT_FIELD_NAME}_decoded: ${structName}${genericStringAny}\n type_arguments: [${struct.typeParams.map((_) => 'string').join(', ')}]\n }\n `\n }\n\n return `\n export class ${structName}${genericString} {\n static TYPE_QNAME = '${module.address}::${module.name}::${struct.name}'\n ${fields.join('\\n')}\n }\n\n ${eventPayload}\n `\n }\n\n generateFunctionTypeParameters(func: InternalMoveFunction) {\n let genericString = ''\n if (func.typeParams && func.typeParams.length > 0) {\n const params = func.typeParams\n .map((v, idx) => {\n return `T${idx}=any`\n })\n .join(',')\n genericString = `<${params}>`\n }\n return genericString\n }\n\n generateStructTypeParameters(struct: InternalMoveStruct, useAny = false) {\n let genericString = ''\n\n if (struct.typeParams && struct.typeParams.length > 0) {\n const params = struct.typeParams\n .map((v, idx) => {\n return useAny ? 'any' : 'T' + idx\n })\n .join(',')\n genericString = `<${params}>`\n }\n return genericString\n }\n\n generateCallArgsStructs(module: InternalMoveModule, func: InternalMoveFunction) {\n if (!func.isEntry) {\n return\n }\n\n const fields = this.getMeaningfulFunctionParams(func.params).map((param) => {\n return generateTypeForDescriptor(param, module.address, this.ADDRESS_TYPE)\n })\n\n const camelFuncName = upperFirst(camelCase(func.name))\n\n const genericString = this.generateFunctionTypeParameters(func)\n return `\n export interface ${camelFuncName}Payload${genericString}\n extends TypedFunctionPayload<[${fields.join(',')}]> {\n arguments_decoded: [${fields.join(',')}],\n type_arguments: [${func.typeParams.map((_) => 'string').join(', ')}]\n }\n `\n }\n\n generateClientFunctions(module: InternalMoveModule, func: InternalMoveFunction) {\n if (func.visibility === InternalMoveFunctionVisibility.PRIVATE) {\n return ''\n }\n if (func.isEntry) {\n return ''\n }\n // const moduleName = normalizeToJSName(module.name)\n const funcName = camelCase(func.name)\n const fields = this.getMeaningfulFunctionParams(func.params).map((param) => {\n return generateTypeForDescriptor(param, module.address, this.ADDRESS_TYPE)\n })\n const genericString = this.generateFunctionTypeParameters(func)\n\n const returns = func.return.map((param) => {\n return generateTypeForDescriptor(param, module.address, this.ADDRESS_TYPE)\n })\n\n const source = `\n ${funcName}${genericString}(type_arguments: [${func.typeParams\n .map((_) => 'string')\n .join(', ')}], args: [${fields.join(',')}], version?: bigint): Promise<[${returns.join(',')}]> {\n return this.viewDecoded('${module.address}::${module.name}::${func.name}', type_arguments, args, version) as any\n }`\n return source\n }\n\n generateOnEntryFunctions(module: InternalMoveModule, func: InternalMoveFunction) {\n if (!func.isEntry) {\n return ''\n }\n\n // const genericString = generateFunctionTypeParameters(func)\n const moduleName = normalizeToJSName(module.name)\n\n const camelFuncName = upperFirst(camelCase(func.name))\n const source = `\n onEntry${camelFuncName}(func: (call: ${moduleName}.${camelFuncName}Payload, ctx: ${this.PREFIX}Context) => void, filter?: CallFilter, fetchConfig?: MoveFetchConfig): ${moduleName} {\n this.onEntryFunctionCall(func, {\n ...filter,\n function: '${module.name}::${func.name}'\n },\n fetchConfig)\n return this\n }`\n\n return source\n }\n\n generateOnEvents(module: InternalMoveModule, struct: InternalMoveStruct): string {\n // for struct that has drop + store\n // if (!isEvent(struct, module)) {\n // return ''\n // }\n\n // const genericString = generateStructTypeParameters(struct)\n\n const moduleName = normalizeToJSName(module.name)\n const source = `\n onEvent${struct.name}(func: (event: ${moduleName}.${normalizeToJSName(struct.name)}Instance, ctx: ${\n this.PREFIX\n }Context) => void, fetchConfig?: MoveFetchConfig): ${moduleName} {\n this.onMoveEvent(func, {\n type: '${module.name}::${struct.name}'\n },\n fetchConfig)\n return this\n }\n `\n return source\n }\n}\n\nexport class AccountCodegen<ModuleType, NetworkType> {\n modules: InternalMoveModule[]\n config: Config<NetworkType>\n abi: ModuleType\n loader: AccountRegister\n moduleGen: AbstractCodegen<ModuleType, NetworkType>\n\n constructor(\n moduleGen: AbstractCodegen<ModuleType, NetworkType>,\n loader: AccountRegister,\n abi: ModuleType,\n modules: InternalMoveModule[],\n config: Config<NetworkType>\n ) {\n // const json = fs.readFileSync(config.srcFile, 'utf-8')\n this.moduleGen = moduleGen\n this.abi = abi\n this.modules = modules\n this.config = config\n this.loader = loader\n }\n\n generate(): OutputFile[] {\n if (!this.modules) {\n return []\n }\n // const baseName = path.basename(this.config.fileName, '.json')\n\n let address: string | undefined\n for (const module of this.modules) {\n address = module.address\n }\n if (!address) {\n return []\n }\n\n const imports = `\n import { CallFilter } from \"@sentio/sdk/move\"\n import {\n MoveCoder, defaultMoveCoder, ${this.moduleGen.PREFIX}BindOptions, ${this.moduleGen.PREFIX}BaseProcessor,\n TypedEventInstance, ${this.moduleGen.PREFIX}Network, TypedFunctionPayload,\n ${this.moduleGen.PREFIX}Context } from \"@sentio/sdk/${this.moduleGen.PREFIX.toLowerCase()}\"\n import { MoveFetchConfig } from \"@sentio/protos\"\n import { ${this.moduleGen.ADDRESS_TYPE}, ModuleClient } from \"@sentio/sdk/${this.moduleGen.PREFIX.toLowerCase()}\"\n `\n\n const dependedAccounts: string[] = []\n\n const moduleImports: string[] = []\n\n const info = this.loader.accountImports.get(address)\n\n if (info) {\n for (const [account] of info.imports.entries()) {\n // Remap to user's filename if possible, TODO codepath not well tested\n const tsAccountModule = './' + (this.loader.accountImports.get(account)?.moduleName || account)\n if (isFrameworkAccount(account) && !isFrameworkAccount(address)) {\n // Decide where to find runtime library\n moduleImports.push(`import { _${account} } from \"@sentio/sdk/${this.moduleGen.PREFIX.toLowerCase()}/builtin\"`)\n } else {\n moduleImports.push(`import * as _${account} from \"${tsAccountModule}.js\"`)\n }\n\n dependedAccounts.push(account)\n }\n }\n\n const source = `\n /* Autogenerated file. Do not edit manually. */\n /* tslint:disable */\n /* eslint-disable */\n\n /* Generated modules for account ${address} */\n\n ${imports}\n\n ${moduleImports.join('\\n')}\n\n ${this.modules.map((m) => this.moduleGen.generateModule(m, this.config.network)).join('\\n')}\n\n const MODULES = JSON.parse('${JSON.stringify(this.abi)}')\n\n export function loadAllTypes(coder: MoveCoder) {\n ${dependedAccounts.map((a) => `_${a}.loadAllTypes(coder)`).join('\\n')}\n for (const m of Object.values(MODULES)) {\n coder.load(m as any)\n }\n }\n\n loadAllTypes(defaultMoveCoder())\n ` // source\n\n return [\n {\n fileName: this.config.fileName + '.ts',\n fileContent: source,\n },\n ]\n }\n}\n"]}
|
|
@@ -13,11 +13,18 @@ export declare abstract class AbstractMoveCoder<StructType> {
|
|
|
13
13
|
private typeMapping;
|
|
14
14
|
private funcMapping;
|
|
15
15
|
contains(account: string, name: string): boolean;
|
|
16
|
-
|
|
17
|
-
protected
|
|
18
|
-
protected
|
|
19
|
-
protected
|
|
20
|
-
|
|
16
|
+
protected abstract getMeaningfulFunctionParams(params: TypeDescriptor[]): TypeDescriptor[];
|
|
17
|
+
protected loadInternal(module: InternalMoveModule): void;
|
|
18
|
+
protected decodeBigInt(data: any): bigint;
|
|
19
|
+
protected encodeBigInt(data: bigint): any;
|
|
20
|
+
getMoveStruct(type: string): InternalMoveStruct;
|
|
21
|
+
getMoveFunction(type: string): InternalMoveFunction;
|
|
22
|
+
decode(data: any, type: TypeDescriptor): any;
|
|
23
|
+
encode(data: any, type: TypeDescriptor): any;
|
|
24
|
+
decodeArray(entries: any[], types: TypeDescriptor[]): any[];
|
|
25
|
+
encodeArray(entriesDecoded: any[], types: TypeDescriptor[]): any[];
|
|
26
|
+
encodeCallArgs(args: any[], func: string): any[];
|
|
27
|
+
decodeCallResult(res: any[], func: string): any[];
|
|
21
28
|
protected filterAndDecodeInternal<T>(typeQname: string, structs: StructWithTag<StructType>[]): DecodedStructWithTag<StructType, T>[];
|
|
22
29
|
protected decodedInternal<T>(typeStruct: StructWithTag<StructType>): DecodedStructWithTag<StructType, T> | undefined;
|
|
23
30
|
}
|
|
@@ -19,14 +19,14 @@ export class AbstractMoveCoder {
|
|
|
19
19
|
this.typeMapping.set(key, struct);
|
|
20
20
|
}
|
|
21
21
|
for (const func of module.exposedFunctions) {
|
|
22
|
-
if (!func.isEntry) {
|
|
23
|
-
|
|
24
|
-
}
|
|
22
|
+
// if (!func.isEntry) {
|
|
23
|
+
// continue
|
|
24
|
+
// }
|
|
25
25
|
const key = [module.address, module.name, func.name].join(SPLITTER);
|
|
26
26
|
this.funcMapping.set(key, func);
|
|
27
27
|
}
|
|
28
28
|
}
|
|
29
|
-
|
|
29
|
+
decodeBigInt(data) {
|
|
30
30
|
if (Array.isArray(data)) {
|
|
31
31
|
// Only sui function need this, strange
|
|
32
32
|
const bytes = data;
|
|
@@ -36,6 +36,9 @@ export class AbstractMoveCoder {
|
|
|
36
36
|
return BigInt(data);
|
|
37
37
|
}
|
|
38
38
|
}
|
|
39
|
+
encodeBigInt(data) {
|
|
40
|
+
return '0x' + data.toString(16);
|
|
41
|
+
}
|
|
39
42
|
getMoveStruct(type) {
|
|
40
43
|
const struct = this.typeMapping.get(type);
|
|
41
44
|
if (!struct) {
|
|
@@ -46,7 +49,7 @@ export class AbstractMoveCoder {
|
|
|
46
49
|
getMoveFunction(type) {
|
|
47
50
|
const func = this.funcMapping.get(type);
|
|
48
51
|
if (!func) {
|
|
49
|
-
throw new Error('Failed to load function' + type + ' type are not imported anywhere');
|
|
52
|
+
throw new Error('Failed to load function ' + type + ' type are not imported anywhere');
|
|
50
53
|
}
|
|
51
54
|
return func;
|
|
52
55
|
}
|
|
@@ -75,7 +78,7 @@ export class AbstractMoveCoder {
|
|
|
75
78
|
case 'U64':
|
|
76
79
|
case 'u128':
|
|
77
80
|
case 'U128':
|
|
78
|
-
return this.
|
|
81
|
+
return this.decodeBigInt(data);
|
|
79
82
|
}
|
|
80
83
|
// process vector
|
|
81
84
|
if (type.qname === VECTOR_STR) {
|
|
@@ -104,6 +107,97 @@ export class AbstractMoveCoder {
|
|
|
104
107
|
}
|
|
105
108
|
return typedData;
|
|
106
109
|
}
|
|
110
|
+
encode(data, type) {
|
|
111
|
+
// process simple type
|
|
112
|
+
if (type.reference) {
|
|
113
|
+
return data;
|
|
114
|
+
}
|
|
115
|
+
switch (type.qname) {
|
|
116
|
+
case 'signer': // TODO check this, aptos only
|
|
117
|
+
case 'address':
|
|
118
|
+
case 'Address':
|
|
119
|
+
case '0x2::object::ID':
|
|
120
|
+
case '0x2::coin::Coin':
|
|
121
|
+
case '0x1::string::String':
|
|
122
|
+
case 'bool':
|
|
123
|
+
case 'Bool':
|
|
124
|
+
case 'u8':
|
|
125
|
+
case 'U8':
|
|
126
|
+
case 'u16':
|
|
127
|
+
case 'U16':
|
|
128
|
+
case 'u32':
|
|
129
|
+
case 'U32':
|
|
130
|
+
return data;
|
|
131
|
+
case 'u64':
|
|
132
|
+
case 'U64':
|
|
133
|
+
case 'u128':
|
|
134
|
+
case 'U128':
|
|
135
|
+
return this.encodeBigInt(data);
|
|
136
|
+
}
|
|
137
|
+
// process vector
|
|
138
|
+
if (type.qname === VECTOR_STR) {
|
|
139
|
+
// vector<u8> as hex string
|
|
140
|
+
if (type.typeArgs[0].qname === 'u8' || type.typeArgs[0].qname === 'U8') {
|
|
141
|
+
return data;
|
|
142
|
+
}
|
|
143
|
+
const res = [];
|
|
144
|
+
for (const entry of data) {
|
|
145
|
+
res.push(this.encode(entry, type.typeArgs[0]));
|
|
146
|
+
}
|
|
147
|
+
return res;
|
|
148
|
+
}
|
|
149
|
+
// Process complex type
|
|
150
|
+
const struct = this.getMoveStruct(type.qname);
|
|
151
|
+
const typeCtx = new Map();
|
|
152
|
+
for (const [idx, typeArg] of type.typeArgs.entries()) {
|
|
153
|
+
typeCtx.set('T' + idx, typeArg);
|
|
154
|
+
}
|
|
155
|
+
const typedData = {};
|
|
156
|
+
for (const field of struct.fields) {
|
|
157
|
+
let filedType = field.type;
|
|
158
|
+
filedType = filedType.applyTypeArgs(typeCtx);
|
|
159
|
+
const value = this.encode(data[field.name], filedType);
|
|
160
|
+
typedData[field.name] = value;
|
|
161
|
+
}
|
|
162
|
+
return typedData;
|
|
163
|
+
}
|
|
164
|
+
decodeArray(entries, types) {
|
|
165
|
+
const entriesDecoded = [];
|
|
166
|
+
for (const [idx, arg] of entries.entries()) {
|
|
167
|
+
// TODO consider apply payload.type_arguments, but this might be hard since we don't code gen for them
|
|
168
|
+
const argType = types[idx];
|
|
169
|
+
try {
|
|
170
|
+
entriesDecoded.push(this.decode(arg, argType));
|
|
171
|
+
}
|
|
172
|
+
catch (e) {
|
|
173
|
+
console.error(e, 'Decoding error for ', JSON.stringify(arg), 'using type', argType);
|
|
174
|
+
return entries;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
return entriesDecoded;
|
|
178
|
+
}
|
|
179
|
+
encodeArray(entriesDecoded, types) {
|
|
180
|
+
const entries = [];
|
|
181
|
+
for (const [idx, arg] of entriesDecoded.entries()) {
|
|
182
|
+
// TODO consider apply payload.type_arguments, but this might be hard since we don't code gen for them
|
|
183
|
+
const argType = types[idx];
|
|
184
|
+
try {
|
|
185
|
+
entries.push(this.encode(arg, argType));
|
|
186
|
+
}
|
|
187
|
+
catch (e) {
|
|
188
|
+
throw Error('Decoding error for ' + JSON.stringify(arg) + 'using type' + argType + e.toString());
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
return entries;
|
|
192
|
+
}
|
|
193
|
+
encodeCallArgs(args, func) {
|
|
194
|
+
const f = this.getMoveFunction(func);
|
|
195
|
+
return this.encodeArray(args, this.getMeaningfulFunctionParams(f.params));
|
|
196
|
+
}
|
|
197
|
+
decodeCallResult(res, func) {
|
|
198
|
+
const f = this.getMoveFunction(func);
|
|
199
|
+
return this.decodeArray(res, f.return);
|
|
200
|
+
}
|
|
107
201
|
filterAndDecodeInternal(typeQname, structs) {
|
|
108
202
|
if (!structs) {
|
|
109
203
|
return [];
|