Comparing version 1.0.4-6 to 1.0.4-7
@@ -1,2 +0,2 @@ | ||
const { Commands } = require('@mysten/sui/transactions'); | ||
const { Commands, Transaction } = require('@mysten/sui/transactions'); | ||
const { bcs } = require('@mysten/sui/bcs'); | ||
@@ -105,2 +105,11 @@ // console.log(bcs); | ||
/** | ||
* Move type for the Coin object of this coin type | ||
* | ||
* @type {string} | ||
*/ | ||
get coinObjectType() { | ||
return '0x2::coin::Coin<'+this.coinType+'>'; | ||
} | ||
get decimals() { | ||
@@ -206,2 +215,11 @@ if (this.metadata) { | ||
/** | ||
* Returns TransactionObjectArgument with Coin of amount to be used in tranasctions | ||
* | ||
* @param {import('@mysten/sui/transactions').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} | ||
*/ | ||
async coinOfAmountToTxCoin(txb, owner, amount, addEmptyCoins = false) { | ||
@@ -220,8 +238,2 @@ const normalizedAmount = await this.lazyNormalizeAmount(amount); | ||
if (this.isSUI()) { | ||
// console.log(txb.gas); | ||
// console.log(bcs); | ||
// console.log(txb.pure(bcs.vector(bcs.u64).serialize([expectedAmountAsBigInt]))); | ||
// console.log(txb.pure.u64(expectedAmountAsBigInt)); | ||
// txb.pure(bcs.vector(bcs.u64).serialize(['0x123'])) | ||
const coinInput = txb.add(Commands.SplitCoins(txb.gas, [txb.pure.u64(expectedAmountAsBigInt)])); | ||
@@ -228,0 +240,0 @@ return coinInput; |
@@ -100,2 +100,8 @@ const SuiCoin = require('./SuiCoin.js'); | ||
/** | ||
* Return instance of SuiCoin of specific type | ||
* | ||
* @param {string} coinType - MoveType, or 'SUI' as helper | ||
* @returns {SuiCoin} | ||
*/ | ||
get(coinType) { | ||
@@ -102,0 +108,0 @@ const normalizedCoinType = this.normalizeCoinType(coinType); |
@@ -105,2 +105,7 @@ const SuiCommonMethods = require('./SuiCommonMethods.js'); | ||
/** | ||
* Instance of SuiCoins class connected to this SuiMaster | ||
* | ||
* @type {SuiCoins} | ||
*/ | ||
get suiCoins() { | ||
@@ -107,0 +112,0 @@ return this._suiCoins; |
@@ -10,4 +10,14 @@ const SuiObject = require('./SuiObject.js'); | ||
const { normalizeSuiAddress } = require('@mysten/sui/utils'); | ||
const SuiMaster = require('./SuiMaster.js'); | ||
const SuiPackage = require('./SuiPackage.js'); | ||
class SuiPackageModule extends SuiCommonMethods { | ||
/** | ||
* SuiPackageModule constructor | ||
* @param {Object} params - Initialization parameters | ||
* @param {SuiPackage} params.package - instance of SuiPackage this module is part of | ||
* @param {SuiMaster} params.suiMaster - instance of SuiMaster | ||
* @param {string} params.moduleName - name of the Move module | ||
*/ | ||
constructor(params = {}) { | ||
@@ -20,2 +30,3 @@ super(params); | ||
} | ||
this._suiMaster = params.suiMaster; | ||
@@ -30,5 +41,2 @@ if (!this._suiMaster) { | ||
// this._objects = {}; | ||
// this._objectsArray = []; | ||
// we need to get very first version's address of this package to use for types, so we are doing this in separate call | ||
@@ -160,6 +168,6 @@ this._checkedOnChain = false; | ||
const suiCoin = await this._suiMaster.suiCoins.get(param.type); | ||
const txCoinToSend = await suiCoin.coinOfAmountToTxCoin(tx, ownerAddress, param.amount); | ||
const suiCoin = await this._suiMaster.suiCoins.get(param[0].type); | ||
const txCoinToSend = await suiCoin.coinOfAmountToTxCoin(tx, ownerAddress, param[0].amount); | ||
callArgs.push(tx.makeMoveVec({ objects: [txCoinToSend]})); | ||
callArgs.push(tx.makeMoveVec({ type: suiCoin.coinObjectType, elements: [txCoinToSend]})); | ||
} else { | ||
@@ -166,0 +174,0 @@ callArgs.push(tx.pure(param)); |
{ | ||
"name": "suidouble", | ||
"version": "1.0.4-6", | ||
"version": "1.0.4-7", | ||
"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,0 +5,0 @@ "main": "index.js", |
@@ -349,5 +349,3 @@ 'use strict' | ||
t.ok(foundChatResponse); | ||
// messageTextAsBytes = [].slice.call(new TextEncoder().encode(messageText)); // regular array with utf data | ||
// suidouble_chat contract store text a bytes (easier to work with unicode things), let's convert it back to js string | ||
foundText = new TextDecoder().decode(new Uint8Array(foundText)); | ||
@@ -362,2 +360,15 @@ | ||
test('testing move call with vector<Coin<..>>', async t => { | ||
const balanceWas = await suiMaster.getBalance(); | ||
const longMessageYouCanNotPostForFree = ('message ').padEnd(500, 'test'); | ||
// you can pass vector of coin, wrapping it's definition in array | ||
const moveCallResult = await contract.moveCall('suidouble_chat', 'post_pay_with_coin_vector', [chatShopObjectId, [{type: 'SUI', amount: 400000000000n}], contract.arg('string', longMessageYouCanNotPostForFree), contract.arg('string', 'metadata')]); | ||
// it's the wrapper over the same move function we've already tested, so lets keep the unit simple: | ||
t.ok(moveCallResult.created.length > 0); | ||
const balanceNow = await suiMaster.getBalance(); | ||
t.ok( balanceNow <= (balanceWas - 400000000000n) ); // vector<Coin<SUI>> paid | ||
}); | ||
test('testing move call deleting object', async t => { | ||
@@ -364,0 +375,0 @@ |
Sorry, the diff of this file is not supported yet
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
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
237008
3823