@0xobelisk/sui-client 1.2.0-pre.71 → 1.2.0-pre.72
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/README.md +7 -8
- package/dist/dubhe.d.ts +4 -4
- package/dist/index.js +116 -214
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +117 -218
- package/dist/index.mjs.map +1 -1
- package/dist/libs/suiContractFactory/index.d.ts +1 -1
- package/dist/libs/suiInteractor/suiInteractor.d.ts +1 -1
- package/dist/libs/suiTxBuilder/index.d.ts +4 -4
- package/dist/types/index.d.ts +2 -2
- package/package.json +19 -75
- package/src/dubhe.ts +150 -252
- package/src/errors/index.ts +2 -4
- package/src/libs/multiSig/client.ts +2 -2
- package/src/libs/suiAccountManager/index.ts +4 -13
- package/src/libs/suiAccountManager/keypair.ts +3 -12
- package/src/libs/suiAccountManager/util.ts +1 -2
- package/src/libs/suiContractFactory/index.ts +27 -33
- package/src/libs/suiContractFactory/types.ts +1 -4
- package/src/libs/suiInteractor/defaultConfig.ts +8 -12
- package/src/libs/suiInteractor/suiInteractor.ts +29 -51
- package/src/libs/suiInteractor/util.ts +1 -2
- package/src/libs/suiModel/suiOwnedObject.ts +3 -3
- package/src/libs/suiModel/suiSharedObject.ts +4 -8
- package/src/libs/suiTxBuilder/index.ts +23 -83
- package/src/libs/suiTxBuilder/util.ts +11 -33
- package/src/metadata/index.ts +1 -2
- package/src/types/index.ts +6 -18
package/dist/index.mjs
CHANGED
|
@@ -37,11 +37,7 @@ import { Ed25519Keypair as Ed25519Keypair2 } from "@mysten/sui/keypairs/ed25519"
|
|
|
37
37
|
// src/libs/suiAccountManager/keypair.ts
|
|
38
38
|
import { Ed25519Keypair } from "@mysten/sui/keypairs/ed25519";
|
|
39
39
|
var getDerivePathForSUI = (derivePathParams = {}) => {
|
|
40
|
-
const {
|
|
41
|
-
accountIndex = 0,
|
|
42
|
-
isExternal = false,
|
|
43
|
-
addressIndex = 0
|
|
44
|
-
} = derivePathParams;
|
|
40
|
+
const { accountIndex = 0, isExternal = false, addressIndex = 0 } = derivePathParams;
|
|
45
41
|
return `m/44'/784'/${accountIndex}'/${isExternal ? 1 : 0}'/${addressIndex}'`;
|
|
46
42
|
};
|
|
47
43
|
var getKeyPair = (mnemonics, derivePathParams = {}) => {
|
|
@@ -94,10 +90,7 @@ var generateMnemonic = (numberOfWords = 24) => {
|
|
|
94
90
|
};
|
|
95
91
|
|
|
96
92
|
// src/libs/suiAccountManager/index.ts
|
|
97
|
-
import {
|
|
98
|
-
SUI_PRIVATE_KEY_PREFIX,
|
|
99
|
-
decodeSuiPrivateKey
|
|
100
|
-
} from "@mysten/sui/cryptography";
|
|
93
|
+
import { SUI_PRIVATE_KEY_PREFIX, decodeSuiPrivateKey } from "@mysten/sui/cryptography";
|
|
101
94
|
var SuiAccountManager = class {
|
|
102
95
|
/**
|
|
103
96
|
* Support the following ways to init the SuiToolkit:
|
|
@@ -123,13 +116,9 @@ var SuiAccountManager = class {
|
|
|
123
116
|
parseSecretKey(secretKey) {
|
|
124
117
|
if (secretKey.startsWith(SUI_PRIVATE_KEY_PREFIX)) {
|
|
125
118
|
const { secretKey: uint8ArraySecretKey } = decodeSuiPrivateKey(secretKey);
|
|
126
|
-
return Ed25519Keypair2.fromSecretKey(
|
|
127
|
-
normalizePrivateKey(uint8ArraySecretKey)
|
|
128
|
-
);
|
|
119
|
+
return Ed25519Keypair2.fromSecretKey(normalizePrivateKey(uint8ArraySecretKey));
|
|
129
120
|
}
|
|
130
|
-
return Ed25519Keypair2.fromSecretKey(
|
|
131
|
-
normalizePrivateKey(hexOrBase64ToUint8Array(secretKey))
|
|
132
|
-
);
|
|
121
|
+
return Ed25519Keypair2.fromSecretKey(normalizePrivateKey(hexOrBase64ToUint8Array(secretKey)));
|
|
133
122
|
}
|
|
134
123
|
/**
|
|
135
124
|
* if derivePathParams is not provided or mnemonics is empty, it will return the currentKeyPair.
|
|
@@ -203,9 +192,7 @@ function makeVecParam(txBlock, args, type) {
|
|
|
203
192
|
const bcsSchema = getPureBcsSchema(type);
|
|
204
193
|
return txBlock.pure(bcs.vector(bcsSchema).serialize(args));
|
|
205
194
|
} else {
|
|
206
|
-
const elements = args.map(
|
|
207
|
-
(arg) => convertObjArg(txBlock, arg)
|
|
208
|
-
);
|
|
195
|
+
const elements = args.map((arg) => convertObjArg(txBlock, arg));
|
|
209
196
|
return txBlock.makeMoveVec({ elements, type });
|
|
210
197
|
}
|
|
211
198
|
}
|
|
@@ -343,10 +330,7 @@ var SuiTx = class {
|
|
|
343
330
|
add(...args) {
|
|
344
331
|
return this.tx.add(...args);
|
|
345
332
|
}
|
|
346
|
-
publish({
|
|
347
|
-
modules,
|
|
348
|
-
dependencies
|
|
349
|
-
}) {
|
|
333
|
+
publish({ modules, dependencies }) {
|
|
350
334
|
return this.tx.publish({ modules, dependencies });
|
|
351
335
|
}
|
|
352
336
|
upgrade(...args) {
|
|
@@ -363,17 +347,12 @@ var SuiTx = class {
|
|
|
363
347
|
);
|
|
364
348
|
}
|
|
365
349
|
splitCoins(coin, amounts) {
|
|
366
|
-
const res = this.tx.splitCoins(
|
|
367
|
-
convertObjArg(this.tx, coin),
|
|
368
|
-
convertAmounts(this.tx, amounts)
|
|
369
|
-
);
|
|
350
|
+
const res = this.tx.splitCoins(convertObjArg(this.tx, coin), convertAmounts(this.tx, amounts));
|
|
370
351
|
return amounts.map((_, i) => res[i]);
|
|
371
352
|
}
|
|
372
353
|
mergeCoins(destination, sources) {
|
|
373
354
|
const destinationObject = convertObjArg(this.tx, destination);
|
|
374
|
-
const sourceObjects = sources.map(
|
|
375
|
-
(source) => convertObjArg(this.tx, source)
|
|
376
|
-
);
|
|
355
|
+
const sourceObjects = sources.map((source) => convertObjArg(this.tx, source));
|
|
377
356
|
return this.tx.mergeCoins(destinationObject, sourceObjects);
|
|
378
357
|
}
|
|
379
358
|
/**
|
|
@@ -386,9 +365,7 @@ var SuiTx = class {
|
|
|
386
365
|
const regex = /(?<package>[a-zA-Z0-9]+)::(?<module>[a-zA-Z0-9_]+)::(?<function>[a-zA-Z0-9_]+)/;
|
|
387
366
|
const match = target.match(regex);
|
|
388
367
|
if (match === null)
|
|
389
|
-
throw new Error(
|
|
390
|
-
"Invalid target format. Expected `${string}::${string}::${string}`"
|
|
391
|
-
);
|
|
368
|
+
throw new Error("Invalid target format. Expected `${string}::${string}::${string}`");
|
|
392
369
|
const convertedArgs = convertArgs(this.tx, args);
|
|
393
370
|
return this.tx.moveCall({
|
|
394
371
|
target,
|
|
@@ -399,9 +376,7 @@ var SuiTx = class {
|
|
|
399
376
|
/* Enhance methods of TransactionBlock */
|
|
400
377
|
transferSuiToMany(recipients, amounts) {
|
|
401
378
|
if (recipients.length !== amounts.length) {
|
|
402
|
-
throw new Error(
|
|
403
|
-
"transferSuiToMany: recipients.length !== amounts.length"
|
|
404
|
-
);
|
|
379
|
+
throw new Error("transferSuiToMany: recipients.length !== amounts.length");
|
|
405
380
|
}
|
|
406
381
|
const coins = this.tx.splitCoins(
|
|
407
382
|
this.tx.gas,
|
|
@@ -409,9 +384,7 @@ var SuiTx = class {
|
|
|
409
384
|
(amount) => typeof amount === "number" || typeof amount === "bigint" ? amount : convertArgs(this.tx, [amount])[0]
|
|
410
385
|
)
|
|
411
386
|
);
|
|
412
|
-
const recipientObjects = recipients.map(
|
|
413
|
-
(recipient) => convertAddressArg(this.tx, recipient)
|
|
414
|
-
);
|
|
387
|
+
const recipientObjects = recipients.map((recipient) => convertAddressArg(this.tx, recipient));
|
|
415
388
|
recipientObjects.forEach((address, index) => {
|
|
416
389
|
this.tx.transferObjects([coins[index]], address);
|
|
417
390
|
});
|
|
@@ -426,10 +399,7 @@ var SuiTx = class {
|
|
|
426
399
|
if (coins.length > 1) {
|
|
427
400
|
this.tx.mergeCoins(mergedCoin, coinObjects.slice(1));
|
|
428
401
|
}
|
|
429
|
-
const [sendCoin] = this.tx.splitCoins(
|
|
430
|
-
mergedCoin,
|
|
431
|
-
convertAmounts(this.tx, [amount])
|
|
432
|
-
);
|
|
402
|
+
const [sendCoin] = this.tx.splitCoins(mergedCoin, convertAmounts(this.tx, [amount]));
|
|
433
403
|
return [sendCoin, mergedCoin];
|
|
434
404
|
}
|
|
435
405
|
splitSUIFromGas(amounts) {
|
|
@@ -441,26 +411,16 @@ var SuiTx = class {
|
|
|
441
411
|
if (coins.length > 1) {
|
|
442
412
|
this.tx.mergeCoins(mergedCoin, coinObjects.slice(1));
|
|
443
413
|
}
|
|
444
|
-
const splitedCoins = this.tx.splitCoins(
|
|
445
|
-
mergedCoin,
|
|
446
|
-
convertAmounts(this.tx, amounts)
|
|
447
|
-
);
|
|
414
|
+
const splitedCoins = this.tx.splitCoins(mergedCoin, convertAmounts(this.tx, amounts));
|
|
448
415
|
return { splitedCoins, mergedCoin };
|
|
449
416
|
}
|
|
450
417
|
transferCoinToMany(coins, sender, recipients, amounts) {
|
|
451
418
|
if (recipients.length !== amounts.length) {
|
|
452
|
-
throw new Error(
|
|
453
|
-
"transferSuiToMany: recipients.length !== amounts.length"
|
|
454
|
-
);
|
|
419
|
+
throw new Error("transferSuiToMany: recipients.length !== amounts.length");
|
|
455
420
|
}
|
|
456
421
|
const coinObjects = coins.map((coin) => convertObjArg(this.tx, coin));
|
|
457
|
-
const { splitedCoins, mergedCoin } = this.splitMultiCoins(
|
|
458
|
-
|
|
459
|
-
amounts
|
|
460
|
-
);
|
|
461
|
-
const recipientObjects = recipients.map(
|
|
462
|
-
(recipient) => convertAddressArg(this.tx, recipient)
|
|
463
|
-
);
|
|
422
|
+
const { splitedCoins, mergedCoin } = this.splitMultiCoins(coinObjects, amounts);
|
|
423
|
+
const recipientObjects = recipients.map((recipient) => convertAddressArg(this.tx, recipient));
|
|
464
424
|
recipientObjects.forEach((address, index) => {
|
|
465
425
|
this.tx.transferObjects([splitedCoins[index]], address);
|
|
466
426
|
});
|
|
@@ -471,10 +431,7 @@ var SuiTx = class {
|
|
|
471
431
|
return this.transferCoinToMany(coins, sender, [recipient], [amount]);
|
|
472
432
|
}
|
|
473
433
|
stakeSui(amount, validatorAddr) {
|
|
474
|
-
const [stakeCoin] = this.tx.splitCoins(
|
|
475
|
-
this.tx.gas,
|
|
476
|
-
convertAmounts(this.tx, [amount])
|
|
477
|
-
);
|
|
434
|
+
const [stakeCoin] = this.tx.splitCoins(this.tx.gas, convertAmounts(this.tx, [amount]));
|
|
478
435
|
return this.tx.moveCall({
|
|
479
436
|
target: "0x3::sui_system::request_add_stake",
|
|
480
437
|
arguments: convertArgs(this.tx, [
|
|
@@ -654,9 +611,7 @@ var SuiInteractor = class {
|
|
|
654
611
|
return parsedObjects;
|
|
655
612
|
} catch (err) {
|
|
656
613
|
await delay(2e3);
|
|
657
|
-
console.warn(
|
|
658
|
-
`Failed to get objects with fullnode ${this.fullNodes[clientIdx]}: ${err}`
|
|
659
|
-
);
|
|
614
|
+
console.warn(`Failed to get objects with fullnode ${this.fullNodes[clientIdx]}: ${err}`);
|
|
660
615
|
}
|
|
661
616
|
}
|
|
662
617
|
throw new Error("Failed to get objects with all fullnodes");
|
|
@@ -760,9 +715,7 @@ var SuiInteractor = class {
|
|
|
760
715
|
const objectIds = suiObjects.map((obj) => obj.objectId);
|
|
761
716
|
const objects = await this.getObjects(objectIds);
|
|
762
717
|
for (const object of objects) {
|
|
763
|
-
const suiObject = suiObjects.find(
|
|
764
|
-
(obj) => obj.objectId === object?.objectId
|
|
765
|
-
);
|
|
718
|
+
const suiObject = suiObjects.find((obj) => obj.objectId === object?.objectId);
|
|
766
719
|
if (suiObject instanceof SuiSharedObject) {
|
|
767
720
|
if (object.owner && typeof object.owner === "object" && "Shared" in object.owner) {
|
|
768
721
|
suiObject.initialSharedVersion = object.owner.Shared.initial_shared_version;
|
|
@@ -919,41 +872,35 @@ var SuiContractFactory = class {
|
|
|
919
872
|
this.packageId = packageId || "";
|
|
920
873
|
this.metadata = metadata || void 0;
|
|
921
874
|
}
|
|
922
|
-
getFuncByModuleName(
|
|
923
|
-
Object.values(this.metadata).forEach(
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
Object.values(value2.parameters).forEach((values) => {
|
|
930
|
-
});
|
|
875
|
+
getFuncByModuleName(_moduleName) {
|
|
876
|
+
Object.values(this.metadata).forEach((value) => {
|
|
877
|
+
const data = value;
|
|
878
|
+
console.log(`moudle name: ${data.name}`);
|
|
879
|
+
Object.entries(data.exposedFunctions).forEach(([key, value2]) => {
|
|
880
|
+
console.log(` func name: ${key}`);
|
|
881
|
+
Object.values(value2.parameters).forEach((_values) => {
|
|
931
882
|
});
|
|
932
|
-
}
|
|
933
|
-
);
|
|
883
|
+
});
|
|
884
|
+
});
|
|
934
885
|
}
|
|
935
886
|
getAllFunc() {
|
|
936
|
-
Object.values(this.metadata).forEach(
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
console.log(` args: ${values}`);
|
|
945
|
-
});
|
|
887
|
+
Object.values(this.metadata).forEach((value) => {
|
|
888
|
+
const data = value;
|
|
889
|
+
console.log(`moudle name: ${data.name}`);
|
|
890
|
+
Object.entries(data.exposedFunctions).forEach(([key, value2]) => {
|
|
891
|
+
console.log(` func name: ${key}`);
|
|
892
|
+
console.log(` ${value2.parameters.length}`);
|
|
893
|
+
Object.values(value2.parameters).forEach((values) => {
|
|
894
|
+
console.log(` args: ${values}`);
|
|
946
895
|
});
|
|
947
|
-
}
|
|
948
|
-
);
|
|
896
|
+
});
|
|
897
|
+
});
|
|
949
898
|
}
|
|
950
899
|
getAllModule() {
|
|
951
|
-
Object.values(this.metadata).forEach(
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
}
|
|
956
|
-
);
|
|
900
|
+
Object.values(this.metadata).forEach((value, index) => {
|
|
901
|
+
const data = value;
|
|
902
|
+
console.log(`${index}. ${data.name}`);
|
|
903
|
+
});
|
|
957
904
|
}
|
|
958
905
|
// async call(arguments: ({
|
|
959
906
|
// kind: "Input";
|
|
@@ -1485,7 +1432,7 @@ var Dubhe = class {
|
|
|
1485
1432
|
__privateAdd(this, _bcs, (bcsmeta) => {
|
|
1486
1433
|
let loopFlag = false;
|
|
1487
1434
|
const bcsJson = {};
|
|
1488
|
-
Object.entries(bcsmeta.objectType.fields).forEach(([
|
|
1435
|
+
Object.entries(bcsmeta.objectType.fields).forEach(([_index, type]) => {
|
|
1489
1436
|
const objName = type.name;
|
|
1490
1437
|
const objType = type.type;
|
|
1491
1438
|
switch (typeof objType) {
|
|
@@ -1672,7 +1619,7 @@ var Dubhe = class {
|
|
|
1672
1619
|
const variantJson = {};
|
|
1673
1620
|
Object.entries(bcsmeta.objectType.variants).forEach(([name, type]) => {
|
|
1674
1621
|
if (type.length > 0) {
|
|
1675
|
-
Object.entries(type).forEach(([
|
|
1622
|
+
Object.entries(type).forEach(([_index, value]) => {
|
|
1676
1623
|
const objType = value.type;
|
|
1677
1624
|
const objName = value.name;
|
|
1678
1625
|
switch (typeof objType) {
|
|
@@ -1848,83 +1795,73 @@ var Dubhe = class {
|
|
|
1848
1795
|
let stillNeedFormat = true;
|
|
1849
1796
|
while (stillNeedFormat === true && loopNum <= maxLoopNum) {
|
|
1850
1797
|
let loopFlag = false;
|
|
1851
|
-
Object.values(metadata).forEach(
|
|
1852
|
-
|
|
1853
|
-
|
|
1854
|
-
|
|
1855
|
-
|
|
1856
|
-
|
|
1857
|
-
|
|
1858
|
-
|
|
1859
|
-
|
|
1860
|
-
|
|
1861
|
-
|
|
1862
|
-
const objectId = `${objMoudleId}::${enumName}`;
|
|
1863
|
-
const bcsmeta = {
|
|
1864
|
-
objectId,
|
|
1865
|
-
objectName: enumName,
|
|
1866
|
-
objectType: enumType
|
|
1867
|
-
};
|
|
1868
|
-
let bcsObj = __privateGet(this, _bcsenum).call(this, bcsmeta);
|
|
1869
|
-
if (bcsObj.loopFlag === true) {
|
|
1870
|
-
loopFlag = bcsObj.loopFlag;
|
|
1871
|
-
}
|
|
1872
|
-
if (__privateGet(this, _object)[objectId] === void 0) {
|
|
1873
|
-
__privateGet(this, _object)[objectId] = bcsObj.bcs;
|
|
1874
|
-
__privateGet(this, _object)[`vector<${objectId}>`] = bcs2.vector(bcsObj.bcs);
|
|
1875
|
-
__privateGet(this, _object)[`vector<vector<${objectId}>>`] = bcs2.vector(
|
|
1876
|
-
bcs2.vector(bcsObj.bcs)
|
|
1877
|
-
);
|
|
1878
|
-
__privateGet(this, _object)[`0x1::option::Option<${objectId}>`] = bcs2.option(
|
|
1879
|
-
bcsObj.bcs
|
|
1880
|
-
);
|
|
1881
|
-
}
|
|
1882
|
-
});
|
|
1883
|
-
}
|
|
1884
|
-
Object.entries(data.structs).forEach(([objectName, objectType]) => {
|
|
1885
|
-
const objectId = `${objMoudleId}::${objectName}`;
|
|
1798
|
+
Object.values(metadata).forEach((moudlevalue) => {
|
|
1799
|
+
const data = moudlevalue;
|
|
1800
|
+
const moduleName = data.name;
|
|
1801
|
+
const itemModuleName = moduleName;
|
|
1802
|
+
if (itemModuleName.endsWith("_genesis")) {
|
|
1803
|
+
this.projectName = itemModuleName.replace("_genesis", "");
|
|
1804
|
+
}
|
|
1805
|
+
const objMoudleId = `${this.packageId}::${moduleName}`;
|
|
1806
|
+
if (data.enums) {
|
|
1807
|
+
Object.entries(data.enums).forEach(([enumName, enumType]) => {
|
|
1808
|
+
const objectId = `${objMoudleId}::${enumName}`;
|
|
1886
1809
|
const bcsmeta = {
|
|
1887
1810
|
objectId,
|
|
1888
|
-
objectName,
|
|
1889
|
-
objectType
|
|
1811
|
+
objectName: enumName,
|
|
1812
|
+
objectType: enumType
|
|
1890
1813
|
};
|
|
1891
|
-
let bcsObj = __privateGet(this,
|
|
1814
|
+
let bcsObj = __privateGet(this, _bcsenum).call(this, bcsmeta);
|
|
1892
1815
|
if (bcsObj.loopFlag === true) {
|
|
1893
1816
|
loopFlag = bcsObj.loopFlag;
|
|
1894
1817
|
}
|
|
1895
|
-
__privateGet(this, _object)[objectId]
|
|
1896
|
-
|
|
1897
|
-
|
|
1898
|
-
bcsObj.bcs
|
|
1899
|
-
|
|
1900
|
-
});
|
|
1901
|
-
Object.entries(data.exposedFunctions).forEach(
|
|
1902
|
-
([funcName, funcvalue]) => {
|
|
1903
|
-
const meta = funcvalue;
|
|
1904
|
-
meta.moduleName = moduleName;
|
|
1905
|
-
meta.funcName = funcName;
|
|
1906
|
-
if (isUndefined(__privateGet(this, _query)[moduleName])) {
|
|
1907
|
-
__privateGet(this, _query)[moduleName] = {};
|
|
1908
|
-
}
|
|
1909
|
-
if (isUndefined(__privateGet(this, _query)[moduleName][funcName])) {
|
|
1910
|
-
__privateGet(this, _query)[moduleName][funcName] = createQuery(
|
|
1911
|
-
meta,
|
|
1912
|
-
(tx, p, typeArguments, isRaw) => __privateGet(this, _read).call(this, meta, tx, p, typeArguments, isRaw)
|
|
1913
|
-
);
|
|
1914
|
-
}
|
|
1915
|
-
if (isUndefined(__privateGet(this, _tx)[moduleName])) {
|
|
1916
|
-
__privateGet(this, _tx)[moduleName] = {};
|
|
1917
|
-
}
|
|
1918
|
-
if (isUndefined(__privateGet(this, _tx)[moduleName][funcName])) {
|
|
1919
|
-
__privateGet(this, _tx)[moduleName][funcName] = createTx(
|
|
1920
|
-
meta,
|
|
1921
|
-
(tx, p, typeArguments, isRaw, onSuccess, onError) => __privateGet(this, _exec).call(this, meta, tx, p, typeArguments, isRaw, onSuccess, onError)
|
|
1922
|
-
);
|
|
1923
|
-
}
|
|
1818
|
+
if (__privateGet(this, _object)[objectId] === void 0) {
|
|
1819
|
+
__privateGet(this, _object)[objectId] = bcsObj.bcs;
|
|
1820
|
+
__privateGet(this, _object)[`vector<${objectId}>`] = bcs2.vector(bcsObj.bcs);
|
|
1821
|
+
__privateGet(this, _object)[`vector<vector<${objectId}>>`] = bcs2.vector(bcs2.vector(bcsObj.bcs));
|
|
1822
|
+
__privateGet(this, _object)[`0x1::option::Option<${objectId}>`] = bcs2.option(bcsObj.bcs);
|
|
1924
1823
|
}
|
|
1925
|
-
);
|
|
1824
|
+
});
|
|
1926
1825
|
}
|
|
1927
|
-
|
|
1826
|
+
Object.entries(data.structs).forEach(([objectName, objectType]) => {
|
|
1827
|
+
const objectId = `${objMoudleId}::${objectName}`;
|
|
1828
|
+
const bcsmeta = {
|
|
1829
|
+
objectId,
|
|
1830
|
+
objectName,
|
|
1831
|
+
objectType
|
|
1832
|
+
};
|
|
1833
|
+
let bcsObj = __privateGet(this, _bcs).call(this, bcsmeta);
|
|
1834
|
+
if (bcsObj.loopFlag === true) {
|
|
1835
|
+
loopFlag = bcsObj.loopFlag;
|
|
1836
|
+
}
|
|
1837
|
+
__privateGet(this, _object)[objectId] = bcsObj.bcs;
|
|
1838
|
+
__privateGet(this, _object)[`vector<${objectId}>`] = bcs2.vector(bcsObj.bcs);
|
|
1839
|
+
__privateGet(this, _object)[`0x1::option::Option<${objectId}>`] = bcs2.option(bcsObj.bcs);
|
|
1840
|
+
});
|
|
1841
|
+
Object.entries(data.exposedFunctions).forEach(([funcName, funcvalue]) => {
|
|
1842
|
+
const meta = funcvalue;
|
|
1843
|
+
meta.moduleName = moduleName;
|
|
1844
|
+
meta.funcName = funcName;
|
|
1845
|
+
if (isUndefined(__privateGet(this, _query)[moduleName])) {
|
|
1846
|
+
__privateGet(this, _query)[moduleName] = {};
|
|
1847
|
+
}
|
|
1848
|
+
if (isUndefined(__privateGet(this, _query)[moduleName][funcName])) {
|
|
1849
|
+
__privateGet(this, _query)[moduleName][funcName] = createQuery(
|
|
1850
|
+
meta,
|
|
1851
|
+
(tx, p, typeArguments, isRaw) => __privateGet(this, _read).call(this, meta, tx, p, typeArguments, isRaw)
|
|
1852
|
+
);
|
|
1853
|
+
}
|
|
1854
|
+
if (isUndefined(__privateGet(this, _tx)[moduleName])) {
|
|
1855
|
+
__privateGet(this, _tx)[moduleName] = {};
|
|
1856
|
+
}
|
|
1857
|
+
if (isUndefined(__privateGet(this, _tx)[moduleName][funcName])) {
|
|
1858
|
+
__privateGet(this, _tx)[moduleName][funcName] = createTx(
|
|
1859
|
+
meta,
|
|
1860
|
+
(tx, p, typeArguments, isRaw, onSuccess, onError) => __privateGet(this, _exec).call(this, meta, tx, p, typeArguments, isRaw, onSuccess, onError)
|
|
1861
|
+
);
|
|
1862
|
+
}
|
|
1863
|
+
});
|
|
1864
|
+
});
|
|
1928
1865
|
stillNeedFormat = loopFlag;
|
|
1929
1866
|
loopNum++;
|
|
1930
1867
|
}
|
|
@@ -1951,9 +1888,7 @@ var Dubhe = class {
|
|
|
1951
1888
|
let baseValue = res[0];
|
|
1952
1889
|
let baseType = res[1];
|
|
1953
1890
|
const value = Uint8Array.from(baseValue);
|
|
1954
|
-
const storageValueMatch = baseType.match(
|
|
1955
|
-
/^.*::storage_value::StorageValue<(.+)>$/
|
|
1956
|
-
);
|
|
1891
|
+
const storageValueMatch = baseType.match(/^.*::storage_value::StorageValue<(.+)>$/);
|
|
1957
1892
|
if (storageValueMatch) {
|
|
1958
1893
|
const innerType = storageValueMatch[1];
|
|
1959
1894
|
if (__privateGet(this, _object)[innerType]) {
|
|
@@ -1968,9 +1903,7 @@ var Dubhe = class {
|
|
|
1968
1903
|
continue;
|
|
1969
1904
|
}
|
|
1970
1905
|
}
|
|
1971
|
-
const storageMapMatch = baseType.match(
|
|
1972
|
-
/^.*::storage_map::StorageMap<(.+)>$/
|
|
1973
|
-
);
|
|
1906
|
+
const storageMapMatch = baseType.match(/^.*::storage_map::StorageMap<(.+)>$/);
|
|
1974
1907
|
if (storageMapMatch) {
|
|
1975
1908
|
const innerType = storageMapMatch[1];
|
|
1976
1909
|
const [keyType, valueType] = innerType.split(",").map((type) => type.trim());
|
|
@@ -2020,24 +1953,18 @@ var Dubhe = class {
|
|
|
2020
1953
|
continue;
|
|
2021
1954
|
}
|
|
2022
1955
|
}
|
|
2023
|
-
console.log(
|
|
2024
|
-
"\n\x1B[41m\x1B[37m ERROR \x1B[0m \x1B[31mUnsupported Type\x1B[0m"
|
|
2025
|
-
);
|
|
1956
|
+
console.log("\n\x1B[41m\x1B[37m ERROR \x1B[0m \x1B[31mUnsupported Type\x1B[0m");
|
|
2026
1957
|
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");
|
|
2027
1958
|
console.log(`\x1B[95m\u2022\x1B[0m Type: \x1B[33m"${baseType}"\x1B[0m`);
|
|
2028
1959
|
if (genericMatch) {
|
|
2029
|
-
console.log(
|
|
2030
|
-
`\x1B[95m\u2022\x1B[0m Generic Base Type: \x1B[33m"${genericMatch[1]}<T>"\x1B[0m`
|
|
2031
|
-
);
|
|
1960
|
+
console.log(`\x1B[95m\u2022\x1B[0m Generic Base Type: \x1B[33m"${genericMatch[1]}<T>"\x1B[0m`);
|
|
2032
1961
|
}
|
|
2033
1962
|
console.log("\x1B[95m\n\u2728 Available Types:\x1B[0m");
|
|
2034
1963
|
Object.keys(__privateGet(this, _object)).forEach((type) => {
|
|
2035
1964
|
console.log(` \x1B[36m\u25C6\x1B[0m ${type}`);
|
|
2036
1965
|
});
|
|
2037
1966
|
console.log("\n\x1B[34m\u{1F4A1} How to Add Custom Type:\x1B[0m");
|
|
2038
|
-
console.log(
|
|
2039
|
-
` You can add custom type by extending the #object map in your code:`
|
|
2040
|
-
);
|
|
1967
|
+
console.log(` You can add custom type by extending the #object map in your code:`);
|
|
2041
1968
|
console.log(
|
|
2042
1969
|
` \x1B[32mdubhe.object["${baseType}"] = bcs.struct("YourTypeName", {
|
|
2043
1970
|
field1: bcs.string(),
|
|
@@ -2089,12 +2016,8 @@ var Dubhe = class {
|
|
|
2089
2016
|
const schemaObject = tx.object(objectId);
|
|
2090
2017
|
const storageValueMatch = storageType.match(/^StorageValue<(.+)>$/);
|
|
2091
2018
|
const storageMapMatch = storageType.match(/^StorageMap<(.+),\s*(.+)>$/);
|
|
2092
|
-
const storageDoubleMapMatch = storageType.match(
|
|
2093
|
-
|
|
2094
|
-
);
|
|
2095
|
-
let processedParams = [
|
|
2096
|
-
schemaObject
|
|
2097
|
-
];
|
|
2019
|
+
const storageDoubleMapMatch = storageType.match(/^StorageDoubleMap<(.+),\s*(.+),\s*(.+)>$/);
|
|
2020
|
+
let processedParams = [schemaObject];
|
|
2098
2021
|
if (storageValueMatch) {
|
|
2099
2022
|
if (params.length > 0) {
|
|
2100
2023
|
console.warn(
|
|
@@ -2230,9 +2153,7 @@ var Dubhe = class {
|
|
|
2230
2153
|
}
|
|
2231
2154
|
} else {
|
|
2232
2155
|
if (onError) {
|
|
2233
|
-
await onError(
|
|
2234
|
-
new Error(`Transaction failed: ${result.effects?.status.error}`)
|
|
2235
|
-
);
|
|
2156
|
+
await onError(new Error(`Transaction failed: ${result.effects?.status.error}`));
|
|
2236
2157
|
}
|
|
2237
2158
|
}
|
|
2238
2159
|
return result;
|
|
@@ -2282,11 +2203,7 @@ var Dubhe = class {
|
|
|
2282
2203
|
const tx = new SuiTx();
|
|
2283
2204
|
const owner = this.accountManager.getAddress(derivePathParams);
|
|
2284
2205
|
const totalAmount = amounts.reduce((a, b) => a + b, 0);
|
|
2285
|
-
const coins = await this.suiInteractor.selectCoins(
|
|
2286
|
-
owner,
|
|
2287
|
-
totalAmount,
|
|
2288
|
-
coinType
|
|
2289
|
-
);
|
|
2206
|
+
const coins = await this.suiInteractor.selectCoins(owner, totalAmount, coinType);
|
|
2290
2207
|
tx.transferCoinToMany(
|
|
2291
2208
|
coins.map((c) => c.objectId),
|
|
2292
2209
|
owner,
|
|
@@ -2296,12 +2213,7 @@ var Dubhe = class {
|
|
|
2296
2213
|
return this.signAndSendTxn({ tx, derivePathParams });
|
|
2297
2214
|
}
|
|
2298
2215
|
async transferCoin(recipient, amount, coinType, derivePathParams) {
|
|
2299
|
-
return this.transferCoinToMany(
|
|
2300
|
-
[recipient],
|
|
2301
|
-
[amount],
|
|
2302
|
-
coinType,
|
|
2303
|
-
derivePathParams
|
|
2304
|
-
);
|
|
2216
|
+
return this.transferCoinToMany([recipient], [amount], coinType, derivePathParams);
|
|
2305
2217
|
}
|
|
2306
2218
|
async transferObjects(objects, recipient, derivePathParams) {
|
|
2307
2219
|
const tx = new SuiTx();
|
|
@@ -2309,12 +2221,7 @@ var Dubhe = class {
|
|
|
2309
2221
|
return this.signAndSendTxn({ tx, derivePathParams });
|
|
2310
2222
|
}
|
|
2311
2223
|
async moveCall(callParams) {
|
|
2312
|
-
const {
|
|
2313
|
-
target,
|
|
2314
|
-
arguments: args = [],
|
|
2315
|
-
typeArguments = [],
|
|
2316
|
-
derivePathParams
|
|
2317
|
-
} = callParams;
|
|
2224
|
+
const { target, arguments: args = [], typeArguments = [], derivePathParams } = callParams;
|
|
2318
2225
|
const tx = new SuiTx();
|
|
2319
2226
|
tx.moveCall(target, args, typeArguments);
|
|
2320
2227
|
return this.signAndSendTxn({ tx, derivePathParams });
|
|
@@ -2361,11 +2268,7 @@ var Dubhe = class {
|
|
|
2361
2268
|
});
|
|
2362
2269
|
}
|
|
2363
2270
|
async getOwnedObjects(owner, cursor, limit) {
|
|
2364
|
-
const ownedObjects = await this.suiInteractor.getOwnedObjects(
|
|
2365
|
-
owner,
|
|
2366
|
-
cursor,
|
|
2367
|
-
limit
|
|
2368
|
-
);
|
|
2271
|
+
const ownedObjects = await this.suiInteractor.getOwnedObjects(owner, cursor, limit);
|
|
2369
2272
|
const ownedObjectsRes = [];
|
|
2370
2273
|
for (const object of ownedObjects.data) {
|
|
2371
2274
|
const objectDetail = await this.getObject(object.data.objectId);
|
|
@@ -2457,18 +2360,14 @@ processKeyParameter_fn = function(tx, keyType, value) {
|
|
|
2457
2360
|
if (keyType.includes("::")) {
|
|
2458
2361
|
return tx.object(value);
|
|
2459
2362
|
}
|
|
2460
|
-
console.log(
|
|
2461
|
-
"\n\x1B[41m\x1B[37m ERROR \x1B[0m \x1B[31mUnsupported Key Type\x1B[0m"
|
|
2462
|
-
);
|
|
2363
|
+
console.log("\n\x1B[41m\x1B[37m ERROR \x1B[0m \x1B[31mUnsupported Key Type\x1B[0m");
|
|
2463
2364
|
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");
|
|
2464
2365
|
console.log(`\x1B[95m\u2022\x1B[0m Type: \x1B[33m"${keyType}"\x1B[0m`);
|
|
2465
2366
|
console.log("\x1B[95m\u2022\x1B[0m Supported Types:\x1B[0m");
|
|
2466
2367
|
console.log(" \x1B[36m\u25C6\x1B[0m u8, u16, u32, u64, u128, u256");
|
|
2467
2368
|
console.log(" \x1B[36m\u25C6\x1B[0m bool");
|
|
2468
2369
|
console.log(" \x1B[36m\u25C6\x1B[0m address");
|
|
2469
|
-
console.log(
|
|
2470
|
-
" \x1B[36m\u25C6\x1B[0m object (format: package::module::type)"
|
|
2471
|
-
);
|
|
2370
|
+
console.log(" \x1B[36m\u25C6\x1B[0m object (format: package::module::type)");
|
|
2472
2371
|
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");
|
|
2473
2372
|
throw new Error(`Unsupported key type: ${keyType}`);
|
|
2474
2373
|
}
|