@leofcoin/endpoints 0.2.5 → 0.2.7
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 +20 -20
- package/exports/api.md +196 -196
- package/exports/http.js +174 -167
- package/exports/shared.js +30 -0
- package/exports/ws.js +99 -92
- package/package.json +1 -1
- package/rollup.config.js +0 -30
- package/tsconfig.json +0 -17
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/exports/api.md
CHANGED
|
@@ -1,197 +1,197 @@
|
|
|
1
|
-
#### [selectAccount(address: `string`)](https://remote.leofcoin.org/select-account?address=)
|
|
2
|
-
`address`: desired address
|
|
3
|
-
> set default account to given address
|
|
4
|
-
```js
|
|
5
|
-
await client.selectAccount(address)
|
|
6
|
-
```
|
|
7
|
-
<br>
|
|
8
|
-
|
|
9
|
-
#### [getBlock(index: `number`)](https://remote.leofcoin.org/getblock?index=0)
|
|
10
|
-
`index`: index of the block to fetch<br>
|
|
11
|
-
```js
|
|
12
|
-
await client.getBlock(10)
|
|
13
|
-
```
|
|
14
|
-
<br>
|
|
15
|
-
|
|
16
|
-
#### [blocks(amount)](https://remote.leofcoin.org/blocks)
|
|
17
|
-
`amount`: the amount to slice
|
|
18
|
-
```js
|
|
19
|
-
await client.blocks(-25)
|
|
20
|
-
```
|
|
21
|
-
<br>
|
|
22
|
-
|
|
23
|
-
#### createTransactionFrom(from: `string`, to: `string`, method: `string`, parameters: `array`, nonce: `number` | `undefined`)
|
|
24
|
-
|
|
25
|
-
`from`:<br>
|
|
26
|
-
`to`: <br>
|
|
27
|
-
`method`: <br>
|
|
28
|
-
`parameters`: <br>
|
|
29
|
-
`nonce`: <br>
|
|
30
|
-
```js
|
|
31
|
-
await client.createTransactionFrom(from, to, method, parameters, nonce)
|
|
32
|
-
```
|
|
33
|
-
<br>
|
|
34
|
-
|
|
35
|
-
#### [lookup(name: `string`)](https://remote.leofcoin.org/lookup?name=ArtOnlineContractFactory)
|
|
36
|
-
`name`: name of the contract to lookup the address and owner of
|
|
37
|
-
```js
|
|
38
|
-
await client.lookup('contractName')
|
|
39
|
-
```
|
|
40
|
-
<br>
|
|
41
|
-
|
|
42
|
-
#### participate(address: `string`)
|
|
43
|
-
`address`: <br>
|
|
44
|
-
|
|
45
|
-
```js
|
|
46
|
-
await client.participate(address)
|
|
47
|
-
```
|
|
48
|
-
<br>
|
|
49
|
-
|
|
50
|
-
#### staticCall(contract: `string`, method: `string`, params: `array`)
|
|
51
|
-
`contract`: contract address todo the call on
|
|
52
|
-
`method`: method/function to call
|
|
53
|
-
`params`: array containing params needed to call the desired method
|
|
54
|
-
```js
|
|
55
|
-
await client.staticCall(contract, method, params)
|
|
56
|
-
```
|
|
57
|
-
<br>
|
|
58
|
-
|
|
59
|
-
#### createContractAddress(owner: `string`, code: `string`, params: `array`)
|
|
60
|
-
`owner`: address of the deployer<br>
|
|
61
|
-
`code`: contract as a string<br>
|
|
62
|
-
`params`: contract constructor params<br>
|
|
63
|
-
|
|
64
|
-
```js
|
|
65
|
-
const address = await client.createContractAddress(owner, code, params)
|
|
66
|
-
```
|
|
67
|
-
<br>
|
|
68
|
-
|
|
69
|
-
#### deployContract(code: `string`, params: `array`)
|
|
70
|
-
`code`: contract as a string<br>
|
|
71
|
-
`params`: contract constructor params<br>
|
|
72
|
-
|
|
73
|
-
```js
|
|
74
|
-
const tx = await client.deployContract(code, params)
|
|
75
|
-
```
|
|
76
|
-
<br>
|
|
77
|
-
|
|
78
|
-
#### [accounts()](https://remote.leofcoin.org/accounts)
|
|
79
|
-
```js
|
|
80
|
-
await client.accounts()
|
|
81
|
-
```
|
|
82
|
-
<br>
|
|
83
|
-
|
|
84
|
-
#### [hasTransactionToHandle()](https://remote.leofcoin.org/hasTransactionToHandle)
|
|
85
|
-
```js
|
|
86
|
-
await client.hasTransactionToHandle()
|
|
87
|
-
```
|
|
88
|
-
<br>
|
|
89
|
-
|
|
90
|
-
#### [balances()](https://remote.leofcoin.org/balances)
|
|
91
|
-
> returns all balances
|
|
92
|
-
```js
|
|
93
|
-
await client.balances()
|
|
94
|
-
```
|
|
95
|
-
<br>
|
|
96
|
-
|
|
97
|
-
#### [balancOf(address: `string`, format: `boolean`)](https://remote.leofcoin.org/balanceOf?address=YTqxKshWH4Qo7KprGYxQVCNYutedaE6YGoUdUPnUdFUVBPrTzgsrP&format=true)
|
|
98
|
-
`address`: The address to check<br>
|
|
99
|
-
`format`: Wether or not to format<br>
|
|
100
|
-
> returns the balance of given address as BigNumber or string (when format is true)
|
|
101
|
-
```js
|
|
102
|
-
await client.balanceOf(address, true)
|
|
103
|
-
```
|
|
104
|
-
<br>
|
|
105
|
-
|
|
106
|
-
#### [getNonce(address: `string`)](https://remote.leofcoin.org/getNonce?address=YTqxKshWH4Qo7KprGYxQVCNYutedaE6YGoUdUPnUdFUVBPrTzgsrP)
|
|
107
|
-
`address`: The address to check<br>
|
|
108
|
-
`format`: Wether or not to format<br>
|
|
109
|
-
> returns the balance of given address as BigNumber or string (when format is true)
|
|
110
|
-
```js
|
|
111
|
-
await client.getNonce(address)
|
|
112
|
-
```
|
|
113
|
-
<br>
|
|
114
|
-
|
|
115
|
-
#### [selectedAccount()](https://remote.leofcoin.org/selectedAccount)
|
|
116
|
-
```js
|
|
117
|
-
await client.selectedAccount()
|
|
118
|
-
```
|
|
119
|
-
<br>
|
|
120
|
-
|
|
121
|
-
#### [peerId()](https://remote.leofcoin.org/peerId)
|
|
122
|
-
```js
|
|
123
|
-
await client.peerId()
|
|
124
|
-
```
|
|
125
|
-
<br>
|
|
126
|
-
|
|
127
|
-
#### [peers()](https://remote.leofcoin.org/peers)
|
|
128
|
-
```js
|
|
129
|
-
await client.peers()
|
|
130
|
-
```
|
|
131
|
-
<br>
|
|
132
|
-
|
|
133
|
-
#### [validators()](https://remote.leofcoin.org/validators)
|
|
134
|
-
```js
|
|
135
|
-
await client.validators()
|
|
136
|
-
```
|
|
137
|
-
<br>
|
|
138
|
-
|
|
139
|
-
#### [nativeBurns()](https://remote.leofcoin.org/nativeBurns)
|
|
140
|
-
```js
|
|
141
|
-
await client.nativeBurns()
|
|
142
|
-
```
|
|
143
|
-
<br>
|
|
144
|
-
|
|
145
|
-
#### [contracts()](https://remote.leofcoin.org/contracts)
|
|
146
|
-
```js
|
|
147
|
-
await client.contracts()
|
|
148
|
-
```
|
|
149
|
-
<br>
|
|
150
|
-
|
|
151
|
-
#### [nativeMints()](https://remote.leofcoin.org/nativeMints)
|
|
152
|
-
```js
|
|
153
|
-
await client.nativeMints()
|
|
154
|
-
```
|
|
155
|
-
<br>
|
|
156
|
-
|
|
157
|
-
#### [nativeToken()](https://remote.leofcoin.org/nativeToken)
|
|
158
|
-
```js
|
|
159
|
-
await client.nativeToken()
|
|
160
|
-
```
|
|
161
|
-
<br>
|
|
162
|
-
|
|
163
|
-
#### [nativeTransfers()](https://remote.leofcoin.org/nativeTransfers)
|
|
164
|
-
```js
|
|
165
|
-
await client. nativeTransfers()
|
|
166
|
-
```
|
|
167
|
-
<br>
|
|
168
|
-
|
|
169
|
-
#### [totalSize()](https://remote.leofcoin.org/totalSize)
|
|
170
|
-
```js
|
|
171
|
-
await client.totalSize()
|
|
172
|
-
```
|
|
173
|
-
<br>
|
|
174
|
-
|
|
175
|
-
#### [totalTransactions()](https://remote.leofcoin.org/totalTransactions)
|
|
176
|
-
```js
|
|
177
|
-
await client.totalTransactions()
|
|
178
|
-
```
|
|
179
|
-
<br>
|
|
180
|
-
|
|
181
|
-
#### [totalBlocks()](https://remote.leofcoin.org/totalBlocks)
|
|
182
|
-
```js
|
|
183
|
-
await client.totalBlocks()
|
|
184
|
-
```
|
|
185
|
-
<br>
|
|
186
|
-
|
|
187
|
-
#### [nativeCalls()](https://remote.leofcoin.org/nativeCalls)
|
|
188
|
-
```js
|
|
189
|
-
await client.nativeCalls()
|
|
190
|
-
```
|
|
191
|
-
<br>
|
|
192
|
-
|
|
193
|
-
#### [participating()](https://remote.leofcoin.org/participating)
|
|
194
|
-
```js
|
|
195
|
-
await client.participating()
|
|
196
|
-
```
|
|
1
|
+
#### [selectAccount(address: `string`)](https://remote.leofcoin.org/select-account?address=)
|
|
2
|
+
`address`: desired address
|
|
3
|
+
> set default account to given address
|
|
4
|
+
```js
|
|
5
|
+
await client.selectAccount(address)
|
|
6
|
+
```
|
|
7
|
+
<br>
|
|
8
|
+
|
|
9
|
+
#### [getBlock(index: `number`)](https://remote.leofcoin.org/getblock?index=0)
|
|
10
|
+
`index`: index of the block to fetch<br>
|
|
11
|
+
```js
|
|
12
|
+
await client.getBlock(10)
|
|
13
|
+
```
|
|
14
|
+
<br>
|
|
15
|
+
|
|
16
|
+
#### [blocks(amount)](https://remote.leofcoin.org/blocks)
|
|
17
|
+
`amount`: the amount to slice
|
|
18
|
+
```js
|
|
19
|
+
await client.blocks(-25)
|
|
20
|
+
```
|
|
21
|
+
<br>
|
|
22
|
+
|
|
23
|
+
#### createTransactionFrom(from: `string`, to: `string`, method: `string`, parameters: `array`, nonce: `number` | `undefined`)
|
|
24
|
+
|
|
25
|
+
`from`:<br>
|
|
26
|
+
`to`: <br>
|
|
27
|
+
`method`: <br>
|
|
28
|
+
`parameters`: <br>
|
|
29
|
+
`nonce`: <br>
|
|
30
|
+
```js
|
|
31
|
+
await client.createTransactionFrom(from, to, method, parameters, nonce)
|
|
32
|
+
```
|
|
33
|
+
<br>
|
|
34
|
+
|
|
35
|
+
#### [lookup(name: `string`)](https://remote.leofcoin.org/lookup?name=ArtOnlineContractFactory)
|
|
36
|
+
`name`: name of the contract to lookup the address and owner of
|
|
37
|
+
```js
|
|
38
|
+
await client.lookup('contractName')
|
|
39
|
+
```
|
|
40
|
+
<br>
|
|
41
|
+
|
|
42
|
+
#### participate(address: `string`)
|
|
43
|
+
`address`: <br>
|
|
44
|
+
|
|
45
|
+
```js
|
|
46
|
+
await client.participate(address)
|
|
47
|
+
```
|
|
48
|
+
<br>
|
|
49
|
+
|
|
50
|
+
#### staticCall(contract: `string`, method: `string`, params: `array`)
|
|
51
|
+
`contract`: contract address todo the call on
|
|
52
|
+
`method`: method/function to call
|
|
53
|
+
`params`: array containing params needed to call the desired method
|
|
54
|
+
```js
|
|
55
|
+
await client.staticCall(contract, method, params)
|
|
56
|
+
```
|
|
57
|
+
<br>
|
|
58
|
+
|
|
59
|
+
#### createContractAddress(owner: `string`, code: `string`, params: `array`)
|
|
60
|
+
`owner`: address of the deployer<br>
|
|
61
|
+
`code`: contract as a string<br>
|
|
62
|
+
`params`: contract constructor params<br>
|
|
63
|
+
|
|
64
|
+
```js
|
|
65
|
+
const address = await client.createContractAddress(owner, code, params)
|
|
66
|
+
```
|
|
67
|
+
<br>
|
|
68
|
+
|
|
69
|
+
#### deployContract(code: `string`, params: `array`)
|
|
70
|
+
`code`: contract as a string<br>
|
|
71
|
+
`params`: contract constructor params<br>
|
|
72
|
+
|
|
73
|
+
```js
|
|
74
|
+
const tx = await client.deployContract(code, params)
|
|
75
|
+
```
|
|
76
|
+
<br>
|
|
77
|
+
|
|
78
|
+
#### [accounts()](https://remote.leofcoin.org/accounts)
|
|
79
|
+
```js
|
|
80
|
+
await client.accounts()
|
|
81
|
+
```
|
|
82
|
+
<br>
|
|
83
|
+
|
|
84
|
+
#### [hasTransactionToHandle()](https://remote.leofcoin.org/hasTransactionToHandle)
|
|
85
|
+
```js
|
|
86
|
+
await client.hasTransactionToHandle()
|
|
87
|
+
```
|
|
88
|
+
<br>
|
|
89
|
+
|
|
90
|
+
#### [balances()](https://remote.leofcoin.org/balances)
|
|
91
|
+
> returns all balances
|
|
92
|
+
```js
|
|
93
|
+
await client.balances()
|
|
94
|
+
```
|
|
95
|
+
<br>
|
|
96
|
+
|
|
97
|
+
#### [balancOf(address: `string`, format: `boolean`)](https://remote.leofcoin.org/balanceOf?address=YTqxKshWH4Qo7KprGYxQVCNYutedaE6YGoUdUPnUdFUVBPrTzgsrP&format=true)
|
|
98
|
+
`address`: The address to check<br>
|
|
99
|
+
`format`: Wether or not to format<br>
|
|
100
|
+
> returns the balance of given address as BigNumber or string (when format is true)
|
|
101
|
+
```js
|
|
102
|
+
await client.balanceOf(address, true)
|
|
103
|
+
```
|
|
104
|
+
<br>
|
|
105
|
+
|
|
106
|
+
#### [getNonce(address: `string`)](https://remote.leofcoin.org/getNonce?address=YTqxKshWH4Qo7KprGYxQVCNYutedaE6YGoUdUPnUdFUVBPrTzgsrP)
|
|
107
|
+
`address`: The address to check<br>
|
|
108
|
+
`format`: Wether or not to format<br>
|
|
109
|
+
> returns the balance of given address as BigNumber or string (when format is true)
|
|
110
|
+
```js
|
|
111
|
+
await client.getNonce(address)
|
|
112
|
+
```
|
|
113
|
+
<br>
|
|
114
|
+
|
|
115
|
+
#### [selectedAccount()](https://remote.leofcoin.org/selectedAccount)
|
|
116
|
+
```js
|
|
117
|
+
await client.selectedAccount()
|
|
118
|
+
```
|
|
119
|
+
<br>
|
|
120
|
+
|
|
121
|
+
#### [peerId()](https://remote.leofcoin.org/peerId)
|
|
122
|
+
```js
|
|
123
|
+
await client.peerId()
|
|
124
|
+
```
|
|
125
|
+
<br>
|
|
126
|
+
|
|
127
|
+
#### [peers()](https://remote.leofcoin.org/peers)
|
|
128
|
+
```js
|
|
129
|
+
await client.peers()
|
|
130
|
+
```
|
|
131
|
+
<br>
|
|
132
|
+
|
|
133
|
+
#### [validators()](https://remote.leofcoin.org/validators)
|
|
134
|
+
```js
|
|
135
|
+
await client.validators()
|
|
136
|
+
```
|
|
137
|
+
<br>
|
|
138
|
+
|
|
139
|
+
#### [nativeBurns()](https://remote.leofcoin.org/nativeBurns)
|
|
140
|
+
```js
|
|
141
|
+
await client.nativeBurns()
|
|
142
|
+
```
|
|
143
|
+
<br>
|
|
144
|
+
|
|
145
|
+
#### [contracts()](https://remote.leofcoin.org/contracts)
|
|
146
|
+
```js
|
|
147
|
+
await client.contracts()
|
|
148
|
+
```
|
|
149
|
+
<br>
|
|
150
|
+
|
|
151
|
+
#### [nativeMints()](https://remote.leofcoin.org/nativeMints)
|
|
152
|
+
```js
|
|
153
|
+
await client.nativeMints()
|
|
154
|
+
```
|
|
155
|
+
<br>
|
|
156
|
+
|
|
157
|
+
#### [nativeToken()](https://remote.leofcoin.org/nativeToken)
|
|
158
|
+
```js
|
|
159
|
+
await client.nativeToken()
|
|
160
|
+
```
|
|
161
|
+
<br>
|
|
162
|
+
|
|
163
|
+
#### [nativeTransfers()](https://remote.leofcoin.org/nativeTransfers)
|
|
164
|
+
```js
|
|
165
|
+
await client. nativeTransfers()
|
|
166
|
+
```
|
|
167
|
+
<br>
|
|
168
|
+
|
|
169
|
+
#### [totalSize()](https://remote.leofcoin.org/totalSize)
|
|
170
|
+
```js
|
|
171
|
+
await client.totalSize()
|
|
172
|
+
```
|
|
173
|
+
<br>
|
|
174
|
+
|
|
175
|
+
#### [totalTransactions()](https://remote.leofcoin.org/totalTransactions)
|
|
176
|
+
```js
|
|
177
|
+
await client.totalTransactions()
|
|
178
|
+
```
|
|
179
|
+
<br>
|
|
180
|
+
|
|
181
|
+
#### [totalBlocks()](https://remote.leofcoin.org/totalBlocks)
|
|
182
|
+
```js
|
|
183
|
+
await client.totalBlocks()
|
|
184
|
+
```
|
|
185
|
+
<br>
|
|
186
|
+
|
|
187
|
+
#### [nativeCalls()](https://remote.leofcoin.org/nativeCalls)
|
|
188
|
+
```js
|
|
189
|
+
await client.nativeCalls()
|
|
190
|
+
```
|
|
191
|
+
<br>
|
|
192
|
+
|
|
193
|
+
#### [participating()](https://remote.leofcoin.org/participating)
|
|
194
|
+
```js
|
|
195
|
+
await client.participating()
|
|
196
|
+
```
|
|
197
197
|
<br>
|
package/exports/http.js
CHANGED
|
@@ -1,167 +1,174 @@
|
|
|
1
|
-
import koa from 'koa'
|
|
2
|
-
import cors from '@koa/cors'
|
|
3
|
-
import Router from '@koa/router'
|
|
4
|
-
import {formatUnits} from '@leofcoin/utils'
|
|
5
|
-
import {readFile} from 'fs/promises'
|
|
6
|
-
import Showdown from 'showdown'
|
|
7
|
-
import
|
|
8
|
-
import {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
|
|
1
|
+
import koa from 'koa'
|
|
2
|
+
import cors from '@koa/cors'
|
|
3
|
+
import Router from '@koa/router'
|
|
4
|
+
import {formatUnits} from '@leofcoin/utils'
|
|
5
|
+
import {readFile} from 'fs/promises'
|
|
6
|
+
import Showdown from 'showdown'
|
|
7
|
+
import shared from './shared'
|
|
8
|
+
import { dirname, join} from 'path'
|
|
9
|
+
import { fileURLToPath } from 'url'
|
|
10
|
+
|
|
11
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
12
|
+
const __dirname = dirname(__filename);
|
|
13
|
+
|
|
14
|
+
const api = new koa()
|
|
15
|
+
const router = new Router()
|
|
16
|
+
|
|
17
|
+
const converter = new Showdown.Converter()
|
|
18
|
+
const apiFile = await readFile(join(__dirname, './api.md'))
|
|
19
|
+
|
|
20
|
+
export default (chain, port, networkVersion) => {
|
|
21
|
+
// api routes
|
|
22
|
+
router.get('/', ctx => {
|
|
23
|
+
ctx.body = converter.makeHtml(apiFile.toString())
|
|
24
|
+
})
|
|
25
|
+
|
|
26
|
+
router.get('/network', ctx => {
|
|
27
|
+
ctx.body = {
|
|
28
|
+
version: networkVersion
|
|
29
|
+
}
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
router.get('/networkStats', async () => {
|
|
33
|
+
ctx.body = await shared.networkStats(chain)
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
router.get('/balances', async ctx => {
|
|
37
|
+
ctx.body = await chain.balances
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
router.get('/balanceOf', async ctx => {
|
|
41
|
+
const balance = (await chain.balances)[ctx.query.address]
|
|
42
|
+
if (balance) ctx.body = ctx.query.format ? formatUnits(balance) : balance
|
|
43
|
+
else ctx.body = 0
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
router.get('/selectedAccount', ctx => ctx.body = peernet.selectedAccount)
|
|
47
|
+
|
|
48
|
+
router.get('/selectAccount', async ctx => {
|
|
49
|
+
try {
|
|
50
|
+
await walletStore.put('selected-account', address)
|
|
51
|
+
} catch (error) {
|
|
52
|
+
}
|
|
53
|
+
return
|
|
54
|
+
})
|
|
55
|
+
|
|
56
|
+
router.get('/accounts', async ctx => {
|
|
57
|
+
ctx.body = JSON.parse(new TextDecoder().decode((await walletStore.get('accounts'))))
|
|
58
|
+
})
|
|
59
|
+
|
|
60
|
+
router.get('/hasTransactionToHandle', async ctx => {
|
|
61
|
+
ctx.body = await chain.hasTransactionToHandle()
|
|
62
|
+
})
|
|
63
|
+
|
|
64
|
+
router.get('/getNonce', async ctx => {
|
|
65
|
+
ctx.body = await chain.getNonce(ctx.query.address)
|
|
66
|
+
})
|
|
67
|
+
|
|
68
|
+
router.get('/getBlock', ctx => ctx.body = chain.blocks[ctx.query.index])
|
|
69
|
+
|
|
70
|
+
router.get('/blocks', ctx => {
|
|
71
|
+
ctx.body = chain.blocks.slice(ctx.query.amount)
|
|
72
|
+
})
|
|
73
|
+
|
|
74
|
+
router.get('/sendTransaction', async ctx => {
|
|
75
|
+
try {
|
|
76
|
+
const tx = await chain.sendTransaction(ctx.query.transaction)
|
|
77
|
+
await tx.wait()
|
|
78
|
+
send(tx)
|
|
79
|
+
} catch (error) {
|
|
80
|
+
send(202)
|
|
81
|
+
}
|
|
82
|
+
})
|
|
83
|
+
|
|
84
|
+
router.get('/peerId', ctx =>
|
|
85
|
+
ctx.body = peernet.peerId
|
|
86
|
+
)
|
|
87
|
+
|
|
88
|
+
router.get('/validators', ctx =>
|
|
89
|
+
ctx.body = chain.validators
|
|
90
|
+
)
|
|
91
|
+
|
|
92
|
+
router.get('/peers', ctx =>
|
|
93
|
+
ctx.body = peernet.peers
|
|
94
|
+
)
|
|
95
|
+
|
|
96
|
+
router.get('/lookup', async ctx => {
|
|
97
|
+
ctx.body = await chain.lookup(ctx.query.name)
|
|
98
|
+
})
|
|
99
|
+
|
|
100
|
+
router.get('/staticCall', async ctx =>
|
|
101
|
+
ctx.body = await chain.staticCall(ctx.query.contract, ctx.query.method, ctx.query.params)
|
|
102
|
+
)
|
|
103
|
+
|
|
104
|
+
router.get('/nativeBurns', ctx =>
|
|
105
|
+
ctx.body = chain.nativeBurns
|
|
106
|
+
)
|
|
107
|
+
|
|
108
|
+
router.get('/contracts', ctx =>
|
|
109
|
+
ctx.body = chain.contracts
|
|
110
|
+
)
|
|
111
|
+
|
|
112
|
+
router.get('/nativeMints', ctx =>
|
|
113
|
+
ctx.body = chain.nativeMints
|
|
114
|
+
)
|
|
115
|
+
|
|
116
|
+
router.get('/nativeToken', ctx =>
|
|
117
|
+
ctx.body = chain.nativeToken
|
|
118
|
+
)
|
|
119
|
+
|
|
120
|
+
router.get('/nativeTransfers', ctx =>
|
|
121
|
+
ctx.body = chain.nativeTransfers
|
|
122
|
+
)
|
|
123
|
+
|
|
124
|
+
router.get('/totalSize', ctx =>
|
|
125
|
+
ctx.body = chain.totalSize
|
|
126
|
+
)
|
|
127
|
+
|
|
128
|
+
router.get('/totalTransactions', ctx =>
|
|
129
|
+
ctx.body = chain.totalTransactions
|
|
130
|
+
)
|
|
131
|
+
|
|
132
|
+
router.get('/totalBlocks', ctx =>
|
|
133
|
+
ctx.body = chain.blocks.length
|
|
134
|
+
)
|
|
135
|
+
|
|
136
|
+
router.get('/nativeCalls', ctx =>
|
|
137
|
+
ctx.body = chain.nativeCalls
|
|
138
|
+
)
|
|
139
|
+
|
|
140
|
+
router.get('/participating', ctx =>
|
|
141
|
+
ctx.body = chain.participating
|
|
142
|
+
)
|
|
143
|
+
|
|
144
|
+
router.get('/participate', async ctx =>
|
|
145
|
+
ctx.body = await chain.participate(ctx.query.address)
|
|
146
|
+
)
|
|
147
|
+
|
|
148
|
+
router.get('/deployContract', async ctx => {
|
|
149
|
+
try {
|
|
150
|
+
const tx = await chain.deployContract(ctx.query.code, ctx.query.params)
|
|
151
|
+
await tx.wait()
|
|
152
|
+
delete tx.wait
|
|
153
|
+
ctx.body = JSON.stringify(tx)
|
|
154
|
+
} catch (error) {
|
|
155
|
+
|
|
156
|
+
}
|
|
157
|
+
})
|
|
158
|
+
|
|
159
|
+
router.get('/createContractAddress', async ctx => {
|
|
160
|
+
try {
|
|
161
|
+
const address = await chain.createContractAddress(ctx.query.owner, ctx.query.code, ctx.query.params)
|
|
162
|
+
ctx.body = address
|
|
163
|
+
} catch (error) {
|
|
164
|
+
|
|
165
|
+
}
|
|
166
|
+
})
|
|
167
|
+
|
|
168
|
+
// todo finish ...
|
|
169
|
+
api.use(cors('*'))
|
|
170
|
+
api.use(router.routes())
|
|
171
|
+
api.listen(port)
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import {formatUnits, BigNumber} from '@leofcoin/utils'
|
|
2
|
+
|
|
3
|
+
export const networkStats = async () => {
|
|
4
|
+
let accountsHolding = 0
|
|
5
|
+
let accountsHoldingAmount = BigNumber.from(0)
|
|
6
|
+
let topHolders = []
|
|
7
|
+
const balances = Object.entries(await chain.balances)
|
|
8
|
+
.map(([holder, amount]) => {
|
|
9
|
+
amount = BigNumber.from(amount)
|
|
10
|
+
return {holder, amount}
|
|
11
|
+
})
|
|
12
|
+
.sort((a, b) => formatUnits(b.amount.sub(a.amount)))
|
|
13
|
+
|
|
14
|
+
for (let {holder, amount} of balances) {
|
|
15
|
+
if (amount.gt(0)) {
|
|
16
|
+
accountsHoldingAmount = accountsHoldingAmount.add(amount)
|
|
17
|
+
accountsHolding += 1
|
|
18
|
+
topHolders.length < 100 && topHolders.push({holder, amount: formatUnits(amount)})
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
return {
|
|
23
|
+
version: networkVersion,
|
|
24
|
+
peers: peernet.peers,
|
|
25
|
+
accounts: await accountsStore.length(),
|
|
26
|
+
accountsHolding,
|
|
27
|
+
accountsHoldingAmount: formatUnits(accountsHoldingAmount).toString(),
|
|
28
|
+
topHolders
|
|
29
|
+
}
|
|
30
|
+
}
|
package/exports/ws.js
CHANGED
|
@@ -1,92 +1,99 @@
|
|
|
1
|
-
import Server from 'socket-request-server'
|
|
2
|
-
import {formatUnits} from '@leofcoin/utils'
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
},
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
},
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
1
|
+
import Server from 'socket-request-server'
|
|
2
|
+
import {formatUnits} from '@leofcoin/utils'
|
|
3
|
+
import shared from './shared'
|
|
4
|
+
|
|
5
|
+
export default (chain, port, networkVersion) => {
|
|
6
|
+
return Server({ port, protocol: networkVersion }, {
|
|
7
|
+
network: async () => {
|
|
8
|
+
send({version: networkVersion})
|
|
9
|
+
},
|
|
10
|
+
networkStats: async ({send}) => {
|
|
11
|
+
send(await shared.networkStats(chain))
|
|
12
|
+
},
|
|
13
|
+
balances: async ({send}) =>
|
|
14
|
+
send(await chain.balances),
|
|
15
|
+
balanceOf: async ({address, format = false}, {send}) => {
|
|
16
|
+
const balance = (await chain.balances)[address]
|
|
17
|
+
if (balance) send(format ? formatUnits(balance) : balance)
|
|
18
|
+
else send(0)
|
|
19
|
+
},
|
|
20
|
+
getNonce: async ({address}, {send}) => send((await chain.balances)[address]),
|
|
21
|
+
selectedAccount: ({send}) => send(peernet.selectedAccount),
|
|
22
|
+
selectAccount: async ({address}, {send}) => {
|
|
23
|
+
try {
|
|
24
|
+
await walletStore.put('selected-account', address)
|
|
25
|
+
send(200)
|
|
26
|
+
} catch (error) {
|
|
27
|
+
send(404)
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
accounts: async ({send}) =>
|
|
31
|
+
send(JSON.parse(new TextDecoder().decode((await walletStore.get('accounts'))))),
|
|
32
|
+
hasTransactionToHandle: async ({send}) =>
|
|
33
|
+
send(await chain.hasTransactionToHandle()),
|
|
34
|
+
getBlock: ({index}, {send}) =>
|
|
35
|
+
send(chain.blocks[index]),
|
|
36
|
+
blocks:({amount}, {send}) => {
|
|
37
|
+
send(chain.blocks.slice(amount))},
|
|
38
|
+
sendTransaction: async (transaction, {send}) => {
|
|
39
|
+
try {
|
|
40
|
+
const tx = await chain.sendTransaction(transaction)
|
|
41
|
+
await tx.wait()
|
|
42
|
+
send(tx)
|
|
43
|
+
} catch (error) {
|
|
44
|
+
send(202)
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
peerId: ({send}) =>
|
|
48
|
+
send(peernet.peerId),
|
|
49
|
+
peers: ({send}) =>
|
|
50
|
+
send(peernet.peers),
|
|
51
|
+
validators: ({send}) =>
|
|
52
|
+
send(chain.validators),
|
|
53
|
+
lookup: async ({name}, {send}) =>
|
|
54
|
+
send(await chain.lookup(name)),
|
|
55
|
+
staticCall: async({contract, method, params}, {send}) =>
|
|
56
|
+
send(await chain.staticCall(contract, method, params)),
|
|
57
|
+
nativeBurns: ({send}) =>
|
|
58
|
+
send(chain.nativeBurns),
|
|
59
|
+
contracts: ({send}) =>
|
|
60
|
+
send(chain.contracts),
|
|
61
|
+
nativeMints: ({send}) =>
|
|
62
|
+
send(chain.nativeMints),
|
|
63
|
+
nativeToken: ({send}) =>
|
|
64
|
+
send(chain.nativeToken),
|
|
65
|
+
nativeTransfers: ({send}) =>
|
|
66
|
+
send(chain.nativeTransfers),
|
|
67
|
+
totalSize: ({send}) =>
|
|
68
|
+
send(chain.totalSize),
|
|
69
|
+
totalTransactions: ({send}) =>
|
|
70
|
+
send(chain.totalTransactions),
|
|
71
|
+
totalBlocks: ({send}) =>
|
|
72
|
+
send(chain.blocks.length),
|
|
73
|
+
nativeCalls: ({send}) =>
|
|
74
|
+
send(chain.nativeCalls),
|
|
75
|
+
participating: ({send}) =>
|
|
76
|
+
send(chain.participating),
|
|
77
|
+
participate: async ({address}, {send}) =>
|
|
78
|
+
send(await chain.participate(address)),
|
|
79
|
+
deployContract: async ({code, params}, {send}) => {
|
|
80
|
+
try {
|
|
81
|
+
const tx = await chain.deployContract(code, params)
|
|
82
|
+
await tx.wait()
|
|
83
|
+
delete tx.wait
|
|
84
|
+
send(tx)
|
|
85
|
+
} catch (error) {
|
|
86
|
+
send(error.message)
|
|
87
|
+
}
|
|
88
|
+
},
|
|
89
|
+
createContractAddress: async ({owner, code, params}, {send}) => {
|
|
90
|
+
try {
|
|
91
|
+
const address = await chain.createContractAddress(owner, code, params)
|
|
92
|
+
send(address)
|
|
93
|
+
} catch (error) {
|
|
94
|
+
send(error)
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
})
|
|
98
|
+
}
|
|
99
|
+
|
package/package.json
CHANGED
package/rollup.config.js
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import resolve from '@rollup/plugin-node-resolve'
|
|
2
|
-
import commonjs from '@rollup/plugin-commonjs'
|
|
3
|
-
import json from '@rollup/plugin-json'
|
|
4
|
-
import wasm from '@rollup/plugin-wasm'
|
|
5
|
-
import rimraf from 'rimraf'
|
|
6
|
-
|
|
7
|
-
rimraf.sync('./exports/**')
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
export default [{
|
|
11
|
-
input: ['./src/peernet.ts', './node_modules/@leofcoin/storage/exports/browser-store.js'],
|
|
12
|
-
output: {
|
|
13
|
-
format: 'es',
|
|
14
|
-
dir: './exports/browser'
|
|
15
|
-
},
|
|
16
|
-
plugins: [
|
|
17
|
-
json(),
|
|
18
|
-
wasm(),
|
|
19
|
-
commonjs(),
|
|
20
|
-
resolve({
|
|
21
|
-
mainFields: ["browser", "module", "main"]
|
|
22
|
-
})
|
|
23
|
-
]
|
|
24
|
-
}, {
|
|
25
|
-
input: ['./src/peernet.ts', './node_modules/@leofcoin/storage/exports/store.js'],
|
|
26
|
-
output: {
|
|
27
|
-
format: 'es',
|
|
28
|
-
dir: './exports'
|
|
29
|
-
}
|
|
30
|
-
}]
|
package/tsconfig.json
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"module": "ES2022",
|
|
4
|
-
"target": "es2022",
|
|
5
|
-
// "noImplicitAny": true,
|
|
6
|
-
"removeComments": true,
|
|
7
|
-
"preserveConstEnums": true,
|
|
8
|
-
"outDir": ".build/",
|
|
9
|
-
"moduleResolution":"NodeNext",
|
|
10
|
-
"allowJs": true,
|
|
11
|
-
"declaration": true
|
|
12
|
-
},
|
|
13
|
-
"include": [
|
|
14
|
-
"./src/**/*"
|
|
15
|
-
],
|
|
16
|
-
"exclude": ["node_modules"]
|
|
17
|
-
}
|