@leofcoin/endpoint-clients 0.3.7 → 0.3.9

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
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
21
  SOFTWARE.
package/README.md CHANGED
@@ -1,208 +1,208 @@
1
- # endpoint-clients
2
-
3
- ## install
4
- ```sh
5
- npm i @leofcoin/endpoint-clients
6
- ```
7
-
8
- ## usage
9
- ```js
10
- import WsClient from '@leofcoin/endpoint-clients/ws'
11
- import HttpClient from '@leofcoin/endpoint-clients/http'
12
-
13
- const networkVersion = 'peach'
14
-
15
- const ws = new WsClient('ws://localhost:4040', networkVersion)
16
- const http = new HttpClient('http://localhost:8080', networkVersion)
17
- ```
18
-
19
- ## api
20
- ### new Client(url, networkVersion)
21
- #### selectAccount(address: `string`)
22
- `address`: desired address
23
- > set default account to given address
24
- ```js
25
- await client.selectAccount(address)
26
- ```
27
- <br>
28
-
29
- #### getBlock(index: `number`)
30
- `index`: index of the block to fetch<br>
31
- ```js
32
- await client.getBlock(10)
33
- ```
34
- <br>
35
-
36
- #### blocks(amount)
37
- `amount`: the amount to slice
38
- ```js
39
- await client.blocks(-25)
40
- ```
41
- <br>
42
-
43
- #### createTransactionFrom(from: `string`, to: `string`, method: `string`, parameters: `array`, nonce: `number` | `undefined`)
44
-
45
- `from`:<br>
46
- `to`: <br>
47
- `method`: <br>
48
- `parameters`: <br>
49
- `nonce`: <br>
50
- ```js
51
- await client.createTransactionFrom(from, to, method, parameters, nonce)
52
- ```
53
- <br>
54
-
55
- #### lookup(name: `string`)
56
- `name`: name of the contract to lookup the address and owner of
57
- ```js
58
- await client.lookup('contractName')
59
- ```
60
- <br>
61
-
62
- #### participate(address: `string`)
63
- `address`: <br>
64
-
65
- ```js
66
- await client.participate(address)
67
- ```
68
- <br>
69
-
70
- #### staticCall(contract: `string`, method: `string`, params: `array`)
71
- `contract`: contract address todo the call on
72
- `method`: method/function to call
73
- `params`: array containing params needed to call the desired method
74
- ```js
75
- await client.staticCall(contract, method, params)
76
- ```
77
- <br>
78
-
79
- #### createContractAddress(owner: `string`, code: `string`, params: `array`)
80
- `owner`: address of the deployer<br>
81
- `code`: contract as a string<br>
82
- `params`: contract constructor params<br>
83
-
84
- ```js
85
- const address = await client.createContractAddress(owner, code, params)
86
- ```
87
- <br>
88
-
89
- #### deployContract(code: `string`, params: `array`)
90
- `code`: contract as a string<br>
91
- `params`: contract constructor params<br>
92
-
93
- ```js
94
- const tx = await client.deployContract(code, params)
95
- ```
96
- <br>
97
-
98
- #### accounts()
99
- ```js
100
- await client.accounts()
101
- ```
102
- <br>
103
-
104
- #### hasTransactionToHandle()
105
- ```js
106
- await client.hasTransactionToHandle()
107
- ```
108
- <br>
109
-
110
- #### balances()
111
- > returns all balances
112
- ```js
113
- await client.balances()
114
- ```
115
- <br>
116
-
117
- #### balancOf(address: `string`, format: `boolean`)
118
- `address`: The address to check<br>
119
- `format`: Wether or not to format<br>
120
- > returns the balance of given address as BigNumber or string (when format is true)
121
- ```js
122
- await client.balanceOf(address, true)
123
- ```
124
- <br>
125
-
126
- #### selectedAccount()
127
- ```js
128
- await client.selectedAccount()
129
- ```
130
- <br>
131
-
132
- #### peerId()
133
- ```js
134
- await client.peerId()
135
- ```
136
- <br>
137
-
138
- #### peers()
139
- ```js
140
- await client.peers()
141
- ```
142
- <br>
143
-
144
- #### validators()
145
- ```js
146
- await client.validators()
147
- ```
148
- <br>
149
-
150
- #### nativeBurns()
151
- ```js
152
- await client.nativeBurns()
153
- ```
154
- <br>
155
-
156
- #### contracts()
157
- ```js
158
- await client.contracts()
159
- ```
160
- <br>
161
-
162
- #### nativeMints()
163
- ```js
164
- await client.nativeMints()
165
- ```
166
- <br>
167
-
168
- #### nativeToken()
169
- ```js
170
- await client.nativeToken()
171
- ```
172
- <br>
173
-
174
- #### nativeTransfers()
175
- ```js
176
- await client. nativeTransfers()
177
- ```
178
- <br>
179
-
180
- #### totalSize()
181
- ```js
182
- await client.totalSize()
183
- ```
184
- <br>
185
-
186
- #### totalTransactions()
187
- ```js
188
- await client.totalTransactions()
189
- ```
190
- <br>
191
-
192
- #### totalBlocks()
193
- ```js
194
- await client.totalBlocks()
195
- ```
196
- <br>
197
-
198
- #### nativeCalls()
199
- ```js
200
- await client.nativeCalls()
201
- ```
202
- <br>
203
-
204
- #### participating()
205
- ```js
206
- await client.participating()
207
- ```
208
- <br>
1
+ # endpoint-clients
2
+
3
+ ## install
4
+ ```sh
5
+ npm i @leofcoin/endpoint-clients
6
+ ```
7
+
8
+ ## usage
9
+ ```js
10
+ import WsClient from '@leofcoin/endpoint-clients/ws'
11
+ import HttpClient from '@leofcoin/endpoint-clients/http'
12
+
13
+ const networkVersion = 'peach'
14
+
15
+ const ws = new WsClient('ws://localhost:4040', networkVersion)
16
+ const http = new HttpClient('http://localhost:8080', networkVersion)
17
+ ```
18
+
19
+ ## api
20
+ ### new Client(url, networkVersion)
21
+ #### selectAccount(address: `string`)
22
+ `address`: desired address
23
+ > set default account to given address
24
+ ```js
25
+ await client.selectAccount(address)
26
+ ```
27
+ <br>
28
+
29
+ #### getBlock(index: `number`)
30
+ `index`: index of the block to fetch<br>
31
+ ```js
32
+ await client.getBlock(10)
33
+ ```
34
+ <br>
35
+
36
+ #### blocks(amount)
37
+ `amount`: the amount to slice
38
+ ```js
39
+ await client.blocks(-25)
40
+ ```
41
+ <br>
42
+
43
+ #### createTransactionFrom(from: `string`, to: `string`, method: `string`, parameters: `array`, nonce: `number` | `undefined`)
44
+
45
+ `from`:<br>
46
+ `to`: <br>
47
+ `method`: <br>
48
+ `parameters`: <br>
49
+ `nonce`: <br>
50
+ ```js
51
+ await client.createTransactionFrom(from, to, method, parameters, nonce)
52
+ ```
53
+ <br>
54
+
55
+ #### lookup(name: `string`)
56
+ `name`: name of the contract to lookup the address and owner of
57
+ ```js
58
+ await client.lookup('contractName')
59
+ ```
60
+ <br>
61
+
62
+ #### participate(address: `string`)
63
+ `address`: <br>
64
+
65
+ ```js
66
+ await client.participate(address)
67
+ ```
68
+ <br>
69
+
70
+ #### staticCall(contract: `string`, method: `string`, params: `array`)
71
+ `contract`: contract address todo the call on
72
+ `method`: method/function to call
73
+ `params`: array containing params needed to call the desired method
74
+ ```js
75
+ await client.staticCall(contract, method, params)
76
+ ```
77
+ <br>
78
+
79
+ #### createContractAddress(owner: `string`, code: `string`, params: `array`)
80
+ `owner`: address of the deployer<br>
81
+ `code`: contract as a string<br>
82
+ `params`: contract constructor params<br>
83
+
84
+ ```js
85
+ const address = await client.createContractAddress(owner, code, params)
86
+ ```
87
+ <br>
88
+
89
+ #### deployContract(code: `string`, params: `array`)
90
+ `code`: contract as a string<br>
91
+ `params`: contract constructor params<br>
92
+
93
+ ```js
94
+ const tx = await client.deployContract(code, params)
95
+ ```
96
+ <br>
97
+
98
+ #### accounts()
99
+ ```js
100
+ await client.accounts()
101
+ ```
102
+ <br>
103
+
104
+ #### hasTransactionToHandle()
105
+ ```js
106
+ await client.hasTransactionToHandle()
107
+ ```
108
+ <br>
109
+
110
+ #### balances()
111
+ > returns all balances
112
+ ```js
113
+ await client.balances()
114
+ ```
115
+ <br>
116
+
117
+ #### balancOf(address: `string`, format: `boolean`)
118
+ `address`: The address to check<br>
119
+ `format`: Wether or not to format<br>
120
+ > returns the balance of given address as BigNumber or string (when format is true)
121
+ ```js
122
+ await client.balanceOf(address, true)
123
+ ```
124
+ <br>
125
+
126
+ #### selectedAccount()
127
+ ```js
128
+ await client.selectedAccount()
129
+ ```
130
+ <br>
131
+
132
+ #### peerId()
133
+ ```js
134
+ await client.peerId()
135
+ ```
136
+ <br>
137
+
138
+ #### peers()
139
+ ```js
140
+ await client.peers()
141
+ ```
142
+ <br>
143
+
144
+ #### validators()
145
+ ```js
146
+ await client.validators()
147
+ ```
148
+ <br>
149
+
150
+ #### nativeBurns()
151
+ ```js
152
+ await client.nativeBurns()
153
+ ```
154
+ <br>
155
+
156
+ #### contracts()
157
+ ```js
158
+ await client.contracts()
159
+ ```
160
+ <br>
161
+
162
+ #### nativeMints()
163
+ ```js
164
+ await client.nativeMints()
165
+ ```
166
+ <br>
167
+
168
+ #### nativeToken()
169
+ ```js
170
+ await client.nativeToken()
171
+ ```
172
+ <br>
173
+
174
+ #### nativeTransfers()
175
+ ```js
176
+ await client. nativeTransfers()
177
+ ```
178
+ <br>
179
+
180
+ #### totalSize()
181
+ ```js
182
+ await client.totalSize()
183
+ ```
184
+ <br>
185
+
186
+ #### totalTransactions()
187
+ ```js
188
+ await client.totalTransactions()
189
+ ```
190
+ <br>
191
+
192
+ #### totalBlocks()
193
+ ```js
194
+ await client.totalBlocks()
195
+ ```
196
+ <br>
197
+
198
+ #### nativeCalls()
199
+ ```js
200
+ await client.nativeCalls()
201
+ ```
202
+ <br>
203
+
204
+ #### participating()
205
+ ```js
206
+ await client.participating()
207
+ ```
208
+ <br>
package/exports/direct.js CHANGED
@@ -11,7 +11,7 @@ class Client {
11
11
  get pubsub() {
12
12
  return {
13
13
  publish: globalThis.pubsub.publish,
14
- subscribe: globalThis.pubsub.subscribe
14
+ subscribe: globalThis.pubsub.subscribe,
15
15
  };
16
16
  }
17
17
  balances() {
@@ -40,10 +40,10 @@ class Client {
40
40
  return chain.hasTransactionToHandle();
41
41
  }
42
42
  getBlock(index) {
43
- return chain.blocks[index - 1];
43
+ return chain.getBlock(index);
44
44
  }
45
45
  blocks(amount) {
46
- return chain.blocks.slice(amount);
46
+ return chain.getBlocks(amount);
47
47
  }
48
48
  sendTransaction(transaction) {
49
49
  return chain.sendTransaction(transaction);
@@ -94,7 +94,7 @@ class Client {
94
94
  return transactionPoolStore.size();
95
95
  }
96
96
  totalBlocks() {
97
- return chain.blocks.length;
97
+ return chain.totalBlocks;
98
98
  }
99
99
  nativeCalls() {
100
100
  return chain.nativeCalls;
@@ -128,7 +128,8 @@ class Client {
128
128
  if (amount.gt(0)) {
129
129
  accountsHoldingAmount = accountsHoldingAmount.add(amount);
130
130
  accountsHolding += 1;
131
- topHolders.length < 100 && topHolders.push({ holder, amount: formatUnits(amount) });
131
+ topHolders.length < 100 &&
132
+ topHolders.push({ holder, amount: formatUnits(amount) });
132
133
  }
133
134
  }
134
135
  return {
@@ -137,7 +138,7 @@ class Client {
137
138
  accounts: await accountsStore.length(),
138
139
  accountsHolding,
139
140
  accountsHoldingAmount: formatUnits(accountsHoldingAmount).toString(),
140
- topHolders
141
+ topHolders,
141
142
  };
142
143
  }
143
144
  getNonce(address) {
package/exports/ws.js CHANGED
@@ -10,12 +10,12 @@ class Client {
10
10
  }
11
11
  async init() {
12
12
  const client = new SocketRequestClient(this.url, this.networkVersion);
13
- this.client = await client.init();
13
+ this.client = (await client.init());
14
14
  }
15
15
  get pubsub() {
16
16
  return {
17
17
  publish: this.client.pubsub.publish,
18
- subscribe: this.client.pubsub.subscribe
18
+ subscribe: this.client.pubsub.subscribe,
19
19
  };
20
20
  }
21
21
  request(url, params) {
package/package.json CHANGED
@@ -1,52 +1,55 @@
1
- {
2
- "name": "@leofcoin/endpoint-clients",
3
- "version": "0.3.7",
4
- "description": "",
5
- "exports": {
6
- ".": {
7
- "import": "./exports/index.js",
8
- "types": "./exports/types/index.d.ts"
9
- },
10
- "./ws": {
11
- "import": "./exports/ws.js",
12
- "types": "./exports/types/ws.d.ts"
13
- },
14
- "./http": {
15
- "import": "./exports/http.js",
16
- "types": "./exports/types/http.d.ts"
17
- },
18
- "./direct": {
19
- "import": "./exports/direct.js",
20
- "types": "./exports/types/direct.d.ts"
21
- },
22
- "./ws.js": "./exports/ws.js",
23
- "./http.js": "./exports/http.js",
24
- "./direct.js": "./exports/direct.js"
25
- },
26
- "types": "./exports/types/index.d.ts",
27
- "type": "module",
28
- "scripts": {
29
- "build": "rollup -c",
30
- "test": "echo \"Error: no test specified\" && exit 1"
31
- },
32
- "repository": {
33
- "type": "git",
34
- "url": "git+https://github.com/leofcoin/endpoint-clients.git"
35
- },
36
- "keywords": [],
37
- "author": "",
38
- "license": "MIT",
39
- "bugs": {
40
- "url": "https://github.com/leofcoin/endpoint-clients/issues"
41
- },
42
- "homepage": "https://github.com/leofcoin/endpoint-clients#readme",
43
- "devDependencies": {
44
- "@rollup/plugin-typescript": "^11.0.0",
45
- "rollup": "^3.14.0",
46
- "tslib": "^2.5.0"
47
- },
48
- "dependencies": {
49
- "@leofcoin/utils": "^1.1.7",
50
- "socket-request-client": "^2.0.0"
51
- }
52
- }
1
+ {
2
+ "name": "@leofcoin/endpoint-clients",
3
+ "version": "0.3.9",
4
+ "description": "",
5
+ "exports": {
6
+ ".": {
7
+ "import": "./exports/index.js",
8
+ "types": "./exports/types/index.d.ts"
9
+ },
10
+ "./ws": {
11
+ "import": "./exports/ws.js",
12
+ "types": "./exports/types/ws.d.ts"
13
+ },
14
+ "./http": {
15
+ "import": "./exports/http.js",
16
+ "types": "./exports/types/http.d.ts"
17
+ },
18
+ "./direct": {
19
+ "import": "./exports/direct.js",
20
+ "types": "./exports/types/direct.d.ts"
21
+ },
22
+ "./ws.js": "./exports/ws.js",
23
+ "./http.js": "./exports/http.js",
24
+ "./direct.js": "./exports/direct.js"
25
+ },
26
+ "files": [
27
+ "exports"
28
+ ],
29
+ "types": "./exports/types/index.d.ts",
30
+ "type": "module",
31
+ "scripts": {
32
+ "build": "rollup -c",
33
+ "test": "echo \"Error: no test specified\" && exit 1"
34
+ },
35
+ "repository": {
36
+ "type": "git",
37
+ "url": "git+https://github.com/leofcoin/endpoint-clients.git"
38
+ },
39
+ "keywords": [],
40
+ "author": "",
41
+ "license": "MIT",
42
+ "bugs": {
43
+ "url": "https://github.com/leofcoin/endpoint-clients/issues"
44
+ },
45
+ "homepage": "https://github.com/leofcoin/endpoint-clients#readme",
46
+ "devDependencies": {
47
+ "@rollup/plugin-typescript": "^11.0.0",
48
+ "rollup": "^3.14.0",
49
+ "tslib": "^2.5.0"
50
+ },
51
+ "dependencies": {
52
+ "@leofcoin/utils": "^1.1.7",
53
+ "socket-request-client": "^2.0.6"
54
+ }
55
+ }
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,14 +0,0 @@
1
- import typescript from '@rollup/plugin-typescript'
2
- export default [{
3
- input: ['./src/index.ts', './src/http.ts', './src/ws.ts', './src/direct.ts'],
4
- output: {
5
- dir: './exports',
6
- format: 'es'
7
- },
8
- plugins: [
9
- typescript()
10
- ],
11
- external: [
12
- './identity.js'
13
- ]
14
- }]
package/src/direct.ts DELETED
@@ -1,177 +0,0 @@
1
- import {formatUnits, BigNumber} from '@leofcoin/utils'
2
-
3
- declare var chain
4
- declare var peernet
5
- declare var transactionPoolStore
6
- declare var accountsStore
7
-
8
- export default class Client {
9
- url: string
10
- networkVersion: string
11
- client;
12
-
13
- constructor(url = 'ws://localhost:4040', networkVersion = 'leofcoin-peach') {
14
- this.url = url
15
- this.networkVersion = networkVersion
16
- }
17
-
18
- get pubsub() {
19
- return {
20
- publish: globalThis.pubsub.publish,
21
- subscribe: globalThis.pubsub.subscribe
22
- }
23
- }
24
-
25
- balances() {
26
- return chain.balances
27
- }
28
-
29
- async balanceOf(address: string, format: boolean) {
30
- const balances = await chain.balances
31
- const balance = balances[address]
32
- return format ? formatUnits(balance) : balance
33
- }
34
-
35
- selectedAccount() {
36
- return peernet.selectedAccount
37
- }
38
-
39
- async selectAccount(address: any) {
40
- try {
41
- await globalThis.walletStore.put('selected-account', address)
42
- } catch (error) {
43
- throw new Error(`couldn't set selected account`)
44
- }
45
- }
46
-
47
- accounts() {
48
- return chain.accounts
49
- }
50
-
51
- hasTransactionToHandle() {
52
- return chain.hasTransactionToHandle()
53
- }
54
-
55
- getBlock(index: number) {
56
- return chain.blocks[index - 1]
57
- }
58
- blocks(amount: number) {
59
- return chain.blocks.slice(amount)
60
- }
61
-
62
- sendTransaction(transaction) {
63
- return chain.sendTransaction(transaction)
64
- }
65
- peerId() {
66
- return peernet.peerId
67
- }
68
- peers() {
69
- return peernet.peers
70
- }
71
- validators() {
72
- return chain.validators
73
- }
74
- lookup(name: string) {
75
- return chain.lookup(name)
76
- }
77
-
78
- staticCall(contract: string, method: string, params: {}) {
79
- return chain.staticCall(contract, method, params)
80
- }
81
- nativeBurns(): number {
82
- return chain.nativeBurns
83
- }
84
- contracts(): number {
85
- return chain.contracts
86
- }
87
- nativeMints(): number {
88
- return chain.nativeMints
89
- }
90
- nativeToken(): string {
91
- return chain.nativeToken
92
- }
93
- nativeTransfers(): number {
94
- return chain.nativeTransfers
95
- }
96
- totalSize(): number {
97
- return chain.totalSize
98
- }
99
- totalTransactions(): number {
100
- return chain.totalTransactions
101
- }
102
- poolTransactions() {
103
- return transactionPoolStore.get()
104
- }
105
- transactionsInPool() {
106
- return transactionPoolStore.length()
107
- }
108
- transactionPoolSize() {
109
- return transactionPoolStore.size()
110
- }
111
- totalBlocks(): number {
112
- return chain.blocks.length
113
- }
114
- nativeCalls(): number {
115
- return chain.nativeCalls
116
- }
117
- participating(): boolean {
118
- return chain.participating
119
- }
120
- participate(address: string): {} {
121
- return chain.participate(address)
122
- }
123
- createContractAddress(owner: string, code: string, params: {}): {} {
124
- return chain.createContractAddress(owner, code, params)
125
- }
126
- deployContract(code: string, params: {}): {} {
127
- return chain.deployContract(code, params)
128
- }
129
- network() {
130
- return chain.network
131
- }
132
-
133
- async networkStats(): Promise<{ version: string; peers: {}[]; accounts: number; accountsHolding: number, accountsHoldingAmount: number, topHolders: any[] }> {
134
- let accountsHolding = 0
135
- let accountsHoldingAmount = BigNumber.from(0)
136
- let topHolders = []
137
- const balances = Object.entries(await chain.balances)
138
- .map(([holder, amount]): {holder: string, amount: BigNumber} => {
139
- amount = BigNumber.from(amount)
140
- return {holder, amount}
141
- })
142
- .sort((a, b) => formatUnits(b.amount.sub(a.amount)))
143
-
144
- for (let {holder, amount} of balances) {
145
- if (amount.gt(0)) {
146
- accountsHoldingAmount = accountsHoldingAmount.add(amount)
147
- accountsHolding += 1
148
- topHolders.length < 100 && topHolders.push({holder, amount: formatUnits(amount)})
149
- }
150
- }
151
-
152
- return {
153
- version: peernet.networkVersion,
154
- peers: peernet.peers.map(([id, peer]) => id),
155
- accounts: await accountsStore.length(),
156
- accountsHolding,
157
- accountsHoldingAmount: formatUnits(accountsHoldingAmount).toString(),
158
- topHolders
159
- }
160
- }
161
-
162
- getNonce(address: string) {
163
- return chain.getNonce(address)
164
- }
165
-
166
- lastBlock() {
167
- return chain.lastBlock
168
- }
169
-
170
- blockHashMap() {
171
- return chain.blockHashMap
172
- }
173
-
174
- bootstrap() {
175
- return chain.blockHashMap
176
- }
177
- }
package/src/http.ts DELETED
@@ -1,160 +0,0 @@
1
-
2
- // see https://developer.mozilla.org/en-US/docs/Web/API/Response#instance_methods
3
- type responseType = 'json' | 'text' | 'arrayBuffer' | 'clone' | 'formData' | 'blob';
4
- type networkVersion = 'peach' | string;
5
-
6
- export default class Client {
7
- url: string;
8
- networkVersion: networkVersion;
9
- get isHttpClient() {
10
- return true
11
- }
12
-
13
- constructor(url, networkVersion) {
14
- this.url = url
15
- this.networkVersion = networkVersion
16
- }
17
-
18
- async _fetch(method: string, params?, type: responseType = 'json') {
19
- params = new URLSearchParams(params).toString()
20
- const response = await fetch(`${this.url}/${method}?${params}`)
21
- return response[type]()
22
- }
23
-
24
- async _fetchString(method: string, params?) {
25
- return String(await this._fetch(method, params, 'text'))
26
- }
27
-
28
- async _fetchNumber(method: string, params?) {
29
- return Number(await this._fetchString(method, params))
30
- }
31
-
32
- async _fetchBoolean(method: string, params?) {
33
- return Boolean((await this._fetchString(method, params)) === 'true')
34
- }
35
-
36
- balances() {
37
- return this._fetch('balances')
38
- }
39
-
40
- balanceOf(address, format) {
41
- return this._fetch(`balanceOf`, {address, format})
42
- }
43
-
44
- selectedAccount() {
45
- return this._fetchString('selectedAccount')
46
- }
47
-
48
- selectAccount(address) {
49
- return this._fetch('selectAccount', {address})
50
- }
51
-
52
- accounts() {
53
- return this._fetch('accounts')
54
- }
55
-
56
- hasTransactionToHandle() {
57
- return this._fetchBoolean('hasTransactionToHandle')
58
- }
59
-
60
- getBlock(index) {
61
- return this._fetch('getBlock', { index })
62
- }
63
- blocks(amount) {
64
- return this._fetch('blocks', {amount})
65
- }
66
-
67
- sendTransaction(transaction) {
68
- return this._fetch('sendTransaction', transaction)
69
- }
70
- peerId() {
71
- return this._fetchString('peerId')
72
- }
73
- peers() {
74
- return this._fetch('peers')
75
- }
76
- validators() {
77
- return this._fetch('validators')
78
- }
79
- lookup(name) {
80
- return this._fetch('lookup', { name })
81
- }
82
-
83
- staticCall(contract, method, params) {
84
- return this._fetch('staticCall', {contract, method, params})
85
- }
86
- nativeBurns() {
87
- return this._fetchNumber('nativeBurns')
88
- }
89
- contracts() {
90
- return this._fetch('contracts')
91
- }
92
- nativeMints() {
93
- return this._fetchNumber('nativeMints')
94
- }
95
- nativeToken() {
96
- return this._fetchString('nativeToken')
97
- }
98
- nativeTransfers() {
99
- return this._fetchNumber('nativeTransfers')
100
- }
101
- totalSize() {
102
- return this._fetchNumber('totalSize')
103
- }
104
- totalTransactions() {
105
- return this._fetchNumber('totalTransactions')
106
- }
107
- poolTransactions() {
108
- return this._fetch('poolTransactions')
109
- }
110
- transactionsInPool() {
111
- return this._fetchNumber('transactionsInPool')
112
- }
113
- transactionPoolSize() {
114
- return this._fetchNumber('transactionPoolSize')
115
- }
116
- totalBlocks() {
117
- return this._fetchNumber('totalBlocks')
118
- }
119
- nativeCalls() {
120
- return this._fetchNumber('nativeCalls')
121
- }
122
- participating() {
123
- return this._fetchBoolean('participating')
124
- }
125
- participate(address) {
126
- return this._fetch('participate', { address })
127
- }
128
-
129
- createContractAddress(owner, code, params) {
130
- return this._fetch('createContractAddress', { owner, code, params })
131
- }
132
-
133
- deployContract(code, params) {
134
- return this._fetch('deployContract', { code, params })
135
- }
136
-
137
- network() {
138
- return this._fetch('network')
139
- }
140
-
141
- networkStats(): Promise<{ version: string; peers: {}[]; accounts: number; accountsHolding: number; }> {
142
- return this._fetch('networkStats')
143
- }
144
-
145
- getNonce(address: string) {
146
- return this._fetchNumber('getNonce', { address })
147
- }
148
-
149
- lastBlock() {
150
- return this._fetch('lastBlock')
151
- }
152
-
153
- blockHashMap() {
154
- return this._fetch('blockHashMap')
155
- }
156
-
157
- bootstrap() {
158
- return this._fetch('blockHashMap')
159
- }
160
- }
package/src/index.ts DELETED
@@ -1,3 +0,0 @@
1
- export {default as ws} from './ws.js'
2
- export {default as http} from './http.js'
3
- export {default as direct} from './direct.js'
package/src/ws.ts DELETED
@@ -1,151 +0,0 @@
1
- import { SocketRequestClient } from 'socket-request-client'
2
- import ClientConnection from 'socket-request-client/connection'
3
-
4
- export default class Client {
5
- url: string
6
- networkVersion: string
7
- client: ClientConnection
8
-
9
- constructor(url = 'ws://localhost:4040', networkVersion = 'leofcoin-peach') {
10
- this.url = url
11
- this.networkVersion = networkVersion
12
- }
13
-
14
- async init() {
15
- const client = new SocketRequestClient(this.url, this.networkVersion)
16
- this.client = await client.init() as ClientConnection
17
- }
18
-
19
- get pubsub() {
20
- return {
21
- publish: this.client.pubsub.publish,
22
- subscribe: this.client.pubsub.subscribe
23
- }
24
- }
25
-
26
- request(url: string, params?: {}) {
27
- return this.client.request({url, params})
28
- }
29
-
30
- balances() {
31
- return this.request('balances')
32
- }
33
-
34
- balanceOf(address: string, format: boolean) {
35
- return this.request('balanceOf', {address, format})
36
- }
37
-
38
- selectedAccount() {
39
- return this.request('selectedAccount')
40
- }
41
-
42
- selectAccount(address: any) {
43
- return this.request('selectAccount', {address})
44
- }
45
-
46
- accounts() {
47
- return this.request('accounts')
48
- }
49
-
50
- hasTransactionToHandle() {
51
- return this.request('hasTransactionToHandle')
52
- }
53
-
54
- getBlock(index: number) {
55
- return this.request('getBlock', { index })
56
- }
57
- blocks(amount: number) {
58
- return this.request('blocks', {amount})
59
- }
60
-
61
- sendTransaction(transaction) {
62
- return this.request('sendTransaction', transaction)
63
- }
64
- peerId() {
65
- return this.request('peerId')
66
- }
67
- peers() {
68
- return this.request('peers')
69
- }
70
- validators() {
71
- return this.request('validators')
72
- }
73
- lookup(name: string) {
74
- return this.request('lookup', { name })
75
- }
76
-
77
- staticCall(contract: string, method: string, params: {}) {
78
- return this.request('staticCall', {contract, method, params})
79
- }
80
- nativeBurns(): Promise<number> {
81
- return this.request('nativeBurns')
82
- }
83
- contracts(): Promise<number> {
84
- return this.request('contracts')
85
- }
86
- nativeMints(): Promise<number> {
87
- return this.request('nativeMints')
88
- }
89
- nativeToken(): Promise<string> {
90
- return this.request('nativeToken')
91
- }
92
- nativeTransfers(): Promise<number> {
93
- return this.request('nativeTransfers')
94
- }
95
- totalSize(): Promise<number> {
96
- return this.request('totalSize')
97
- }
98
- totalTransactions(): Promise<number> {
99
- return this.request('totalTransactions')
100
- }
101
- poolTransactions() {
102
- return this.request('poolTransactions')
103
- }
104
- transactionsInPool() {
105
- return this.request('transactionsInPool')
106
- }
107
- transactionPoolSize() {
108
- return this.request('transactionPoolSize')
109
- }
110
- totalBlocks(): Promise<number> {
111
- return this.request('totalBlocks')
112
- }
113
- nativeCalls(): Promise<number> {
114
- return this.request('nativeCalls')
115
- }
116
- participating(): Promise<boolean> {
117
- return this.request('participating')
118
- }
119
- participate(address: string): {} {
120
- return this.request('participate', { address })
121
- }
122
- createContractAddress(owner: string, code: string, params: {}): {} {
123
- return this.request('createContractAddress', { owner, code, params })
124
- }
125
- deployContract(code: string, params: {}): {} {
126
- return this.request('deployContract', { code, params })
127
- }
128
- network() {
129
- return this.request('network')
130
- }
131
-
132
- networkStats(): Promise<{ version: string; peers: {}[]; accounts: number; accountsHolding: number }> {
133
- return this.request('networkStats')
134
- }
135
-
136
- getNonce(address: string) {
137
- return this.request('getNonce', { address })
138
- }
139
-
140
- lastBlock() {
141
- return this.request('lastBlock')
142
- }
143
-
144
- blockHashMap() {
145
- return this.request('blockHashMap')
146
- }
147
-
148
- bootstrap() {
149
- return this.request('blockHashMap')
150
- }
151
- }
package/test/index.js DELETED
@@ -1,17 +0,0 @@
1
- import { needsImplementations } from './spec.js';
2
- import WsClient from './../exports/ws.js'
3
- import HttpClient from './../exports/http.js'
4
- import DirectClient from './../exports/direct.js'
5
-
6
- try {
7
- const wsNeeds = needsImplementations(new WsClient())
8
- if (wsNeeds.length > 0) throw new Error(`ws: missing implementations ${wsNeeds.length > 2 ? wsNeeds.join(', ') : wsNeeds.join(' & ')}`)
9
-
10
- const httpNeeds = needsImplementations(new HttpClient())
11
- if (httpNeeds.length > 0) throw new Error(`http: missing implementations ${httpNeeds.length > 2 ? httpNeeds.join(', ') : httpNeeds.join(' & ')}`)
12
-
13
- const directNeeds = needsImplementations(new DirectClient())
14
- if (directNeeds.length > 0) throw new Error(`direct: missing implementations ${directNeeds.length > 2 ? directNeeds.join(', ') : directNeeds.join(' & ')}`)
15
- } catch (error) {
16
- console.error(error);
17
- }
package/test/spec.js DELETED
@@ -1,45 +0,0 @@
1
- export const implementations = [
2
- 'accounts',
3
- 'balanceOf',
4
- 'balances',
5
- 'blocks',
6
- 'contracts',
7
- 'createContractAddress',
8
- 'createTransactionFrom',
9
- 'deployContract',
10
- 'getBlock',
11
- 'hasTransactionToHandle',
12
- 'lookup',
13
- 'nativeBurns',
14
- 'nativeCalls',
15
- 'nativeMints',
16
- 'nativeToken',
17
- 'nativeTransfers',
18
- 'participate',
19
- 'participating',
20
- 'peerId',
21
- 'peers',
22
- 'pubsub',
23
- 'selectAccount',
24
- 'selectedAccount',
25
- 'staticCall',
26
- 'totalBlocks',
27
- 'totalSize',
28
- 'totalTransactions',
29
- 'validators',
30
- 'lastBlock'
31
- ]
32
-
33
- export const needsImplementations = (client) => {
34
- const needs = []
35
- for (const key of implementations) {
36
- try {
37
- if (!client[key] && key === 'pubsub' && !client.isHttpClient) needs.push(key)
38
- } catch (error) {
39
- if (error.message !== "Cannot read properties of undefined (reading 'pubsub')") throw new Error(error)
40
- }
41
-
42
- }
43
- console.log(needs);
44
- return needs
45
- }
package/tsconfig.json DELETED
@@ -1,16 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "module": "NodeNext",
4
- "target": "es2022",
5
- "outDir": "./exports",
6
- "moduleResolution":"NodeNext",
7
- "allowJs": true,
8
- "declaration": true,
9
- "declarationDir": "./exports/types",
10
- "allowSyntheticDefaultImports": true,
11
- "resolveJsonModule": true
12
- },
13
- "include": [
14
- "./src/**/*"
15
- ]
16
- }