@0xobelisk/client 0.0.1 → 0.0.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.
- package/README.md +2 -0
- package/dist/framework/bcs.d.ts +3 -0
- package/dist/framework/loader.d.ts +11 -0
- package/dist/framework/util.d.ts +90 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +373 -14
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +375 -11
- package/dist/index.mjs.map +1 -1
- package/dist/libs/suiContractFactory/index.d.ts +21 -0
- package/dist/libs/suiContractFactory/types.d.ts +49 -0
- package/dist/libs/suiRpcProvider/index.d.ts +109 -1
- package/dist/metadata/index.d.ts +34 -0
- package/dist/obelisk.d.ts +194 -213
- package/dist/types/index.d.ts +62 -1
- package/package.json +8 -11
- package/src/framework/bcs.ts +6 -0
- package/src/framework/loader.ts +152 -0
- package/src/framework/util.ts +219 -0
- package/src/index.ts +1 -0
- package/src/libs/suiContractFactory/index.ts +121 -0
- package/src/libs/suiContractFactory/types.ts +54 -0
- package/src/libs/suiRpcProvider/index.ts +31 -0
- package/src/metadata/index.ts +40 -0
- package/src/obelisk.ts +215 -16
- package/src/types/index.ts +75 -1
- package/dist/test/tsconfig.tsbuildinfo +0 -1
package/README.md
CHANGED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { FieldsWithTypes, Type } from './util';
|
|
2
|
+
export type PrimitiveValue = string | number | boolean | bigint;
|
|
3
|
+
export declare class StructClassLoader {
|
|
4
|
+
#private;
|
|
5
|
+
private map;
|
|
6
|
+
register(...classes: any): void;
|
|
7
|
+
fromFields(type: Type, value: Record<string, any> | PrimitiveValue): any;
|
|
8
|
+
fromFieldsWithTypes(type: Type, value: FieldsWithTypes | PrimitiveValue): any;
|
|
9
|
+
}
|
|
10
|
+
export declare const structClassLoaderSource: StructClassLoader;
|
|
11
|
+
export declare const structClassLoaderOnchain: StructClassLoader;
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { ObjectCallArg, ObjectId, TransactionArgument, TransactionBlock } from '@mysten/sui.js';
|
|
2
|
+
/** A Move type, e.g., `address`, `bool`, `u64`, `vector<u64>`, `0x2::sui::SUI`... */
|
|
3
|
+
export type Type = string;
|
|
4
|
+
export interface FieldsWithTypes {
|
|
5
|
+
fields: Record<string, any>;
|
|
6
|
+
type: string;
|
|
7
|
+
}
|
|
8
|
+
export type ObjectArg = ObjectId | ObjectCallArg | TransactionArgument;
|
|
9
|
+
export type PureArg = bigint | string | number | boolean | null | TransactionArgument | Array<PureArg>;
|
|
10
|
+
export type GenericArg = ObjectArg | PureArg | Array<ObjectArg> | Array<PureArg> | Array<GenericArg>;
|
|
11
|
+
export declare function parseTypeName(name: Type): {
|
|
12
|
+
typeName: string;
|
|
13
|
+
typeArgs: Type[];
|
|
14
|
+
};
|
|
15
|
+
export declare function obj(txb: TransactionBlock, arg: ObjectArg): {
|
|
16
|
+
kind: "Input";
|
|
17
|
+
index: number;
|
|
18
|
+
type?: "object" | "pure" | undefined;
|
|
19
|
+
value?: any;
|
|
20
|
+
} | {
|
|
21
|
+
kind: "GasCoin";
|
|
22
|
+
} | {
|
|
23
|
+
kind: "Result";
|
|
24
|
+
index: number;
|
|
25
|
+
} | {
|
|
26
|
+
kind: "NestedResult";
|
|
27
|
+
index: number;
|
|
28
|
+
resultIndex: number;
|
|
29
|
+
};
|
|
30
|
+
export declare function pure(txb: TransactionBlock, arg: PureArg, type: Type): {
|
|
31
|
+
kind: "Input";
|
|
32
|
+
index: number;
|
|
33
|
+
type?: "object" | "pure" | undefined;
|
|
34
|
+
value?: any;
|
|
35
|
+
} | {
|
|
36
|
+
kind: "GasCoin";
|
|
37
|
+
} | {
|
|
38
|
+
kind: "Result";
|
|
39
|
+
index: number;
|
|
40
|
+
} | {
|
|
41
|
+
kind: "NestedResult";
|
|
42
|
+
index: number;
|
|
43
|
+
resultIndex: number;
|
|
44
|
+
};
|
|
45
|
+
export declare function option(txb: TransactionBlock, type: Type, arg: GenericArg | null): {
|
|
46
|
+
kind: "Input";
|
|
47
|
+
index: number;
|
|
48
|
+
type?: "object" | "pure" | undefined;
|
|
49
|
+
value?: any;
|
|
50
|
+
} | {
|
|
51
|
+
kind: "GasCoin";
|
|
52
|
+
} | {
|
|
53
|
+
kind: "Result";
|
|
54
|
+
index: number;
|
|
55
|
+
} | {
|
|
56
|
+
kind: "NestedResult";
|
|
57
|
+
index: number;
|
|
58
|
+
resultIndex: number;
|
|
59
|
+
};
|
|
60
|
+
export declare function generic(txb: TransactionBlock, type: Type, arg: GenericArg): {
|
|
61
|
+
kind: "Input";
|
|
62
|
+
index: number;
|
|
63
|
+
type?: "object" | "pure" | undefined;
|
|
64
|
+
value?: any;
|
|
65
|
+
} | {
|
|
66
|
+
kind: "GasCoin";
|
|
67
|
+
} | {
|
|
68
|
+
kind: "Result";
|
|
69
|
+
index: number;
|
|
70
|
+
} | {
|
|
71
|
+
kind: "NestedResult";
|
|
72
|
+
index: number;
|
|
73
|
+
resultIndex: number;
|
|
74
|
+
};
|
|
75
|
+
export declare function vector(txb: TransactionBlock, itemType: Type, items: Array<GenericArg> | TransactionArgument): {
|
|
76
|
+
kind: "Input";
|
|
77
|
+
index: number;
|
|
78
|
+
type?: "object" | "pure" | undefined;
|
|
79
|
+
value?: any;
|
|
80
|
+
} | {
|
|
81
|
+
kind: "GasCoin";
|
|
82
|
+
} | {
|
|
83
|
+
kind: "Result";
|
|
84
|
+
index: number;
|
|
85
|
+
} | {
|
|
86
|
+
kind: "NestedResult";
|
|
87
|
+
index: number;
|
|
88
|
+
resultIndex: number;
|
|
89
|
+
};
|
|
90
|
+
export declare function typeArgIsPure(type: Type): boolean;
|
package/dist/index.d.ts
CHANGED
|
@@ -3,4 +3,5 @@ export { Obelisk } from './obelisk';
|
|
|
3
3
|
export { SuiAccountManager } from './libs/suiAccountManager';
|
|
4
4
|
export { SuiTxBlock } from './libs/suiTxBuilder';
|
|
5
5
|
export { SuiRpcProvider } from './libs/suiRpcProvider';
|
|
6
|
+
export { SuiContractFactory } from './libs/suiContractFactory';
|
|
6
7
|
export type * from './types';
|
package/dist/index.js
CHANGED
|
@@ -16,23 +16,37 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
16
16
|
return to;
|
|
17
17
|
};
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var __accessCheck = (obj2, member, msg) => {
|
|
20
|
+
if (!member.has(obj2))
|
|
21
|
+
throw TypeError("Cannot " + msg);
|
|
22
|
+
};
|
|
23
|
+
var __privateGet = (obj2, member, getter) => {
|
|
24
|
+
__accessCheck(obj2, member, "read from private field");
|
|
25
|
+
return getter ? getter.call(obj2) : member.get(obj2);
|
|
26
|
+
};
|
|
27
|
+
var __privateAdd = (obj2, member, value) => {
|
|
28
|
+
if (member.has(obj2))
|
|
29
|
+
throw TypeError("Cannot add the same private member more than once");
|
|
30
|
+
member instanceof WeakSet ? member.add(obj2) : member.set(obj2, value);
|
|
31
|
+
};
|
|
19
32
|
|
|
20
33
|
// src/index.ts
|
|
21
34
|
var src_exports = {};
|
|
22
35
|
__export(src_exports, {
|
|
23
36
|
Obelisk: () => Obelisk,
|
|
24
|
-
SUI_CLOCK_OBJECT_ID: () =>
|
|
25
|
-
SUI_SYSTEM_STATE_OBJECT_ID: () =>
|
|
37
|
+
SUI_CLOCK_OBJECT_ID: () => import_sui11.SUI_CLOCK_OBJECT_ID,
|
|
38
|
+
SUI_SYSTEM_STATE_OBJECT_ID: () => import_sui11.SUI_SYSTEM_STATE_OBJECT_ID,
|
|
26
39
|
SuiAccountManager: () => SuiAccountManager,
|
|
40
|
+
SuiContractFactory: () => SuiContractFactory,
|
|
27
41
|
SuiRpcProvider: () => SuiRpcProvider,
|
|
28
42
|
SuiTxBlock: () => SuiTxBlock,
|
|
29
|
-
TransactionBlock: () =>
|
|
43
|
+
TransactionBlock: () => import_sui11.TransactionBlock
|
|
30
44
|
});
|
|
31
45
|
module.exports = __toCommonJS(src_exports);
|
|
32
|
-
var
|
|
46
|
+
var import_sui11 = require("@mysten/sui.js");
|
|
33
47
|
|
|
34
48
|
// src/obelisk.ts
|
|
35
|
-
var
|
|
49
|
+
var import_sui10 = require("@mysten/sui.js");
|
|
36
50
|
|
|
37
51
|
// src/libs/suiAccountManager/index.ts
|
|
38
52
|
var import_sui3 = require("@mysten/sui.js");
|
|
@@ -244,6 +258,28 @@ var SuiRpcProvider = class {
|
|
|
244
258
|
async getBalance(addr, coinType) {
|
|
245
259
|
return this.provider.getBalance({ owner: addr, coinType });
|
|
246
260
|
}
|
|
261
|
+
async getDynamicFieldObject(parentId, name) {
|
|
262
|
+
return this.provider.getDynamicFieldObject({ parentId, name });
|
|
263
|
+
}
|
|
264
|
+
async getDynamicFields(parentId, cursor, limit) {
|
|
265
|
+
return this.provider.getDynamicFields({ parentId, cursor, limit });
|
|
266
|
+
}
|
|
267
|
+
async getObject(id) {
|
|
268
|
+
const options = { showContent: true, showDisplay: true, showType: true };
|
|
269
|
+
const object = await this.provider.getObject({ id, options });
|
|
270
|
+
const objectId = (0, import_sui6.getObjectId)(object);
|
|
271
|
+
const objectType = (0, import_sui6.getObjectType)(object);
|
|
272
|
+
const objectVersion = (0, import_sui6.getObjectVersion)(object);
|
|
273
|
+
const objectFields = (0, import_sui6.getObjectFields)(object);
|
|
274
|
+
const objectDisplay = (0, import_sui6.getObjectDisplay)(object);
|
|
275
|
+
return {
|
|
276
|
+
objectId,
|
|
277
|
+
objectType,
|
|
278
|
+
objectVersion,
|
|
279
|
+
objectFields,
|
|
280
|
+
objectDisplay
|
|
281
|
+
};
|
|
282
|
+
}
|
|
247
283
|
async getObjects(ids) {
|
|
248
284
|
const options = { showContent: true, showDisplay: true, showType: true };
|
|
249
285
|
const objects = await this.provider.multiGetObjects({ ids, options });
|
|
@@ -263,6 +299,9 @@ var SuiRpcProvider = class {
|
|
|
263
299
|
});
|
|
264
300
|
return parsedObjects;
|
|
265
301
|
}
|
|
302
|
+
async getNormalizedMoveModulesByPackage(packageId) {
|
|
303
|
+
return this.provider.getNormalizedMoveModulesByPackage({ package: packageId });
|
|
304
|
+
}
|
|
266
305
|
/**
|
|
267
306
|
* @description Select coins that add up to the given amount.
|
|
268
307
|
* @param addr the address of the owner
|
|
@@ -536,7 +575,191 @@ var SuiTxBlock = class {
|
|
|
536
575
|
}
|
|
537
576
|
};
|
|
538
577
|
|
|
578
|
+
// src/libs/suiContractFactory/index.ts
|
|
579
|
+
var SuiContractFactory = class {
|
|
580
|
+
// readonly #query: MapMessageQuery<ApiTypes> = {};
|
|
581
|
+
// readonly #tx: MapMessageTx<ApiTypes> = {};
|
|
582
|
+
/**
|
|
583
|
+
* Support the following ways to init the SuiToolkit:
|
|
584
|
+
* 1. mnemonics
|
|
585
|
+
* 2. secretKey (base64 or hex)
|
|
586
|
+
* If none of them is provided, will generate a random mnemonics with 24 words.
|
|
587
|
+
*
|
|
588
|
+
* @param mnemonics, 12 or 24 mnemonics words, separated by space
|
|
589
|
+
* @param secretKey, base64 or hex string, when mnemonics is provided, secretKey will be ignored
|
|
590
|
+
*/
|
|
591
|
+
constructor({ packageId, metadata } = {}) {
|
|
592
|
+
this.packageId = packageId || "";
|
|
593
|
+
this.metadata = metadata || void 0;
|
|
594
|
+
}
|
|
595
|
+
getFuncByModuleName(moduleName) {
|
|
596
|
+
Object.values(this.metadata).forEach(
|
|
597
|
+
(value) => {
|
|
598
|
+
const data = value;
|
|
599
|
+
console.log(`moudle name: ${data.name}`);
|
|
600
|
+
Object.entries(data.exposedFunctions).forEach(([key, value2]) => {
|
|
601
|
+
console.log(` func name: ${key}`);
|
|
602
|
+
Object.values(value2.parameters).forEach((values) => {
|
|
603
|
+
});
|
|
604
|
+
});
|
|
605
|
+
}
|
|
606
|
+
);
|
|
607
|
+
}
|
|
608
|
+
getAllFunc() {
|
|
609
|
+
Object.values(this.metadata).forEach(
|
|
610
|
+
(value) => {
|
|
611
|
+
const data = value;
|
|
612
|
+
console.log(`moudle name: ${data.name}`);
|
|
613
|
+
Object.entries(data.exposedFunctions).forEach(([key, value2]) => {
|
|
614
|
+
console.log(` func name: ${key}`);
|
|
615
|
+
console.log(` ${value2.parameters.length}`);
|
|
616
|
+
Object.values(value2.parameters).forEach((values) => {
|
|
617
|
+
console.log(` args: ${values}`);
|
|
618
|
+
});
|
|
619
|
+
});
|
|
620
|
+
}
|
|
621
|
+
);
|
|
622
|
+
}
|
|
623
|
+
getAllModule() {
|
|
624
|
+
Object.values(this.metadata).forEach(
|
|
625
|
+
(value, index) => {
|
|
626
|
+
const data = value;
|
|
627
|
+
console.log(`${index}. ${data.name}`);
|
|
628
|
+
}
|
|
629
|
+
);
|
|
630
|
+
}
|
|
631
|
+
async worldCall() {
|
|
632
|
+
}
|
|
633
|
+
// async call(arguments: ({
|
|
634
|
+
// kind: "Input";
|
|
635
|
+
// index: number;
|
|
636
|
+
// type?: "object" | "pure" | undefined;
|
|
637
|
+
// value?: any;
|
|
638
|
+
// } | {
|
|
639
|
+
// kind: "GasCoin";
|
|
640
|
+
// } | {
|
|
641
|
+
// kind: "Result";
|
|
642
|
+
// index: number;
|
|
643
|
+
// } | {
|
|
644
|
+
// kind: "NestedResult";
|
|
645
|
+
// index: number;
|
|
646
|
+
// resultIndex: number;
|
|
647
|
+
// })[], derivePathParams?: DerivePathParams) {
|
|
648
|
+
// const tx = new TransactionBlock();
|
|
649
|
+
// tx.moveCall({
|
|
650
|
+
// target: `${this.packageId}::${}::${}`,
|
|
651
|
+
// arguments,
|
|
652
|
+
// })
|
|
653
|
+
// return ;
|
|
654
|
+
// }
|
|
655
|
+
};
|
|
656
|
+
|
|
657
|
+
// src/framework/util.ts
|
|
658
|
+
var import_sui9 = require("@mysten/sui.js");
|
|
659
|
+
var import_bcs = require("@mysten/bcs");
|
|
660
|
+
function parseTypeName(name) {
|
|
661
|
+
const parsed = import_sui9.bcs.parseTypeName(name);
|
|
662
|
+
return { typeName: parsed.name, typeArgs: parsed.params };
|
|
663
|
+
}
|
|
664
|
+
function obj(txb, arg) {
|
|
665
|
+
return (0, import_sui9.is)(arg, import_sui9.TransactionArgument) ? arg : txb.object(arg);
|
|
666
|
+
}
|
|
667
|
+
function pure(txb, arg, type) {
|
|
668
|
+
if ((0, import_sui9.is)(arg, import_sui9.TransactionArgument)) {
|
|
669
|
+
return obj(txb, arg);
|
|
670
|
+
}
|
|
671
|
+
function convertType(type2) {
|
|
672
|
+
const { typeName: typeName2, typeArgs: typeArgs2 } = parseTypeName(type2);
|
|
673
|
+
switch (typeName2) {
|
|
674
|
+
case "0x1::string::String":
|
|
675
|
+
case "0x1::ascii::String":
|
|
676
|
+
return import_bcs.BCS.STRING;
|
|
677
|
+
case "0x2::object::ID":
|
|
678
|
+
return import_bcs.BCS.ADDRESS;
|
|
679
|
+
case "0x1::option::Option":
|
|
680
|
+
return `vector<${convertType(typeArgs2[0])}>`;
|
|
681
|
+
case "vector":
|
|
682
|
+
return `vector<${convertType(typeArgs2[0])}>`;
|
|
683
|
+
default:
|
|
684
|
+
return type2;
|
|
685
|
+
}
|
|
686
|
+
}
|
|
687
|
+
function isOrHasNestedTransactionArgument(arg2) {
|
|
688
|
+
if (Array.isArray(arg2)) {
|
|
689
|
+
return arg2.some((item) => isOrHasNestedTransactionArgument(item));
|
|
690
|
+
}
|
|
691
|
+
return (0, import_sui9.is)(arg2, import_sui9.TransactionArgument);
|
|
692
|
+
}
|
|
693
|
+
function convertArg(arg2, type2) {
|
|
694
|
+
const { typeName: typeName2, typeArgs: typeArgs2 } = parseTypeName(type2);
|
|
695
|
+
if (typeName2 === "0x1::option::Option") {
|
|
696
|
+
if (arg2 === null) {
|
|
697
|
+
return [];
|
|
698
|
+
} else {
|
|
699
|
+
return [convertArg(arg2, typeArgs2[0])];
|
|
700
|
+
}
|
|
701
|
+
} else if (typeName2 === "vector" && Array.isArray(arg2)) {
|
|
702
|
+
return arg2.map((item) => convertArg(item, typeArgs2[0]));
|
|
703
|
+
} else if (typeName2 === "0x2::object::ID" || typeName2 === "address") {
|
|
704
|
+
return (0, import_sui9.normalizeSuiAddress)(arg2);
|
|
705
|
+
} else {
|
|
706
|
+
return arg2;
|
|
707
|
+
}
|
|
708
|
+
}
|
|
709
|
+
const { typeName, typeArgs } = parseTypeName(type);
|
|
710
|
+
switch (typeName) {
|
|
711
|
+
case "0x1::option::Option":
|
|
712
|
+
if (arg === null) {
|
|
713
|
+
return txb.pure([], `vector<${convertType(typeArgs[0])}>`);
|
|
714
|
+
}
|
|
715
|
+
if (isOrHasNestedTransactionArgument(arg)) {
|
|
716
|
+
throw new Error("nesting TransactionArgument is not currently supported");
|
|
717
|
+
}
|
|
718
|
+
break;
|
|
719
|
+
case "vector":
|
|
720
|
+
if (!Array.isArray(arg)) {
|
|
721
|
+
throw new Error("expected an array for vector type");
|
|
722
|
+
}
|
|
723
|
+
if (arg.length === 0) {
|
|
724
|
+
return txb.pure([], `vector<${convertType(typeArgs[0])}>`);
|
|
725
|
+
}
|
|
726
|
+
if (arg.some((arg2) => Array.isArray(arg2) && isOrHasNestedTransactionArgument(arg2))) {
|
|
727
|
+
throw new Error("nesting TransactionArgument is not currently supported");
|
|
728
|
+
}
|
|
729
|
+
if ((0, import_sui9.is)(arg[0], import_sui9.TransactionArgument) && arg.filter((arg2) => !(0, import_sui9.is)(arg2, import_sui9.TransactionArgument)).length > 0) {
|
|
730
|
+
throw new Error("mixing TransactionArgument with other types is not currently supported");
|
|
731
|
+
}
|
|
732
|
+
if ((0, import_sui9.is)(arg[0], import_sui9.TransactionArgument)) {
|
|
733
|
+
return txb.makeMoveVec({
|
|
734
|
+
objects: arg,
|
|
735
|
+
type: typeArgs[0]
|
|
736
|
+
});
|
|
737
|
+
}
|
|
738
|
+
}
|
|
739
|
+
return txb.pure(convertArg(arg, type), convertType(type));
|
|
740
|
+
}
|
|
741
|
+
|
|
539
742
|
// src/obelisk.ts
|
|
743
|
+
function isUndefined(value) {
|
|
744
|
+
return value === void 0;
|
|
745
|
+
}
|
|
746
|
+
function withMeta(meta, creator) {
|
|
747
|
+
creator.meta = meta;
|
|
748
|
+
return creator;
|
|
749
|
+
}
|
|
750
|
+
function createQuery(meta, fn) {
|
|
751
|
+
return withMeta(meta, async (tx, params) => {
|
|
752
|
+
const result = await fn(tx, params);
|
|
753
|
+
return result;
|
|
754
|
+
});
|
|
755
|
+
}
|
|
756
|
+
function createTx(meta, fn) {
|
|
757
|
+
return withMeta(meta, async (tx, params, isRaw) => {
|
|
758
|
+
const result = await fn(tx, params, isRaw);
|
|
759
|
+
return result;
|
|
760
|
+
});
|
|
761
|
+
}
|
|
762
|
+
var _query, _tx, _exec, _read;
|
|
540
763
|
var Obelisk = class {
|
|
541
764
|
/**
|
|
542
765
|
* Support the following ways to init the SuiToolkit:
|
|
@@ -549,20 +772,86 @@ var Obelisk = class {
|
|
|
549
772
|
* @param networkType, 'testnet' | 'mainnet' | 'devnet' | 'localnet', default is 'devnet'
|
|
550
773
|
* @param fullnodeUrl, the fullnode url, default is the preconfig fullnode url for the given network type
|
|
551
774
|
* @param faucetUrl, the faucet url, default is the preconfig faucet url for the given network type
|
|
775
|
+
* @param packageId
|
|
552
776
|
*/
|
|
553
777
|
constructor({
|
|
554
778
|
mnemonics,
|
|
555
779
|
secretKey,
|
|
556
780
|
networkType,
|
|
557
781
|
fullnodeUrl,
|
|
558
|
-
faucetUrl
|
|
782
|
+
faucetUrl,
|
|
783
|
+
packageId,
|
|
784
|
+
metadata
|
|
559
785
|
} = {}) {
|
|
786
|
+
__privateAdd(this, _query, {});
|
|
787
|
+
__privateAdd(this, _tx, {});
|
|
788
|
+
__privateAdd(this, _exec, async (meta, tx, params, isRaw) => {
|
|
789
|
+
tx.moveCall({
|
|
790
|
+
target: `${this.contractFactory.packageId}::${meta.moudleName}::${meta.funcName}`,
|
|
791
|
+
arguments: params
|
|
792
|
+
});
|
|
793
|
+
if (isRaw === true) {
|
|
794
|
+
return tx;
|
|
795
|
+
}
|
|
796
|
+
return await this.signAndSendTxn(tx);
|
|
797
|
+
});
|
|
798
|
+
__privateAdd(this, _read, async (meta, tx, params) => {
|
|
799
|
+
tx.moveCall({
|
|
800
|
+
target: `${this.contractFactory.packageId}::${meta.moudleName}::${meta.funcName}`,
|
|
801
|
+
arguments: params
|
|
802
|
+
});
|
|
803
|
+
return await this.inspectTxn(tx);
|
|
804
|
+
});
|
|
560
805
|
this.accountManager = new SuiAccountManager({ mnemonics, secretKey });
|
|
561
806
|
this.rpcProvider = new SuiRpcProvider({
|
|
562
807
|
fullnodeUrl,
|
|
563
808
|
faucetUrl,
|
|
564
809
|
networkType
|
|
565
810
|
});
|
|
811
|
+
this.epsId = "0xf2196f638c3174e18c0e31aa630a02fd516c2c5deec1ded72c0fea864c9f091a";
|
|
812
|
+
this.componentsId = "0x3bc407eb543149e42846ade59ac2a3c901584af4339dc1ecd0affd090529545f";
|
|
813
|
+
this.packageId = packageId;
|
|
814
|
+
this.metadata = metadata;
|
|
815
|
+
Object.values(metadata).forEach((value) => {
|
|
816
|
+
let data = value;
|
|
817
|
+
let moduleName = data.name;
|
|
818
|
+
Object.entries(data.exposedFunctions).forEach(([funcName, value2]) => {
|
|
819
|
+
let meta = value2;
|
|
820
|
+
meta.moudleName = moduleName;
|
|
821
|
+
meta.funcName = funcName;
|
|
822
|
+
if (isUndefined(__privateGet(this, _query)[moduleName])) {
|
|
823
|
+
__privateGet(this, _query)[moduleName] = {};
|
|
824
|
+
}
|
|
825
|
+
if (isUndefined(__privateGet(this, _query)[moduleName][funcName])) {
|
|
826
|
+
__privateGet(this, _query)[moduleName][funcName] = createQuery(meta, (tx, p) => __privateGet(this, _read).call(this, meta, tx, p));
|
|
827
|
+
}
|
|
828
|
+
if (isUndefined(__privateGet(this, _tx)[moduleName])) {
|
|
829
|
+
__privateGet(this, _tx)[moduleName] = {};
|
|
830
|
+
}
|
|
831
|
+
if (isUndefined(__privateGet(this, _tx)[moduleName][funcName])) {
|
|
832
|
+
__privateGet(this, _tx)[moduleName][funcName] = createTx(meta, (tx, p, isRaw) => __privateGet(this, _exec).call(this, meta, tx, p, isRaw));
|
|
833
|
+
}
|
|
834
|
+
});
|
|
835
|
+
});
|
|
836
|
+
this.contractFactory = new SuiContractFactory({
|
|
837
|
+
packageId,
|
|
838
|
+
metadata
|
|
839
|
+
});
|
|
840
|
+
}
|
|
841
|
+
// async initialize() {
|
|
842
|
+
// const metadata = await this.loadData();
|
|
843
|
+
// this.metadata = metadata as SuiMoveNormalizedModules;
|
|
844
|
+
// this.contractFactory = new SuiContractFactory({
|
|
845
|
+
// packageId: this.packageId,
|
|
846
|
+
// metadata: this.metadata
|
|
847
|
+
// })
|
|
848
|
+
// return metadata
|
|
849
|
+
// }
|
|
850
|
+
get query() {
|
|
851
|
+
return __privateGet(this, _query);
|
|
852
|
+
}
|
|
853
|
+
get tx() {
|
|
854
|
+
return __privateGet(this, _tx);
|
|
566
855
|
}
|
|
567
856
|
/**
|
|
568
857
|
* if derivePathParams is not provided or mnemonics is empty, it will return the currentSigner.
|
|
@@ -572,7 +861,7 @@ var Obelisk = class {
|
|
|
572
861
|
*/
|
|
573
862
|
getSigner(derivePathParams) {
|
|
574
863
|
const keyPair = this.accountManager.getKeyPair(derivePathParams);
|
|
575
|
-
return new
|
|
864
|
+
return new import_sui10.RawSigner(keyPair, this.rpcProvider.provider);
|
|
576
865
|
}
|
|
577
866
|
/**
|
|
578
867
|
* @description Switch the current account with the given derivePathParams
|
|
@@ -594,6 +883,12 @@ var Obelisk = class {
|
|
|
594
883
|
provider() {
|
|
595
884
|
return this.rpcProvider.provider;
|
|
596
885
|
}
|
|
886
|
+
getPackageId() {
|
|
887
|
+
return this.contractFactory.packageId;
|
|
888
|
+
}
|
|
889
|
+
getMetadata() {
|
|
890
|
+
return this.contractFactory.metadata;
|
|
891
|
+
}
|
|
597
892
|
/**
|
|
598
893
|
* Request some SUI from faucet
|
|
599
894
|
* @Returns {Promise<boolean>}, true if the request is successful, false otherwise.
|
|
@@ -606,6 +901,9 @@ var Obelisk = class {
|
|
|
606
901
|
const owner = this.accountManager.getAddress(derivePathParams);
|
|
607
902
|
return this.rpcProvider.getBalance(owner, coinType);
|
|
608
903
|
}
|
|
904
|
+
async getObject(objectId) {
|
|
905
|
+
return this.rpcProvider.getObject(objectId);
|
|
906
|
+
}
|
|
609
907
|
async getObjects(objectIds) {
|
|
610
908
|
return this.rpcProvider.getObjects(objectIds);
|
|
611
909
|
}
|
|
@@ -727,29 +1025,90 @@ var Obelisk = class {
|
|
|
727
1025
|
*/
|
|
728
1026
|
async inspectTxn(tx, derivePathParams) {
|
|
729
1027
|
tx = tx instanceof SuiTxBlock ? tx.txBlock : tx;
|
|
1028
|
+
console.log(this.getAddress(derivePathParams));
|
|
730
1029
|
return this.rpcProvider.provider.devInspectTransactionBlock({
|
|
731
1030
|
transactionBlock: tx,
|
|
732
1031
|
sender: this.getAddress(derivePathParams)
|
|
733
1032
|
});
|
|
734
1033
|
}
|
|
735
|
-
async
|
|
736
|
-
const tx = new
|
|
1034
|
+
async getBirthTime(objectId, derivePathParams) {
|
|
1035
|
+
const tx = new import_sui10.TransactionBlock();
|
|
737
1036
|
tx.moveCall({
|
|
738
|
-
target:
|
|
1037
|
+
// target: `0x12b216923e5454e1f076ccb5fc638b59f8aba2175c34df9899de71124d66badd::status_system::get_pet_state`,
|
|
1038
|
+
target: `0x6afbf113a5872b781a2a0068b95c0d9d0ee89428518fdd65f862c841eab45b82::pet_system::get_pet_basic_info`,
|
|
739
1039
|
arguments: [
|
|
740
|
-
//
|
|
741
|
-
tx.pure(
|
|
1040
|
+
// tx.pure("0x6fa43c68221960f942572905f3c198a5bccaa0700506b3b6bd83dd9b007e6324"),
|
|
1041
|
+
// tx.pure("0xbf64721f0961a0426ccde6b8d9343e2cb2c26a105a5c33e57074580fd98b2cb1"),
|
|
1042
|
+
// tx.pure("0x6"),
|
|
1043
|
+
obj(tx, "0x26804211486be597a89c46c16b929d7031fb7c701ecf89d4c750e49459b4bea2"),
|
|
1044
|
+
pure(tx, "0x35ba3bfb8590dbd060f41cd58c7b140d67efd2126648409cd231c74cff2828b8", `0x2::object::ID`),
|
|
1045
|
+
obj(tx, "0x6")
|
|
742
1046
|
]
|
|
743
1047
|
});
|
|
744
|
-
return this.
|
|
745
|
-
}
|
|
1048
|
+
return await this.inspectTxn(tx, derivePathParams);
|
|
1049
|
+
}
|
|
1050
|
+
async getWorld(worldObjectId) {
|
|
1051
|
+
return this.rpcProvider.getObject(worldObjectId);
|
|
1052
|
+
}
|
|
1053
|
+
async getAllEntities(worldId, cursor, limit) {
|
|
1054
|
+
const parentId = (await this.rpcProvider.getObject(worldId)).objectFields.entities.fields.id.id;
|
|
1055
|
+
return await this.rpcProvider.getDynamicFields(parentId, cursor, limit);
|
|
1056
|
+
}
|
|
1057
|
+
async getEntity(worldId, entityId) {
|
|
1058
|
+
const parentId = (await this.rpcProvider.getObject(worldId)).objectFields.entities.fields.id.id;
|
|
1059
|
+
const name = {
|
|
1060
|
+
type: "0x2::object::ID",
|
|
1061
|
+
value: entityId
|
|
1062
|
+
};
|
|
1063
|
+
return await this.rpcProvider.getDynamicFieldObject(parentId, name);
|
|
1064
|
+
}
|
|
1065
|
+
async getEntityComponents(worldId, entityId, cursor, limit) {
|
|
1066
|
+
const parentContent = (await this.getEntity(worldId, entityId)).data.content;
|
|
1067
|
+
const parentId = parentContent.fields.value.fields.components.fields.id.id;
|
|
1068
|
+
return await this.rpcProvider.getDynamicFields(parentId, cursor, limit);
|
|
1069
|
+
}
|
|
1070
|
+
async getEntityComponent(entityId, componentId) {
|
|
1071
|
+
const parentId = (await this.rpcProvider.getObject(entityId)).objectFields.id.id;
|
|
1072
|
+
const name = {
|
|
1073
|
+
type: "0x2::object::ID",
|
|
1074
|
+
value: componentId
|
|
1075
|
+
};
|
|
1076
|
+
return await this.rpcProvider.getDynamicFieldObject(parentId, name);
|
|
1077
|
+
}
|
|
1078
|
+
// async loadData() {
|
|
1079
|
+
// const jsonFileName = `metadata/${this.packageId}.json`;
|
|
1080
|
+
// try {
|
|
1081
|
+
// const data = await fs.promises.readFile(jsonFileName, 'utf-8');
|
|
1082
|
+
// const jsonData = JSON.parse(data);
|
|
1083
|
+
// return jsonData as SuiMoveNormalizedModules;
|
|
1084
|
+
// } catch (error) {
|
|
1085
|
+
// if (this.packageId !== undefined) {
|
|
1086
|
+
// const jsonData = await this.rpcProvider.getNormalizedMoveModulesByPackage(this.packageId);
|
|
1087
|
+
// fs.writeFile(jsonFileName, JSON.stringify(jsonData, null, 2), (err) => {
|
|
1088
|
+
// if (err) {
|
|
1089
|
+
// console.error('写入文件时出错:', err);
|
|
1090
|
+
// } else {
|
|
1091
|
+
// console.log('JSON 数据已保存到文件:', jsonFileName);
|
|
1092
|
+
// }
|
|
1093
|
+
// });
|
|
1094
|
+
// return jsonData as SuiMoveNormalizedModules;
|
|
1095
|
+
// } else {
|
|
1096
|
+
// console.error('please set your package id.');
|
|
1097
|
+
// }
|
|
1098
|
+
// }
|
|
1099
|
+
// }
|
|
746
1100
|
};
|
|
1101
|
+
_query = new WeakMap();
|
|
1102
|
+
_tx = new WeakMap();
|
|
1103
|
+
_exec = new WeakMap();
|
|
1104
|
+
_read = new WeakMap();
|
|
747
1105
|
// Annotate the CommonJS export names for ESM import in node:
|
|
748
1106
|
0 && (module.exports = {
|
|
749
1107
|
Obelisk,
|
|
750
1108
|
SUI_CLOCK_OBJECT_ID,
|
|
751
1109
|
SUI_SYSTEM_STATE_OBJECT_ID,
|
|
752
1110
|
SuiAccountManager,
|
|
1111
|
+
SuiContractFactory,
|
|
753
1112
|
SuiRpcProvider,
|
|
754
1113
|
SuiTxBlock,
|
|
755
1114
|
TransactionBlock
|