@leofcoin/launch-chain 0.2.6 → 0.2.8
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/index.d.ts +1 -1
- package/index.js +66 -40
- package/package.json +2 -2
- package/src/index.ts +70 -43
- package/test.js +1 -3
package/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import Chain from '@leofcoin/chain/chain';
|
|
2
2
|
import WSClient from '@leofcoin/endpoint-clients/ws';
|
|
3
3
|
import HttpClient from '@leofcoin/endpoint-clients/http';
|
|
4
|
-
type launchMode = 'direct' | 'remote';
|
|
4
|
+
type launchMode = 'direct' | 'remote' | 'server';
|
|
5
5
|
type endpointReturns = {
|
|
6
6
|
http?: string[];
|
|
7
7
|
ws?: string[];
|
package/index.js
CHANGED
|
@@ -72,72 +72,98 @@ const launch = async (options, password) => {
|
|
|
72
72
|
options = defaultOptions;
|
|
73
73
|
else
|
|
74
74
|
options = { ...defaultOptions, ...options };
|
|
75
|
-
const
|
|
75
|
+
const clients = {
|
|
76
76
|
http: [],
|
|
77
77
|
ws: []
|
|
78
78
|
};
|
|
79
|
-
const
|
|
79
|
+
const endpoints = {
|
|
80
80
|
http: [],
|
|
81
81
|
ws: []
|
|
82
82
|
};
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
83
|
+
let chain;
|
|
84
|
+
if (options.mode === 'remote') {
|
|
85
|
+
if (options.http) {
|
|
86
|
+
for (const endpoint of options.http) {
|
|
87
|
+
if (endpoint.port && !endpoint.url)
|
|
88
|
+
endpoint.url = `http://localhost:${endpoint.port}`;
|
|
89
|
+
const client = await getHttp(endpoint.url, options.networkVersion);
|
|
90
|
+
if (client)
|
|
91
|
+
endpoints.http.push(endpoint.url) && clients.http.push({ url: endpoint.url, client });
|
|
92
|
+
}
|
|
90
93
|
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
94
|
+
if (options.ws) {
|
|
95
|
+
for (const endpoint of options.ws) {
|
|
96
|
+
if (endpoint.port && !endpoint.url)
|
|
97
|
+
endpoint.url = `ws://localhost:${endpoint.port}`;
|
|
98
|
+
const client = await getWS(endpoint.url, options.networkVersion);
|
|
99
|
+
if (client)
|
|
100
|
+
endpoints.ws.push(endpoint.url) && clients.ws.push({ url: endpoint.url, client });
|
|
101
|
+
}
|
|
99
102
|
}
|
|
103
|
+
if (endpoints.http.length === 0 && endpoints.ws.length === 0)
|
|
104
|
+
throw new Error(`no remotes connected`);
|
|
100
105
|
}
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
106
|
+
else if (options.mode === 'direct') {
|
|
107
|
+
await new Node({ network: options.network, stars: options.stars, networkVersion: options.networkVersion }, password);
|
|
108
|
+
await nodeConfig({ network: options.network, stars: options.stars, networkVersion: options.networkVersion });
|
|
109
|
+
chain = await new Chain();
|
|
110
|
+
if (options.ws) {
|
|
111
|
+
const importee = await import('@leofcoin/endpoints/ws');
|
|
112
|
+
const wsServer = importee.default;
|
|
113
|
+
for (const endpoint of options.ws) {
|
|
114
|
+
if (endpoint.port && !endpoint.url)
|
|
115
|
+
endpoint.url = `ws://localhost:${endpoint.port}`;
|
|
116
|
+
await wsServer(chain, endpoint.port, options.networkVersion);
|
|
117
|
+
endpoints.ws.push(endpoint.url);
|
|
118
|
+
const client = await getWS(endpoint.url, options.networkVersion);
|
|
119
|
+
if (client)
|
|
120
|
+
endpoints.ws.push(endpoint.url) && clients.ws.push({ url: endpoint.url, client });
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
if (options.http) {
|
|
124
|
+
const importee = await import('@leofcoin/endpoints/http');
|
|
125
|
+
const httpServer = importee.default;
|
|
126
|
+
for (const endpoint of options.http) {
|
|
127
|
+
if (endpoint.port && !endpoint.url)
|
|
128
|
+
endpoint.url = `http://localhost:${endpoint.port}`;
|
|
129
|
+
await httpServer(chain, endpoint.port, options.networkVersion);
|
|
130
|
+
endpoints.http.push(endpoint.url);
|
|
131
|
+
const client = await getHttp(endpoint.url, options.networkVersion);
|
|
132
|
+
if (client)
|
|
133
|
+
endpoints.http.push(endpoint.url) && clients.http.push({ url: endpoint.url, client });
|
|
134
|
+
}
|
|
135
|
+
}
|
|
115
136
|
}
|
|
116
137
|
else {
|
|
117
|
-
if (options.forceRemote)
|
|
118
|
-
throw new Error(`forceRemote was set but no remotes connected`);
|
|
119
138
|
await new Node({ network: options.network, stars: options.stars, networkVersion: options.networkVersion }, password);
|
|
120
139
|
await nodeConfig({ network: options.network, stars: options.stars, networkVersion: options.networkVersion });
|
|
121
140
|
chain = await new Chain();
|
|
122
141
|
if (options.ws) {
|
|
123
142
|
const importee = await import('@leofcoin/endpoints/ws');
|
|
124
143
|
const wsServer = importee.default;
|
|
125
|
-
|
|
126
|
-
|
|
144
|
+
for (const endpoint of options.ws) {
|
|
145
|
+
if (endpoint.port && !endpoint.url)
|
|
146
|
+
endpoint.url = `ws://localhost:${endpoint.port}`;
|
|
147
|
+
await wsServer(chain, endpoint.port, options.networkVersion);
|
|
148
|
+
endpoints.ws.push(endpoint.url);
|
|
149
|
+
}
|
|
127
150
|
}
|
|
128
151
|
if (options.http) {
|
|
129
152
|
const importee = await import('@leofcoin/endpoints/http');
|
|
130
153
|
const httpServer = importee.default;
|
|
131
|
-
|
|
132
|
-
|
|
154
|
+
for (const endpoint of options.http) {
|
|
155
|
+
if (endpoint.port && !endpoint.url)
|
|
156
|
+
endpoint.url = `http://localhost:${endpoint.port}`;
|
|
157
|
+
await httpServer(chain, endpoint.port, options.networkVersion);
|
|
158
|
+
endpoints.http.push(endpoint.url);
|
|
159
|
+
}
|
|
133
160
|
}
|
|
134
|
-
mode = 'direct';
|
|
135
161
|
}
|
|
136
162
|
return {
|
|
137
163
|
chain,
|
|
138
|
-
mode,
|
|
164
|
+
mode: options.mode,
|
|
139
165
|
endpoints,
|
|
140
|
-
clients
|
|
166
|
+
clients
|
|
141
167
|
};
|
|
142
168
|
};
|
|
143
169
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leofcoin/launch-chain",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.8",
|
|
4
4
|
"description": "",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./index.js"
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"dependencies": {
|
|
26
26
|
"@leofcoin/chain": "^1.4.8",
|
|
27
27
|
"@leofcoin/endpoint-clients": "^0.2.3",
|
|
28
|
-
"@leofcoin/endpoints": "^0.2.
|
|
28
|
+
"@leofcoin/endpoints": "^0.2.10"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
31
|
"@rollup/plugin-typescript": "^11.0.0",
|
package/src/index.ts
CHANGED
|
@@ -4,7 +4,7 @@ import nodeConfig from '@leofcoin/lib/node-config'
|
|
|
4
4
|
import WSClient from '@leofcoin/endpoint-clients/ws'
|
|
5
5
|
import HttpClient from '@leofcoin/endpoint-clients/http'
|
|
6
6
|
|
|
7
|
-
type launchMode = 'direct' | 'remote'
|
|
7
|
+
type launchMode = 'direct' | 'remote' | 'server'
|
|
8
8
|
|
|
9
9
|
type endpointReturns = {
|
|
10
10
|
http?: string[],
|
|
@@ -38,7 +38,7 @@ type launchOptions = {
|
|
|
38
38
|
http?: endpointOptions[] | undefined,
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
-
const defaultOptions:launchOptions = {
|
|
41
|
+
const defaultOptions: launchOptions = {
|
|
42
42
|
network: 'leofcoin:peach',
|
|
43
43
|
networkVersion: 'peach',
|
|
44
44
|
stars: ['wss://peach.leofcoin.org'],
|
|
@@ -119,53 +119,71 @@ const launch = async (options: launchOptions, password: string): Promise<launchR
|
|
|
119
119
|
if (!options) options = defaultOptions
|
|
120
120
|
else options = {...defaultOptions, ...options }
|
|
121
121
|
|
|
122
|
-
const
|
|
122
|
+
const clients: clientReturns = {
|
|
123
123
|
http: [],
|
|
124
124
|
ws: []
|
|
125
125
|
}
|
|
126
126
|
|
|
127
|
-
const
|
|
127
|
+
const endpoints: endpointReturns = {
|
|
128
128
|
http: [],
|
|
129
129
|
ws: []
|
|
130
130
|
}
|
|
131
131
|
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
132
|
+
let chain: Chain
|
|
133
|
+
|
|
134
|
+
if (options.mode === 'remote') {
|
|
135
|
+
if (options.http) {
|
|
136
|
+
for (const endpoint of options.http) {
|
|
137
|
+
if (endpoint.port && !endpoint.url) endpoint.url = `http://localhost:${endpoint.port}`
|
|
138
|
+
const client = await getHttp(endpoint.url, options.networkVersion)
|
|
139
|
+
if (client) endpoints.http.push(endpoint.url) && clients.http.push({url: endpoint.url, client})
|
|
140
|
+
}
|
|
137
141
|
}
|
|
138
|
-
|
|
142
|
+
|
|
143
|
+
if (options.ws) {
|
|
144
|
+
for (const endpoint of options.ws) {
|
|
145
|
+
if (endpoint.port && !endpoint.url) endpoint.url = `ws://localhost:${endpoint.port}`
|
|
146
|
+
const client = await getWS(endpoint.url, options.networkVersion)
|
|
147
|
+
if (client) endpoints.ws.push(endpoint.url) && clients.ws.push({url: endpoint.url, client})
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
if (endpoints.http.length === 0 && endpoints.ws.length === 0) throw new Error(`no remotes connected`)
|
|
151
|
+
} else if (options.mode === 'direct') {
|
|
152
|
+
await new Node({ network: options.network, stars: options.stars, networkVersion: options.networkVersion }, password)
|
|
153
|
+
await nodeConfig({ network: options.network, stars: options.stars, networkVersion: options.networkVersion })
|
|
139
154
|
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
const
|
|
144
|
-
|
|
155
|
+
chain = await new Chain()
|
|
156
|
+
|
|
157
|
+
if (options.ws) {
|
|
158
|
+
const importee = await import('@leofcoin/endpoints/ws')
|
|
159
|
+
const wsServer = importee.default
|
|
160
|
+
|
|
161
|
+
for (const endpoint of options.ws) {
|
|
162
|
+
if (endpoint.port && !endpoint.url) endpoint.url = `ws://localhost:${endpoint.port}`
|
|
163
|
+
|
|
164
|
+
await wsServer(chain, endpoint.port, options.networkVersion)
|
|
165
|
+
endpoints.ws.push(endpoint.url)
|
|
166
|
+
|
|
167
|
+
const client = await getWS(endpoint.url, options.networkVersion)
|
|
168
|
+
if (client) endpoints.ws.push(endpoint.url) && clients.ws.push({url: endpoint.url, client})
|
|
169
|
+
}
|
|
145
170
|
}
|
|
146
|
-
}
|
|
147
171
|
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
}
|
|
172
|
+
if (options.http) {
|
|
173
|
+
const importee = await import('@leofcoin/endpoints/http')
|
|
174
|
+
const httpServer = importee.default
|
|
152
175
|
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
mode = 'remote'
|
|
166
|
-
} else {
|
|
167
|
-
if (options.forceRemote) throw new Error(`forceRemote was set but no remotes connected`)
|
|
168
|
-
|
|
176
|
+
for (const endpoint of options.http) {
|
|
177
|
+
if (endpoint.port && !endpoint.url) endpoint.url = `http://localhost:${endpoint.port}`
|
|
178
|
+
|
|
179
|
+
await httpServer(chain, endpoint.port, options.networkVersion)
|
|
180
|
+
endpoints.http.push(endpoint.url)
|
|
181
|
+
|
|
182
|
+
const client = await getHttp(endpoint.url, options.networkVersion)
|
|
183
|
+
if (client) endpoints.http.push(endpoint.url) && clients.http.push({url: endpoint.url, client})
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
} else {
|
|
169
187
|
await new Node({ network: options.network, stars: options.stars, networkVersion: options.networkVersion }, password)
|
|
170
188
|
await nodeConfig({ network: options.network, stars: options.stars, networkVersion: options.networkVersion })
|
|
171
189
|
|
|
@@ -174,22 +192,31 @@ const launch = async (options: launchOptions, password: string): Promise<launchR
|
|
|
174
192
|
if (options.ws) {
|
|
175
193
|
const importee = await import('@leofcoin/endpoints/ws')
|
|
176
194
|
const wsServer = importee.default
|
|
177
|
-
|
|
178
|
-
|
|
195
|
+
|
|
196
|
+
for (const endpoint of options.ws) {
|
|
197
|
+
if (endpoint.port && !endpoint.url) endpoint.url = `ws://localhost:${endpoint.port}`
|
|
198
|
+
await wsServer(chain, endpoint.port, options.networkVersion)
|
|
199
|
+
endpoints.ws.push(endpoint.url)
|
|
200
|
+
}
|
|
179
201
|
}
|
|
202
|
+
|
|
180
203
|
if (options.http) {
|
|
181
204
|
const importee = await import('@leofcoin/endpoints/http')
|
|
182
205
|
const httpServer = importee.default
|
|
183
|
-
|
|
184
|
-
|
|
206
|
+
|
|
207
|
+
for (const endpoint of options.http) {
|
|
208
|
+
if (endpoint.port && !endpoint.url) endpoint.url = `http://localhost:${endpoint.port}`
|
|
209
|
+
await httpServer(chain, endpoint.port, options.networkVersion)
|
|
210
|
+
endpoints.http.push(endpoint.url)
|
|
211
|
+
}
|
|
185
212
|
}
|
|
186
|
-
mode = 'direct'
|
|
187
213
|
}
|
|
214
|
+
|
|
188
215
|
return {
|
|
189
216
|
chain,
|
|
190
|
-
mode,
|
|
217
|
+
mode: options.mode,
|
|
191
218
|
endpoints,
|
|
192
|
-
clients
|
|
219
|
+
clients
|
|
193
220
|
}
|
|
194
221
|
}
|
|
195
222
|
|
package/test.js
CHANGED
|
@@ -3,8 +3,6 @@ import launch from './index.js'
|
|
|
3
3
|
const {chain, endpoints, clients, mode } = await launch({
|
|
4
4
|
network: 'leofcoin:peach',
|
|
5
5
|
networkVersion: 'peach',
|
|
6
|
-
|
|
7
|
-
ws: [{ url:'wss://ws-remote.leofcoin.org'}],
|
|
8
|
-
http: [{ url: 'https://remote.leofcoin.org' }]
|
|
6
|
+
mode: 'direct'
|
|
9
7
|
})
|
|
10
8
|
console.log(await clients.ws[0].client.networkStats());
|