@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/README.md
CHANGED
|
@@ -25,10 +25,10 @@ export const dubheConfig = {
|
|
|
25
25
|
schemas: {
|
|
26
26
|
counter: {
|
|
27
27
|
structure: {
|
|
28
|
-
value: 'StorageValue<u32>'
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
}
|
|
28
|
+
value: 'StorageValue<u32>'
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
32
|
} as DubheConfig;
|
|
33
33
|
```
|
|
34
34
|
|
|
@@ -55,7 +55,7 @@ const dubhe = new Dubhe({
|
|
|
55
55
|
networkType: network,
|
|
56
56
|
packageId: packageId,
|
|
57
57
|
metadata: metadata,
|
|
58
|
-
secretKey: privkey
|
|
58
|
+
secretKey: privkey
|
|
59
59
|
});
|
|
60
60
|
```
|
|
61
61
|
|
|
@@ -68,7 +68,7 @@ const dubhe = new Dubhe({
|
|
|
68
68
|
networkType: network,
|
|
69
69
|
packageId: packageId,
|
|
70
70
|
metadata: metadata,
|
|
71
|
-
secretKey: privkey
|
|
71
|
+
secretKey: privkey
|
|
72
72
|
});
|
|
73
73
|
```
|
|
74
74
|
|
|
@@ -166,8 +166,7 @@ const numberKey = await dubhe.entity_key_from_u256(123);
|
|
|
166
166
|
To query objects owned by a specific address:
|
|
167
167
|
|
|
168
168
|
```typescript
|
|
169
|
-
const owner =
|
|
170
|
-
'0xfa99b5b0463fcfb7d0203c701a76da5eda21a96190eb1368ab36a437cc89195e';
|
|
169
|
+
const owner = '0xfa99b5b0463fcfb7d0203c701a76da5eda21a96190eb1368ab36a437cc89195e';
|
|
171
170
|
const ownedObjects = await dubhe.getOwnedObjects(owner);
|
|
172
171
|
```
|
|
173
172
|
|
package/dist/dubhe.d.ts
CHANGED
|
@@ -36,18 +36,18 @@ export declare class Dubhe {
|
|
|
36
36
|
* @param fullnodeUrl, the fullnode url, default is the preconfig fullnode url for the given network type
|
|
37
37
|
* @param packageId
|
|
38
38
|
*/
|
|
39
|
-
constructor({ mnemonics, secretKey, networkType, fullnodeUrls, packageId, metadata
|
|
39
|
+
constructor({ mnemonics, secretKey, networkType, fullnodeUrls, packageId, metadata }?: DubheParams);
|
|
40
40
|
get query(): MapMoudleFuncQuery;
|
|
41
41
|
get tx(): MapMoudleFuncTx;
|
|
42
42
|
get object(): MapObjectStruct;
|
|
43
43
|
view(dryResult: DevInspectResults): any[];
|
|
44
|
-
state({ tx, schema, params, customModuleName
|
|
44
|
+
state({ tx, schema, params, customModuleName }: {
|
|
45
45
|
tx: Transaction;
|
|
46
46
|
schema: string;
|
|
47
47
|
params: any[];
|
|
48
48
|
customModuleName?: string;
|
|
49
49
|
}): Promise<any[] | undefined>;
|
|
50
|
-
parseState({ schema, objectId, storageType, params, customModuleName
|
|
50
|
+
parseState({ schema, objectId, storageType, params, customModuleName }: {
|
|
51
51
|
schema: string;
|
|
52
52
|
objectId: string;
|
|
53
53
|
storageType: string;
|
|
@@ -89,7 +89,7 @@ export declare class Dubhe {
|
|
|
89
89
|
getObject(objectId: string): Promise<SuiObjectData>;
|
|
90
90
|
getObjects(objectIds: string[]): Promise<SuiObjectData[]>;
|
|
91
91
|
signTxn(tx: Uint8Array | Transaction | SuiTx, derivePathParams?: DerivePathParams): Promise<import("@mysten/sui/dist/cjs/cryptography").SignatureWithBytes>;
|
|
92
|
-
signAndSendTxn({ tx, derivePathParams, onSuccess, onError
|
|
92
|
+
signAndSendTxn({ tx, derivePathParams, onSuccess, onError }: {
|
|
93
93
|
tx: Uint8Array | Transaction | SuiTx;
|
|
94
94
|
derivePathParams?: DerivePathParams;
|
|
95
95
|
onSuccess?: (result: SuiTransactionBlockResponse) => void | Promise<void>;
|
package/dist/index.js
CHANGED
|
@@ -78,11 +78,7 @@ var import_ed255192 = require("@mysten/sui/keypairs/ed25519");
|
|
|
78
78
|
// src/libs/suiAccountManager/keypair.ts
|
|
79
79
|
var import_ed25519 = require("@mysten/sui/keypairs/ed25519");
|
|
80
80
|
var getDerivePathForSUI = (derivePathParams = {}) => {
|
|
81
|
-
const {
|
|
82
|
-
accountIndex = 0,
|
|
83
|
-
isExternal = false,
|
|
84
|
-
addressIndex = 0
|
|
85
|
-
} = derivePathParams;
|
|
81
|
+
const { accountIndex = 0, isExternal = false, addressIndex = 0 } = derivePathParams;
|
|
86
82
|
return `m/44'/784'/${accountIndex}'/${isExternal ? 1 : 0}'/${addressIndex}'`;
|
|
87
83
|
};
|
|
88
84
|
var getKeyPair = (mnemonics, derivePathParams = {}) => {
|
|
@@ -161,13 +157,9 @@ var SuiAccountManager = class {
|
|
|
161
157
|
parseSecretKey(secretKey) {
|
|
162
158
|
if (secretKey.startsWith(import_cryptography.SUI_PRIVATE_KEY_PREFIX)) {
|
|
163
159
|
const { secretKey: uint8ArraySecretKey } = (0, import_cryptography.decodeSuiPrivateKey)(secretKey);
|
|
164
|
-
return import_ed255192.Ed25519Keypair.fromSecretKey(
|
|
165
|
-
normalizePrivateKey(uint8ArraySecretKey)
|
|
166
|
-
);
|
|
160
|
+
return import_ed255192.Ed25519Keypair.fromSecretKey(normalizePrivateKey(uint8ArraySecretKey));
|
|
167
161
|
}
|
|
168
|
-
return import_ed255192.Ed25519Keypair.fromSecretKey(
|
|
169
|
-
normalizePrivateKey(hexOrBase64ToUint8Array(secretKey))
|
|
170
|
-
);
|
|
162
|
+
return import_ed255192.Ed25519Keypair.fromSecretKey(normalizePrivateKey(hexOrBase64ToUint8Array(secretKey)));
|
|
171
163
|
}
|
|
172
164
|
/**
|
|
173
165
|
* if derivePathParams is not provided or mnemonics is empty, it will return the currentKeyPair.
|
|
@@ -236,9 +228,7 @@ function makeVecParam(txBlock, args, type) {
|
|
|
236
228
|
const bcsSchema = (0, import_transactions.getPureBcsSchema)(type);
|
|
237
229
|
return txBlock.pure(import_bcs.bcs.vector(bcsSchema).serialize(args));
|
|
238
230
|
} else {
|
|
239
|
-
const elements = args.map(
|
|
240
|
-
(arg) => convertObjArg(txBlock, arg)
|
|
241
|
-
);
|
|
231
|
+
const elements = args.map((arg) => convertObjArg(txBlock, arg));
|
|
242
232
|
return txBlock.makeMoveVec({ elements, type });
|
|
243
233
|
}
|
|
244
234
|
}
|
|
@@ -376,10 +366,7 @@ var SuiTx = class {
|
|
|
376
366
|
add(...args) {
|
|
377
367
|
return this.tx.add(...args);
|
|
378
368
|
}
|
|
379
|
-
publish({
|
|
380
|
-
modules,
|
|
381
|
-
dependencies
|
|
382
|
-
}) {
|
|
369
|
+
publish({ modules, dependencies }) {
|
|
383
370
|
return this.tx.publish({ modules, dependencies });
|
|
384
371
|
}
|
|
385
372
|
upgrade(...args) {
|
|
@@ -396,17 +383,12 @@ var SuiTx = class {
|
|
|
396
383
|
);
|
|
397
384
|
}
|
|
398
385
|
splitCoins(coin, amounts) {
|
|
399
|
-
const res = this.tx.splitCoins(
|
|
400
|
-
convertObjArg(this.tx, coin),
|
|
401
|
-
convertAmounts(this.tx, amounts)
|
|
402
|
-
);
|
|
386
|
+
const res = this.tx.splitCoins(convertObjArg(this.tx, coin), convertAmounts(this.tx, amounts));
|
|
403
387
|
return amounts.map((_, i) => res[i]);
|
|
404
388
|
}
|
|
405
389
|
mergeCoins(destination, sources) {
|
|
406
390
|
const destinationObject = convertObjArg(this.tx, destination);
|
|
407
|
-
const sourceObjects = sources.map(
|
|
408
|
-
(source) => convertObjArg(this.tx, source)
|
|
409
|
-
);
|
|
391
|
+
const sourceObjects = sources.map((source) => convertObjArg(this.tx, source));
|
|
410
392
|
return this.tx.mergeCoins(destinationObject, sourceObjects);
|
|
411
393
|
}
|
|
412
394
|
/**
|
|
@@ -419,9 +401,7 @@ var SuiTx = class {
|
|
|
419
401
|
const regex = /(?<package>[a-zA-Z0-9]+)::(?<module>[a-zA-Z0-9_]+)::(?<function>[a-zA-Z0-9_]+)/;
|
|
420
402
|
const match = target.match(regex);
|
|
421
403
|
if (match === null)
|
|
422
|
-
throw new Error(
|
|
423
|
-
"Invalid target format. Expected `${string}::${string}::${string}`"
|
|
424
|
-
);
|
|
404
|
+
throw new Error("Invalid target format. Expected `${string}::${string}::${string}`");
|
|
425
405
|
const convertedArgs = convertArgs(this.tx, args);
|
|
426
406
|
return this.tx.moveCall({
|
|
427
407
|
target,
|
|
@@ -432,9 +412,7 @@ var SuiTx = class {
|
|
|
432
412
|
/* Enhance methods of TransactionBlock */
|
|
433
413
|
transferSuiToMany(recipients, amounts) {
|
|
434
414
|
if (recipients.length !== amounts.length) {
|
|
435
|
-
throw new Error(
|
|
436
|
-
"transferSuiToMany: recipients.length !== amounts.length"
|
|
437
|
-
);
|
|
415
|
+
throw new Error("transferSuiToMany: recipients.length !== amounts.length");
|
|
438
416
|
}
|
|
439
417
|
const coins = this.tx.splitCoins(
|
|
440
418
|
this.tx.gas,
|
|
@@ -442,9 +420,7 @@ var SuiTx = class {
|
|
|
442
420
|
(amount) => typeof amount === "number" || typeof amount === "bigint" ? amount : convertArgs(this.tx, [amount])[0]
|
|
443
421
|
)
|
|
444
422
|
);
|
|
445
|
-
const recipientObjects = recipients.map(
|
|
446
|
-
(recipient) => convertAddressArg(this.tx, recipient)
|
|
447
|
-
);
|
|
423
|
+
const recipientObjects = recipients.map((recipient) => convertAddressArg(this.tx, recipient));
|
|
448
424
|
recipientObjects.forEach((address, index) => {
|
|
449
425
|
this.tx.transferObjects([coins[index]], address);
|
|
450
426
|
});
|
|
@@ -459,10 +435,7 @@ var SuiTx = class {
|
|
|
459
435
|
if (coins.length > 1) {
|
|
460
436
|
this.tx.mergeCoins(mergedCoin, coinObjects.slice(1));
|
|
461
437
|
}
|
|
462
|
-
const [sendCoin] = this.tx.splitCoins(
|
|
463
|
-
mergedCoin,
|
|
464
|
-
convertAmounts(this.tx, [amount])
|
|
465
|
-
);
|
|
438
|
+
const [sendCoin] = this.tx.splitCoins(mergedCoin, convertAmounts(this.tx, [amount]));
|
|
466
439
|
return [sendCoin, mergedCoin];
|
|
467
440
|
}
|
|
468
441
|
splitSUIFromGas(amounts) {
|
|
@@ -474,26 +447,16 @@ var SuiTx = class {
|
|
|
474
447
|
if (coins.length > 1) {
|
|
475
448
|
this.tx.mergeCoins(mergedCoin, coinObjects.slice(1));
|
|
476
449
|
}
|
|
477
|
-
const splitedCoins = this.tx.splitCoins(
|
|
478
|
-
mergedCoin,
|
|
479
|
-
convertAmounts(this.tx, amounts)
|
|
480
|
-
);
|
|
450
|
+
const splitedCoins = this.tx.splitCoins(mergedCoin, convertAmounts(this.tx, amounts));
|
|
481
451
|
return { splitedCoins, mergedCoin };
|
|
482
452
|
}
|
|
483
453
|
transferCoinToMany(coins, sender, recipients, amounts) {
|
|
484
454
|
if (recipients.length !== amounts.length) {
|
|
485
|
-
throw new Error(
|
|
486
|
-
"transferSuiToMany: recipients.length !== amounts.length"
|
|
487
|
-
);
|
|
455
|
+
throw new Error("transferSuiToMany: recipients.length !== amounts.length");
|
|
488
456
|
}
|
|
489
457
|
const coinObjects = coins.map((coin) => convertObjArg(this.tx, coin));
|
|
490
|
-
const { splitedCoins, mergedCoin } = this.splitMultiCoins(
|
|
491
|
-
|
|
492
|
-
amounts
|
|
493
|
-
);
|
|
494
|
-
const recipientObjects = recipients.map(
|
|
495
|
-
(recipient) => convertAddressArg(this.tx, recipient)
|
|
496
|
-
);
|
|
458
|
+
const { splitedCoins, mergedCoin } = this.splitMultiCoins(coinObjects, amounts);
|
|
459
|
+
const recipientObjects = recipients.map((recipient) => convertAddressArg(this.tx, recipient));
|
|
497
460
|
recipientObjects.forEach((address, index) => {
|
|
498
461
|
this.tx.transferObjects([splitedCoins[index]], address);
|
|
499
462
|
});
|
|
@@ -504,10 +467,7 @@ var SuiTx = class {
|
|
|
504
467
|
return this.transferCoinToMany(coins, sender, [recipient], [amount]);
|
|
505
468
|
}
|
|
506
469
|
stakeSui(amount, validatorAddr) {
|
|
507
|
-
const [stakeCoin] = this.tx.splitCoins(
|
|
508
|
-
this.tx.gas,
|
|
509
|
-
convertAmounts(this.tx, [amount])
|
|
510
|
-
);
|
|
470
|
+
const [stakeCoin] = this.tx.splitCoins(this.tx.gas, convertAmounts(this.tx, [amount]));
|
|
511
471
|
return this.tx.moveCall({
|
|
512
472
|
target: "0x3::sui_system::request_add_stake",
|
|
513
473
|
arguments: convertArgs(this.tx, [
|
|
@@ -687,9 +647,7 @@ var SuiInteractor = class {
|
|
|
687
647
|
return parsedObjects;
|
|
688
648
|
} catch (err) {
|
|
689
649
|
await delay(2e3);
|
|
690
|
-
console.warn(
|
|
691
|
-
`Failed to get objects with fullnode ${this.fullNodes[clientIdx]}: ${err}`
|
|
692
|
-
);
|
|
650
|
+
console.warn(`Failed to get objects with fullnode ${this.fullNodes[clientIdx]}: ${err}`);
|
|
693
651
|
}
|
|
694
652
|
}
|
|
695
653
|
throw new Error("Failed to get objects with all fullnodes");
|
|
@@ -793,9 +751,7 @@ var SuiInteractor = class {
|
|
|
793
751
|
const objectIds = suiObjects.map((obj) => obj.objectId);
|
|
794
752
|
const objects = await this.getObjects(objectIds);
|
|
795
753
|
for (const object of objects) {
|
|
796
|
-
const suiObject = suiObjects.find(
|
|
797
|
-
(obj) => obj.objectId === object?.objectId
|
|
798
|
-
);
|
|
754
|
+
const suiObject = suiObjects.find((obj) => obj.objectId === object?.objectId);
|
|
799
755
|
if (suiObject instanceof SuiSharedObject) {
|
|
800
756
|
if (object.owner && typeof object.owner === "object" && "Shared" in object.owner) {
|
|
801
757
|
suiObject.initialSharedVersion = object.owner.Shared.initial_shared_version;
|
|
@@ -952,41 +908,35 @@ var SuiContractFactory = class {
|
|
|
952
908
|
this.packageId = packageId || "";
|
|
953
909
|
this.metadata = metadata || void 0;
|
|
954
910
|
}
|
|
955
|
-
getFuncByModuleName(
|
|
956
|
-
Object.values(this.metadata).forEach(
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
Object.values(value2.parameters).forEach((values) => {
|
|
963
|
-
});
|
|
911
|
+
getFuncByModuleName(_moduleName) {
|
|
912
|
+
Object.values(this.metadata).forEach((value) => {
|
|
913
|
+
const data = value;
|
|
914
|
+
console.log(`moudle name: ${data.name}`);
|
|
915
|
+
Object.entries(data.exposedFunctions).forEach(([key, value2]) => {
|
|
916
|
+
console.log(` func name: ${key}`);
|
|
917
|
+
Object.values(value2.parameters).forEach((_values) => {
|
|
964
918
|
});
|
|
965
|
-
}
|
|
966
|
-
);
|
|
919
|
+
});
|
|
920
|
+
});
|
|
967
921
|
}
|
|
968
922
|
getAllFunc() {
|
|
969
|
-
Object.values(this.metadata).forEach(
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
console.log(` args: ${values}`);
|
|
978
|
-
});
|
|
923
|
+
Object.values(this.metadata).forEach((value) => {
|
|
924
|
+
const data = value;
|
|
925
|
+
console.log(`moudle name: ${data.name}`);
|
|
926
|
+
Object.entries(data.exposedFunctions).forEach(([key, value2]) => {
|
|
927
|
+
console.log(` func name: ${key}`);
|
|
928
|
+
console.log(` ${value2.parameters.length}`);
|
|
929
|
+
Object.values(value2.parameters).forEach((values) => {
|
|
930
|
+
console.log(` args: ${values}`);
|
|
979
931
|
});
|
|
980
|
-
}
|
|
981
|
-
);
|
|
932
|
+
});
|
|
933
|
+
});
|
|
982
934
|
}
|
|
983
935
|
getAllModule() {
|
|
984
|
-
Object.values(this.metadata).forEach(
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
}
|
|
989
|
-
);
|
|
936
|
+
Object.values(this.metadata).forEach((value, index) => {
|
|
937
|
+
const data = value;
|
|
938
|
+
console.log(`${index}. ${data.name}`);
|
|
939
|
+
});
|
|
990
940
|
}
|
|
991
941
|
// async call(arguments: ({
|
|
992
942
|
// kind: "Input";
|
|
@@ -1518,7 +1468,7 @@ var Dubhe = class {
|
|
|
1518
1468
|
__privateAdd(this, _bcs, (bcsmeta) => {
|
|
1519
1469
|
let loopFlag = false;
|
|
1520
1470
|
const bcsJson = {};
|
|
1521
|
-
Object.entries(bcsmeta.objectType.fields).forEach(([
|
|
1471
|
+
Object.entries(bcsmeta.objectType.fields).forEach(([_index, type]) => {
|
|
1522
1472
|
const objName = type.name;
|
|
1523
1473
|
const objType = type.type;
|
|
1524
1474
|
switch (typeof objType) {
|
|
@@ -1705,7 +1655,7 @@ var Dubhe = class {
|
|
|
1705
1655
|
const variantJson = {};
|
|
1706
1656
|
Object.entries(bcsmeta.objectType.variants).forEach(([name, type]) => {
|
|
1707
1657
|
if (type.length > 0) {
|
|
1708
|
-
Object.entries(type).forEach(([
|
|
1658
|
+
Object.entries(type).forEach(([_index, value]) => {
|
|
1709
1659
|
const objType = value.type;
|
|
1710
1660
|
const objName = value.name;
|
|
1711
1661
|
switch (typeof objType) {
|
|
@@ -1881,83 +1831,73 @@ var Dubhe = class {
|
|
|
1881
1831
|
let stillNeedFormat = true;
|
|
1882
1832
|
while (stillNeedFormat === true && loopNum <= maxLoopNum) {
|
|
1883
1833
|
let loopFlag = false;
|
|
1884
|
-
Object.values(metadata).forEach(
|
|
1885
|
-
|
|
1886
|
-
|
|
1887
|
-
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
|
|
1894
|
-
|
|
1895
|
-
const objectId = `${objMoudleId}::${enumName}`;
|
|
1896
|
-
const bcsmeta = {
|
|
1897
|
-
objectId,
|
|
1898
|
-
objectName: enumName,
|
|
1899
|
-
objectType: enumType
|
|
1900
|
-
};
|
|
1901
|
-
let bcsObj = __privateGet(this, _bcsenum).call(this, bcsmeta);
|
|
1902
|
-
if (bcsObj.loopFlag === true) {
|
|
1903
|
-
loopFlag = bcsObj.loopFlag;
|
|
1904
|
-
}
|
|
1905
|
-
if (__privateGet(this, _object)[objectId] === void 0) {
|
|
1906
|
-
__privateGet(this, _object)[objectId] = bcsObj.bcs;
|
|
1907
|
-
__privateGet(this, _object)[`vector<${objectId}>`] = import_bcs3.bcs.vector(bcsObj.bcs);
|
|
1908
|
-
__privateGet(this, _object)[`vector<vector<${objectId}>>`] = import_bcs3.bcs.vector(
|
|
1909
|
-
import_bcs3.bcs.vector(bcsObj.bcs)
|
|
1910
|
-
);
|
|
1911
|
-
__privateGet(this, _object)[`0x1::option::Option<${objectId}>`] = import_bcs3.bcs.option(
|
|
1912
|
-
bcsObj.bcs
|
|
1913
|
-
);
|
|
1914
|
-
}
|
|
1915
|
-
});
|
|
1916
|
-
}
|
|
1917
|
-
Object.entries(data.structs).forEach(([objectName, objectType]) => {
|
|
1918
|
-
const objectId = `${objMoudleId}::${objectName}`;
|
|
1834
|
+
Object.values(metadata).forEach((moudlevalue) => {
|
|
1835
|
+
const data = moudlevalue;
|
|
1836
|
+
const moduleName = data.name;
|
|
1837
|
+
const itemModuleName = moduleName;
|
|
1838
|
+
if (itemModuleName.endsWith("_genesis")) {
|
|
1839
|
+
this.projectName = itemModuleName.replace("_genesis", "");
|
|
1840
|
+
}
|
|
1841
|
+
const objMoudleId = `${this.packageId}::${moduleName}`;
|
|
1842
|
+
if (data.enums) {
|
|
1843
|
+
Object.entries(data.enums).forEach(([enumName, enumType]) => {
|
|
1844
|
+
const objectId = `${objMoudleId}::${enumName}`;
|
|
1919
1845
|
const bcsmeta = {
|
|
1920
1846
|
objectId,
|
|
1921
|
-
objectName,
|
|
1922
|
-
objectType
|
|
1847
|
+
objectName: enumName,
|
|
1848
|
+
objectType: enumType
|
|
1923
1849
|
};
|
|
1924
|
-
let bcsObj = __privateGet(this,
|
|
1850
|
+
let bcsObj = __privateGet(this, _bcsenum).call(this, bcsmeta);
|
|
1925
1851
|
if (bcsObj.loopFlag === true) {
|
|
1926
1852
|
loopFlag = bcsObj.loopFlag;
|
|
1927
1853
|
}
|
|
1928
|
-
__privateGet(this, _object)[objectId]
|
|
1929
|
-
|
|
1930
|
-
|
|
1931
|
-
bcsObj.bcs
|
|
1932
|
-
|
|
1933
|
-
});
|
|
1934
|
-
Object.entries(data.exposedFunctions).forEach(
|
|
1935
|
-
([funcName, funcvalue]) => {
|
|
1936
|
-
const meta = funcvalue;
|
|
1937
|
-
meta.moduleName = moduleName;
|
|
1938
|
-
meta.funcName = funcName;
|
|
1939
|
-
if (isUndefined(__privateGet(this, _query)[moduleName])) {
|
|
1940
|
-
__privateGet(this, _query)[moduleName] = {};
|
|
1941
|
-
}
|
|
1942
|
-
if (isUndefined(__privateGet(this, _query)[moduleName][funcName])) {
|
|
1943
|
-
__privateGet(this, _query)[moduleName][funcName] = createQuery(
|
|
1944
|
-
meta,
|
|
1945
|
-
(tx, p, typeArguments, isRaw) => __privateGet(this, _read).call(this, meta, tx, p, typeArguments, isRaw)
|
|
1946
|
-
);
|
|
1947
|
-
}
|
|
1948
|
-
if (isUndefined(__privateGet(this, _tx)[moduleName])) {
|
|
1949
|
-
__privateGet(this, _tx)[moduleName] = {};
|
|
1950
|
-
}
|
|
1951
|
-
if (isUndefined(__privateGet(this, _tx)[moduleName][funcName])) {
|
|
1952
|
-
__privateGet(this, _tx)[moduleName][funcName] = createTx(
|
|
1953
|
-
meta,
|
|
1954
|
-
(tx, p, typeArguments, isRaw, onSuccess, onError) => __privateGet(this, _exec).call(this, meta, tx, p, typeArguments, isRaw, onSuccess, onError)
|
|
1955
|
-
);
|
|
1956
|
-
}
|
|
1854
|
+
if (__privateGet(this, _object)[objectId] === void 0) {
|
|
1855
|
+
__privateGet(this, _object)[objectId] = bcsObj.bcs;
|
|
1856
|
+
__privateGet(this, _object)[`vector<${objectId}>`] = import_bcs3.bcs.vector(bcsObj.bcs);
|
|
1857
|
+
__privateGet(this, _object)[`vector<vector<${objectId}>>`] = import_bcs3.bcs.vector(import_bcs3.bcs.vector(bcsObj.bcs));
|
|
1858
|
+
__privateGet(this, _object)[`0x1::option::Option<${objectId}>`] = import_bcs3.bcs.option(bcsObj.bcs);
|
|
1957
1859
|
}
|
|
1958
|
-
);
|
|
1860
|
+
});
|
|
1959
1861
|
}
|
|
1960
|
-
|
|
1862
|
+
Object.entries(data.structs).forEach(([objectName, objectType]) => {
|
|
1863
|
+
const objectId = `${objMoudleId}::${objectName}`;
|
|
1864
|
+
const bcsmeta = {
|
|
1865
|
+
objectId,
|
|
1866
|
+
objectName,
|
|
1867
|
+
objectType
|
|
1868
|
+
};
|
|
1869
|
+
let bcsObj = __privateGet(this, _bcs).call(this, bcsmeta);
|
|
1870
|
+
if (bcsObj.loopFlag === true) {
|
|
1871
|
+
loopFlag = bcsObj.loopFlag;
|
|
1872
|
+
}
|
|
1873
|
+
__privateGet(this, _object)[objectId] = bcsObj.bcs;
|
|
1874
|
+
__privateGet(this, _object)[`vector<${objectId}>`] = import_bcs3.bcs.vector(bcsObj.bcs);
|
|
1875
|
+
__privateGet(this, _object)[`0x1::option::Option<${objectId}>`] = import_bcs3.bcs.option(bcsObj.bcs);
|
|
1876
|
+
});
|
|
1877
|
+
Object.entries(data.exposedFunctions).forEach(([funcName, funcvalue]) => {
|
|
1878
|
+
const meta = funcvalue;
|
|
1879
|
+
meta.moduleName = moduleName;
|
|
1880
|
+
meta.funcName = funcName;
|
|
1881
|
+
if (isUndefined(__privateGet(this, _query)[moduleName])) {
|
|
1882
|
+
__privateGet(this, _query)[moduleName] = {};
|
|
1883
|
+
}
|
|
1884
|
+
if (isUndefined(__privateGet(this, _query)[moduleName][funcName])) {
|
|
1885
|
+
__privateGet(this, _query)[moduleName][funcName] = createQuery(
|
|
1886
|
+
meta,
|
|
1887
|
+
(tx, p, typeArguments, isRaw) => __privateGet(this, _read).call(this, meta, tx, p, typeArguments, isRaw)
|
|
1888
|
+
);
|
|
1889
|
+
}
|
|
1890
|
+
if (isUndefined(__privateGet(this, _tx)[moduleName])) {
|
|
1891
|
+
__privateGet(this, _tx)[moduleName] = {};
|
|
1892
|
+
}
|
|
1893
|
+
if (isUndefined(__privateGet(this, _tx)[moduleName][funcName])) {
|
|
1894
|
+
__privateGet(this, _tx)[moduleName][funcName] = createTx(
|
|
1895
|
+
meta,
|
|
1896
|
+
(tx, p, typeArguments, isRaw, onSuccess, onError) => __privateGet(this, _exec).call(this, meta, tx, p, typeArguments, isRaw, onSuccess, onError)
|
|
1897
|
+
);
|
|
1898
|
+
}
|
|
1899
|
+
});
|
|
1900
|
+
});
|
|
1961
1901
|
stillNeedFormat = loopFlag;
|
|
1962
1902
|
loopNum++;
|
|
1963
1903
|
}
|
|
@@ -1984,9 +1924,7 @@ var Dubhe = class {
|
|
|
1984
1924
|
let baseValue = res[0];
|
|
1985
1925
|
let baseType = res[1];
|
|
1986
1926
|
const value = Uint8Array.from(baseValue);
|
|
1987
|
-
const storageValueMatch = baseType.match(
|
|
1988
|
-
/^.*::storage_value::StorageValue<(.+)>$/
|
|
1989
|
-
);
|
|
1927
|
+
const storageValueMatch = baseType.match(/^.*::storage_value::StorageValue<(.+)>$/);
|
|
1990
1928
|
if (storageValueMatch) {
|
|
1991
1929
|
const innerType = storageValueMatch[1];
|
|
1992
1930
|
if (__privateGet(this, _object)[innerType]) {
|
|
@@ -2001,9 +1939,7 @@ var Dubhe = class {
|
|
|
2001
1939
|
continue;
|
|
2002
1940
|
}
|
|
2003
1941
|
}
|
|
2004
|
-
const storageMapMatch = baseType.match(
|
|
2005
|
-
/^.*::storage_map::StorageMap<(.+)>$/
|
|
2006
|
-
);
|
|
1942
|
+
const storageMapMatch = baseType.match(/^.*::storage_map::StorageMap<(.+)>$/);
|
|
2007
1943
|
if (storageMapMatch) {
|
|
2008
1944
|
const innerType = storageMapMatch[1];
|
|
2009
1945
|
const [keyType, valueType] = innerType.split(",").map((type) => type.trim());
|
|
@@ -2053,24 +1989,18 @@ var Dubhe = class {
|
|
|
2053
1989
|
continue;
|
|
2054
1990
|
}
|
|
2055
1991
|
}
|
|
2056
|
-
console.log(
|
|
2057
|
-
"\n\x1B[41m\x1B[37m ERROR \x1B[0m \x1B[31mUnsupported Type\x1B[0m"
|
|
2058
|
-
);
|
|
1992
|
+
console.log("\n\x1B[41m\x1B[37m ERROR \x1B[0m \x1B[31mUnsupported Type\x1B[0m");
|
|
2059
1993
|
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");
|
|
2060
1994
|
console.log(`\x1B[95m\u2022\x1B[0m Type: \x1B[33m"${baseType}"\x1B[0m`);
|
|
2061
1995
|
if (genericMatch) {
|
|
2062
|
-
console.log(
|
|
2063
|
-
`\x1B[95m\u2022\x1B[0m Generic Base Type: \x1B[33m"${genericMatch[1]}<T>"\x1B[0m`
|
|
2064
|
-
);
|
|
1996
|
+
console.log(`\x1B[95m\u2022\x1B[0m Generic Base Type: \x1B[33m"${genericMatch[1]}<T>"\x1B[0m`);
|
|
2065
1997
|
}
|
|
2066
1998
|
console.log("\x1B[95m\n\u2728 Available Types:\x1B[0m");
|
|
2067
1999
|
Object.keys(__privateGet(this, _object)).forEach((type) => {
|
|
2068
2000
|
console.log(` \x1B[36m\u25C6\x1B[0m ${type}`);
|
|
2069
2001
|
});
|
|
2070
2002
|
console.log("\n\x1B[34m\u{1F4A1} How to Add Custom Type:\x1B[0m");
|
|
2071
|
-
console.log(
|
|
2072
|
-
` You can add custom type by extending the #object map in your code:`
|
|
2073
|
-
);
|
|
2003
|
+
console.log(` You can add custom type by extending the #object map in your code:`);
|
|
2074
2004
|
console.log(
|
|
2075
2005
|
` \x1B[32mdubhe.object["${baseType}"] = bcs.struct("YourTypeName", {
|
|
2076
2006
|
field1: bcs.string(),
|
|
@@ -2122,12 +2052,8 @@ var Dubhe = class {
|
|
|
2122
2052
|
const schemaObject = tx.object(objectId);
|
|
2123
2053
|
const storageValueMatch = storageType.match(/^StorageValue<(.+)>$/);
|
|
2124
2054
|
const storageMapMatch = storageType.match(/^StorageMap<(.+),\s*(.+)>$/);
|
|
2125
|
-
const storageDoubleMapMatch = storageType.match(
|
|
2126
|
-
|
|
2127
|
-
);
|
|
2128
|
-
let processedParams = [
|
|
2129
|
-
schemaObject
|
|
2130
|
-
];
|
|
2055
|
+
const storageDoubleMapMatch = storageType.match(/^StorageDoubleMap<(.+),\s*(.+),\s*(.+)>$/);
|
|
2056
|
+
let processedParams = [schemaObject];
|
|
2131
2057
|
if (storageValueMatch) {
|
|
2132
2058
|
if (params.length > 0) {
|
|
2133
2059
|
console.warn(
|
|
@@ -2263,9 +2189,7 @@ var Dubhe = class {
|
|
|
2263
2189
|
}
|
|
2264
2190
|
} else {
|
|
2265
2191
|
if (onError) {
|
|
2266
|
-
await onError(
|
|
2267
|
-
new Error(`Transaction failed: ${result.effects?.status.error}`)
|
|
2268
|
-
);
|
|
2192
|
+
await onError(new Error(`Transaction failed: ${result.effects?.status.error}`));
|
|
2269
2193
|
}
|
|
2270
2194
|
}
|
|
2271
2195
|
return result;
|
|
@@ -2315,11 +2239,7 @@ var Dubhe = class {
|
|
|
2315
2239
|
const tx = new SuiTx();
|
|
2316
2240
|
const owner = this.accountManager.getAddress(derivePathParams);
|
|
2317
2241
|
const totalAmount = amounts.reduce((a, b) => a + b, 0);
|
|
2318
|
-
const coins = await this.suiInteractor.selectCoins(
|
|
2319
|
-
owner,
|
|
2320
|
-
totalAmount,
|
|
2321
|
-
coinType
|
|
2322
|
-
);
|
|
2242
|
+
const coins = await this.suiInteractor.selectCoins(owner, totalAmount, coinType);
|
|
2323
2243
|
tx.transferCoinToMany(
|
|
2324
2244
|
coins.map((c) => c.objectId),
|
|
2325
2245
|
owner,
|
|
@@ -2329,12 +2249,7 @@ var Dubhe = class {
|
|
|
2329
2249
|
return this.signAndSendTxn({ tx, derivePathParams });
|
|
2330
2250
|
}
|
|
2331
2251
|
async transferCoin(recipient, amount, coinType, derivePathParams) {
|
|
2332
|
-
return this.transferCoinToMany(
|
|
2333
|
-
[recipient],
|
|
2334
|
-
[amount],
|
|
2335
|
-
coinType,
|
|
2336
|
-
derivePathParams
|
|
2337
|
-
);
|
|
2252
|
+
return this.transferCoinToMany([recipient], [amount], coinType, derivePathParams);
|
|
2338
2253
|
}
|
|
2339
2254
|
async transferObjects(objects, recipient, derivePathParams) {
|
|
2340
2255
|
const tx = new SuiTx();
|
|
@@ -2342,12 +2257,7 @@ var Dubhe = class {
|
|
|
2342
2257
|
return this.signAndSendTxn({ tx, derivePathParams });
|
|
2343
2258
|
}
|
|
2344
2259
|
async moveCall(callParams) {
|
|
2345
|
-
const {
|
|
2346
|
-
target,
|
|
2347
|
-
arguments: args = [],
|
|
2348
|
-
typeArguments = [],
|
|
2349
|
-
derivePathParams
|
|
2350
|
-
} = callParams;
|
|
2260
|
+
const { target, arguments: args = [], typeArguments = [], derivePathParams } = callParams;
|
|
2351
2261
|
const tx = new SuiTx();
|
|
2352
2262
|
tx.moveCall(target, args, typeArguments);
|
|
2353
2263
|
return this.signAndSendTxn({ tx, derivePathParams });
|
|
@@ -2394,11 +2304,7 @@ var Dubhe = class {
|
|
|
2394
2304
|
});
|
|
2395
2305
|
}
|
|
2396
2306
|
async getOwnedObjects(owner, cursor, limit) {
|
|
2397
|
-
const ownedObjects = await this.suiInteractor.getOwnedObjects(
|
|
2398
|
-
owner,
|
|
2399
|
-
cursor,
|
|
2400
|
-
limit
|
|
2401
|
-
);
|
|
2307
|
+
const ownedObjects = await this.suiInteractor.getOwnedObjects(owner, cursor, limit);
|
|
2402
2308
|
const ownedObjectsRes = [];
|
|
2403
2309
|
for (const object of ownedObjects.data) {
|
|
2404
2310
|
const objectDetail = await this.getObject(object.data.objectId);
|
|
@@ -2490,18 +2396,14 @@ processKeyParameter_fn = function(tx, keyType, value) {
|
|
|
2490
2396
|
if (keyType.includes("::")) {
|
|
2491
2397
|
return tx.object(value);
|
|
2492
2398
|
}
|
|
2493
|
-
console.log(
|
|
2494
|
-
"\n\x1B[41m\x1B[37m ERROR \x1B[0m \x1B[31mUnsupported Key Type\x1B[0m"
|
|
2495
|
-
);
|
|
2399
|
+
console.log("\n\x1B[41m\x1B[37m ERROR \x1B[0m \x1B[31mUnsupported Key Type\x1B[0m");
|
|
2496
2400
|
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");
|
|
2497
2401
|
console.log(`\x1B[95m\u2022\x1B[0m Type: \x1B[33m"${keyType}"\x1B[0m`);
|
|
2498
2402
|
console.log("\x1B[95m\u2022\x1B[0m Supported Types:\x1B[0m");
|
|
2499
2403
|
console.log(" \x1B[36m\u25C6\x1B[0m u8, u16, u32, u64, u128, u256");
|
|
2500
2404
|
console.log(" \x1B[36m\u25C6\x1B[0m bool");
|
|
2501
2405
|
console.log(" \x1B[36m\u25C6\x1B[0m address");
|
|
2502
|
-
console.log(
|
|
2503
|
-
" \x1B[36m\u25C6\x1B[0m object (format: package::module::type)"
|
|
2504
|
-
);
|
|
2406
|
+
console.log(" \x1B[36m\u25C6\x1B[0m object (format: package::module::type)");
|
|
2505
2407
|
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");
|
|
2506
2408
|
throw new Error(`Unsupported key type: ${keyType}`);
|
|
2507
2409
|
}
|