suidouble 1.9.0 → 1.12.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/lib/SuiCoin.js CHANGED
@@ -244,14 +244,14 @@ class SuiCoin {
244
244
  return coinInput;
245
245
  } else {
246
246
  // some other coin
247
- const coinInput = txb.add(Commands.SplitCoins(txb.object(coinIds[0]), [txb.pure(expectedAmountAsBigInt)]));
247
+ const coinInput = txb.add(Commands.SplitCoins(txb.object(coinIds[0]), [txb.pure.u64(expectedAmountAsBigInt)]));
248
248
  return coinInput;
249
249
  }
250
250
  } else {
251
251
  // few coin objects to merge
252
252
  const coinIdToMergeIn = coinIds.shift();
253
253
  txb.add(Commands.MergeCoins(txb.object(coinIdToMergeIn), coinIds.map((id)=>{return txb.object(id);})));
254
- const coinInputSplet = txb.add(Commands.SplitCoins(txb.object(coinIdToMergeIn), [txb.pure(expectedAmountAsBigInt)]));
254
+ const coinInputSplet = txb.add(Commands.SplitCoins(txb.object(coinIdToMergeIn), [txb.pure.u64(expectedAmountAsBigInt)]));
255
255
 
256
256
  return coinInputSplet;
257
257
  }
package/lib/SuiMaster.js CHANGED
@@ -402,5 +402,6 @@ class SuiMaster extends SuiCommonMethods {
402
402
  SuiMaster.MIST_PER_SUI = BigInt(MIST_PER_SUI);
403
403
  SuiMaster.Transaction = Transaction;
404
404
  SuiMaster.Commands = Commands;
405
+ SuiMaster.SuiUtils = SuiUtils;
405
406
 
406
407
  module.exports = SuiMaster;
package/lib/SuiPackage.js CHANGED
@@ -394,9 +394,9 @@ class SuiPackage extends SuiObject {
394
394
  }
395
395
  }
396
396
 
397
- async publish() {
397
+ async publish(params = {}) {
398
398
  if (!this._isBuilt) {
399
- await this.build();
399
+ await this.build(params);
400
400
  }
401
401
  if (this.address) {
402
402
  throw new Error('already published. Maybe you need to upgrade() it?');
@@ -438,11 +438,11 @@ class SuiPackage extends SuiObject {
438
438
  return this.address;
439
439
  }
440
440
 
441
- async upgrade() {
441
+ async upgrade(params = {}) {
442
442
  await this.checkOnChainIfNeeded();
443
443
 
444
444
  if (!this._isBuilt) {
445
- await this.build();
445
+ await this.build(params);
446
446
  }
447
447
 
448
448
  this.log('upgrading package...');
@@ -503,7 +503,7 @@ class SuiPackage extends SuiObject {
503
503
  * Build a Move project using `sui move build`
504
504
  * @returns Boolean true on success
505
505
  */
506
- async build() {
506
+ async build(params = {}) {
507
507
  this.log('builing a package...');
508
508
 
509
509
  const path = this._path;
@@ -512,7 +512,11 @@ class SuiPackage extends SuiObject {
512
512
  throw new Error('Cant build a package with no path defined');
513
513
  }
514
514
 
515
- const buildResult = await SuiCliCommands.exec(`sui move build --dump-bytecode-as-base64 --path ${path}`);
515
+ let command = `sui move build --dump-bytecode-as-base64 --path ${path}`;
516
+ if (params.withUnpublishedDependencies) {
517
+ command = `sui move build --with-unpublished-dependencies --dump-bytecode-as-base64 --path ${path}`;
518
+ }
519
+ const buildResult = await SuiCliCommands.exec(command);
516
520
  const { modules, dependencies, digest } = JSON.parse(buildResult);
517
521
 
518
522
  this._builtModules = modules;
package/lib/SuiUtils.js CHANGED
@@ -104,6 +104,30 @@ class SuiUtils extends SuiCommonMethods {
104
104
  return WebSocketClient;
105
105
  }
106
106
 
107
+ /**
108
+ * Makes an instance for SuiClient for a specific chain using RPC
109
+ * @param {Object} params parameters
110
+ * @param {string} params.chainname 'mainnet', 'devnet', 'testnet', 'localnet'
111
+ * @param {string} params.url rpc url
112
+ * @param {Object} params.rpc rpc settings
113
+ * @param {Object.<string, string>} params.rpc.headers rpc headers
114
+ * @returns SuiClient
115
+ */
116
+ static suiClientForRPC(params = {}) {
117
+ const providerName = params.providerName || params.chainname || params.chain;
118
+ delete params.providerName;
119
+ delete params.chainName;
120
+ delete params.chain;
121
+ params.WebSocketConstructor = SuiUtils.WebSocketConstructor();
122
+
123
+ const transport = new SuiHTTPTransport(params);
124
+ const client = new SuiClient({ transport: transport });
125
+
126
+ client.providerName = providerName;
127
+
128
+ return client;
129
+ }
130
+
107
131
  /**
108
132
  * Makes an instance for SuiClient for a specific chain, eg: 'mainnet'
109
133
  * @param {string} chainname
@@ -161,7 +185,12 @@ class SuiUtils extends SuiCommonMethods {
161
185
  url = clientParam.transport.websocketClient.endpoint;
162
186
  }
163
187
 
164
- if (url.indexOf('devnet') !== -1) {
188
+ if (clientParam.providerName) {
189
+ providerName = clientParam.providerName;
190
+ if (['devnet', 'mainnet', 'testnet', 'localnet'].indexOf(clientParam.providerName) === -1) {
191
+ providerName = 'sui:'+clientParam.providerName; // no prefix - add prefix
192
+ }
193
+ } else if (url.indexOf('devnet') !== -1) {
165
194
  providerName = 'sui:devnet';
166
195
  } else if (url.indexOf('testnet') !== -1) {
167
196
  providerName = 'sui:testnet';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "suidouble",
3
- "version": "1.9.0",
3
+ "version": "1.12.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": {
@@ -21,7 +21,7 @@
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.9.0",
24
+ "@mysten/sui": "^1.12.0",
25
25
  "@wallet-standard/core": "^1.0.3",
26
26
  "websocket": "^1.0.35"
27
27
  },
@@ -0,0 +1,38 @@
1
+ 'use strict'
2
+
3
+ const t = require('tap');
4
+ const { test } = t;
5
+
6
+ const { SuiMaster } = require('..');
7
+
8
+ let suiMaster = null;
9
+
10
+ test('spawn local test node', async t => {
11
+ const rpcClient = SuiMaster.SuiUtils.suiClientForRPC({
12
+ chain: 'mainnet',
13
+ url: 'https://fullnode.mainnet.sui.io',
14
+ rpc: {
15
+ // headers: {"x-allthatnode-api-key": "xxxxxxxxxx"},
16
+ }
17
+ });
18
+
19
+ const suiMaster = new SuiMaster({
20
+ client: rpcClient,
21
+ as: 'somebody', // pseudo-address
22
+ });
23
+ await suiMaster.initialize();
24
+
25
+ t.ok(suiMaster.address); // there should be some address
26
+ t.ok(`${suiMaster.address}`.indexOf('0x') === 0); // adress is string starting with '0x'
27
+
28
+
29
+ const suiCoin = suiMaster.suiCoins.get('sui');
30
+ await suiCoin.getMetadata();
31
+
32
+ const balance = await suiCoin.getBalance('0xac5bceec1b789ff840d7d4e6ce4ce61c90d190a7f8c4f4ddf0bff6ee2413c33c');
33
+
34
+ t.ok(balance > 0n);
35
+ });
36
+
37
+ test('stops', async t => {
38
+ });