suidouble 1.11.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/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/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.11.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.11.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
+ });