@leofcoin/endpoints 0.1.4 → 0.2.1

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/exports/api.md ADDED
@@ -0,0 +1,188 @@
1
+ #### selectAccount(address: `string`)
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`)
10
+ `index`: index of the block to fetch<br>
11
+ ```js
12
+ await client.getBlock(10)
13
+ ```
14
+ <br>
15
+
16
+ #### blocks(amount)
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`)
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()
79
+ ```js
80
+ await client.accounts()
81
+ ```
82
+ <br>
83
+
84
+ #### hasTransactionToHandle()
85
+ ```js
86
+ await client.hasTransactionToHandle()
87
+ ```
88
+ <br>
89
+
90
+ #### balances()
91
+ > returns all balances
92
+ ```js
93
+ await client.balances()
94
+ ```
95
+ <br>
96
+
97
+ #### balancOf(address: `string`, format: `boolean`)
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
+ #### selectedAccount()
107
+ ```js
108
+ await client.selectedAccount()
109
+ ```
110
+ <br>
111
+
112
+ #### peerId()
113
+ ```js
114
+ await client.peerId()
115
+ ```
116
+ <br>
117
+
118
+ #### peers()
119
+ ```js
120
+ await client.peers()
121
+ ```
122
+ <br>
123
+
124
+ #### validators()
125
+ ```js
126
+ await client.validators()
127
+ ```
128
+ <br>
129
+
130
+ #### nativeBurns()
131
+ ```js
132
+ await client.nativeBurns()
133
+ ```
134
+ <br>
135
+
136
+ #### contracts()
137
+ ```js
138
+ await client.contracts()
139
+ ```
140
+ <br>
141
+
142
+ #### nativeMints()
143
+ ```js
144
+ await client.nativeMints()
145
+ ```
146
+ <br>
147
+
148
+ #### nativeToken()
149
+ ```js
150
+ await client.nativeToken()
151
+ ```
152
+ <br>
153
+
154
+ #### nativeTransfers()
155
+ ```js
156
+ await client. nativeTransfers()
157
+ ```
158
+ <br>
159
+
160
+ #### totalSize()
161
+ ```js
162
+ await client.totalSize()
163
+ ```
164
+ <br>
165
+
166
+ #### totalTransactions()
167
+ ```js
168
+ await client.totalTransactions()
169
+ ```
170
+ <br>
171
+
172
+ #### totalBlocks()
173
+ ```js
174
+ await client.totalBlocks()
175
+ ```
176
+ <br>
177
+
178
+ #### nativeCalls()
179
+ ```js
180
+ await client.nativeCalls()
181
+ ```
182
+ <br>
183
+
184
+ #### participating()
185
+ ```js
186
+ await client.participating()
187
+ ```
188
+ <br>
package/exports/http.js CHANGED
@@ -2,11 +2,21 @@ import koa from 'koa'
2
2
  import cors from '@koa/cors'
3
3
  import Router from '@koa/router'
4
4
  import {formatUnits} from '@leofcoin/utils'
5
+ import {readFile} from 'fs/promises'
6
+ import Showdown from 'showdown'
5
7
 
6
8
  const api = new koa()
7
9
  const router = new Router()
8
10
 
11
+ const converter = new showdown.Converter()
12
+ const apiFile = await readFile('./api.md')
13
+
9
14
  export default (chain, port, networkVersion) => {
15
+ // api routes
16
+ router.get('/', ctx => {
17
+ ctx.body = converter.makeHtml(apiFile.toString())
18
+ })
19
+
10
20
  router.get('/network', ctx => {
11
21
  ctx.body = networkVersion
12
22
  })
@@ -30,12 +40,95 @@ export default (chain, port, networkVersion) => {
30
40
  return
31
41
  })
32
42
 
43
+ router.get('/accounts', async ctx => {
44
+ ctx.body = JSON.parse(new TextDecoder().decode((await walletStore.get('accounts'))))
45
+ })
46
+
47
+ router.get('/hasTransactionToHandle', async ctx => {
48
+ ctx.body = await chain.hasTransactionToHandle()
49
+ })
50
+ router.get('/getBlock', ctx => ctx.body = chain.blocks[ctx.query.index])
51
+
52
+ router.get('/blocks', ctx => {
53
+ ctx.body = chain.blocks.slice(ctx.query.amount)
54
+ })
55
+
56
+ router.get('/createTransactionFrom', async ctx => {
57
+ try {
58
+ const tx = await chain.createTransactionFrom(ctx.query.from, ctx.query.to, ctx.query.method, ctx.query.parameters, ctx.query.nonce)
59
+ await tx.wait()
60
+ send(tx)
61
+ } catch (error) {
62
+ send(202)
63
+ }
64
+ })
65
+
66
+ router.get('/peerId', ctx =>
67
+ ctx.body = peernet.peerId
68
+ )
69
+
70
+ router.get('/validators', ctx =>
71
+ ctx.body = chain.validators
72
+ )
73
+
74
+ router.get('/lookup', ctx =>
75
+ ctx.body = chain.lookup(ctx.query.name)
76
+ )
77
+
78
+ router.get('/staticCall', async ctx =>
79
+ ctx.body = await chain.staticCall(ctx.query.contract, ctx.query.method, ctx.query.params)
80
+ )
81
+
82
+ router.get('/nativeBurns', ctx =>
83
+ ctx.body = chain.nativeBurns
84
+ )
85
+
86
+ router.get('/contracts', ctx =>
87
+ ctx.body = chain.contracts
88
+ )
89
+
90
+ router.get('/nativeMints', ctx =>
91
+ ctx.body = chain.nativeMints
92
+ )
93
+
94
+ router.get('/nativeToken', ctx =>
95
+ ctx.body = chain.nativeToken
96
+ )
97
+
98
+ router.get('/nativeTransfers', ctx =>
99
+ ctx.body = chain.nativeTransfers
100
+ )
101
+
102
+ router.get('/totalSize', ctx =>
103
+ ctx.body = chain.totalSize
104
+ )
105
+
106
+ router.get('/totalTransactions', ctx =>
107
+ ctx.body = chain.totalTransactions
108
+ )
109
+
110
+ router.get('/totalBlocks', ctx =>
111
+ ctx.body = chain.blocks.length
112
+ )
113
+
114
+ router.get('/nativeCalls', ctx =>
115
+ ctx.body = chain.nativeCalls
116
+ )
117
+
118
+ router.get('/participating', ctx =>
119
+ ctx.body = chain.participating
120
+ )
121
+
122
+ router.get('participate', async ctx =>
123
+ ctx.body = await chain.participate(ctx.query.address)
124
+ )
125
+
33
126
  router.get('/deployContract', async ctx => {
34
127
  try {
35
128
  const tx = await chain.deployContract(ctx.query.code, ctx.query.params)
36
129
  await tx.wait()
37
130
  delete tx.wait
38
- ctx.body = tx
131
+ ctx.body = JSON.stringify(tx)
39
132
  } catch (error) {
40
133
 
41
134
  }
package/exports/ws.js CHANGED
@@ -38,7 +38,7 @@ export default (chain, port, protocol) => {
38
38
  peerId: ({send}) =>
39
39
  send(peernet.peerId),
40
40
  peers: ({send}) =>
41
- send(node.peers),
41
+ send(peernet.peers),
42
42
  validators: ({send}) =>
43
43
  send(chain.validators),
44
44
  lookup: async ({name}, {send}) =>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leofcoin/endpoints",
3
- "version": "0.1.4",
3
+ "version": "0.2.1",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "exports": {
@@ -26,6 +26,7 @@
26
26
  "@koa/router": "^12.0.0",
27
27
  "@leofcoin/utils": "^1.1.5",
28
28
  "koa": "^2.14.1",
29
+ "showdown": "^2.1.0",
29
30
  "socket-request-server": "^1.6.3"
30
31
  }
31
32
  }
@@ -0,0 +1,30 @@
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 ADDED
@@ -0,0 +1,17 @@
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
+ "sourceMap": true,
11
+ "allowJs": true
12
+ },
13
+ "include": [
14
+ "./src/**/*"
15
+ ],
16
+ "exclude": ["node_modules"]
17
+ }