@leofcoin/endpoints 0.2.5 → 0.2.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
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,181 @@
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 { dirname, join} from 'path'
8
- import { fileURLToPath } from 'url'
9
-
10
- const __filename = fileURLToPath(import.meta.url);
11
- const __dirname = dirname(__filename);
12
-
13
- const api = new koa()
14
- const router = new Router()
15
-
16
- const converter = new Showdown.Converter()
17
- const apiFile = await readFile(join(__dirname, './api.md'))
18
-
19
- export default (chain, port, networkVersion) => {
20
- // api routes
21
- router.get('/', ctx => {
22
- ctx.body = converter.makeHtml(apiFile.toString())
23
- })
24
-
25
- router.get('/network', ctx => {
26
- ctx.body = networkVersion
27
- })
28
-
29
- router.get('/balances', async ctx => {
30
- ctx.body = await chain.balances
31
- })
32
-
33
- router.get('/balanceOf', async ctx => {
34
- const balance = (await chain.balances)[ctx.query.address]
35
- if (balance) ctx.body = ctx.query.format ? formatUnits(balance) : balance
36
- else ctx.body = 0
37
- })
38
-
39
- router.get('/selectedAccount', ctx => ctx.body = peernet.selectedAccount)
40
-
41
- router.get('/selectAccount', async ctx => {
42
- try {
43
- await walletStore.put('selected-account', address)
44
- } catch (error) {
45
- }
46
- return
47
- })
48
-
49
- router.get('/accounts', async ctx => {
50
- ctx.body = JSON.parse(new TextDecoder().decode((await walletStore.get('accounts'))))
51
- })
52
-
53
- router.get('/hasTransactionToHandle', async ctx => {
54
- ctx.body = await chain.hasTransactionToHandle()
55
- })
56
-
57
- router.get('/getNonce', async ctx => {
58
- ctx.body = await chain.getNonce(ctx.query.address)
59
- })
60
-
61
- router.get('/getBlock', ctx => ctx.body = chain.blocks[ctx.query.index])
62
-
63
- router.get('/blocks', ctx => {
64
- ctx.body = chain.blocks.slice(ctx.query.amount)
65
- })
66
-
67
- router.get('/sendTransaction', async ctx => {
68
- try {
69
- const tx = await chain.sendTransaction(ctx.query.transaction)
70
- await tx.wait()
71
- send(tx)
72
- } catch (error) {
73
- send(202)
74
- }
75
- })
76
-
77
- router.get('/peerId', ctx =>
78
- ctx.body = peernet.peerId
79
- )
80
-
81
- router.get('/validators', ctx =>
82
- ctx.body = chain.validators
83
- )
84
-
85
- router.get('/peers', ctx =>
86
- ctx.body = peernet.peers
87
- )
88
-
89
- router.get('/lookup', async ctx => {
90
- ctx.body = await chain.lookup(ctx.query.name)
91
- })
92
-
93
- router.get('/staticCall', async ctx =>
94
- ctx.body = await chain.staticCall(ctx.query.contract, ctx.query.method, ctx.query.params)
95
- )
96
-
97
- router.get('/nativeBurns', ctx =>
98
- ctx.body = chain.nativeBurns
99
- )
100
-
101
- router.get('/contracts', ctx =>
102
- ctx.body = chain.contracts
103
- )
104
-
105
- router.get('/nativeMints', ctx =>
106
- ctx.body = chain.nativeMints
107
- )
108
-
109
- router.get('/nativeToken', ctx =>
110
- ctx.body = chain.nativeToken
111
- )
112
-
113
- router.get('/nativeTransfers', ctx =>
114
- ctx.body = chain.nativeTransfers
115
- )
116
-
117
- router.get('/totalSize', ctx =>
118
- ctx.body = chain.totalSize
119
- )
120
-
121
- router.get('/totalTransactions', ctx =>
122
- ctx.body = chain.totalTransactions
123
- )
124
-
125
- router.get('/totalBlocks', ctx =>
126
- ctx.body = chain.blocks.length
127
- )
128
-
129
- router.get('/nativeCalls', ctx =>
130
- ctx.body = chain.nativeCalls
131
- )
132
-
133
- router.get('/participating', ctx =>
134
- ctx.body = chain.participating
135
- )
136
-
137
- router.get('/participate', async ctx =>
138
- ctx.body = await chain.participate(ctx.query.address)
139
- )
140
-
141
- router.get('/deployContract', async ctx => {
142
- try {
143
- const tx = await chain.deployContract(ctx.query.code, ctx.query.params)
144
- await tx.wait()
145
- delete tx.wait
146
- ctx.body = JSON.stringify(tx)
147
- } catch (error) {
148
-
149
- }
150
- })
151
-
152
- router.get('/createContractAddress', async ctx => {
153
- try {
154
- const address = await chain.createContractAddress(ctx.query.owner, ctx.query.code, ctx.query.params)
155
- ctx.body = address
156
- } catch (error) {
157
-
158
- }
159
- })
160
-
161
- // todo finish ...
162
- api.use(cors('*'))
163
- api.use(router.routes())
164
- api.listen(port)
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 { dirname, join} from 'path'
8
+ import { fileURLToPath } from 'url'
9
+
10
+ const __filename = fileURLToPath(import.meta.url);
11
+ const __dirname = dirname(__filename);
12
+
13
+ const api = new koa()
14
+ const router = new Router()
15
+
16
+ const converter = new Showdown.Converter()
17
+ const apiFile = await readFile(join(__dirname, './api.md'))
18
+
19
+ export default (chain, port, networkVersion) => {
20
+ // api routes
21
+ router.get('/', ctx => {
22
+ ctx.body = converter.makeHtml(apiFile.toString())
23
+ })
24
+
25
+ router.get('/network', ctx => {
26
+ ctx.body = {
27
+ version: networkVersion
28
+ }
29
+ })
30
+
31
+ router.get('/networkStats', async () => {
32
+ ctx.body = {
33
+ version: networkVersion,
34
+ peers: peernet.peers,
35
+ accounts: await accountsStore.length(),
36
+ accountsHolding: Object.values(await chain.balances).reduce((previous, current) => {
37
+ const amount = Number(formatUnits(current)) || 0
38
+ return previous + isNaN(amount) ? 0 : amount
39
+ }, 0)
40
+ }
41
+ })
42
+
43
+ router.get('/balances', async ctx => {
44
+ ctx.body = await chain.balances
45
+ })
46
+
47
+ router.get('/balanceOf', async ctx => {
48
+ const balance = (await chain.balances)[ctx.query.address]
49
+ if (balance) ctx.body = ctx.query.format ? formatUnits(balance) : balance
50
+ else ctx.body = 0
51
+ })
52
+
53
+ router.get('/selectedAccount', ctx => ctx.body = peernet.selectedAccount)
54
+
55
+ router.get('/selectAccount', async ctx => {
56
+ try {
57
+ await walletStore.put('selected-account', address)
58
+ } catch (error) {
59
+ }
60
+ return
61
+ })
62
+
63
+ router.get('/accounts', async ctx => {
64
+ ctx.body = JSON.parse(new TextDecoder().decode((await walletStore.get('accounts'))))
65
+ })
66
+
67
+ router.get('/hasTransactionToHandle', async ctx => {
68
+ ctx.body = await chain.hasTransactionToHandle()
69
+ })
70
+
71
+ router.get('/getNonce', async ctx => {
72
+ ctx.body = await chain.getNonce(ctx.query.address)
73
+ })
74
+
75
+ router.get('/getBlock', ctx => ctx.body = chain.blocks[ctx.query.index])
76
+
77
+ router.get('/blocks', ctx => {
78
+ ctx.body = chain.blocks.slice(ctx.query.amount)
79
+ })
80
+
81
+ router.get('/sendTransaction', async ctx => {
82
+ try {
83
+ const tx = await chain.sendTransaction(ctx.query.transaction)
84
+ await tx.wait()
85
+ send(tx)
86
+ } catch (error) {
87
+ send(202)
88
+ }
89
+ })
90
+
91
+ router.get('/peerId', ctx =>
92
+ ctx.body = peernet.peerId
93
+ )
94
+
95
+ router.get('/validators', ctx =>
96
+ ctx.body = chain.validators
97
+ )
98
+
99
+ router.get('/peers', ctx =>
100
+ ctx.body = peernet.peers
101
+ )
102
+
103
+ router.get('/lookup', async ctx => {
104
+ ctx.body = await chain.lookup(ctx.query.name)
105
+ })
106
+
107
+ router.get('/staticCall', async ctx =>
108
+ ctx.body = await chain.staticCall(ctx.query.contract, ctx.query.method, ctx.query.params)
109
+ )
110
+
111
+ router.get('/nativeBurns', ctx =>
112
+ ctx.body = chain.nativeBurns
113
+ )
114
+
115
+ router.get('/contracts', ctx =>
116
+ ctx.body = chain.contracts
117
+ )
118
+
119
+ router.get('/nativeMints', ctx =>
120
+ ctx.body = chain.nativeMints
121
+ )
122
+
123
+ router.get('/nativeToken', ctx =>
124
+ ctx.body = chain.nativeToken
125
+ )
126
+
127
+ router.get('/nativeTransfers', ctx =>
128
+ ctx.body = chain.nativeTransfers
129
+ )
130
+
131
+ router.get('/totalSize', ctx =>
132
+ ctx.body = chain.totalSize
133
+ )
134
+
135
+ router.get('/totalTransactions', ctx =>
136
+ ctx.body = chain.totalTransactions
137
+ )
138
+
139
+ router.get('/totalBlocks', ctx =>
140
+ ctx.body = chain.blocks.length
141
+ )
142
+
143
+ router.get('/nativeCalls', ctx =>
144
+ ctx.body = chain.nativeCalls
145
+ )
146
+
147
+ router.get('/participating', ctx =>
148
+ ctx.body = chain.participating
149
+ )
150
+
151
+ router.get('/participate', async ctx =>
152
+ ctx.body = await chain.participate(ctx.query.address)
153
+ )
154
+
155
+ router.get('/deployContract', async ctx => {
156
+ try {
157
+ const tx = await chain.deployContract(ctx.query.code, ctx.query.params)
158
+ await tx.wait()
159
+ delete tx.wait
160
+ ctx.body = JSON.stringify(tx)
161
+ } catch (error) {
162
+
163
+ }
164
+ })
165
+
166
+ router.get('/createContractAddress', async ctx => {
167
+ try {
168
+ const address = await chain.createContractAddress(ctx.query.owner, ctx.query.code, ctx.query.params)
169
+ ctx.body = address
170
+ } catch (error) {
171
+
172
+ }
173
+ })
174
+
175
+ // todo finish ...
176
+ api.use(cors('*'))
177
+ api.use(router.routes())
178
+ api.listen(port)
179
+ }
180
+
181
+
package/exports/ws.js CHANGED
@@ -1,92 +1,106 @@
1
- import Server from 'socket-request-server'
2
- import {formatUnits} from '@leofcoin/utils'
3
-
4
- export default (chain, port, protocol) => {
5
- return Server({ port, protocol }, {
6
- balances: async ({send}) =>
7
- send(await chain.balances),
8
- balanceOf: async ({address, format = false}, {send}) => {
9
- const balance = (await chain.balances)[address]
10
- if (balance) send(format ? formatUnits(balance) : balance)
11
- else send(0)
12
- },
13
- getNonce: async ({address}, {send}) => send((await chain.balances)[address]),
14
- selectedAccount: ({send}) => send(peernet.selectedAccount),
15
- selectAccount: async ({address}, {send}) => {
16
- try {
17
- await walletStore.put('selected-account', address)
18
- send(200)
19
- } catch (error) {
20
- send(404)
21
- }
22
- },
23
- accounts: async ({send}) =>
24
- send(JSON.parse(new TextDecoder().decode((await walletStore.get('accounts'))))),
25
- hasTransactionToHandle: ({send}) =>
26
- send(chain.hasTransactionToHandle()),
27
- getBlock: ({index}, {send}) =>
28
- send(chain.blocks[index]),
29
- blocks:({amount}, {send}) => {
30
- send(chain.blocks.slice(amount))},
31
- sendTransaction: async (transaction, {send}) => {
32
- try {
33
- const tx = await chain.sendTransaction(transaction)
34
- await tx.wait()
35
- send(tx)
36
- } catch (error) {
37
- send(202)
38
- }
39
- },
40
- peerId: ({send}) =>
41
- send(peernet.peerId),
42
- peers: ({send}) =>
43
- send(peernet.peers),
44
- validators: ({send}) =>
45
- send(chain.validators),
46
- lookup: async ({name}, {send}) =>
47
- send(await chain.lookup(name)),
48
- staticCall: async({contract, method, params}, {send}) =>
49
- send(await chain.staticCall(contract, method, params)),
50
- nativeBurns: ({send}) =>
51
- send(chain.nativeBurns),
52
- contracts: ({send}) =>
53
- send(chain.contracts),
54
- nativeMints: ({send}) =>
55
- send(chain.nativeMints),
56
- nativeToken: ({send}) =>
57
- send(chain.nativeToken),
58
- nativeTransfers: ({send}) =>
59
- send(chain.nativeTransfers),
60
- totalSize: ({send}) =>
61
- send(chain.totalSize),
62
- totalTransactions: ({send}) =>
63
- send(chain.totalTransactions),
64
- totalBlocks: ({send}) =>
65
- send(chain.blocks.length),
66
- nativeCalls: ({send}) =>
67
- send(chain.nativeCalls),
68
- participating: ({send}) =>
69
- send(chain.participating),
70
- participate: async ({address}, {send}) =>
71
- send(await chain.participate(address)),
72
- deployContract: async ({code, params}, {send}) => {
73
- try {
74
- const tx = await chain.deployContract(code, params)
75
- await tx.wait()
76
- delete tx.wait
77
- send(tx)
78
- } catch (error) {
79
- send(error.message)
80
- }
81
- },
82
- createContractAddress: async ({owner, code, params}, {send}) => {
83
- try {
84
- const address = await chain.createContractAddress(owner, code, params)
85
- send(address)
86
- } catch (error) {
87
- send(error)
88
- }
89
- }
90
- })
91
- }
92
-
1
+ import Server from 'socket-request-server'
2
+ import {formatUnits} from '@leofcoin/utils'
3
+
4
+ export default (chain, port, networkVersion) => {
5
+ return Server({ port, protocol: networkVersion }, {
6
+ network: async () => {
7
+ send({version: networkVersion})
8
+ },
9
+ networkStats: async () => {
10
+ send({
11
+ version: networkVersion,
12
+ peers: peernet.peers,
13
+ accounts: await accountsStore.length(),
14
+ accountsHolding: Object.values(await chain.balances).reduce((previous, current) => {
15
+ const amount = Number(formatUnits(current)) || 0
16
+ return previous + isNaN(amount) ? 0 : amount
17
+ }, 0)
18
+ })
19
+ },
20
+ balances: async ({send}) =>
21
+ send(await chain.balances),
22
+ balanceOf: async ({address, format = false}, {send}) => {
23
+ const balance = (await chain.balances)[address]
24
+ if (balance) send(format ? formatUnits(balance) : balance)
25
+ else send(0)
26
+ },
27
+ getNonce: async ({address}, {send}) => send((await chain.balances)[address]),
28
+ selectedAccount: ({send}) => send(peernet.selectedAccount),
29
+ selectAccount: async ({address}, {send}) => {
30
+ try {
31
+ await walletStore.put('selected-account', address)
32
+ send(200)
33
+ } catch (error) {
34
+ send(404)
35
+ }
36
+ },
37
+ accounts: async ({send}) =>
38
+ send(JSON.parse(new TextDecoder().decode((await walletStore.get('accounts'))))),
39
+ hasTransactionToHandle: ({send}) =>
40
+ send(chain.hasTransactionToHandle()),
41
+ getBlock: ({index}, {send}) =>
42
+ send(chain.blocks[index]),
43
+ blocks:({amount}, {send}) => {
44
+ send(chain.blocks.slice(amount))},
45
+ sendTransaction: async (transaction, {send}) => {
46
+ try {
47
+ const tx = await chain.sendTransaction(transaction)
48
+ await tx.wait()
49
+ send(tx)
50
+ } catch (error) {
51
+ send(202)
52
+ }
53
+ },
54
+ peerId: ({send}) =>
55
+ send(peernet.peerId),
56
+ peers: ({send}) =>
57
+ send(peernet.peers),
58
+ validators: ({send}) =>
59
+ send(chain.validators),
60
+ lookup: async ({name}, {send}) =>
61
+ send(await chain.lookup(name)),
62
+ staticCall: async({contract, method, params}, {send}) =>
63
+ send(await chain.staticCall(contract, method, params)),
64
+ nativeBurns: ({send}) =>
65
+ send(chain.nativeBurns),
66
+ contracts: ({send}) =>
67
+ send(chain.contracts),
68
+ nativeMints: ({send}) =>
69
+ send(chain.nativeMints),
70
+ nativeToken: ({send}) =>
71
+ send(chain.nativeToken),
72
+ nativeTransfers: ({send}) =>
73
+ send(chain.nativeTransfers),
74
+ totalSize: ({send}) =>
75
+ send(chain.totalSize),
76
+ totalTransactions: ({send}) =>
77
+ send(chain.totalTransactions),
78
+ totalBlocks: ({send}) =>
79
+ send(chain.blocks.length),
80
+ nativeCalls: ({send}) =>
81
+ send(chain.nativeCalls),
82
+ participating: ({send}) =>
83
+ send(chain.participating),
84
+ participate: async ({address}, {send}) =>
85
+ send(await chain.participate(address)),
86
+ deployContract: async ({code, params}, {send}) => {
87
+ try {
88
+ const tx = await chain.deployContract(code, params)
89
+ await tx.wait()
90
+ delete tx.wait
91
+ send(tx)
92
+ } catch (error) {
93
+ send(error.message)
94
+ }
95
+ },
96
+ createContractAddress: async ({owner, code, params}, {send}) => {
97
+ try {
98
+ const address = await chain.createContractAddress(owner, code, params)
99
+ send(address)
100
+ } catch (error) {
101
+ send(error)
102
+ }
103
+ }
104
+ })
105
+ }
106
+
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leofcoin/endpoints",
3
- "version": "0.2.5",
3
+ "version": "0.2.6",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "exports": {
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
- }