@0xobelisk/sui-client 1.0.0 → 1.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/dist/dubhe.d.ts CHANGED
@@ -39,6 +39,13 @@ export declare class Dubhe {
39
39
  get tx(): MapMoudleFuncTx;
40
40
  get object(): MapObjectStruct;
41
41
  view(dryResult: DevInspectResults): any[];
42
+ state({ schema, struct, objectId, storageType, params, }: {
43
+ schema: string;
44
+ struct: string;
45
+ objectId: string;
46
+ storageType: string;
47
+ params: any[];
48
+ }): Promise<any[]>;
42
49
  /**
43
50
  * if derivePathParams is not provided or mnemonics is empty, it will return the keypair.
44
51
  * else:
package/dist/index.js CHANGED
@@ -40,6 +40,10 @@ var __privateAdd = (obj, member, value) => {
40
40
  throw TypeError("Cannot add the same private member more than once");
41
41
  member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
42
42
  };
43
+ var __privateMethod = (obj, member, method) => {
44
+ __accessCheck(obj, member, "access private method");
45
+ return method;
46
+ };
43
47
 
44
48
  // src/index.ts
45
49
  var src_exports = {};
@@ -1006,7 +1010,7 @@ function createTx(meta, fn) {
1006
1010
  }
1007
1011
  );
1008
1012
  }
1009
- var _query, _tx, _object, _exec, _read, _bcs;
1013
+ var _query, _tx, _object, _exec, _read, _bcs, _processKeyParameter, processKeyParameter_fn;
1010
1014
  var Dubhe = class {
1011
1015
  /**
1012
1016
  * Support the following ways to init the DubheClient:
@@ -1028,6 +1032,7 @@ var Dubhe = class {
1028
1032
  packageId,
1029
1033
  metadata
1030
1034
  } = {}) {
1035
+ __privateAdd(this, _processKeyParameter);
1031
1036
  __privateAdd(this, _query, {});
1032
1037
  __privateAdd(this, _tx, {});
1033
1038
  __privateAdd(this, _object, {
@@ -1394,6 +1399,62 @@ var Dubhe = class {
1394
1399
  let baseValue = res[0];
1395
1400
  let baseType = res[1];
1396
1401
  const value = Uint8Array.from(baseValue);
1402
+ const storageValueMatch = baseType.match(
1403
+ /^.*::storage_value::StorageValue<(.+)>$/
1404
+ );
1405
+ if (storageValueMatch) {
1406
+ const innerType = storageValueMatch[1];
1407
+ if (__privateGet(this, _object)[innerType]) {
1408
+ const storageValueBcs = import_bcs3.bcs.struct("StorageValue", {
1409
+ contents: import_bcs3.bcs.vector(
1410
+ import_bcs3.bcs.struct("Entry", {
1411
+ value: __privateGet(this, _object)[innerType]
1412
+ })
1413
+ )
1414
+ });
1415
+ returnValues.push(storageValueBcs.parse(value));
1416
+ continue;
1417
+ }
1418
+ }
1419
+ const storageMapMatch = baseType.match(
1420
+ /^.*::storage_map::StorageMap<(.+)>$/
1421
+ );
1422
+ if (storageMapMatch) {
1423
+ const innerType = storageMapMatch[1];
1424
+ const [keyType, valueType] = innerType.split(",").map((type) => type.trim());
1425
+ if (__privateGet(this, _object)[keyType] && __privateGet(this, _object)[valueType]) {
1426
+ const storageMapBcs = import_bcs3.bcs.struct("StorageMap", {
1427
+ contents: import_bcs3.bcs.vector(
1428
+ import_bcs3.bcs.struct("Entry", {
1429
+ key: __privateGet(this, _object)[keyType],
1430
+ value: __privateGet(this, _object)[valueType]
1431
+ })
1432
+ )
1433
+ });
1434
+ returnValues.push(storageMapBcs.parse(value));
1435
+ continue;
1436
+ }
1437
+ }
1438
+ const storageDoubleMapMatch = baseType.match(
1439
+ /^.*::storage_double_map::StorageDoubleMap<(.+)>$/
1440
+ );
1441
+ if (storageDoubleMapMatch) {
1442
+ const innerType = storageDoubleMapMatch[1];
1443
+ const [key1, key2, valueType] = innerType.split(",").map((type) => type.trim());
1444
+ if (__privateGet(this, _object)[key1] && __privateGet(this, _object)[key2] && __privateGet(this, _object)[valueType]) {
1445
+ const storageDoubleMapBcs = import_bcs3.bcs.struct("StorageDoubleMap", {
1446
+ contents: import_bcs3.bcs.vector(
1447
+ import_bcs3.bcs.struct("Entry", {
1448
+ key1: __privateGet(this, _object)[key1],
1449
+ key2: __privateGet(this, _object)[key2],
1450
+ value: __privateGet(this, _object)[valueType]
1451
+ })
1452
+ )
1453
+ });
1454
+ returnValues.push(storageDoubleMapBcs.parse(value));
1455
+ continue;
1456
+ }
1457
+ }
1397
1458
  if (__privateGet(this, _object)[baseType]) {
1398
1459
  returnValues.push(__privateGet(this, _object)[baseType].parse(value));
1399
1460
  continue;
@@ -1440,6 +1501,56 @@ var Dubhe = class {
1440
1501
  throw new ContractDataParsingError(dryResult);
1441
1502
  }
1442
1503
  }
1504
+ async state({
1505
+ schema,
1506
+ struct,
1507
+ objectId,
1508
+ storageType,
1509
+ params
1510
+ }) {
1511
+ const tx = new import_transactions3.Transaction();
1512
+ const moduleName = `${schema}_schema`;
1513
+ const functionName = `get_${struct}`;
1514
+ const schemaObject = tx.object(objectId);
1515
+ const storageValueMatch = storageType.match(/^StorageValue<(.+)>$/);
1516
+ const storageMapMatch = storageType.match(/^StorageMap<(.+),\s*(.+)>$/);
1517
+ const storageDoubleMapMatch = storageType.match(
1518
+ /^StorageDoubleMap<(.+),\s*(.+),\s*(.+)>$/
1519
+ );
1520
+ let processedParams = [
1521
+ schemaObject
1522
+ ];
1523
+ if (storageValueMatch) {
1524
+ if (params.length > 0) {
1525
+ console.warn(
1526
+ "StorageValue does not require additional parameters. Extra parameters will be ignored."
1527
+ );
1528
+ }
1529
+ } else if (storageMapMatch) {
1530
+ if (params.length !== 1) {
1531
+ throw new Error("StorageMap requires exactly one key parameter");
1532
+ }
1533
+ const keyType = storageMapMatch[1].trim();
1534
+ processedParams.push(__privateMethod(this, _processKeyParameter, processKeyParameter_fn).call(this, tx, keyType, params[0]));
1535
+ } else if (storageDoubleMapMatch) {
1536
+ if (params.length !== 2) {
1537
+ throw new Error("StorageDoubleMap requires exactly two key parameters");
1538
+ }
1539
+ const key1Type = storageDoubleMapMatch[1].trim();
1540
+ const key2Type = storageDoubleMapMatch[2].trim();
1541
+ processedParams.push(__privateMethod(this, _processKeyParameter, processKeyParameter_fn).call(this, tx, key1Type, params[0]));
1542
+ processedParams.push(__privateMethod(this, _processKeyParameter, processKeyParameter_fn).call(this, tx, key2Type, params[1]));
1543
+ } else {
1544
+ throw new Error(
1545
+ `Invalid storage type: ${storageType}. Must be StorageValue<V>, StorageMap<K,V>, or StorageDoubleMap<K1,K2,V>`
1546
+ );
1547
+ }
1548
+ const queryResponse = await this.query[moduleName][functionName]({
1549
+ tx,
1550
+ params: processedParams
1551
+ });
1552
+ return this.view(queryResponse);
1553
+ }
1443
1554
  /**
1444
1555
  * if derivePathParams is not provided or mnemonics is empty, it will return the keypair.
1445
1556
  * else:
@@ -1707,6 +1818,45 @@ _object = new WeakMap();
1707
1818
  _exec = new WeakMap();
1708
1819
  _read = new WeakMap();
1709
1820
  _bcs = new WeakMap();
1821
+ _processKeyParameter = new WeakSet();
1822
+ processKeyParameter_fn = function(tx, keyType, value) {
1823
+ switch (keyType.toLowerCase()) {
1824
+ case "u8":
1825
+ return tx.pure.u8(value);
1826
+ case "u16":
1827
+ return tx.pure.u16(value);
1828
+ case "u32":
1829
+ return tx.pure.u32(value);
1830
+ case "u64":
1831
+ return tx.pure.u64(value);
1832
+ case "u128":
1833
+ return tx.pure.u128(value);
1834
+ case "u256":
1835
+ return tx.pure.u256(value);
1836
+ case "bool":
1837
+ return tx.pure.bool(value);
1838
+ case "address":
1839
+ return tx.pure.address(value);
1840
+ default:
1841
+ if (keyType.includes("::")) {
1842
+ return tx.object(value);
1843
+ }
1844
+ console.log(
1845
+ "\n\x1B[41m\x1B[37m ERROR \x1B[0m \x1B[31mUnsupported Key Type\x1B[0m"
1846
+ );
1847
+ console.log("\x1B[90m\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\x1B[0m");
1848
+ console.log(`\x1B[95m\u2022\x1B[0m Type: \x1B[33m"${keyType}"\x1B[0m`);
1849
+ console.log("\x1B[95m\u2022\x1B[0m Supported Types:\x1B[0m");
1850
+ console.log(" \x1B[36m\u25C6\x1B[0m u8, u16, u32, u64, u128, u256");
1851
+ console.log(" \x1B[36m\u25C6\x1B[0m bool");
1852
+ console.log(" \x1B[36m\u25C6\x1B[0m address");
1853
+ console.log(
1854
+ " \x1B[36m\u25C6\x1B[0m object (format: package::module::type)"
1855
+ );
1856
+ console.log("\x1B[90m\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\x1B[0m\n");
1857
+ throw new Error(`Unsupported key type: ${keyType}`);
1858
+ }
1859
+ };
1710
1860
 
1711
1861
  // src/libs/multiSig/client.ts
1712
1862
  var import_multisig = require("@mysten/sui/multisig");