suidouble 1.0.5 → 1.6.0

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 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 block yourself:
297
+ If you need more flexebility, there's always an option to construct the transaction yourself:
298
298
 
299
299
  ```javascript
300
- const { TransactionBlock, Transactions } = require('suidobule'); // this exposes classes from the "@mysten/sui.js", so you don't have to import them separately
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 txb = new TransactionBlock();
303
- txb.moveCall({
302
+ const tx = new Transaction();
303
+ tx.moveCall({
304
304
  target: `package_id::module_id::method_name`,
305
305
  arguments: [
306
- txb.pure(contract.arg('u256', something)),
307
- txb.object(someid),
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: txb});
311
+ const moveCallResult = await contract.moveCall('suidouble_chat', 'post_pay', {tx: tx});
311
312
  ```
312
313
 
313
314
 
package/index.js CHANGED
@@ -16,4 +16,5 @@ module.exports = {
16
16
  Transaction: Transaction,
17
17
  Commands: Commands,
18
18
  SuiUtils: SuiUtils,
19
+ txInput: SuiUtils.txInput,
19
20
  };
package/lib/SuiPackage.js CHANGED
@@ -452,8 +452,8 @@ class SuiPackage extends SuiObject {
452
452
 
453
453
  const authorizeUpgradeArguments = [
454
454
  cap,
455
- tx.pure(this.arg('u8', UpgradePolicyCOMPATIBLE)),
456
- tx.pure(this.arg('vector<u8>', this._builtDigest)),
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({
@@ -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,6 +1,7 @@
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
 
@@ -8,6 +9,23 @@ const WebSocketClient = require('websocket').w3cwebsocket;
8
9
 
9
10
  class SuiUtils extends SuiCommonMethods {
10
11
 
12
+ /**
13
+ * Attacha the parameter input into transaction, to be used for moveCall
14
+ * accepts an Inputs.Pure (result of .pureInput) or type + value directly
15
+ *
16
+ * @param {Transaction} tx
17
+ * @param {Inputs.Pure | String} typeOrInput
18
+ * @param {any | undefined} value
19
+ * @returns Argument
20
+ */
21
+ static txInput(tx, typeOrInput, value = null) {
22
+ if (typeOrInput && typeOrInput.Pure && typeOrInput.Pure.bytes) {
23
+ return tx.pure(this.pureInputToBytes(typeOrInput));
24
+ } else {
25
+ return tx.pure(this.pureInputToBytes(this.pureInput(typeOrInput, value)));
26
+ }
27
+ }
28
+
11
29
  /**
12
30
  * Returns and Inputs.Pure for a given type
13
31
  * to be used as moveCall parameters
@@ -58,6 +76,14 @@ class SuiUtils extends SuiCommonMethods {
58
76
  }
59
77
  }
60
78
 
79
+ /**
80
+ * Convert sui's PureInput into bcs serialized bytes
81
+ * @param {Inputs.Pure} pureInput
82
+ */
83
+ static pureInputToBytes(pureInput) {
84
+ return fromB64(pureInput.Pure.bytes);
85
+ }
86
+
61
87
  /**
62
88
  * Wrapper for sui's utils normalizeSuiAddress
63
89
  * Perform the following operations:
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "suidouble",
3
- "version": "1.0.5",
3
+ "version": "1.6.0",
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 -j=1 ./test/*.test.js",
8
- "coverage": "tap -j=1 ./test/*.test.js"
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.5",
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": "^16.3.4"
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
  }
@@ -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], tx.pure('0x1d20dcdb2bca4f508ea9613994683eb4e76e9c4ed371169677c1be02aaf0b12a')); // send it anywhere
92
+ tx.transferObjects([coinInput], '0x1d20dcdb2bca4f508ea9613994683eb4e76e9c4ed371169677c1be02aaf0b12a'); // send it anywhere
93
93
 
94
94
  const result = await suiMaster.signAndExecuteTransaction({
95
95
  transaction: tx,