@0xobelisk/sui-client 0.5.25 → 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/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
  );
@@ -200,18 +198,24 @@ export class Dubhe {
200
198
  const objMoudleId = `${packageId}::${moduleName}`;
201
199
 
202
200
  Object.entries(data.structs).forEach(([objectName, objectType]) => {
203
- const objId = `${objMoudleId}::${objectName}`;
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[objId])) {
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
- this.#object[objId] = bcsObj.bcs;
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 Dubhe {
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 Dubhe {
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 Dubhe {
527
529
  let baseType = res[1];
528
530
 
529
531
  const value = Uint8Array.from(baseValue);
530
- returnValues.push(this.object[baseType].parse(value));
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 Dubhe {
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 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
845
  async getOwnedObjects(owner: string, cursor?: string, limit?: number) {
878
846
  const ownedObjects = await this.suiInteractor.getOwnedObjects(
879
847
  owner,
@@ -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
  };