Comparing version 1.0.5 to 1.6.0-1
@@ -8,2 +8,3 @@ const SuiMaster = require('./lib/SuiMaster.js'); | ||
const { Transaction, Commands } = require('@mysten/sui/transactions'); | ||
const { bcs } = require('@mysten/sui/bcs'); | ||
@@ -20,2 +21,4 @@ module.exports = { | ||
SuiUtils: SuiUtils, | ||
txInput: SuiUtils.txInput, | ||
bcs, | ||
}; |
@@ -1,4 +0,3 @@ | ||
const { Commands, Transaction } = require('@mysten/sui/transactions'); | ||
const { Commands, Transaction, TransactionObjectArgument } = require('@mysten/sui/transactions'); | ||
const { bcs } = require('@mysten/sui/bcs'); | ||
// console.log(bcs); | ||
@@ -28,3 +27,11 @@ | ||
/** Coin metadata object */ | ||
class SuiCoin { | ||
/** | ||
* SuiCoin constructor | ||
* @param {Object} params - Initialization parameters | ||
* @param {string} params.coinType - sui object type for a coin, without Coin<...>, only the inside type | ||
* @param {SuiCoins} params.suiCoins - instance of SuiCoins | ||
*/ | ||
constructor(params = {}) { | ||
@@ -218,7 +225,7 @@ this._coinType = params.coinType; | ||
* | ||
* @param {import('@mysten/sui/transactions').Transaction} txb - Native SUI SDK Transaction | ||
* @param {Transaction} txb - Native SUI SDK Transaction | ||
* @param {string} owner - address of the owner | ||
* @param {BigInt|string} amount - amount of coin. BigIng or String to be normalized via Coin decimals, "0.05" for 0.05 sui | ||
* @param {boolean} addEmptyCoins - attach coins == 0 to the list | ||
* @returns {import('@mysten/sui/transactions').TransactionObjectArgument} | ||
* @returns {TransactionObjectArgument} | ||
*/ | ||
@@ -225,0 +232,0 @@ async coinOfAmountToTxCoin(txb, owner, amount, addEmptyCoins = false) { |
@@ -455,4 +455,4 @@ const SuiCliCommands = require('./SuiCliCommands.js'); | ||
cap, | ||
tx.pure(this.arg('u8', UpgradePolicyCOMPATIBLE)), | ||
tx.pure(this.arg('vector<u8>', this._builtDigest)), | ||
this._suiMaster.utils.txInput(tx, 'u8', UpgradePolicyCOMPATIBLE), | ||
this._suiMaster.utils.txInput(tx, 'vector<u8>', this._builtDigest), | ||
]; | ||
@@ -459,0 +459,0 @@ |
@@ -169,2 +169,7 @@ const SuiObject = require('./SuiObject.js'); | ||
callArgs.push(tx.makeMoveVec({ type: suiCoin.coinObjectType, elements: [txCoinToSend]})); | ||
} else if (typeof param === 'string' && param.indexOf('0x') === 0) { | ||
callArgs.push(tx.object(param)); | ||
} else if (param && param.Pure && param.Pure.bytes) { | ||
// already Pure | ||
callArgs.push(this._suiMaster.utils.txInput(tx, param)); | ||
} else { | ||
@@ -171,0 +176,0 @@ callArgs.push(tx.pure(param)); |
const SuiCommonMethods = require('./SuiCommonMethods.js'); | ||
const { Inputs } = require('@mysten/sui/transactions'); | ||
const { Inputs, Transaction, Argument } = require('@mysten/sui/transactions'); | ||
const { bcs } = require('@mysten/sui/bcs'); | ||
const { fromB64 } = require('@mysten/bcs'); | ||
const { SuiClient, getFullnodeUrl, SuiHTTPTransport } = require('@mysten/sui/client'); | ||
@@ -9,5 +10,23 @@ const { normalizeSuiAddress } = require('@mysten/sui/utils'); | ||
/** Helpful methods using in different places of suidouble */ | ||
class SuiUtils extends SuiCommonMethods { | ||
/** | ||
* Attach the parameter input into transaction, to be used for moveCall | ||
* accepts an Inputs.Pure (result of .pureInput) or type + value directly | ||
* | ||
* @param {Transaction} tx | ||
* @param {string | Inputs.Pure} typeOrInput | ||
* @param {?Argument} value | ||
* @returns Argument | ||
*/ | ||
static txInput(tx, typeOrInput, value = null) { | ||
if (typeOrInput && typeOrInput.Pure && typeOrInput.Pure.bytes) { | ||
return tx.pure(SuiUtils.pureInputToBytes(typeOrInput)); | ||
} else { | ||
return tx.pure(SuiUtils.pureInputToBytes(SuiUtils.pureInput(typeOrInput, value))); | ||
} | ||
} | ||
/** | ||
* Returns and Inputs.Pure for a given type | ||
@@ -23,9 +42,3 @@ * to be used as moveCall parameters | ||
* | ||
* or: | ||
* wrapped in tx.pure if you are going to construct tx yourself: | ||
* const tx = new Transaction(); | ||
* tx.moveCall({ target: `x.x.x`, arguments: [ | ||
* tx.pure(SuiUtils.pureInput('u8',22)), | ||
* tx.pure(SuiUtils.pureInput('string','test')), | ||
* ] }); | ||
* if you are going to construct tx yourself, you'd better use SuiUtils.txInput static method | ||
* | ||
@@ -64,7 +77,17 @@ * @param {string} type | ||
/** | ||
* Convert sui's PureInput into bcs serialized bytes | ||
* @param {Inputs.Pure} pureInput | ||
*/ | ||
static pureInputToBytes(pureInput) { | ||
return fromB64(pureInput.Pure.bytes); | ||
} | ||
/** | ||
* Wrapper for sui's utils normalizeSuiAddress | ||
* Perform the following operations: | ||
* <pre> | ||
* 1. Make the address lower case | ||
* 2. Prepend `0x` if the string does not start with `0x`. | ||
* 3. Add more zeros if the length of the address(excluding `0x`) is less than `SUI_ADDRESS_LENGTH` | ||
* </pre> | ||
* | ||
@@ -74,3 +97,3 @@ * @param {string} address | ||
*/ | ||
normalizeSuiAddress(address) { | ||
static normalizeSuiAddress(address) { | ||
return normalizeSuiAddress(address); | ||
@@ -82,3 +105,3 @@ } | ||
* returning native WebSocket in browser and websocket's w3cwebsocket in node | ||
* @returns | ||
* @returns WebSocketClient | ||
*/ | ||
@@ -85,0 +108,0 @@ static WebSocketConstructor() { |
{ | ||
"name": "suidouble", | ||
"version": "1.0.5", | ||
"version": "1.6.0-1", | ||
"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", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "tap -j=1 ./test/*.test.js", | ||
"coverage": "tap -j=1 ./test/*.test.js" | ||
"test": "tap -j1 -t120 ./test/*.test.js", | ||
"coverage": "tap -j1 -t120 ./test/*.test.js" | ||
}, | ||
@@ -24,3 +24,3 @@ "keywords": [ | ||
"dependencies": { | ||
"@mysten/sui": "1.0.5", | ||
"@mysten/sui": "^1.6.0", | ||
"@wallet-standard/core": "^1.0.3", | ||
@@ -30,3 +30,3 @@ "websocket": "^1.0.35" | ||
"devDependencies": { | ||
"tap": "^16.3.4" | ||
"tap": "^21.0.1" | ||
}, | ||
@@ -39,7 +39,3 @@ "browser": { | ||
"tap": { | ||
"branches": 90, | ||
"lines": 90, | ||
"functions": 90, | ||
"statements": 90 | ||
} | ||
} |
@@ -297,16 +297,17 @@ # suidouble | ||
If you need more flexebility, there's always an option to construct the transaction block yourself: | ||
If you need more flexebility, there's always an option to construct the transaction yourself: | ||
```javascript | ||
const { TransactionBlock, Transactions } = require('suidobule'); // this exposes classes from the "@mysten/sui.js", so you don't have to import them separately | ||
const { Transaction, txInput } = require('suidobule'); // this exposes classes from the "@mysten/sui.js", so you don't have to import them separately | ||
const txb = new TransactionBlock(); | ||
txb.moveCall({ | ||
const tx = new Transaction(); | ||
tx.moveCall({ | ||
target: `package_id::module_id::method_name`, | ||
arguments: [ | ||
txb.pure(contract.arg('u256', something)), | ||
txb.object(someid), | ||
txInput(tx, 'u256', some_value), | ||
txInput(tx, 'vector<bool>', some_array), | ||
tx.object('0xc060006111016b8a020ad5b33834984a437aaa7d3c74c18e09a95d48aceab08c'), // object ids are ok t | ||
], | ||
}); | ||
const moveCallResult = await contract.moveCall('suidouble_chat', 'post_pay', {tx: txb}); | ||
const moveCallResult = await contract.moveCall('suidouble_chat', 'post_pay', {tx: tx}); | ||
``` | ||
@@ -313,0 +314,0 @@ |
@@ -92,3 +92,3 @@ 'use strict' | ||
const coinInput = await suiCoin.coinOfAmountToTxCoin(tx, suiMaster.address, suiMaster.MIST_PER_SUI); // pick 1 SUI | ||
tx.transferObjects([coinInput], tx.pure('0x1d20dcdb2bca4f508ea9613994683eb4e76e9c4ed371169677c1be02aaf0b12a')); // send it anywhere | ||
tx.transferObjects([coinInput], '0x1d20dcdb2bca4f508ea9613994683eb4e76e9c4ed371169677c1be02aaf0b12a'); // send it anywhere | ||
@@ -95,0 +95,0 @@ const result = await suiMaster.signAndExecuteTransaction({ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
239812
3889
484
2
+ Added@mysten/bcs@1.0.4(transitive)
+ Added@mysten/sui@1.9.0(transitive)
+ Addedbase-x@5.0.0(transitive)
+ Addedbs58@6.0.0(transitive)
+ Addedvalibot@0.36.0(transitive)
- Removed@mysten/bcs@1.0.2(transitive)
- Removed@mysten/sui@1.0.5(transitive)
- Removedbase-x@4.0.0(transitive)
- Removedbs58@5.0.0(transitive)
- Removedvalibot@0.25.0(transitive)
Updated@mysten/sui@^1.6.0