suidouble 1.11.0 → 1.13.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/SuiInBrowser.js +30 -5
- package/lib/SuiMaster.js +1 -0
- package/lib/SuiUtils.js +30 -1
- package/package.json +2 -2
- package/test/rpc.test.js +38 -0
package/lib/SuiInBrowser.js
CHANGED
|
@@ -25,6 +25,8 @@ class SuiInBrowser extends SuiCommonMethods {
|
|
|
25
25
|
this._client = null;
|
|
26
26
|
this._suiMaster = null;
|
|
27
27
|
|
|
28
|
+
this._rpcSettings = null;
|
|
29
|
+
|
|
28
30
|
setTimeout(()=>{
|
|
29
31
|
this.initialize();
|
|
30
32
|
}, 50);
|
|
@@ -119,6 +121,10 @@ class SuiInBrowser extends SuiCommonMethods {
|
|
|
119
121
|
const wasConnectedToChain = this._connectedChain;
|
|
120
122
|
this._connectedChain = suiInBrowserAdapter.connectedChain;
|
|
121
123
|
|
|
124
|
+
if (this._connectedChain == 'sui:unknown') {
|
|
125
|
+
this._connectedChain = 'sui:mainnet'; // custom RPC in Sui Wallet
|
|
126
|
+
}
|
|
127
|
+
|
|
122
128
|
if (this._connectedChain != wasConnectedToChain) {
|
|
123
129
|
this.log('chain was switched');
|
|
124
130
|
this._client = null;
|
|
@@ -130,6 +136,23 @@ class SuiInBrowser extends SuiCommonMethods {
|
|
|
130
136
|
this.emit('connected');
|
|
131
137
|
}
|
|
132
138
|
|
|
139
|
+
/**
|
|
140
|
+
* Switch connection to use custom RPC endpoint
|
|
141
|
+
* @param {Object} params parameters
|
|
142
|
+
* @param {string} params.url rpc url
|
|
143
|
+
* @param {Object} params.rpc rpc settings
|
|
144
|
+
* @param {Object.<string, string>} params.rpc.headers rpc headers
|
|
145
|
+
*/
|
|
146
|
+
async setRPC(params = {}) {
|
|
147
|
+
this._rpcSettings = params;
|
|
148
|
+
this._client = null;
|
|
149
|
+
this._suiMaster = null;
|
|
150
|
+
|
|
151
|
+
await this.initClient();
|
|
152
|
+
|
|
153
|
+
this.emit('rpc');
|
|
154
|
+
}
|
|
155
|
+
|
|
133
156
|
adapterDisconnected(suiInBrowserAdapter) {
|
|
134
157
|
this._isConnected = false;
|
|
135
158
|
this._connectedAddress = null;
|
|
@@ -181,13 +204,17 @@ class SuiInBrowser extends SuiCommonMethods {
|
|
|
181
204
|
const chainSettings = SuiInBrowser.getChainsSettings();
|
|
182
205
|
// https://github.com/MystenLabs/sui/blob/827f1138a09190975172ec99389751ca95cce5df/sdk/typescript/src/rpc/connection.ts#L32
|
|
183
206
|
|
|
184
|
-
if (
|
|
207
|
+
if (this._rpcSettings) {
|
|
208
|
+
this._rpcSettings.providerName = chainName.split('sui:').join('');
|
|
209
|
+
this._client = SuiMaster.SuiUtils.suiClientForRPC(this._rpcSettings);
|
|
210
|
+
} else if (!chainSettings[chainName]) {
|
|
185
211
|
this.log('error', 'invalid chain', chainName);
|
|
186
212
|
throw new Error('invalid chain: '+chainName);
|
|
213
|
+
} else {
|
|
214
|
+
this._client = new SuiClient({url: chainSettings[chainName].fullnode});
|
|
215
|
+
this._client.endpoint = chainSettings[chainName].fullnode;
|
|
187
216
|
}
|
|
188
217
|
|
|
189
|
-
this._client = new SuiClient({url: chainSettings[chainName].fullnode});
|
|
190
|
-
this._client.endpoint = chainSettings[chainName].fullnode;
|
|
191
218
|
this._suiMaster = new SuiMaster({
|
|
192
219
|
debug: this._debug,
|
|
193
220
|
signer: this,
|
|
@@ -218,8 +245,6 @@ class SuiInBrowser extends SuiCommonMethods {
|
|
|
218
245
|
});
|
|
219
246
|
}
|
|
220
247
|
});
|
|
221
|
-
|
|
222
|
-
|
|
223
248
|
}
|
|
224
249
|
|
|
225
250
|
static getChainsSettings() {
|
package/lib/SuiMaster.js
CHANGED
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 (
|
|
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.
|
|
3
|
+
"version": "1.13.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.
|
|
24
|
+
"@mysten/sui": "^1.13.0",
|
|
25
25
|
"@wallet-standard/core": "^1.0.3",
|
|
26
26
|
"websocket": "^1.0.35"
|
|
27
27
|
},
|
package/test/rpc.test.js
ADDED
|
@@ -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
|
+
});
|