@leofcoin/launch-chain 0.3.4 → 0.3.6

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/LICENSE CHANGED
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) 2022 vandeurenglenn
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ MIT License
2
+
3
+ Copyright (c) 2022 vandeurenglenn
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,11 +1,13 @@
1
1
  # lauch-chain
2
+
2
3
  > launch chain & peernet (reuses exposed transports when already running)
3
4
 
4
5
  ## usage
6
+
5
7
  ```js
6
8
  import launch from '@leofcoin/launch-chain'
7
9
 
8
- const {chain, endpoints, mode} = await launch()
10
+ const { chain, endpoints, mode } = await launch()
9
11
  // chain is undefined when mode is remote
10
12
  // endpoints contain urls to connect to the desired remote
11
13
  // when mode is remote means an instance is already running
@@ -13,6 +15,7 @@ const {chain, endpoints, mode} = await launch()
13
15
  ```
14
16
 
15
17
  ## options
18
+
16
19
  ### default
17
20
 
18
21
  ```js
@@ -31,7 +34,8 @@ const {chain, endpoints, mode} = await launch()
31
34
  }
32
35
  ```
33
36
 
34
- ### disabling options
37
+ ### disabling options
38
+
35
39
  ```js
36
40
  stars: [] // note that disabling stars results in no peer discovery
37
41
  {
@@ -41,22 +45,21 @@ stars: [] // note that disabling stars results in no peer discovery
41
45
  ```
42
46
 
43
47
  ## build for browser
48
+
44
49
  no prebuild are provided since the esm switch, everything is written with the browser in mind so some simple ignores are enough to build.
45
50
 
46
51
  ### rollup
52
+
47
53
  ```js
48
- external: [
49
- '@koush/wrtc',
50
- '@leofcoin/endpoints/ws',
51
- '@leofcoin/endpoints/http'
52
- ]
54
+ external: ['@koush/wrtc', '@leofcoin/endpoints/ws', '@leofcoin/endpoints/http']
53
55
  ```
54
56
 
55
57
  ### webpack
58
+
56
59
  ```js
57
- externals: {
60
+ externals: {
58
61
  '@koush/wrtc': false,
59
62
  '@leofcoin/endpoints/ws': false,
60
63
  '@leofcoin/endpoints/http': false
61
64
  }
62
- ```
65
+ ```
@@ -11,12 +11,16 @@ const defaultOptions = {
11
11
  stars: networks.leofcoin.peach.stars,
12
12
  forceRemote: false,
13
13
  mode: 'direct',
14
- ws: [{
14
+ ws: [
15
+ {
15
16
  port: 4040
16
- }],
17
- http: [{
17
+ }
18
+ ],
19
+ http: [
20
+ {
18
21
  port: 8080
19
- }]
22
+ }
23
+ ]
20
24
  };
21
25
  /**
22
26
  *
@@ -106,7 +110,7 @@ const launch = async (options, password) => {
106
110
  else if (options.mode === 'direct') {
107
111
  await new Node({ network: options.network, stars: options.stars, networkVersion: options.networkVersion }, password);
108
112
  await nodeConfig({ network: options.network, stars: options.stars, networkVersion: options.networkVersion });
109
- chain = await new Chain();
113
+ chain = await new Chain({ network: options.network, stars: options.stars, networkVersion: options.networkVersion });
110
114
  if (options.ws) {
111
115
  const importee = await import('@leofcoin/endpoints/ws');
112
116
  const wsServer = importee.default;
@@ -135,7 +139,7 @@ const launch = async (options, password) => {
135
139
  else {
136
140
  await new Node({ network: options.network, stars: options.stars, networkVersion: options.networkVersion }, password);
137
141
  await nodeConfig({ network: options.network, stars: options.stars, networkVersion: options.networkVersion });
138
- chain = await new Chain();
142
+ chain = await new Chain({ network: options.network, stars: options.stars, networkVersion: options.networkVersion });
139
143
  if (options.ws) {
140
144
  const importee = await import('@leofcoin/endpoints/ws');
141
145
  const wsServer = importee.default;
package/package.json CHANGED
@@ -1,36 +1,41 @@
1
- {
2
- "name": "@leofcoin/launch-chain",
3
- "version": "0.3.4",
4
- "description": "",
5
- "exports": {
6
- ".": "./index.js"
7
- },
8
- "types": "./index.d.ts",
9
- "type": "module",
10
- "scripts": {
11
- "build": "rollup -c",
12
- "test": "echo \"Error: no test specified\" && exit 1"
13
- },
14
- "repository": {
15
- "type": "git",
16
- "url": "git+https://github.com/leofcoin/launch-chain.git"
17
- },
18
- "keywords": [],
19
- "author": "",
20
- "license": "MIT",
21
- "bugs": {
22
- "url": "https://github.com/leofcoin/launch-chain/issues"
23
- },
24
- "homepage": "https://github.com/leofcoin/launch-chain#readme",
25
- "dependencies": {
26
- "@leofcoin/chain": "^1.4.8",
27
- "@leofcoin/endpoint-clients": "^0.3.5",
28
- "@leofcoin/endpoints": "^0.2.10",
29
- "@leofcoin/networks": "^1.0.0"
30
- },
31
- "devDependencies": {
32
- "@rollup/plugin-typescript": "^11.0.0",
33
- "rollup": "^3.9.1",
34
- "tslib": "^2.4.1"
35
- }
36
- }
1
+ {
2
+ "name": "@leofcoin/launch-chain",
3
+ "version": "0.3.6",
4
+ "description": "",
5
+ "exports": {
6
+ ".": {
7
+ "import": "./exports/index.js",
8
+ "types": "./exports/index.d.ts"
9
+ }
10
+ },
11
+ "files": [
12
+ "exports"
13
+ ],
14
+ "type": "module",
15
+ "scripts": {
16
+ "build": "rollup -c",
17
+ "test": "echo \"Error: no test specified\" && exit 1"
18
+ },
19
+ "repository": {
20
+ "type": "git",
21
+ "url": "git+https://github.com/leofcoin/launch-chain.git"
22
+ },
23
+ "keywords": [],
24
+ "author": "",
25
+ "license": "MIT",
26
+ "bugs": {
27
+ "url": "https://github.com/leofcoin/launch-chain/issues"
28
+ },
29
+ "homepage": "https://github.com/leofcoin/launch-chain#readme",
30
+ "dependencies": {
31
+ "@leofcoin/chain": "^1.6.2",
32
+ "@leofcoin/endpoint-clients": "^0.3.9",
33
+ "@leofcoin/endpoints": "^0.3.3",
34
+ "@leofcoin/networks": "^1.1.5"
35
+ },
36
+ "devDependencies": {
37
+ "@rollup/plugin-typescript": "^11.1.6",
38
+ "rollup": "^4.12.1",
39
+ "tslib": "^2.6.2"
40
+ }
41
+ }
package/.gitattributes DELETED
@@ -1,2 +0,0 @@
1
- # Auto detect text files and perform LF normalization
2
- * text=auto
package/rollup.config.js DELETED
@@ -1,13 +0,0 @@
1
- import typescript from '@rollup/plugin-typescript';
2
- import tsconfig from './tsconfig.json' assert { type: 'json'};
3
-
4
- export default [{
5
- input: ['./src/index.ts'],
6
- output: {
7
- format: 'es',
8
- dir: './'
9
- },
10
- plugins: [
11
- typescript(tsconfig)
12
- ]
13
- }]
package/src/index.ts DELETED
@@ -1,224 +0,0 @@
1
- import Node from '@leofcoin/chain/node'
2
- import Chain from '@leofcoin/chain/chain'
3
- import nodeConfig from '@leofcoin/lib/node-config'
4
- import WSClient from '@leofcoin/endpoint-clients/ws'
5
- import HttpClient from '@leofcoin/endpoint-clients/http'
6
- import networks from '@leofcoin/networks'
7
-
8
- type launchMode = 'direct' | 'remote' | 'server'
9
-
10
- type endpointReturns = {
11
- http?: string[],
12
- ws?: string[],
13
- }
14
-
15
- type clientReturns = {
16
- http?: HttpClient[],
17
- ws?: WSClient[],
18
- }
19
-
20
- type launchReturn = {
21
- chain: Chain,
22
- mode: launchMode,
23
- endpoints: endpointReturns,
24
- clients: clientReturns
25
- }
26
-
27
- type endpointOptions = {
28
- port: number,
29
- url?: string
30
- }
31
-
32
- type launchOptions = {
33
- network?: string,
34
- networkVersion?: string,
35
- stars: string[],
36
- forceRemote: boolean,
37
- mode?: launchMode,
38
- ws?: endpointOptions[] | undefined,
39
- http?: endpointOptions[] | undefined,
40
- }
41
-
42
- const defaultOptions: launchOptions = {
43
- network: 'leofcoin:peach',
44
- networkVersion: 'peach',
45
- stars: networks.leofcoin.peach.stars,
46
- forceRemote: false,
47
- mode: 'direct',
48
- ws: [{
49
- port: 4040
50
- }],
51
- http: [{
52
- port: 8080
53
- }]
54
- }
55
-
56
- /**
57
- *
58
- * @param {string} url
59
- * @param {string} networkVersion network/testnet-network sepperate by -
60
- * @returns Promise(boolean)
61
- */
62
- const getHttp = async (url: string, networkVersion: string): Promise<undefined | HttpClient> => {
63
- try {
64
- const client = new HttpClient(url, networkVersion)
65
- await client.network()
66
- return client
67
- } catch (error) {
68
- return undefined
69
- }
70
- }
71
-
72
- const tryWs = (url: string, networkVersion: string): Promise<WSClient> => new Promise(async (resolve, reject) => {
73
- try {
74
- const socket = await new WSClient(url, networkVersion)
75
- await socket.init()
76
- resolve(socket)
77
- } catch (error) {
78
- reject(error)
79
- }
80
- })
81
-
82
- /**
83
- *
84
- * @param {string} url
85
- * @param {string} networkVersion network/testnet-network sepperate by -
86
- * @returns Promise(boolean)
87
- */
88
- const getWS = async (url: string, networkVersion: string): Promise<WSClient> => {
89
- try {
90
- const ws = await tryWs(url, networkVersion)
91
- return ws
92
- } catch (error) {
93
- return undefined
94
- }
95
- }
96
-
97
- /**
98
- *
99
- * @param {string} httpURL
100
- * @param {string} wsURL
101
- * @param {string} networkVersion
102
- * @returns Promise({http: boolean, ws: boolean})
103
- */
104
- const hasClient = async (httpURL: string, wsURL: string, networkVersion: string) => {
105
- const ws = await getWS(wsURL, networkVersion)
106
- const http = await getHttp(httpURL, networkVersion)
107
- return {http, ws}
108
- }
109
-
110
- // chain is undefined when mode is remote
111
- // endpoints contain urls to connect to the desired remote
112
- // when mode is remote means an instance is already running
113
- // when mode is direct means chain is directly available and no endpoint is needed to interact with it
114
- /**
115
- *
116
- * @param {object} options { ws: boolean || {url: string, port: number}, http: boolean || {url: string, port: number}, network}
117
- * @returns '{ mode: string, endpoints: object, chain}'
118
- */
119
- const launch = async (options: launchOptions, password: string): Promise<launchReturn> => {
120
- if (!options) options = defaultOptions
121
- else options = {...defaultOptions, ...options }
122
-
123
- const clients: clientReturns = {
124
- http: [],
125
- ws: []
126
- }
127
-
128
- const endpoints: endpointReturns = {
129
- http: [],
130
- ws: []
131
- }
132
-
133
- let chain: Chain
134
-
135
- if (options.mode === 'remote') {
136
- if (options.http) {
137
- for (const endpoint of options.http) {
138
- if (endpoint.port && !endpoint.url) endpoint.url = `http://localhost:${endpoint.port}`
139
- const client = await getHttp(endpoint.url, options.networkVersion)
140
- if (client) endpoints.http.push(endpoint.url) && clients.http.push(client)
141
- }
142
- }
143
-
144
- if (options.ws) {
145
- for (const endpoint of options.ws) {
146
- if (endpoint.port && !endpoint.url) endpoint.url = `ws://localhost:${endpoint.port}`
147
- const client = await getWS(endpoint.url, options.networkVersion)
148
- client && endpoints.ws.push(endpoint.url) && clients.ws.push(client)
149
- }
150
- }
151
- if (endpoints.http.length === 0 && endpoints.ws.length === 0) throw new Error(`no remotes connected`)
152
- } else if (options.mode === 'direct') {
153
- await new Node({ network: options.network, stars: options.stars, networkVersion: options.networkVersion }, password)
154
- await nodeConfig({ network: options.network, stars: options.stars, networkVersion: options.networkVersion })
155
-
156
- chain = await new Chain()
157
-
158
- if (options.ws) {
159
- const importee = await import('@leofcoin/endpoints/ws')
160
- const wsServer = importee.default
161
-
162
- for (const endpoint of options.ws) {
163
- if (endpoint.port && !endpoint.url) endpoint.url = `ws://localhost:${endpoint.port}`
164
-
165
- await wsServer(chain, endpoint.port, options.networkVersion)
166
- endpoints.ws.push(endpoint.url)
167
-
168
- const client = await getWS(endpoint.url, options.networkVersion)
169
- client && clients.ws.push(client)
170
- }
171
- }
172
-
173
- if (options.http) {
174
- const importee = await import('@leofcoin/endpoints/http')
175
- const httpServer = importee.default
176
-
177
- for (const endpoint of options.http) {
178
- if (endpoint.port && !endpoint.url) endpoint.url = `http://localhost:${endpoint.port}`
179
-
180
- await httpServer(chain, endpoint.port, options.networkVersion)
181
- endpoints.http.push(endpoint.url)
182
-
183
- const client = await getHttp(endpoint.url, options.networkVersion)
184
- client && clients.http.push(client)
185
- }
186
- }
187
- } else {
188
- await new Node({ network: options.network, stars: options.stars, networkVersion: options.networkVersion }, password)
189
- await nodeConfig({ network: options.network, stars: options.stars, networkVersion: options.networkVersion })
190
-
191
- chain = await new Chain()
192
-
193
- if (options.ws) {
194
- const importee = await import('@leofcoin/endpoints/ws')
195
- const wsServer = importee.default
196
-
197
- for (const endpoint of options.ws) {
198
- if (endpoint.port && !endpoint.url) endpoint.url = `ws://localhost:${endpoint.port}`
199
- await wsServer(chain, endpoint.port, options.networkVersion)
200
- endpoints.ws.push(endpoint.url)
201
- }
202
- }
203
-
204
- if (options.http) {
205
- const importee = await import('@leofcoin/endpoints/http')
206
- const httpServer = importee.default
207
-
208
- for (const endpoint of options.http) {
209
- if (endpoint.port && !endpoint.url) endpoint.url = `http://localhost:${endpoint.port}`
210
- await httpServer(chain, endpoint.port, options.networkVersion)
211
- endpoints.http.push(endpoint.url)
212
- }
213
- }
214
- }
215
-
216
- return {
217
- chain,
218
- mode: options.mode,
219
- endpoints,
220
- clients
221
- }
222
- }
223
-
224
- export { launch as default}
package/test.js DELETED
@@ -1,8 +0,0 @@
1
- import launch from './index.js'
2
-
3
- const {chain, endpoints, clients, mode } = await launch({
4
- network: 'leofcoin:peach',
5
- networkVersion: 'peach',
6
- mode: 'direct'
7
- })
8
- console.log(await clients.ws[0].networkStats());
package/tsconfig.json DELETED
@@ -1,14 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "target": "ESNext",
4
- "module": "NodeNext",
5
- "outDir": "./",
6
- "moduleResolution":"nodenext",
7
- "allowJs": true,
8
- "declaration": true
9
- },
10
- "include": [
11
- "./src/**/*"
12
- ],
13
- "exclude": ["./node_modules"]
14
- }
File without changes