@leofcoin/launch-chain 0.4.18 → 0.4.20

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/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # lauch-chain
1
+ # launch-chain
2
2
 
3
3
  > launch chain & peernet (reuses exposed transports when already running)
4
4
 
@@ -7,7 +7,10 @@
7
7
  ```js
8
8
  import launch from '@leofcoin/launch-chain'
9
9
 
10
- const { chain, endpoints, mode } = await launch()
10
+ const { chain, endpoints, mode } = await launch(
11
+ { mode: 'direct' },
12
+ process.env.LEOFCOIN_PASSWORD
13
+ )
11
14
  // chain is undefined when mode is remote
12
15
  // endpoints contain urls to connect to the desired remote
13
16
  // when mode is remote means an instance is already running
@@ -21,7 +24,7 @@ const { chain, endpoints, mode } = await launch()
21
24
  ```js
22
25
  {
23
26
  network: 'leofcoin:peach',
24
- stars: ['wss://peach.leofcoin.org'],
27
+ stars: ['wss://star.leofcoin.org'],
25
28
  forceRemote: false, // when set to true only tries to connect to an external/local exposed node
26
29
  ws: {
27
30
  port: 4040,
@@ -3,15 +3,15 @@ import WSClient from '@leofcoin/endpoint-clients/ws';
3
3
  import HttpClient from '@leofcoin/endpoint-clients/http';
4
4
  type launchMode = 'direct' | 'remote' | 'server';
5
5
  type endpointReturns = {
6
- http?: string[];
7
- ws?: string[];
6
+ http: string[];
7
+ ws: string[];
8
8
  };
9
9
  type clientReturns = {
10
- http?: HttpClient[];
11
- ws?: WSClient[];
10
+ http: HttpClient[];
11
+ ws: WSClient[];
12
12
  };
13
13
  type launchReturn = {
14
- chain: Chain;
14
+ chain?: Chain;
15
15
  mode: launchMode;
16
16
  endpoints: endpointReturns;
17
17
  clients: clientReturns;
@@ -23,8 +23,8 @@ type endpointOptions = {
23
23
  type launchOptions = {
24
24
  network?: string;
25
25
  networkVersion?: string;
26
- stars: string[];
27
- forceRemote: boolean;
26
+ stars?: string[];
27
+ forceRemote?: boolean;
28
28
  mode?: launchMode;
29
29
  ws?: endpointOptions[] | undefined;
30
30
  http?: endpointOptions[] | undefined;
@@ -34,5 +34,5 @@ type launchOptions = {
34
34
  * @param {object} options { ws: boolean || {url: string, port: number}, http: boolean || {url: string, port: number}, network}
35
35
  * @returns '{ mode: string, endpoints: object, chain}'
36
36
  */
37
- declare const launch: (options: launchOptions, password: string) => Promise<launchReturn>;
37
+ declare const launch: (input: launchOptions | undefined, password: string) => Promise<launchReturn>;
38
38
  export { launch as default };
package/exports/index.js CHANGED
@@ -72,11 +72,8 @@ const getWS = async (url, networkVersion) => {
72
72
  * @param {object} options { ws: boolean || {url: string, port: number}, http: boolean || {url: string, port: number}, network}
73
73
  * @returns '{ mode: string, endpoints: object, chain}'
74
74
  */
75
- const launch = async (options, password) => {
76
- if (!options)
77
- options = defaultOptions;
78
- else
79
- options = { ...defaultOptions, ...options };
75
+ const launch = async (input = {}, password) => {
76
+ const options = { ...defaultOptions, ...input };
80
77
  const clients = {
81
78
  http: [],
82
79
  ws: []
@@ -89,19 +86,22 @@ const launch = async (options, password) => {
89
86
  if (options.mode === 'remote') {
90
87
  if (options.http) {
91
88
  for (const endpoint of options.http) {
92
- if (endpoint.port && !endpoint.url)
93
- endpoint.url = `http://localhost:${endpoint.port}`;
94
- const client = await getHttp(endpoint.url, options.networkVersion);
95
- if (client)
96
- endpoints.http.push(endpoint.url) && clients.http.push(client);
89
+ const url = endpoint.url ?? `http://localhost:${endpoint.port}`;
90
+ const client = await getHttp(url, options.networkVersion);
91
+ if (client) {
92
+ endpoints.http.push(url);
93
+ clients.http.push(client);
94
+ }
97
95
  }
98
96
  }
99
97
  if (options.ws) {
100
98
  for (const endpoint of options.ws) {
101
- if (endpoint.port && !endpoint.url)
102
- endpoint.url = `ws://localhost:${endpoint.port}`;
103
- const client = await getWS(endpoint.url, options.networkVersion);
104
- client && endpoints.ws.push(endpoint.url) && clients.ws.push(client);
99
+ const url = endpoint.url ?? `ws://localhost:${endpoint.port}`;
100
+ const client = await getWS(url, options.networkVersion);
101
+ if (client) {
102
+ endpoints.ws.push(url);
103
+ clients.ws.push(client);
104
+ }
105
105
  }
106
106
  }
107
107
  if (endpoints.http.length === 0 && endpoints.ws.length === 0)
@@ -117,11 +117,10 @@ const launch = async (options, password) => {
117
117
  const importee = await import('@leofcoin/endpoints/ws');
118
118
  const wsServer = importee.default;
119
119
  for (const endpoint of options.ws) {
120
- if (endpoint.port && !endpoint.url)
121
- endpoint.url = `ws://localhost:${endpoint.port}`;
120
+ const url = endpoint.url ?? `ws://localhost:${endpoint.port}`;
122
121
  await wsServer(chain, endpoint.port, options.networkVersion);
123
- endpoints.ws.push(endpoint.url);
124
- const client = await getWS(endpoint.url, options.networkVersion);
122
+ endpoints.ws.push(url);
123
+ const client = await getWS(url, options.networkVersion);
125
124
  client && clients.ws.push(client);
126
125
  }
127
126
  }
@@ -129,11 +128,10 @@ const launch = async (options, password) => {
129
128
  const importee = await import('@leofcoin/endpoints/http');
130
129
  const httpServer = importee.default;
131
130
  for (const endpoint of options.http) {
132
- if (endpoint.port && !endpoint.url)
133
- endpoint.url = `http://localhost:${endpoint.port}`;
131
+ const url = endpoint.url ?? `http://localhost:${endpoint.port}`;
134
132
  await httpServer(chain, endpoint.port, options.networkVersion);
135
- endpoints.http.push(endpoint.url);
136
- const client = await getHttp(endpoint.url, options.networkVersion);
133
+ endpoints.http.push(url);
134
+ const client = await getHttp(url, options.networkVersion);
137
135
  client && clients.http.push(client);
138
136
  }
139
137
  }
@@ -148,20 +146,18 @@ const launch = async (options, password) => {
148
146
  const importee = await import('@leofcoin/endpoints/ws');
149
147
  const wsServer = importee.default;
150
148
  for (const endpoint of options.ws) {
151
- if (endpoint.port && !endpoint.url)
152
- endpoint.url = `ws://localhost:${endpoint.port}`;
149
+ const url = endpoint.url ?? `ws://localhost:${endpoint.port}`;
153
150
  await wsServer(chain, endpoint.port, options.networkVersion);
154
- endpoints.ws.push(endpoint.url);
151
+ endpoints.ws.push(url);
155
152
  }
156
153
  }
157
154
  if (options.http) {
158
155
  const importee = await import('@leofcoin/endpoints/http');
159
156
  const httpServer = importee.default;
160
157
  for (const endpoint of options.http) {
161
- if (endpoint.port && !endpoint.url)
162
- endpoint.url = `http://localhost:${endpoint.port}`;
158
+ const url = endpoint.url ?? `http://localhost:${endpoint.port}`;
163
159
  await httpServer(chain, endpoint.port, options.networkVersion);
164
- endpoints.http.push(endpoint.url);
160
+ endpoints.http.push(url);
165
161
  }
166
162
  }
167
163
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leofcoin/launch-chain",
3
- "version": "0.4.18",
3
+ "version": "0.4.20",
4
4
  "description": "",
5
5
  "exports": {
6
6
  ".": {
@@ -14,11 +14,12 @@
14
14
  "type": "module",
15
15
  "scripts": {
16
16
  "build": "rollup -c",
17
- "test": "echo \"Error: no test specified\" && exit 1"
17
+ "test": "node --test test/*.test.js"
18
18
  },
19
19
  "repository": {
20
20
  "type": "git",
21
- "url": "git+https://github.com/leofcoin/launch-chain.git"
21
+ "url": "https://github.com/leofcoin/monorepo.git",
22
+ "directory": "packages/launch-chain"
22
23
  },
23
24
  "keywords": [],
24
25
  "author": "",
@@ -26,16 +27,17 @@
26
27
  "bugs": {
27
28
  "url": "https://github.com/leofcoin/launch-chain/issues"
28
29
  },
29
- "homepage": "https://github.com/leofcoin/launch-chain#readme",
30
+ "homepage": "https://github.com/leofcoin/monorepo/tree/main/packages/launch-chain#readme",
30
31
  "dependencies": {
31
- "@leofcoin/chain": "^1.8.5",
32
+ "@leofcoin/chain": "^1.10.11",
32
33
  "@leofcoin/endpoint-clients": "^0.3.15",
33
34
  "@leofcoin/endpoints": "^0.4.8",
34
- "@leofcoin/networks": "^1.1.25"
35
+ "@leofcoin/networks": "^1.1.30"
35
36
  },
36
37
  "devDependencies": {
37
38
  "@rollup/plugin-typescript": "^12.3.0",
38
- "rollup": "^4.54.0",
39
- "tslib": "^2.8.1"
39
+ "rollup": "^4.62.4",
40
+ "tslib": "^2.8.1",
41
+ "typescript": "^6.0.3"
40
42
  }
41
43
  }