@0xobelisk/sui-client 0.5.24 → 0.5.26
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/LICENSE +1 -1
- package/README.md +18 -18
- package/dist/{obelisk.d.ts → dubhe.d.ts} +5 -9
- package/dist/index.d.ts +1 -1
- package/dist/index.js +40 -49
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +39 -48
- package/dist/index.mjs.map +1 -1
- package/dist/types/index.d.ts +5 -4
- package/package.json +4 -4
- package/src/{obelisk.ts → dubhe.ts} +42 -74
- package/src/index.ts +1 -1
- package/src/types/index.ts +5 -4
|
@@ -16,8 +16,8 @@ import { SuiInteractor } from './libs/suiInteractor';
|
|
|
16
16
|
import {
|
|
17
17
|
MapObjectStruct,
|
|
18
18
|
MoveStructType,
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
DubheObjectContent,
|
|
20
|
+
SuiDubheReturnType,
|
|
21
21
|
} from './types';
|
|
22
22
|
import { SuiContractFactory } from './libs/suiContractFactory';
|
|
23
23
|
import {
|
|
@@ -31,7 +31,7 @@ import {
|
|
|
31
31
|
FaucetNetworkType,
|
|
32
32
|
MapMoudleFuncQuery,
|
|
33
33
|
MapMoudleFuncTx,
|
|
34
|
-
|
|
34
|
+
DubheParams,
|
|
35
35
|
SuiTxArg,
|
|
36
36
|
// SuiTxArgument,
|
|
37
37
|
SuiObjectArg,
|
|
@@ -39,7 +39,6 @@ import {
|
|
|
39
39
|
} from './types';
|
|
40
40
|
import { normalizeHexAddress, numberToAddressHex } from './utils';
|
|
41
41
|
import { bcs, fromHEX, toHEX } from '@mysten/bcs';
|
|
42
|
-
import { TypeTagSerializer } from '@mysten/sui/bcs';
|
|
43
42
|
|
|
44
43
|
export function isUndefined(value?: unknown): value is undefined {
|
|
45
44
|
return value === undefined;
|
|
@@ -94,17 +93,16 @@ function createTx(
|
|
|
94
93
|
typeArguments?: string[],
|
|
95
94
|
isRaw?: boolean
|
|
96
95
|
): Promise<SuiTransactionBlockResponse | TransactionResult> => {
|
|
97
|
-
// const result = await fn(tx, params, typeArguments, isRaw);
|
|
98
96
|
return await fn(tx, params, typeArguments, isRaw);
|
|
99
97
|
}
|
|
100
98
|
);
|
|
101
99
|
}
|
|
102
100
|
|
|
103
101
|
/**
|
|
104
|
-
* @class
|
|
102
|
+
* @class Dubhe
|
|
105
103
|
* @description This class is used to aggregate the tools that used to interact with SUI network.
|
|
106
104
|
*/
|
|
107
|
-
export class
|
|
105
|
+
export class Dubhe {
|
|
108
106
|
public accountManager: SuiAccountManager;
|
|
109
107
|
public suiInteractor: SuiInteractor;
|
|
110
108
|
public contractFactory: SuiContractFactory;
|
|
@@ -159,7 +157,7 @@ export class Obelisk {
|
|
|
159
157
|
};
|
|
160
158
|
|
|
161
159
|
/**
|
|
162
|
-
* Support the following ways to init the
|
|
160
|
+
* Support the following ways to init the DubheClient:
|
|
163
161
|
* 1. mnemonics
|
|
164
162
|
* 2. secretKey (base64 or hex)
|
|
165
163
|
* If none of them is provided, will generate a random mnemonics with 24 words.
|
|
@@ -177,7 +175,7 @@ export class Obelisk {
|
|
|
177
175
|
fullnodeUrls,
|
|
178
176
|
packageId,
|
|
179
177
|
metadata,
|
|
180
|
-
}:
|
|
178
|
+
}: DubheParams = {}) {
|
|
181
179
|
// Init the account manager
|
|
182
180
|
this.accountManager = new SuiAccountManager({ mnemonics, secretKey });
|
|
183
181
|
// Init the rpc provider
|
|
@@ -200,18 +198,24 @@ export class Obelisk {
|
|
|
200
198
|
const objMoudleId = `${packageId}::${moduleName}`;
|
|
201
199
|
|
|
202
200
|
Object.entries(data.structs).forEach(([objectName, objectType]) => {
|
|
203
|
-
const
|
|
201
|
+
const objectId = `${objMoudleId}::${objectName}`;
|
|
204
202
|
const bcsmeta: MoveStructType = {
|
|
203
|
+
objectId,
|
|
205
204
|
objectName,
|
|
206
205
|
objectType,
|
|
207
206
|
};
|
|
208
|
-
// if (isUndefined(this.#object[
|
|
207
|
+
// if (isUndefined(this.#object[objectId])) {
|
|
209
208
|
let bcsObj = this.#bcs(bcsmeta);
|
|
210
209
|
if (bcsObj.loopFlag === true) {
|
|
211
210
|
loopFlag = bcsObj.loopFlag;
|
|
212
211
|
}
|
|
213
|
-
|
|
214
|
-
|
|
212
|
+
|
|
213
|
+
this.#object[objectId] = bcsObj.bcs;
|
|
214
|
+
|
|
215
|
+
this.#object[`vector<${objectId}>`] = bcs.vector(bcsObj.bcs);
|
|
216
|
+
this.#object[`0x1::option::Option<${objectId}>`] = bcs.option(
|
|
217
|
+
bcsObj.bcs
|
|
218
|
+
);
|
|
215
219
|
});
|
|
216
220
|
|
|
217
221
|
Object.entries(data.exposedFunctions).forEach(
|
|
@@ -458,7 +462,6 @@ export class Obelisk {
|
|
|
458
462
|
default:
|
|
459
463
|
// throw new Error('Unsupported type');
|
|
460
464
|
}
|
|
461
|
-
|
|
462
465
|
case 'TypeParameter':
|
|
463
466
|
bcsJson[objName] = bcs.u128();
|
|
464
467
|
return;
|
|
@@ -518,7 +521,6 @@ export class Obelisk {
|
|
|
518
521
|
view(dryResult: DevInspectResults) {
|
|
519
522
|
let returnValues = [];
|
|
520
523
|
|
|
521
|
-
// "success" | "failure";
|
|
522
524
|
if (dryResult.effects.status.status === 'success') {
|
|
523
525
|
const resultList = dryResult.results![0].returnValues!;
|
|
524
526
|
|
|
@@ -527,7 +529,31 @@ export class Obelisk {
|
|
|
527
529
|
let baseType = res[1];
|
|
528
530
|
|
|
529
531
|
const value = Uint8Array.from(baseValue);
|
|
530
|
-
|
|
532
|
+
|
|
533
|
+
if (!this.#object[baseType]) {
|
|
534
|
+
console.log(
|
|
535
|
+
'\n\x1b[41m\x1b[37m ERROR \x1b[0m \x1b[31mUnsupported Type\x1b[0m'
|
|
536
|
+
);
|
|
537
|
+
console.log('\x1b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\x1b[0m');
|
|
538
|
+
console.log(`\x1b[95m•\x1b[0m Type: \x1b[33m"${baseType}"\x1b[0m`);
|
|
539
|
+
console.log('\x1b[95m\n✨ Available Types:\x1b[0m');
|
|
540
|
+
Object.keys(this.#object).forEach((type) => {
|
|
541
|
+
console.log(` \x1b[36m◆\x1b[0m ${type}`);
|
|
542
|
+
});
|
|
543
|
+
console.log('\n\x1b[34m💡 How to Add Custom Type:\x1b[0m');
|
|
544
|
+
console.log(
|
|
545
|
+
` You can add custom type by extending the #object map in your code:`
|
|
546
|
+
);
|
|
547
|
+
console.log(
|
|
548
|
+
` \x1b[32mdubhe.object["${baseType}"] = bcs.struct("YourTypeName", {\n field1: bcs.string(),\n field2: bcs.u64(),\n // ... other fields\n });\x1b[0m`
|
|
549
|
+
);
|
|
550
|
+
console.log(
|
|
551
|
+
'\x1b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\x1b[0m\n'
|
|
552
|
+
);
|
|
553
|
+
throw new Error(`Unsupported type: ${baseType}`);
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
returnValues.push(this.#object[baseType].parse(value));
|
|
531
557
|
}
|
|
532
558
|
return returnValues;
|
|
533
559
|
} else {
|
|
@@ -816,64 +842,6 @@ export class Obelisk {
|
|
|
816
842
|
});
|
|
817
843
|
}
|
|
818
844
|
|
|
819
|
-
async getWorld(worldObjectId: string) {
|
|
820
|
-
return this.suiInteractor.getObject(worldObjectId);
|
|
821
|
-
}
|
|
822
|
-
|
|
823
|
-
async listSchemaNames(worldId: string) {
|
|
824
|
-
const worldObject = await this.getObject(worldId);
|
|
825
|
-
const newObjectContent = worldObject.content;
|
|
826
|
-
if (newObjectContent != null) {
|
|
827
|
-
const objectContent = newObjectContent as ObeliskObjectContent;
|
|
828
|
-
const objectFields = objectContent.fields as Record<string, any>;
|
|
829
|
-
return objectFields['schema_names'];
|
|
830
|
-
} else {
|
|
831
|
-
return [];
|
|
832
|
-
}
|
|
833
|
-
}
|
|
834
|
-
|
|
835
|
-
async getEntity(
|
|
836
|
-
worldId: string,
|
|
837
|
-
schemaName: string,
|
|
838
|
-
entityId?: string
|
|
839
|
-
): Promise<any[] | undefined> {
|
|
840
|
-
const schemaModuleName = `${schemaName}_schema`;
|
|
841
|
-
const tx = new Transaction();
|
|
842
|
-
const params = [tx.object(worldId)] as TransactionArgument[];
|
|
843
|
-
|
|
844
|
-
if (entityId !== undefined) {
|
|
845
|
-
params.push(tx.object(entityId));
|
|
846
|
-
}
|
|
847
|
-
|
|
848
|
-
const dryResult = (await this.query[schemaModuleName].get(
|
|
849
|
-
tx,
|
|
850
|
-
params
|
|
851
|
-
)) as DevInspectResults;
|
|
852
|
-
// "success" | "failure";
|
|
853
|
-
return this.view(dryResult);
|
|
854
|
-
}
|
|
855
|
-
|
|
856
|
-
async containEntity(
|
|
857
|
-
worldId: string,
|
|
858
|
-
schemaName: string,
|
|
859
|
-
entityId?: string
|
|
860
|
-
): Promise<boolean | undefined> {
|
|
861
|
-
const schemaModuleName = `${schemaName}_schema`;
|
|
862
|
-
const tx = new Transaction();
|
|
863
|
-
const params = [tx.object(worldId)] as TransactionArgument[];
|
|
864
|
-
|
|
865
|
-
if (entityId !== undefined) {
|
|
866
|
-
params.push(tx.object(entityId));
|
|
867
|
-
}
|
|
868
|
-
|
|
869
|
-
const dryResult = (await this.query[schemaModuleName].contains(
|
|
870
|
-
tx,
|
|
871
|
-
params
|
|
872
|
-
)) as DevInspectResults;
|
|
873
|
-
|
|
874
|
-
return this.view(dryResult) as boolean | undefined;
|
|
875
|
-
}
|
|
876
|
-
|
|
877
845
|
async getOwnedObjects(owner: string, cursor?: string, limit?: number) {
|
|
878
846
|
const ownedObjects = await this.suiInteractor.getOwnedObjects(
|
|
879
847
|
owner,
|
package/src/index.ts
CHANGED
|
@@ -6,7 +6,7 @@ export * from '@mysten/sui/keypairs/ed25519';
|
|
|
6
6
|
export * from '@mysten/sui/keypairs/secp256k1';
|
|
7
7
|
export * from '@mysten/sui/keypairs/secp256r1';
|
|
8
8
|
export { bcs, BcsType } from '@mysten/bcs';
|
|
9
|
-
export {
|
|
9
|
+
export { Dubhe } from './dubhe';
|
|
10
10
|
export { SuiAccountManager } from './libs/suiAccountManager';
|
|
11
11
|
export { SuiTx } from './libs/suiTxBuilder';
|
|
12
12
|
export { MultiSigClient } from './libs/multiSig';
|
package/src/types/index.ts
CHANGED
|
@@ -25,7 +25,7 @@ import { SuiMoveMoudleFuncType } from '../libs/suiContractFactory/types';
|
|
|
25
25
|
export const ObjectContentFields = record(string(), any());
|
|
26
26
|
export type ObjectContentFields = Infer<typeof ObjectContentFields>;
|
|
27
27
|
|
|
28
|
-
export type
|
|
28
|
+
export type DubheObjectData = {
|
|
29
29
|
objectId: string;
|
|
30
30
|
objectType: string;
|
|
31
31
|
objectVersion: number;
|
|
@@ -33,14 +33,14 @@ export type ObeliskObjectData = {
|
|
|
33
33
|
objectFields: ObjectContentFields;
|
|
34
34
|
};
|
|
35
35
|
|
|
36
|
-
export type
|
|
36
|
+
export type DubheObjectContent = {
|
|
37
37
|
dataType: 'moveObject';
|
|
38
38
|
fields: MoveStruct;
|
|
39
39
|
hasPublicTransfer: boolean;
|
|
40
40
|
type: string;
|
|
41
41
|
};
|
|
42
42
|
|
|
43
|
-
export type
|
|
43
|
+
export type DubheParams = {
|
|
44
44
|
mnemonics?: string;
|
|
45
45
|
secretKey?: string;
|
|
46
46
|
fullnodeUrls?: string[];
|
|
@@ -124,6 +124,7 @@ export type MoveStructValueType = {
|
|
|
124
124
|
}[];
|
|
125
125
|
};
|
|
126
126
|
export type MoveStructType = {
|
|
127
|
+
objectId: string;
|
|
127
128
|
objectType: MoveStructValueType;
|
|
128
129
|
objectName: string;
|
|
129
130
|
};
|
|
@@ -275,6 +276,6 @@ export type ObjectContent = {
|
|
|
275
276
|
dataType: string;
|
|
276
277
|
};
|
|
277
278
|
|
|
278
|
-
export type
|
|
279
|
+
export type SuiDubheReturnType<T extends boolean> = T extends true
|
|
279
280
|
? SuiTransactionBlockResponse
|
|
280
281
|
: SuiTx;
|