@0xobelisk/sui-client 1.2.0-pre.71 → 1.2.0-pre.73
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 +156 -215
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +157 -219
- 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 +200 -253
- 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) {
|
|
@@ -1633,7 +1583,7 @@ var Dubhe = class {
|
|
|
1633
1583
|
for (let i = 0; i < vectorDepth; i++) {
|
|
1634
1584
|
innerType = innerType.Vector;
|
|
1635
1585
|
}
|
|
1636
|
-
if ("Struct" in innerType) {
|
|
1586
|
+
if (typeof innerType === "object" && innerType !== null && "Struct" in innerType) {
|
|
1637
1587
|
const structType2 = innerType.Struct;
|
|
1638
1588
|
const structId = `${structType2.address}::${structType2.module}::${structType2.name}`;
|
|
1639
1589
|
let bcsType = __privateGet(this, _object)[structId];
|
|
@@ -1648,6 +1598,45 @@ var Dubhe = class {
|
|
|
1648
1598
|
bcsJson[objName] = baseType;
|
|
1649
1599
|
return;
|
|
1650
1600
|
}
|
|
1601
|
+
if (typeof innerType === "string") {
|
|
1602
|
+
let baseType;
|
|
1603
|
+
switch (innerType) {
|
|
1604
|
+
case "U8":
|
|
1605
|
+
baseType = import_bcs3.bcs.u8();
|
|
1606
|
+
break;
|
|
1607
|
+
case "U16":
|
|
1608
|
+
baseType = import_bcs3.bcs.u16();
|
|
1609
|
+
break;
|
|
1610
|
+
case "U32":
|
|
1611
|
+
baseType = import_bcs3.bcs.u32();
|
|
1612
|
+
break;
|
|
1613
|
+
case "U64":
|
|
1614
|
+
baseType = import_bcs3.bcs.u64();
|
|
1615
|
+
break;
|
|
1616
|
+
case "U128":
|
|
1617
|
+
baseType = import_bcs3.bcs.u128();
|
|
1618
|
+
break;
|
|
1619
|
+
case "U256":
|
|
1620
|
+
baseType = import_bcs3.bcs.u256();
|
|
1621
|
+
break;
|
|
1622
|
+
case "Bool":
|
|
1623
|
+
baseType = import_bcs3.bcs.bool();
|
|
1624
|
+
break;
|
|
1625
|
+
case "Address":
|
|
1626
|
+
baseType = import_bcs3.bcs.bytes(32).transform({
|
|
1627
|
+
input: (val) => (0, import_bcs3.fromHEX)(val),
|
|
1628
|
+
output: (val) => (0, import_bcs3.toHEX)(val)
|
|
1629
|
+
});
|
|
1630
|
+
break;
|
|
1631
|
+
default:
|
|
1632
|
+
return;
|
|
1633
|
+
}
|
|
1634
|
+
for (let i = 0; i <= vectorDepth; i++) {
|
|
1635
|
+
baseType = import_bcs3.bcs.vector(baseType);
|
|
1636
|
+
}
|
|
1637
|
+
bcsJson[objName] = baseType;
|
|
1638
|
+
return;
|
|
1639
|
+
}
|
|
1651
1640
|
}
|
|
1652
1641
|
return;
|
|
1653
1642
|
case "TypeParameter":
|
|
@@ -1705,7 +1694,7 @@ var Dubhe = class {
|
|
|
1705
1694
|
const variantJson = {};
|
|
1706
1695
|
Object.entries(bcsmeta.objectType.variants).forEach(([name, type]) => {
|
|
1707
1696
|
if (type.length > 0) {
|
|
1708
|
-
Object.entries(type).forEach(([
|
|
1697
|
+
Object.entries(type).forEach(([_index, value]) => {
|
|
1709
1698
|
const objType = value.type;
|
|
1710
1699
|
const objName = value.name;
|
|
1711
1700
|
switch (typeof objType) {
|
|
@@ -1881,83 +1870,73 @@ var Dubhe = class {
|
|
|
1881
1870
|
let stillNeedFormat = true;
|
|
1882
1871
|
while (stillNeedFormat === true && loopNum <= maxLoopNum) {
|
|
1883
1872
|
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}`;
|
|
1873
|
+
Object.values(metadata).forEach((moudlevalue) => {
|
|
1874
|
+
const data = moudlevalue;
|
|
1875
|
+
const moduleName = data.name;
|
|
1876
|
+
const itemModuleName = moduleName;
|
|
1877
|
+
if (itemModuleName.endsWith("_genesis")) {
|
|
1878
|
+
this.projectName = itemModuleName.replace("_genesis", "");
|
|
1879
|
+
}
|
|
1880
|
+
const objMoudleId = `${this.packageId}::${moduleName}`;
|
|
1881
|
+
if (data.enums) {
|
|
1882
|
+
Object.entries(data.enums).forEach(([enumName, enumType]) => {
|
|
1883
|
+
const objectId = `${objMoudleId}::${enumName}`;
|
|
1919
1884
|
const bcsmeta = {
|
|
1920
1885
|
objectId,
|
|
1921
|
-
objectName,
|
|
1922
|
-
objectType
|
|
1886
|
+
objectName: enumName,
|
|
1887
|
+
objectType: enumType
|
|
1923
1888
|
};
|
|
1924
|
-
let bcsObj = __privateGet(this,
|
|
1889
|
+
let bcsObj = __privateGet(this, _bcsenum).call(this, bcsmeta);
|
|
1925
1890
|
if (bcsObj.loopFlag === true) {
|
|
1926
1891
|
loopFlag = bcsObj.loopFlag;
|
|
1927
1892
|
}
|
|
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
|
-
}
|
|
1893
|
+
if (__privateGet(this, _object)[objectId] === void 0) {
|
|
1894
|
+
__privateGet(this, _object)[objectId] = bcsObj.bcs;
|
|
1895
|
+
__privateGet(this, _object)[`vector<${objectId}>`] = import_bcs3.bcs.vector(bcsObj.bcs);
|
|
1896
|
+
__privateGet(this, _object)[`vector<vector<${objectId}>>`] = import_bcs3.bcs.vector(import_bcs3.bcs.vector(bcsObj.bcs));
|
|
1897
|
+
__privateGet(this, _object)[`0x1::option::Option<${objectId}>`] = import_bcs3.bcs.option(bcsObj.bcs);
|
|
1957
1898
|
}
|
|
1958
|
-
);
|
|
1899
|
+
});
|
|
1959
1900
|
}
|
|
1960
|
-
|
|
1901
|
+
Object.entries(data.structs).forEach(([objectName, objectType]) => {
|
|
1902
|
+
const objectId = `${objMoudleId}::${objectName}`;
|
|
1903
|
+
const bcsmeta = {
|
|
1904
|
+
objectId,
|
|
1905
|
+
objectName,
|
|
1906
|
+
objectType
|
|
1907
|
+
};
|
|
1908
|
+
let bcsObj = __privateGet(this, _bcs).call(this, bcsmeta);
|
|
1909
|
+
if (bcsObj.loopFlag === true) {
|
|
1910
|
+
loopFlag = bcsObj.loopFlag;
|
|
1911
|
+
}
|
|
1912
|
+
__privateGet(this, _object)[objectId] = bcsObj.bcs;
|
|
1913
|
+
__privateGet(this, _object)[`vector<${objectId}>`] = import_bcs3.bcs.vector(bcsObj.bcs);
|
|
1914
|
+
__privateGet(this, _object)[`0x1::option::Option<${objectId}>`] = import_bcs3.bcs.option(bcsObj.bcs);
|
|
1915
|
+
});
|
|
1916
|
+
Object.entries(data.exposedFunctions).forEach(([funcName, funcvalue]) => {
|
|
1917
|
+
const meta = funcvalue;
|
|
1918
|
+
meta.moduleName = moduleName;
|
|
1919
|
+
meta.funcName = funcName;
|
|
1920
|
+
if (isUndefined(__privateGet(this, _query)[moduleName])) {
|
|
1921
|
+
__privateGet(this, _query)[moduleName] = {};
|
|
1922
|
+
}
|
|
1923
|
+
if (isUndefined(__privateGet(this, _query)[moduleName][funcName])) {
|
|
1924
|
+
__privateGet(this, _query)[moduleName][funcName] = createQuery(
|
|
1925
|
+
meta,
|
|
1926
|
+
(tx, p, typeArguments, isRaw) => __privateGet(this, _read).call(this, meta, tx, p, typeArguments, isRaw)
|
|
1927
|
+
);
|
|
1928
|
+
}
|
|
1929
|
+
if (isUndefined(__privateGet(this, _tx)[moduleName])) {
|
|
1930
|
+
__privateGet(this, _tx)[moduleName] = {};
|
|
1931
|
+
}
|
|
1932
|
+
if (isUndefined(__privateGet(this, _tx)[moduleName][funcName])) {
|
|
1933
|
+
__privateGet(this, _tx)[moduleName][funcName] = createTx(
|
|
1934
|
+
meta,
|
|
1935
|
+
(tx, p, typeArguments, isRaw, onSuccess, onError) => __privateGet(this, _exec).call(this, meta, tx, p, typeArguments, isRaw, onSuccess, onError)
|
|
1936
|
+
);
|
|
1937
|
+
}
|
|
1938
|
+
});
|
|
1939
|
+
});
|
|
1961
1940
|
stillNeedFormat = loopFlag;
|
|
1962
1941
|
loopNum++;
|
|
1963
1942
|
}
|
|
@@ -1984,9 +1963,7 @@ var Dubhe = class {
|
|
|
1984
1963
|
let baseValue = res[0];
|
|
1985
1964
|
let baseType = res[1];
|
|
1986
1965
|
const value = Uint8Array.from(baseValue);
|
|
1987
|
-
const storageValueMatch = baseType.match(
|
|
1988
|
-
/^.*::storage_value::StorageValue<(.+)>$/
|
|
1989
|
-
);
|
|
1966
|
+
const storageValueMatch = baseType.match(/^.*::storage_value::StorageValue<(.+)>$/);
|
|
1990
1967
|
if (storageValueMatch) {
|
|
1991
1968
|
const innerType = storageValueMatch[1];
|
|
1992
1969
|
if (__privateGet(this, _object)[innerType]) {
|
|
@@ -2001,9 +1978,7 @@ var Dubhe = class {
|
|
|
2001
1978
|
continue;
|
|
2002
1979
|
}
|
|
2003
1980
|
}
|
|
2004
|
-
const storageMapMatch = baseType.match(
|
|
2005
|
-
/^.*::storage_map::StorageMap<(.+)>$/
|
|
2006
|
-
);
|
|
1981
|
+
const storageMapMatch = baseType.match(/^.*::storage_map::StorageMap<(.+)>$/);
|
|
2007
1982
|
if (storageMapMatch) {
|
|
2008
1983
|
const innerType = storageMapMatch[1];
|
|
2009
1984
|
const [keyType, valueType] = innerType.split(",").map((type) => type.trim());
|
|
@@ -2053,24 +2028,18 @@ var Dubhe = class {
|
|
|
2053
2028
|
continue;
|
|
2054
2029
|
}
|
|
2055
2030
|
}
|
|
2056
|
-
console.log(
|
|
2057
|
-
"\n\x1B[41m\x1B[37m ERROR \x1B[0m \x1B[31mUnsupported Type\x1B[0m"
|
|
2058
|
-
);
|
|
2031
|
+
console.log("\n\x1B[41m\x1B[37m ERROR \x1B[0m \x1B[31mUnsupported Type\x1B[0m");
|
|
2059
2032
|
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
2033
|
console.log(`\x1B[95m\u2022\x1B[0m Type: \x1B[33m"${baseType}"\x1B[0m`);
|
|
2061
2034
|
if (genericMatch) {
|
|
2062
|
-
console.log(
|
|
2063
|
-
`\x1B[95m\u2022\x1B[0m Generic Base Type: \x1B[33m"${genericMatch[1]}<T>"\x1B[0m`
|
|
2064
|
-
);
|
|
2035
|
+
console.log(`\x1B[95m\u2022\x1B[0m Generic Base Type: \x1B[33m"${genericMatch[1]}<T>"\x1B[0m`);
|
|
2065
2036
|
}
|
|
2066
2037
|
console.log("\x1B[95m\n\u2728 Available Types:\x1B[0m");
|
|
2067
2038
|
Object.keys(__privateGet(this, _object)).forEach((type) => {
|
|
2068
2039
|
console.log(` \x1B[36m\u25C6\x1B[0m ${type}`);
|
|
2069
2040
|
});
|
|
2070
2041
|
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
|
-
);
|
|
2042
|
+
console.log(` You can add custom type by extending the #object map in your code:`);
|
|
2074
2043
|
console.log(
|
|
2075
2044
|
` \x1B[32mdubhe.object["${baseType}"] = bcs.struct("YourTypeName", {
|
|
2076
2045
|
field1: bcs.string(),
|
|
@@ -2122,12 +2091,8 @@ var Dubhe = class {
|
|
|
2122
2091
|
const schemaObject = tx.object(objectId);
|
|
2123
2092
|
const storageValueMatch = storageType.match(/^StorageValue<(.+)>$/);
|
|
2124
2093
|
const storageMapMatch = storageType.match(/^StorageMap<(.+),\s*(.+)>$/);
|
|
2125
|
-
const storageDoubleMapMatch = storageType.match(
|
|
2126
|
-
|
|
2127
|
-
);
|
|
2128
|
-
let processedParams = [
|
|
2129
|
-
schemaObject
|
|
2130
|
-
];
|
|
2094
|
+
const storageDoubleMapMatch = storageType.match(/^StorageDoubleMap<(.+),\s*(.+),\s*(.+)>$/);
|
|
2095
|
+
let processedParams = [schemaObject];
|
|
2131
2096
|
if (storageValueMatch) {
|
|
2132
2097
|
if (params.length > 0) {
|
|
2133
2098
|
console.warn(
|
|
@@ -2263,9 +2228,7 @@ var Dubhe = class {
|
|
|
2263
2228
|
}
|
|
2264
2229
|
} else {
|
|
2265
2230
|
if (onError) {
|
|
2266
|
-
await onError(
|
|
2267
|
-
new Error(`Transaction failed: ${result.effects?.status.error}`)
|
|
2268
|
-
);
|
|
2231
|
+
await onError(new Error(`Transaction failed: ${result.effects?.status.error}`));
|
|
2269
2232
|
}
|
|
2270
2233
|
}
|
|
2271
2234
|
return result;
|
|
@@ -2315,11 +2278,7 @@ var Dubhe = class {
|
|
|
2315
2278
|
const tx = new SuiTx();
|
|
2316
2279
|
const owner = this.accountManager.getAddress(derivePathParams);
|
|
2317
2280
|
const totalAmount = amounts.reduce((a, b) => a + b, 0);
|
|
2318
|
-
const coins = await this.suiInteractor.selectCoins(
|
|
2319
|
-
owner,
|
|
2320
|
-
totalAmount,
|
|
2321
|
-
coinType
|
|
2322
|
-
);
|
|
2281
|
+
const coins = await this.suiInteractor.selectCoins(owner, totalAmount, coinType);
|
|
2323
2282
|
tx.transferCoinToMany(
|
|
2324
2283
|
coins.map((c) => c.objectId),
|
|
2325
2284
|
owner,
|
|
@@ -2329,12 +2288,7 @@ var Dubhe = class {
|
|
|
2329
2288
|
return this.signAndSendTxn({ tx, derivePathParams });
|
|
2330
2289
|
}
|
|
2331
2290
|
async transferCoin(recipient, amount, coinType, derivePathParams) {
|
|
2332
|
-
return this.transferCoinToMany(
|
|
2333
|
-
[recipient],
|
|
2334
|
-
[amount],
|
|
2335
|
-
coinType,
|
|
2336
|
-
derivePathParams
|
|
2337
|
-
);
|
|
2291
|
+
return this.transferCoinToMany([recipient], [amount], coinType, derivePathParams);
|
|
2338
2292
|
}
|
|
2339
2293
|
async transferObjects(objects, recipient, derivePathParams) {
|
|
2340
2294
|
const tx = new SuiTx();
|
|
@@ -2342,12 +2296,7 @@ var Dubhe = class {
|
|
|
2342
2296
|
return this.signAndSendTxn({ tx, derivePathParams });
|
|
2343
2297
|
}
|
|
2344
2298
|
async moveCall(callParams) {
|
|
2345
|
-
const {
|
|
2346
|
-
target,
|
|
2347
|
-
arguments: args = [],
|
|
2348
|
-
typeArguments = [],
|
|
2349
|
-
derivePathParams
|
|
2350
|
-
} = callParams;
|
|
2299
|
+
const { target, arguments: args = [], typeArguments = [], derivePathParams } = callParams;
|
|
2351
2300
|
const tx = new SuiTx();
|
|
2352
2301
|
tx.moveCall(target, args, typeArguments);
|
|
2353
2302
|
return this.signAndSendTxn({ tx, derivePathParams });
|
|
@@ -2394,11 +2343,7 @@ var Dubhe = class {
|
|
|
2394
2343
|
});
|
|
2395
2344
|
}
|
|
2396
2345
|
async getOwnedObjects(owner, cursor, limit) {
|
|
2397
|
-
const ownedObjects = await this.suiInteractor.getOwnedObjects(
|
|
2398
|
-
owner,
|
|
2399
|
-
cursor,
|
|
2400
|
-
limit
|
|
2401
|
-
);
|
|
2346
|
+
const ownedObjects = await this.suiInteractor.getOwnedObjects(owner, cursor, limit);
|
|
2402
2347
|
const ownedObjectsRes = [];
|
|
2403
2348
|
for (const object of ownedObjects.data) {
|
|
2404
2349
|
const objectDetail = await this.getObject(object.data.objectId);
|
|
@@ -2490,18 +2435,14 @@ processKeyParameter_fn = function(tx, keyType, value) {
|
|
|
2490
2435
|
if (keyType.includes("::")) {
|
|
2491
2436
|
return tx.object(value);
|
|
2492
2437
|
}
|
|
2493
|
-
console.log(
|
|
2494
|
-
"\n\x1B[41m\x1B[37m ERROR \x1B[0m \x1B[31mUnsupported Key Type\x1B[0m"
|
|
2495
|
-
);
|
|
2438
|
+
console.log("\n\x1B[41m\x1B[37m ERROR \x1B[0m \x1B[31mUnsupported Key Type\x1B[0m");
|
|
2496
2439
|
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
2440
|
console.log(`\x1B[95m\u2022\x1B[0m Type: \x1B[33m"${keyType}"\x1B[0m`);
|
|
2498
2441
|
console.log("\x1B[95m\u2022\x1B[0m Supported Types:\x1B[0m");
|
|
2499
2442
|
console.log(" \x1B[36m\u25C6\x1B[0m u8, u16, u32, u64, u128, u256");
|
|
2500
2443
|
console.log(" \x1B[36m\u25C6\x1B[0m bool");
|
|
2501
2444
|
console.log(" \x1B[36m\u25C6\x1B[0m address");
|
|
2502
|
-
console.log(
|
|
2503
|
-
" \x1B[36m\u25C6\x1B[0m object (format: package::module::type)"
|
|
2504
|
-
);
|
|
2445
|
+
console.log(" \x1B[36m\u25C6\x1B[0m object (format: package::module::type)");
|
|
2505
2446
|
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
2447
|
throw new Error(`Unsupported key type: ${keyType}`);
|
|
2507
2448
|
}
|