@0xobelisk/sui-client 0.5.25 → 0.5.27
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/dist/dubhe.d.ts +0 -4
- package/dist/index.js +67 -44
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +67 -44
- package/dist/index.mjs.map +1 -1
- package/dist/types/index.d.ts +1 -0
- package/package.json +1 -1
- package/src/dubhe.ts +67 -67
- package/src/types/index.ts +1 -0
package/src/dubhe.ts
CHANGED
|
@@ -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,7 +93,6 @@ 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
|
);
|
|
@@ -142,6 +140,22 @@ export class Dubhe {
|
|
|
142
140
|
'0x1::option::Option<u128>': bcs.option(bcs.u128()),
|
|
143
141
|
'0x1::option::Option<u256>': bcs.option(bcs.u256()),
|
|
144
142
|
'0x1::option::Option<bool>': bcs.option(bcs.bool()),
|
|
143
|
+
'0x1::option::Option<vector<address>>': bcs.option(
|
|
144
|
+
bcs.vector(
|
|
145
|
+
bcs.bytes(32).transform({
|
|
146
|
+
// To change the input type, you need to provide a type definition for the input
|
|
147
|
+
input: (val: string) => fromHEX(val),
|
|
148
|
+
output: (val) => toHEX(val),
|
|
149
|
+
})
|
|
150
|
+
)
|
|
151
|
+
),
|
|
152
|
+
'0x1::option::Option<vector<u8>>': bcs.option(bcs.vector(bcs.u8())),
|
|
153
|
+
'0x1::option::Option<vector<u16>>': bcs.option(bcs.vector(bcs.u16())),
|
|
154
|
+
'0x1::option::Option<vector<u32>>': bcs.option(bcs.vector(bcs.u32())),
|
|
155
|
+
'0x1::option::Option<vector<u64>>': bcs.option(bcs.vector(bcs.u64())),
|
|
156
|
+
'0x1::option::Option<vector<u128>>': bcs.option(bcs.vector(bcs.u128())),
|
|
157
|
+
'0x1::option::Option<vector<u256>>': bcs.option(bcs.vector(bcs.u256())),
|
|
158
|
+
'0x1::option::Option<vector<bool>>': bcs.option(bcs.vector(bcs.bool())),
|
|
145
159
|
'vector<address>': bcs.vector(
|
|
146
160
|
bcs.bytes(32).transform({
|
|
147
161
|
// To change the input type, you need to provide a type definition for the input
|
|
@@ -156,6 +170,22 @@ export class Dubhe {
|
|
|
156
170
|
'vector<u128>': bcs.vector(bcs.u128()),
|
|
157
171
|
'vector<u256>': bcs.vector(bcs.u256()),
|
|
158
172
|
'vector<bool>': bcs.vector(bcs.bool()),
|
|
173
|
+
'vector<vector<address>>': bcs.vector(
|
|
174
|
+
bcs.vector(
|
|
175
|
+
bcs.bytes(32).transform({
|
|
176
|
+
// To change the input type, you need to provide a type definition for the input
|
|
177
|
+
input: (val: string) => fromHEX(val),
|
|
178
|
+
output: (val) => toHEX(val),
|
|
179
|
+
})
|
|
180
|
+
)
|
|
181
|
+
),
|
|
182
|
+
'vector<vector<u8>>': bcs.vector(bcs.vector(bcs.u8())),
|
|
183
|
+
'vector<vector<u16>>': bcs.vector(bcs.vector(bcs.u16())),
|
|
184
|
+
'vector<vector<u32>>': bcs.vector(bcs.vector(bcs.u32())),
|
|
185
|
+
'vector<vector<u64>>': bcs.vector(bcs.vector(bcs.u64())),
|
|
186
|
+
'vector<vector<u128>>': bcs.vector(bcs.vector(bcs.u128())),
|
|
187
|
+
'vector<vector<u256>>': bcs.vector(bcs.vector(bcs.u256())),
|
|
188
|
+
'vector<vector<bool>>': bcs.vector(bcs.vector(bcs.bool())),
|
|
159
189
|
};
|
|
160
190
|
|
|
161
191
|
/**
|
|
@@ -200,18 +230,24 @@ export class Dubhe {
|
|
|
200
230
|
const objMoudleId = `${packageId}::${moduleName}`;
|
|
201
231
|
|
|
202
232
|
Object.entries(data.structs).forEach(([objectName, objectType]) => {
|
|
203
|
-
const
|
|
233
|
+
const objectId = `${objMoudleId}::${objectName}`;
|
|
204
234
|
const bcsmeta: MoveStructType = {
|
|
235
|
+
objectId,
|
|
205
236
|
objectName,
|
|
206
237
|
objectType,
|
|
207
238
|
};
|
|
208
|
-
// if (isUndefined(this.#object[
|
|
239
|
+
// if (isUndefined(this.#object[objectId])) {
|
|
209
240
|
let bcsObj = this.#bcs(bcsmeta);
|
|
210
241
|
if (bcsObj.loopFlag === true) {
|
|
211
242
|
loopFlag = bcsObj.loopFlag;
|
|
212
243
|
}
|
|
213
|
-
|
|
214
|
-
|
|
244
|
+
|
|
245
|
+
this.#object[objectId] = bcsObj.bcs;
|
|
246
|
+
|
|
247
|
+
this.#object[`vector<${objectId}>`] = bcs.vector(bcsObj.bcs);
|
|
248
|
+
this.#object[`0x1::option::Option<${objectId}>`] = bcs.option(
|
|
249
|
+
bcsObj.bcs
|
|
250
|
+
);
|
|
215
251
|
});
|
|
216
252
|
|
|
217
253
|
Object.entries(data.exposedFunctions).forEach(
|
|
@@ -458,7 +494,6 @@ export class Dubhe {
|
|
|
458
494
|
default:
|
|
459
495
|
// throw new Error('Unsupported type');
|
|
460
496
|
}
|
|
461
|
-
|
|
462
497
|
case 'TypeParameter':
|
|
463
498
|
bcsJson[objName] = bcs.u128();
|
|
464
499
|
return;
|
|
@@ -518,7 +553,6 @@ export class Dubhe {
|
|
|
518
553
|
view(dryResult: DevInspectResults) {
|
|
519
554
|
let returnValues = [];
|
|
520
555
|
|
|
521
|
-
// "success" | "failure";
|
|
522
556
|
if (dryResult.effects.status.status === 'success') {
|
|
523
557
|
const resultList = dryResult.results![0].returnValues!;
|
|
524
558
|
|
|
@@ -527,7 +561,31 @@ export class Dubhe {
|
|
|
527
561
|
let baseType = res[1];
|
|
528
562
|
|
|
529
563
|
const value = Uint8Array.from(baseValue);
|
|
530
|
-
|
|
564
|
+
|
|
565
|
+
if (!this.#object[baseType]) {
|
|
566
|
+
console.log(
|
|
567
|
+
'\n\x1b[41m\x1b[37m ERROR \x1b[0m \x1b[31mUnsupported Type\x1b[0m'
|
|
568
|
+
);
|
|
569
|
+
console.log('\x1b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\x1b[0m');
|
|
570
|
+
console.log(`\x1b[95m•\x1b[0m Type: \x1b[33m"${baseType}"\x1b[0m`);
|
|
571
|
+
console.log('\x1b[95m\n✨ Available Types:\x1b[0m');
|
|
572
|
+
Object.keys(this.#object).forEach((type) => {
|
|
573
|
+
console.log(` \x1b[36m◆\x1b[0m ${type}`);
|
|
574
|
+
});
|
|
575
|
+
console.log('\n\x1b[34m💡 How to Add Custom Type:\x1b[0m');
|
|
576
|
+
console.log(
|
|
577
|
+
` You can add custom type by extending the #object map in your code:`
|
|
578
|
+
);
|
|
579
|
+
console.log(
|
|
580
|
+
` \x1b[32mdubhe.object["${baseType}"] = bcs.struct("YourTypeName", {\n field1: bcs.string(),\n field2: bcs.u64(),\n // ... other fields\n });\x1b[0m`
|
|
581
|
+
);
|
|
582
|
+
console.log(
|
|
583
|
+
'\x1b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\x1b[0m\n'
|
|
584
|
+
);
|
|
585
|
+
throw new Error(`Unsupported type: ${baseType}`);
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
returnValues.push(this.#object[baseType].parse(value));
|
|
531
589
|
}
|
|
532
590
|
return returnValues;
|
|
533
591
|
} else {
|
|
@@ -816,64 +874,6 @@ export class Dubhe {
|
|
|
816
874
|
});
|
|
817
875
|
}
|
|
818
876
|
|
|
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 DubheObjectContent;
|
|
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
877
|
async getOwnedObjects(owner: string, cursor?: string, limit?: number) {
|
|
878
878
|
const ownedObjects = await this.suiInteractor.getOwnedObjects(
|
|
879
879
|
owner,
|