suidouble 1.0.5 → 1.6.0-1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -7
- package/index.js +3 -0
- package/lib/SuiCoin.js +11 -4
- package/lib/SuiPackage.js +2 -2
- package/lib/SuiPackageModule.js +5 -0
- package/lib/SuiUtils.js +33 -10
- package/package.json +5 -9
- package/test/coins.test.js +1 -1
package/README.md
CHANGED
|
@@ -294,20 +294,21 @@ Don't forget to test transactions sending real money on devnet/testnet first!
|
|
|
294
294
|
|
|
295
295
|
##### composing transaction block yourself
|
|
296
296
|
|
|
297
|
-
If you need more flexebility, there's always an option to construct the transaction
|
|
297
|
+
If you need more flexebility, there's always an option to construct the transaction yourself:
|
|
298
298
|
|
|
299
299
|
```javascript
|
|
300
|
-
const {
|
|
300
|
+
const { Transaction, txInput } = require('suidobule'); // this exposes classes from the "@mysten/sui.js", so you don't have to import them separately
|
|
301
301
|
|
|
302
|
-
const
|
|
303
|
-
|
|
302
|
+
const tx = new Transaction();
|
|
303
|
+
tx.moveCall({
|
|
304
304
|
target: `package_id::module_id::method_name`,
|
|
305
305
|
arguments: [
|
|
306
|
-
|
|
307
|
-
|
|
306
|
+
txInput(tx, 'u256', some_value),
|
|
307
|
+
txInput(tx, 'vector<bool>', some_array),
|
|
308
|
+
tx.object('0xc060006111016b8a020ad5b33834984a437aaa7d3c74c18e09a95d48aceab08c'), // object ids are ok t
|
|
308
309
|
],
|
|
309
310
|
});
|
|
310
|
-
const moveCallResult = await contract.moveCall('suidouble_chat', 'post_pay', {tx:
|
|
311
|
+
const moveCallResult = await contract.moveCall('suidouble_chat', 'post_pay', {tx: tx});
|
|
311
312
|
```
|
|
312
313
|
|
|
313
314
|
|
package/index.js
CHANGED
|
@@ -5,6 +5,7 @@ const SuiObject = require('./lib/SuiObject.js');
|
|
|
5
5
|
const SuiUtils = require('./lib/SuiUtils.js');
|
|
6
6
|
const SuiLocalTestValidator = require('./lib/SuiLocalTestValidator.js');
|
|
7
7
|
const { Transaction, Commands } = require('@mysten/sui/transactions');
|
|
8
|
+
const { bcs } = require('@mysten/sui/bcs');
|
|
8
9
|
|
|
9
10
|
module.exports = {
|
|
10
11
|
SuiMaster,
|
|
@@ -16,4 +17,6 @@ module.exports = {
|
|
|
16
17
|
Transaction: Transaction,
|
|
17
18
|
Commands: Commands,
|
|
18
19
|
SuiUtils: SuiUtils,
|
|
20
|
+
txInput: SuiUtils.txInput,
|
|
21
|
+
bcs,
|
|
19
22
|
};
|
package/lib/SuiCoin.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
const { Commands, Transaction } = require('@mysten/sui/transactions');
|
|
1
|
+
const { Commands, Transaction, TransactionObjectArgument } = require('@mysten/sui/transactions');
|
|
2
2
|
const { bcs } = require('@mysten/sui/bcs');
|
|
3
|
-
// console.log(bcs);
|
|
4
3
|
|
|
5
4
|
|
|
6
5
|
const safeList = {
|
|
@@ -25,7 +24,15 @@ const safeList = {
|
|
|
25
24
|
},
|
|
26
25
|
};
|
|
27
26
|
|
|
27
|
+
/** Coin metadata object */
|
|
28
28
|
class SuiCoin {
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* SuiCoin constructor
|
|
32
|
+
* @param {Object} params - Initialization parameters
|
|
33
|
+
* @param {string} params.coinType - sui object type for a coin, without Coin<...>, only the inside type
|
|
34
|
+
* @param {SuiCoins} params.suiCoins - instance of SuiCoins
|
|
35
|
+
*/
|
|
29
36
|
constructor(params = {}) {
|
|
30
37
|
this._coinType = params.coinType;
|
|
31
38
|
this._suiCoins = params.suiCoins;
|
|
@@ -214,11 +221,11 @@ class SuiCoin {
|
|
|
214
221
|
/**
|
|
215
222
|
* Returns TransactionObjectArgument with Coin of amount to be used in tranasctions
|
|
216
223
|
*
|
|
217
|
-
* @param {
|
|
224
|
+
* @param {Transaction} txb - Native SUI SDK Transaction
|
|
218
225
|
* @param {string} owner - address of the owner
|
|
219
226
|
* @param {BigInt|string} amount - amount of coin. BigIng or String to be normalized via Coin decimals, "0.05" for 0.05 sui
|
|
220
227
|
* @param {boolean} addEmptyCoins - attach coins == 0 to the list
|
|
221
|
-
* @returns {
|
|
228
|
+
* @returns {TransactionObjectArgument}
|
|
222
229
|
*/
|
|
223
230
|
async coinOfAmountToTxCoin(txb, owner, amount, addEmptyCoins = false) {
|
|
224
231
|
const normalizedAmount = await this.lazyNormalizeAmount(amount);
|
package/lib/SuiPackage.js
CHANGED
|
@@ -452,8 +452,8 @@ class SuiPackage extends SuiObject {
|
|
|
452
452
|
|
|
453
453
|
const authorizeUpgradeArguments = [
|
|
454
454
|
cap,
|
|
455
|
-
|
|
456
|
-
|
|
455
|
+
this._suiMaster.utils.txInput(tx, 'u8', UpgradePolicyCOMPATIBLE),
|
|
456
|
+
this._suiMaster.utils.txInput(tx, 'vector<u8>', this._builtDigest),
|
|
457
457
|
];
|
|
458
458
|
|
|
459
459
|
const ticket = tx.moveCall({
|
package/lib/SuiPackageModule.js
CHANGED
|
@@ -166,6 +166,11 @@ class SuiPackageModule extends SuiCommonMethods {
|
|
|
166
166
|
const txCoinToSend = await suiCoin.coinOfAmountToTxCoin(tx, ownerAddress, param[0].amount);
|
|
167
167
|
|
|
168
168
|
callArgs.push(tx.makeMoveVec({ type: suiCoin.coinObjectType, elements: [txCoinToSend]}));
|
|
169
|
+
} else if (typeof param === 'string' && param.indexOf('0x') === 0) {
|
|
170
|
+
callArgs.push(tx.object(param));
|
|
171
|
+
} else if (param && param.Pure && param.Pure.bytes) {
|
|
172
|
+
// already Pure
|
|
173
|
+
callArgs.push(this._suiMaster.utils.txInput(tx, param));
|
|
169
174
|
} else {
|
|
170
175
|
callArgs.push(tx.pure(param));
|
|
171
176
|
}
|
package/lib/SuiUtils.js
CHANGED
|
@@ -1,13 +1,32 @@
|
|
|
1
1
|
const SuiCommonMethods = require('./SuiCommonMethods.js');
|
|
2
|
-
const { Inputs } = require('@mysten/sui/transactions');
|
|
2
|
+
const { Inputs, Transaction, Argument } = require('@mysten/sui/transactions');
|
|
3
3
|
const { bcs } = require('@mysten/sui/bcs');
|
|
4
|
+
const { fromB64 } = require('@mysten/bcs');
|
|
4
5
|
const { SuiClient, getFullnodeUrl, SuiHTTPTransport } = require('@mysten/sui/client');
|
|
5
6
|
const { normalizeSuiAddress } = require('@mysten/sui/utils');
|
|
6
7
|
|
|
7
8
|
const WebSocketClient = require('websocket').w3cwebsocket;
|
|
8
9
|
|
|
10
|
+
/** Helpful methods using in different places of suidouble */
|
|
9
11
|
class SuiUtils extends SuiCommonMethods {
|
|
10
12
|
|
|
13
|
+
/**
|
|
14
|
+
* Attach the parameter input into transaction, to be used for moveCall
|
|
15
|
+
* accepts an Inputs.Pure (result of .pureInput) or type + value directly
|
|
16
|
+
*
|
|
17
|
+
* @param {Transaction} tx
|
|
18
|
+
* @param {string | Inputs.Pure} typeOrInput
|
|
19
|
+
* @param {?Argument} value
|
|
20
|
+
* @returns Argument
|
|
21
|
+
*/
|
|
22
|
+
static txInput(tx, typeOrInput, value = null) {
|
|
23
|
+
if (typeOrInput && typeOrInput.Pure && typeOrInput.Pure.bytes) {
|
|
24
|
+
return tx.pure(SuiUtils.pureInputToBytes(typeOrInput));
|
|
25
|
+
} else {
|
|
26
|
+
return tx.pure(SuiUtils.pureInputToBytes(SuiUtils.pureInput(typeOrInput, value)));
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
11
30
|
/**
|
|
12
31
|
* Returns and Inputs.Pure for a given type
|
|
13
32
|
* to be used as moveCall parameters
|
|
@@ -19,13 +38,7 @@ class SuiUtils extends SuiCommonMethods {
|
|
|
19
38
|
* SuiUtils.pureInput('string', 'metadata')
|
|
20
39
|
* ]);
|
|
21
40
|
*
|
|
22
|
-
*
|
|
23
|
-
* wrapped in tx.pure if you are going to construct tx yourself:
|
|
24
|
-
* const tx = new Transaction();
|
|
25
|
-
* tx.moveCall({ target: `x.x.x`, arguments: [
|
|
26
|
-
* tx.pure(SuiUtils.pureInput('u8',22)),
|
|
27
|
-
* tx.pure(SuiUtils.pureInput('string','test')),
|
|
28
|
-
* ] });
|
|
41
|
+
* if you are going to construct tx yourself, you'd better use SuiUtils.txInput static method
|
|
29
42
|
*
|
|
30
43
|
* @param {string} type
|
|
31
44
|
* @param {value} value
|
|
@@ -58,24 +71,34 @@ class SuiUtils extends SuiCommonMethods {
|
|
|
58
71
|
}
|
|
59
72
|
}
|
|
60
73
|
|
|
74
|
+
/**
|
|
75
|
+
* Convert sui's PureInput into bcs serialized bytes
|
|
76
|
+
* @param {Inputs.Pure} pureInput
|
|
77
|
+
*/
|
|
78
|
+
static pureInputToBytes(pureInput) {
|
|
79
|
+
return fromB64(pureInput.Pure.bytes);
|
|
80
|
+
}
|
|
81
|
+
|
|
61
82
|
/**
|
|
62
83
|
* Wrapper for sui's utils normalizeSuiAddress
|
|
63
84
|
* Perform the following operations:
|
|
85
|
+
* <pre>
|
|
64
86
|
* 1. Make the address lower case
|
|
65
87
|
* 2. Prepend `0x` if the string does not start with `0x`.
|
|
66
88
|
* 3. Add more zeros if the length of the address(excluding `0x`) is less than `SUI_ADDRESS_LENGTH`
|
|
89
|
+
* </pre>
|
|
67
90
|
*
|
|
68
91
|
* @param {string} address
|
|
69
92
|
* @returns string
|
|
70
93
|
*/
|
|
71
|
-
normalizeSuiAddress(address) {
|
|
94
|
+
static normalizeSuiAddress(address) {
|
|
72
95
|
return normalizeSuiAddress(address);
|
|
73
96
|
}
|
|
74
97
|
|
|
75
98
|
/**
|
|
76
99
|
* As SUI removed websocket dependency for a node, we'll have it here as constructor wrapper
|
|
77
100
|
* returning native WebSocket in browser and websocket's w3cwebsocket in node
|
|
78
|
-
* @returns
|
|
101
|
+
* @returns WebSocketClient
|
|
79
102
|
*/
|
|
80
103
|
static WebSocketConstructor() {
|
|
81
104
|
return WebSocketClient;
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "suidouble",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.6.0-1",
|
|
4
4
|
"description": "Set of provider, package and object classes for javascript representation of Sui Move smart contracts. Use same code for publishing, upgrading, integration testing, interaction with smart contracts and integration in browser web3 dapps",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
7
|
-
"test": "tap -
|
|
8
|
-
"coverage": "tap -
|
|
7
|
+
"test": "tap -j1 -t120 ./test/*.test.js",
|
|
8
|
+
"coverage": "tap -j1 -t120 ./test/*.test.js"
|
|
9
9
|
},
|
|
10
10
|
"keywords": [
|
|
11
11
|
"sui",
|
|
@@ -21,12 +21,12 @@
|
|
|
21
21
|
"author": "Jeka Kiselyov <jeka911@gmail.com> (https://github.com/jeka-kiselyov)",
|
|
22
22
|
"license": "Apache-2.0",
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@mysten/sui": "1.0
|
|
24
|
+
"@mysten/sui": "^1.6.0",
|
|
25
25
|
"@wallet-standard/core": "^1.0.3",
|
|
26
26
|
"websocket": "^1.0.35"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
|
-
"tap": "^
|
|
29
|
+
"tap": "^21.0.1"
|
|
30
30
|
},
|
|
31
31
|
"browser": {
|
|
32
32
|
"child_process": false,
|
|
@@ -34,9 +34,5 @@
|
|
|
34
34
|
"path": false
|
|
35
35
|
},
|
|
36
36
|
"tap": {
|
|
37
|
-
"branches": 90,
|
|
38
|
-
"lines": 90,
|
|
39
|
-
"functions": 90,
|
|
40
|
-
"statements": 90
|
|
41
37
|
}
|
|
42
38
|
}
|
package/test/coins.test.js
CHANGED
|
@@ -89,7 +89,7 @@ test('getting coin objects for a transaction', async t => {
|
|
|
89
89
|
|
|
90
90
|
const tx = new Transaction();
|
|
91
91
|
const coinInput = await suiCoin.coinOfAmountToTxCoin(tx, suiMaster.address, suiMaster.MIST_PER_SUI); // pick 1 SUI
|
|
92
|
-
tx.transferObjects([coinInput],
|
|
92
|
+
tx.transferObjects([coinInput], '0x1d20dcdb2bca4f508ea9613994683eb4e76e9c4ed371169677c1be02aaf0b12a'); // send it anywhere
|
|
93
93
|
|
|
94
94
|
const result = await suiMaster.signAndExecuteTransaction({
|
|
95
95
|
transaction: tx,
|