@0xobelisk/sui-client 1.0.0 → 1.0.1

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/index.mjs CHANGED
@@ -11,6 +11,10 @@ var __privateAdd = (obj, member, value) => {
11
11
  throw TypeError("Cannot add the same private member more than once");
12
12
  member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
13
13
  };
14
+ var __privateMethod = (obj, member, method) => {
15
+ __accessCheck(obj, member, "access private method");
16
+ return method;
17
+ };
14
18
 
15
19
  // src/index.ts
16
20
  export * from "@mysten/sui/client";
@@ -973,7 +977,7 @@ function createTx(meta, fn) {
973
977
  }
974
978
  );
975
979
  }
976
- var _query, _tx, _object, _exec, _read, _bcs;
980
+ var _query, _tx, _object, _exec, _read, _bcs, _processKeyParameter, processKeyParameter_fn;
977
981
  var Dubhe = class {
978
982
  /**
979
983
  * Support the following ways to init the DubheClient:
@@ -995,6 +999,7 @@ var Dubhe = class {
995
999
  packageId,
996
1000
  metadata
997
1001
  } = {}) {
1002
+ __privateAdd(this, _processKeyParameter);
998
1003
  __privateAdd(this, _query, {});
999
1004
  __privateAdd(this, _tx, {});
1000
1005
  __privateAdd(this, _object, {
@@ -1361,6 +1366,62 @@ var Dubhe = class {
1361
1366
  let baseValue = res[0];
1362
1367
  let baseType = res[1];
1363
1368
  const value = Uint8Array.from(baseValue);
1369
+ const storageValueMatch = baseType.match(
1370
+ /^.*::storage_value::StorageValue<(.+)>$/
1371
+ );
1372
+ if (storageValueMatch) {
1373
+ const innerType = storageValueMatch[1];
1374
+ if (__privateGet(this, _object)[innerType]) {
1375
+ const storageValueBcs = bcs2.struct("StorageValue", {
1376
+ contents: bcs2.vector(
1377
+ bcs2.struct("Entry", {
1378
+ value: __privateGet(this, _object)[innerType]
1379
+ })
1380
+ )
1381
+ });
1382
+ returnValues.push(storageValueBcs.parse(value));
1383
+ continue;
1384
+ }
1385
+ }
1386
+ const storageMapMatch = baseType.match(
1387
+ /^.*::storage_map::StorageMap<(.+)>$/
1388
+ );
1389
+ if (storageMapMatch) {
1390
+ const innerType = storageMapMatch[1];
1391
+ const [keyType, valueType] = innerType.split(",").map((type) => type.trim());
1392
+ if (__privateGet(this, _object)[keyType] && __privateGet(this, _object)[valueType]) {
1393
+ const storageMapBcs = bcs2.struct("StorageMap", {
1394
+ contents: bcs2.vector(
1395
+ bcs2.struct("Entry", {
1396
+ key: __privateGet(this, _object)[keyType],
1397
+ value: __privateGet(this, _object)[valueType]
1398
+ })
1399
+ )
1400
+ });
1401
+ returnValues.push(storageMapBcs.parse(value));
1402
+ continue;
1403
+ }
1404
+ }
1405
+ const storageDoubleMapMatch = baseType.match(
1406
+ /^.*::storage_double_map::StorageDoubleMap<(.+)>$/
1407
+ );
1408
+ if (storageDoubleMapMatch) {
1409
+ const innerType = storageDoubleMapMatch[1];
1410
+ const [key1, key2, valueType] = innerType.split(",").map((type) => type.trim());
1411
+ if (__privateGet(this, _object)[key1] && __privateGet(this, _object)[key2] && __privateGet(this, _object)[valueType]) {
1412
+ const storageDoubleMapBcs = bcs2.struct("StorageDoubleMap", {
1413
+ contents: bcs2.vector(
1414
+ bcs2.struct("Entry", {
1415
+ key1: __privateGet(this, _object)[key1],
1416
+ key2: __privateGet(this, _object)[key2],
1417
+ value: __privateGet(this, _object)[valueType]
1418
+ })
1419
+ )
1420
+ });
1421
+ returnValues.push(storageDoubleMapBcs.parse(value));
1422
+ continue;
1423
+ }
1424
+ }
1364
1425
  if (__privateGet(this, _object)[baseType]) {
1365
1426
  returnValues.push(__privateGet(this, _object)[baseType].parse(value));
1366
1427
  continue;
@@ -1407,6 +1468,54 @@ var Dubhe = class {
1407
1468
  throw new ContractDataParsingError(dryResult);
1408
1469
  }
1409
1470
  }
1471
+ async state({
1472
+ schema,
1473
+ struct,
1474
+ objectId,
1475
+ storageType,
1476
+ params
1477
+ }) {
1478
+ const tx = new Transaction2();
1479
+ const moduleName = `${schema}_schema`;
1480
+ const functionName = `get_${struct}`;
1481
+ const schemaObject = tx.object(objectId);
1482
+ const storageValueMatch = storageType.match(/^StorageValue<(.+)>$/);
1483
+ const storageMapMatch = storageType.match(/^StorageMap<(.+),\s*(.+)>$/);
1484
+ const storageDoubleMapMatch = storageType.match(
1485
+ /^StorageDoubleMap<(.+),\s*(.+),\s*(.+)>$/
1486
+ );
1487
+ let processedParams = [schemaObject];
1488
+ if (storageValueMatch) {
1489
+ if (params.length > 0) {
1490
+ console.warn(
1491
+ "StorageValue does not require additional parameters. Extra parameters will be ignored."
1492
+ );
1493
+ }
1494
+ } else if (storageMapMatch) {
1495
+ if (params.length !== 1) {
1496
+ throw new Error("StorageMap requires exactly one key parameter");
1497
+ }
1498
+ const keyType = storageMapMatch[1].trim();
1499
+ processedParams.push(__privateMethod(this, _processKeyParameter, processKeyParameter_fn).call(this, tx, keyType, params[0]));
1500
+ } else if (storageDoubleMapMatch) {
1501
+ if (params.length !== 2) {
1502
+ throw new Error("StorageDoubleMap requires exactly two key parameters");
1503
+ }
1504
+ const key1Type = storageDoubleMapMatch[1].trim();
1505
+ const key2Type = storageDoubleMapMatch[2].trim();
1506
+ processedParams.push(__privateMethod(this, _processKeyParameter, processKeyParameter_fn).call(this, tx, key1Type, params[0]));
1507
+ processedParams.push(__privateMethod(this, _processKeyParameter, processKeyParameter_fn).call(this, tx, key2Type, params[1]));
1508
+ } else {
1509
+ throw new Error(
1510
+ `Invalid storage type: ${storageType}. Must be StorageValue<V>, StorageMap<K,V>, or StorageDoubleMap<K1,K2,V>`
1511
+ );
1512
+ }
1513
+ const queryResponse = await this.query[moduleName][functionName]({
1514
+ tx,
1515
+ params: processedParams
1516
+ });
1517
+ return this.view(queryResponse);
1518
+ }
1410
1519
  /**
1411
1520
  * if derivePathParams is not provided or mnemonics is empty, it will return the keypair.
1412
1521
  * else:
@@ -1674,6 +1783,45 @@ _object = new WeakMap();
1674
1783
  _exec = new WeakMap();
1675
1784
  _read = new WeakMap();
1676
1785
  _bcs = new WeakMap();
1786
+ _processKeyParameter = new WeakSet();
1787
+ processKeyParameter_fn = function(tx, keyType, value) {
1788
+ switch (keyType.toLowerCase()) {
1789
+ case "u8":
1790
+ return tx.pure(value, "u8");
1791
+ case "u16":
1792
+ return tx.pure(value, "u16");
1793
+ case "u32":
1794
+ return tx.pure(value, "u32");
1795
+ case "u64":
1796
+ return tx.pure(value, "u64");
1797
+ case "u128":
1798
+ return tx.pure(value, "u128");
1799
+ case "u256":
1800
+ return tx.pure(value, "u256");
1801
+ case "bool":
1802
+ return tx.pure(value, "bool");
1803
+ case "address":
1804
+ return tx.pure(value, "address");
1805
+ default:
1806
+ if (keyType.includes("::")) {
1807
+ return tx.object(value);
1808
+ }
1809
+ console.log(
1810
+ "\n\x1B[41m\x1B[37m ERROR \x1B[0m \x1B[31mUnsupported Key Type\x1B[0m"
1811
+ );
1812
+ 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");
1813
+ console.log(`\x1B[95m\u2022\x1B[0m Type: \x1B[33m"${keyType}"\x1B[0m`);
1814
+ console.log("\x1B[95m\u2022\x1B[0m Supported Types:\x1B[0m");
1815
+ console.log(" \x1B[36m\u25C6\x1B[0m u8, u16, u32, u64, u128, u256");
1816
+ console.log(" \x1B[36m\u25C6\x1B[0m bool");
1817
+ console.log(" \x1B[36m\u25C6\x1B[0m address");
1818
+ console.log(
1819
+ " \x1B[36m\u25C6\x1B[0m object (format: package::module::type)"
1820
+ );
1821
+ 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");
1822
+ throw new Error(`Unsupported key type: ${keyType}`);
1823
+ }
1824
+ };
1677
1825
 
1678
1826
  // src/libs/multiSig/client.ts
1679
1827
  import { MultiSigPublicKey } from "@mysten/sui/multisig";