suidouble 1.0.4-5 → 1.0.4-7
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/lib/SuiCoin.js +19 -7
- package/lib/SuiCoins.js +6 -0
- package/lib/SuiMaster.js +5 -0
- package/lib/SuiPackageModule.js +14 -6
- package/lib/SuiUtils.js +1 -1
- package/package.json +1 -1
- package/test/sui_master_onlocal.test.js +14 -3
- package/test/test_move_contracts/suidouble_chat/sources/suidouble_chat.move +13 -1
package/lib/SuiCoin.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const { Commands } = require('@mysten/sui/transactions');
|
|
1
|
+
const { Commands, Transaction } = require('@mysten/sui/transactions');
|
|
2
2
|
const { bcs } = require('@mysten/sui/bcs');
|
|
3
3
|
// console.log(bcs);
|
|
4
4
|
|
|
@@ -102,6 +102,15 @@ class SuiCoin {
|
|
|
102
102
|
return '0x'+this._coinType;
|
|
103
103
|
}
|
|
104
104
|
|
|
105
|
+
/**
|
|
106
|
+
* Move type for the Coin object of this coin type
|
|
107
|
+
*
|
|
108
|
+
* @type {string}
|
|
109
|
+
*/
|
|
110
|
+
get coinObjectType() {
|
|
111
|
+
return '0x2::coin::Coin<'+this.coinType+'>';
|
|
112
|
+
}
|
|
113
|
+
|
|
105
114
|
get decimals() {
|
|
106
115
|
if (this.metadata) {
|
|
107
116
|
return this.metadata.decimals;
|
|
@@ -202,6 +211,15 @@ class SuiCoin {
|
|
|
202
211
|
return totalAmount;
|
|
203
212
|
}
|
|
204
213
|
|
|
214
|
+
/**
|
|
215
|
+
* Returns TransactionObjectArgument with Coin of amount to be used in tranasctions
|
|
216
|
+
*
|
|
217
|
+
* @param {import('@mysten/sui/transactions').Transaction} txb - Native SUI SDK Transaction
|
|
218
|
+
* @param {string} owner - address of the owner
|
|
219
|
+
* @param {BigInt|string} amount - amount of coin. BigIng or String to be normalized via Coin decimals, "0.05" for 0.05 sui
|
|
220
|
+
* @param {boolean} addEmptyCoins - attach coins == 0 to the list
|
|
221
|
+
* @returns {import('@mysten/sui/transactions').TransactionObjectArgument}
|
|
222
|
+
*/
|
|
205
223
|
async coinOfAmountToTxCoin(txb, owner, amount, addEmptyCoins = false) {
|
|
206
224
|
const normalizedAmount = await this.lazyNormalizeAmount(amount);
|
|
207
225
|
|
|
@@ -215,12 +233,6 @@ class SuiCoin {
|
|
|
215
233
|
if (coinIds.length == 1) {
|
|
216
234
|
// only one coin object enough to cover the expense
|
|
217
235
|
if (this.isSUI()) {
|
|
218
|
-
// console.log(txb.gas);
|
|
219
|
-
// console.log(bcs);
|
|
220
|
-
// console.log(txb.pure(bcs.vector(bcs.u64).serialize([expectedAmountAsBigInt])));
|
|
221
|
-
// console.log(txb.pure.u64(expectedAmountAsBigInt));
|
|
222
|
-
// txb.pure(bcs.vector(bcs.u64).serialize(['0x123']))
|
|
223
|
-
|
|
224
236
|
const coinInput = txb.add(Commands.SplitCoins(txb.gas, [txb.pure.u64(expectedAmountAsBigInt)]));
|
|
225
237
|
return coinInput;
|
|
226
238
|
} else {
|
package/lib/SuiCoins.js
CHANGED
|
@@ -97,6 +97,12 @@ class SuiCoins extends SuiCommonMethods {
|
|
|
97
97
|
return coinType;
|
|
98
98
|
}
|
|
99
99
|
|
|
100
|
+
/**
|
|
101
|
+
* Return instance of SuiCoin of specific type
|
|
102
|
+
*
|
|
103
|
+
* @param {string} coinType - MoveType, or 'SUI' as helper
|
|
104
|
+
* @returns {SuiCoin}
|
|
105
|
+
*/
|
|
100
106
|
get(coinType) {
|
|
101
107
|
const normalizedCoinType = this.normalizeCoinType(coinType);
|
|
102
108
|
let suiCoin = this._coins[normalizedCoinType];
|
package/lib/SuiMaster.js
CHANGED
package/lib/SuiPackageModule.js
CHANGED
|
@@ -7,8 +7,18 @@ const SuiEvent = require('./SuiEvent.js');
|
|
|
7
7
|
|
|
8
8
|
const { Transaction } = require('@mysten/sui/transactions');
|
|
9
9
|
const { normalizeSuiAddress } = require('@mysten/sui/utils');
|
|
10
|
+
const SuiMaster = require('./SuiMaster.js');
|
|
11
|
+
const SuiPackage = require('./SuiPackage.js');
|
|
10
12
|
|
|
11
13
|
class SuiPackageModule extends SuiCommonMethods {
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* SuiPackageModule constructor
|
|
17
|
+
* @param {Object} params - Initialization parameters
|
|
18
|
+
* @param {SuiPackage} params.package - instance of SuiPackage this module is part of
|
|
19
|
+
* @param {SuiMaster} params.suiMaster - instance of SuiMaster
|
|
20
|
+
* @param {string} params.moduleName - name of the Move module
|
|
21
|
+
*/
|
|
12
22
|
constructor(params = {}) {
|
|
13
23
|
super(params);
|
|
14
24
|
|
|
@@ -16,6 +26,7 @@ class SuiPackageModule extends SuiCommonMethods {
|
|
|
16
26
|
if (!this._package) {
|
|
17
27
|
throw new Error('package is required for SuiPackageModule');
|
|
18
28
|
}
|
|
29
|
+
|
|
19
30
|
this._suiMaster = params.suiMaster;
|
|
20
31
|
if (!this._suiMaster) {
|
|
21
32
|
throw new Error('suiMaster is requried for SuiPackageModule');
|
|
@@ -25,9 +36,6 @@ class SuiPackageModule extends SuiCommonMethods {
|
|
|
25
36
|
throw new Error('moduleName is required for SuiPackageModule');
|
|
26
37
|
}
|
|
27
38
|
|
|
28
|
-
// this._objects = {};
|
|
29
|
-
// this._objectsArray = [];
|
|
30
|
-
|
|
31
39
|
// we need to get very first version's address of this package to use for types, so we are doing this in separate call
|
|
32
40
|
this._checkedOnChain = false;
|
|
33
41
|
this._normalizedMoveModule = {};
|
|
@@ -154,10 +162,10 @@ class SuiPackageModule extends SuiCommonMethods {
|
|
|
154
162
|
// vector<Coin<SUI>>
|
|
155
163
|
const ownerAddress = this._suiMaster.address;
|
|
156
164
|
|
|
157
|
-
const suiCoin = await this._suiMaster.suiCoins.get(param.type);
|
|
158
|
-
const txCoinToSend = await suiCoin.coinOfAmountToTxCoin(tx, ownerAddress, param.amount);
|
|
165
|
+
const suiCoin = await this._suiMaster.suiCoins.get(param[0].type);
|
|
166
|
+
const txCoinToSend = await suiCoin.coinOfAmountToTxCoin(tx, ownerAddress, param[0].amount);
|
|
159
167
|
|
|
160
|
-
callArgs.push(tx.makeMoveVec({
|
|
168
|
+
callArgs.push(tx.makeMoveVec({ type: suiCoin.coinObjectType, elements: [txCoinToSend]}));
|
|
161
169
|
} else {
|
|
162
170
|
callArgs.push(tx.pure(param));
|
|
163
171
|
}
|
package/lib/SuiUtils.js
CHANGED
|
@@ -128,7 +128,7 @@ class SuiUtils extends SuiCommonMethods {
|
|
|
128
128
|
client = SuiUtils.suiClientFor('mainnet');
|
|
129
129
|
providerName = 'sui:mainnet';
|
|
130
130
|
} else {
|
|
131
|
-
if (clientParam && clientParam.constructor && clientParam.
|
|
131
|
+
if (clientParam && clientParam.constructor && (clientParam.endpoint || clientParam.transport)) {
|
|
132
132
|
client = clientParam;
|
|
133
133
|
let url = '';
|
|
134
134
|
if (clientParam.endpoint) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "suidouble",
|
|
3
|
-
"version": "1.0.4-
|
|
3
|
+
"version": "1.0.4-7",
|
|
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": {
|
|
@@ -346,9 +346,7 @@ test('testing move call with coins', async t => {
|
|
|
346
346
|
|
|
347
347
|
t.ok(foundChatTopMessage);
|
|
348
348
|
t.ok(foundChatResponse);
|
|
349
|
-
|
|
350
|
-
// messageTextAsBytes = [].slice.call(new TextEncoder().encode(messageText)); // regular array with utf data
|
|
351
|
-
// suidouble_chat contract store text a bytes (easier to work with unicode things), let's convert it back to js string
|
|
349
|
+
|
|
352
350
|
foundText = new TextDecoder().decode(new Uint8Array(foundText));
|
|
353
351
|
|
|
354
352
|
t.equal(foundText, longMessageYouCanNotPostForFree);
|
|
@@ -358,6 +356,19 @@ test('testing move call with coins', async t => {
|
|
|
358
356
|
t.ok( balanceNow <= (balanceWas - 400000000000n) );
|
|
359
357
|
});
|
|
360
358
|
|
|
359
|
+
test('testing move call with vector<Coin<..>>', async t => {
|
|
360
|
+
const balanceWas = await suiMaster.getBalance();
|
|
361
|
+
const longMessageYouCanNotPostForFree = ('message ').padEnd(500, 'test');
|
|
362
|
+
|
|
363
|
+
// you can pass vector of coin, wrapping it's definition in array
|
|
364
|
+
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')]);
|
|
365
|
+
// it's the wrapper over the same move function we've already tested, so lets keep the unit simple:
|
|
366
|
+
t.ok(moveCallResult.created.length > 0);
|
|
367
|
+
|
|
368
|
+
const balanceNow = await suiMaster.getBalance();
|
|
369
|
+
t.ok( balanceNow <= (balanceWas - 400000000000n) ); // vector<Coin<SUI>> paid
|
|
370
|
+
});
|
|
371
|
+
|
|
361
372
|
test('testing move call deleting object', async t => {
|
|
362
373
|
|
|
363
374
|
console.error('chatResponseToDelete', chatResponseToDelete);
|
|
@@ -3,7 +3,7 @@ module suidouble_chat::suidouble_chat {
|
|
|
3
3
|
use sui::object::{Self, UID, ID};
|
|
4
4
|
use sui::transfer;
|
|
5
5
|
use sui::tx_context::{Self, TxContext};
|
|
6
|
-
use std::vector::length;
|
|
6
|
+
use std::vector::{Self, length};
|
|
7
7
|
|
|
8
8
|
use sui::dynamic_object_field::{Self};
|
|
9
9
|
|
|
@@ -12,6 +12,7 @@ module suidouble_chat::suidouble_chat {
|
|
|
12
12
|
use sui::balance::{Self, Balance};
|
|
13
13
|
|
|
14
14
|
use std::debug;
|
|
15
|
+
use sui::pay;
|
|
15
16
|
|
|
16
17
|
use sui::event::emit;
|
|
17
18
|
|
|
@@ -168,6 +169,17 @@ module suidouble_chat::suidouble_chat {
|
|
|
168
169
|
transfer::share_object(chat_top_message);
|
|
169
170
|
}
|
|
170
171
|
|
|
172
|
+
public entry fun post_pay_with_coin_vector(
|
|
173
|
+
chat_shop: &mut ChatShop,
|
|
174
|
+
coins: vector<Coin<SUI>>,
|
|
175
|
+
text: vector<u8>,
|
|
176
|
+
metadata: vector<u8>,
|
|
177
|
+
ctx: &mut TxContext
|
|
178
|
+
) {
|
|
179
|
+
let base = vector::pop_back(&mut coins);
|
|
180
|
+
pay::join_vec(&mut base, coins);
|
|
181
|
+
post_pay(chat_shop, base, text, metadata, ctx);
|
|
182
|
+
}
|
|
171
183
|
|
|
172
184
|
/// Mint (post) a ChatResponse object
|
|
173
185
|
public entry fun reply(
|