@0xobelisk/sui-client 0.5.31 → 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/dubhe.d.ts +7 -0
- package/dist/index.js +149 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +149 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/dubhe.ts +172 -0
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,54 @@ 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 = [schemaObject];
|
|
1521
|
+
if (storageValueMatch) {
|
|
1522
|
+
if (params.length > 0) {
|
|
1523
|
+
console.warn(
|
|
1524
|
+
"StorageValue does not require additional parameters. Extra parameters will be ignored."
|
|
1525
|
+
);
|
|
1526
|
+
}
|
|
1527
|
+
} else if (storageMapMatch) {
|
|
1528
|
+
if (params.length !== 1) {
|
|
1529
|
+
throw new Error("StorageMap requires exactly one key parameter");
|
|
1530
|
+
}
|
|
1531
|
+
const keyType = storageMapMatch[1].trim();
|
|
1532
|
+
processedParams.push(__privateMethod(this, _processKeyParameter, processKeyParameter_fn).call(this, tx, keyType, params[0]));
|
|
1533
|
+
} else if (storageDoubleMapMatch) {
|
|
1534
|
+
if (params.length !== 2) {
|
|
1535
|
+
throw new Error("StorageDoubleMap requires exactly two key parameters");
|
|
1536
|
+
}
|
|
1537
|
+
const key1Type = storageDoubleMapMatch[1].trim();
|
|
1538
|
+
const key2Type = storageDoubleMapMatch[2].trim();
|
|
1539
|
+
processedParams.push(__privateMethod(this, _processKeyParameter, processKeyParameter_fn).call(this, tx, key1Type, params[0]));
|
|
1540
|
+
processedParams.push(__privateMethod(this, _processKeyParameter, processKeyParameter_fn).call(this, tx, key2Type, params[1]));
|
|
1541
|
+
} else {
|
|
1542
|
+
throw new Error(
|
|
1543
|
+
`Invalid storage type: ${storageType}. Must be StorageValue<V>, StorageMap<K,V>, or StorageDoubleMap<K1,K2,V>`
|
|
1544
|
+
);
|
|
1545
|
+
}
|
|
1546
|
+
const queryResponse = await this.query[moduleName][functionName]({
|
|
1547
|
+
tx,
|
|
1548
|
+
params: processedParams
|
|
1549
|
+
});
|
|
1550
|
+
return this.view(queryResponse);
|
|
1551
|
+
}
|
|
1443
1552
|
/**
|
|
1444
1553
|
* if derivePathParams is not provided or mnemonics is empty, it will return the keypair.
|
|
1445
1554
|
* else:
|
|
@@ -1707,6 +1816,45 @@ _object = new WeakMap();
|
|
|
1707
1816
|
_exec = new WeakMap();
|
|
1708
1817
|
_read = new WeakMap();
|
|
1709
1818
|
_bcs = new WeakMap();
|
|
1819
|
+
_processKeyParameter = new WeakSet();
|
|
1820
|
+
processKeyParameter_fn = function(tx, keyType, value) {
|
|
1821
|
+
switch (keyType.toLowerCase()) {
|
|
1822
|
+
case "u8":
|
|
1823
|
+
return tx.pure(value, "u8");
|
|
1824
|
+
case "u16":
|
|
1825
|
+
return tx.pure(value, "u16");
|
|
1826
|
+
case "u32":
|
|
1827
|
+
return tx.pure(value, "u32");
|
|
1828
|
+
case "u64":
|
|
1829
|
+
return tx.pure(value, "u64");
|
|
1830
|
+
case "u128":
|
|
1831
|
+
return tx.pure(value, "u128");
|
|
1832
|
+
case "u256":
|
|
1833
|
+
return tx.pure(value, "u256");
|
|
1834
|
+
case "bool":
|
|
1835
|
+
return tx.pure(value, "bool");
|
|
1836
|
+
case "address":
|
|
1837
|
+
return tx.pure(value, "address");
|
|
1838
|
+
default:
|
|
1839
|
+
if (keyType.includes("::")) {
|
|
1840
|
+
return tx.object(value);
|
|
1841
|
+
}
|
|
1842
|
+
console.log(
|
|
1843
|
+
"\n\x1B[41m\x1B[37m ERROR \x1B[0m \x1B[31mUnsupported Key Type\x1B[0m"
|
|
1844
|
+
);
|
|
1845
|
+
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");
|
|
1846
|
+
console.log(`\x1B[95m\u2022\x1B[0m Type: \x1B[33m"${keyType}"\x1B[0m`);
|
|
1847
|
+
console.log("\x1B[95m\u2022\x1B[0m Supported Types:\x1B[0m");
|
|
1848
|
+
console.log(" \x1B[36m\u25C6\x1B[0m u8, u16, u32, u64, u128, u256");
|
|
1849
|
+
console.log(" \x1B[36m\u25C6\x1B[0m bool");
|
|
1850
|
+
console.log(" \x1B[36m\u25C6\x1B[0m address");
|
|
1851
|
+
console.log(
|
|
1852
|
+
" \x1B[36m\u25C6\x1B[0m object (format: package::module::type)"
|
|
1853
|
+
);
|
|
1854
|
+
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");
|
|
1855
|
+
throw new Error(`Unsupported key type: ${keyType}`);
|
|
1856
|
+
}
|
|
1857
|
+
};
|
|
1710
1858
|
|
|
1711
1859
|
// src/libs/multiSig/client.ts
|
|
1712
1860
|
var import_multisig = require("@mysten/sui/multisig");
|