@leofcoin/endpoints 0.2.3 → 0.2.5

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/README.md CHANGED
@@ -1,2 +1,9 @@
1
1
  # endpoints
2
2
 
3
+ ```js
4
+ http(chain, port, networkVersion)
5
+ ```
6
+
7
+ ```js
8
+ wss(chain, port, networkVersion)
9
+ ```
package/exports/api.md CHANGED
@@ -103,6 +103,15 @@ await client.balanceOf(address, true)
103
103
  ```
104
104
  <br>
105
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
+
106
115
  #### [selectedAccount()](https://remote.leofcoin.org/selectedAccount)
107
116
  ```js
108
117
  await client.selectedAccount()
package/exports/http.js CHANGED
@@ -4,12 +4,17 @@ import Router from '@koa/router'
4
4
  import {formatUnits} from '@leofcoin/utils'
5
5
  import {readFile} from 'fs/promises'
6
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);
7
12
 
8
13
  const api = new koa()
9
14
  const router = new Router()
10
15
 
11
16
  const converter = new Showdown.Converter()
12
- const apiFile = await readFile('./api.md')
17
+ const apiFile = await readFile(join(__dirname, './api.md'))
13
18
 
14
19
  export default (chain, port, networkVersion) => {
15
20
  // api routes
@@ -25,9 +30,10 @@ export default (chain, port, networkVersion) => {
25
30
  ctx.body = await chain.balances
26
31
  })
27
32
 
28
- router.get('balanceOf', async ctx => {
29
- const balance = (await chain.balances)[ctx.query.address]
30
- ctx.body = ctx.query.format ? formatUnits(balance) : balance
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
31
37
  })
32
38
 
33
39
  router.get('/selectedAccount', ctx => ctx.body = peernet.selectedAccount)
@@ -47,15 +53,20 @@ export default (chain, port, networkVersion) => {
47
53
  router.get('/hasTransactionToHandle', async ctx => {
48
54
  ctx.body = await chain.hasTransactionToHandle()
49
55
  })
56
+
57
+ router.get('/getNonce', async ctx => {
58
+ ctx.body = await chain.getNonce(ctx.query.address)
59
+ })
60
+
50
61
  router.get('/getBlock', ctx => ctx.body = chain.blocks[ctx.query.index])
51
62
 
52
63
  router.get('/blocks', ctx => {
53
64
  ctx.body = chain.blocks.slice(ctx.query.amount)
54
65
  })
55
66
 
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)
67
+ router.get('/sendTransaction', async ctx => {
68
+ try {
69
+ const tx = await chain.sendTransaction(ctx.query.transaction)
59
70
  await tx.wait()
60
71
  send(tx)
61
72
  } catch (error) {
@@ -71,6 +82,10 @@ export default (chain, port, networkVersion) => {
71
82
  ctx.body = chain.validators
72
83
  )
73
84
 
85
+ router.get('/peers', ctx =>
86
+ ctx.body = peernet.peers
87
+ )
88
+
74
89
  router.get('/lookup', async ctx => {
75
90
  ctx.body = await chain.lookup(ctx.query.name)
76
91
  })
@@ -119,7 +134,7 @@ export default (chain, port, networkVersion) => {
119
134
  ctx.body = chain.participating
120
135
  )
121
136
 
122
- router.get('participate', async ctx =>
137
+ router.get('/participate', async ctx =>
123
138
  ctx.body = await chain.participate(ctx.query.address)
124
139
  )
125
140
 
package/exports/ws.js CHANGED
@@ -6,9 +6,11 @@ export default (chain, port, protocol) => {
6
6
  balances: async ({send}) =>
7
7
  send(await chain.balances),
8
8
  balanceOf: async ({address, format = false}, {send}) => {
9
- const balance = (await chain.balances)[address]
10
- send(format ? formatUnits(balance) : balance)
9
+ const balance = (await chain.balances)[address]
10
+ if (balance) send(format ? formatUnits(balance) : balance)
11
+ else send(0)
11
12
  },
13
+ getNonce: async ({address}, {send}) => send((await chain.balances)[address]),
12
14
  selectedAccount: ({send}) => send(peernet.selectedAccount),
13
15
  selectAccount: async ({address}, {send}) => {
14
16
  try {
@@ -26,9 +28,9 @@ export default (chain, port, protocol) => {
26
28
  send(chain.blocks[index]),
27
29
  blocks:({amount}, {send}) => {
28
30
  send(chain.blocks.slice(amount))},
29
- createTransactionFrom: async ({from, to, method, parameters, nonce}, {send}) => {
31
+ sendTransaction: async (transaction, {send}) => {
30
32
  try {
31
- const tx = await chain.createTransactionFrom(from, to, method, parameters, nonce)
33
+ const tx = await chain.sendTransaction(transaction)
32
34
  await tx.wait()
33
35
  send(tx)
34
36
  } catch (error) {
package/package.json CHANGED
@@ -1,9 +1,10 @@
1
1
  {
2
2
  "name": "@leofcoin/endpoints",
3
- "version": "0.2.3",
3
+ "version": "0.2.5",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "exports": {
7
+ "./api": "./exportys/api.md",
7
8
  "./http": "./exports/http.js",
8
9
  "./ws": "./exports/ws.js"
9
10
  },