@leofcoin/endpoint-clients 0.1.6 → 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/README.md +205 -0
- package/exports/http.js +3 -0
- package/package.json +1 -1
- package/test/index.js +13 -0
- package/test/spec.js +43 -0
package/README.md
CHANGED
|
@@ -1,2 +1,207 @@
|
|
|
1
1
|
# endpoint-clients
|
|
2
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 = 'leofcoin-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
|
+
### selectAccount(address: `string`)
|
|
21
|
+
`address`: desired address
|
|
22
|
+
> set default account to given address
|
|
23
|
+
```js
|
|
24
|
+
await client.selectAccount(address)
|
|
25
|
+
```
|
|
26
|
+
<br>
|
|
27
|
+
|
|
28
|
+
### getBlock(index: `number`)
|
|
29
|
+
`index`: index of the block to fetch<br>
|
|
30
|
+
```js
|
|
31
|
+
await client.getBlock(10)
|
|
32
|
+
```
|
|
33
|
+
<br>
|
|
34
|
+
|
|
35
|
+
### blocks(amount)
|
|
36
|
+
`amount`: the amount to slice
|
|
37
|
+
```js
|
|
38
|
+
await client.blocks(-25)
|
|
39
|
+
```
|
|
40
|
+
<br>
|
|
41
|
+
|
|
42
|
+
### createTransactionFrom(from: `string`, to: `string`, method: `string`, parameters: `array`, nonce: `number` | `undefined`)
|
|
43
|
+
|
|
44
|
+
`from`:<br>
|
|
45
|
+
`to`: <br>
|
|
46
|
+
`method`: <br>
|
|
47
|
+
`parameters`: <br>
|
|
48
|
+
`nonce`: <br>
|
|
49
|
+
```js
|
|
50
|
+
await client.createTransactionFrom(from, to, method, parameters, nonce)
|
|
51
|
+
```
|
|
52
|
+
<br>
|
|
53
|
+
|
|
54
|
+
### lookup(name: `string`)
|
|
55
|
+
`name`: name of the contract to lookup the address and owner of
|
|
56
|
+
```js
|
|
57
|
+
await client.lookup('contractName')
|
|
58
|
+
```
|
|
59
|
+
<br>
|
|
60
|
+
|
|
61
|
+
### participate(address: `string`)
|
|
62
|
+
`address`: <br>
|
|
63
|
+
|
|
64
|
+
```js
|
|
65
|
+
await client.participate(address)
|
|
66
|
+
```
|
|
67
|
+
<br>
|
|
68
|
+
|
|
69
|
+
### staticCall(contract: `string`, method: `string`, params: `array`)
|
|
70
|
+
`contract`: contract address todo the call on
|
|
71
|
+
`method`: method/function to call
|
|
72
|
+
`params`: array containing params needed to call the desired method
|
|
73
|
+
```js
|
|
74
|
+
await client.staticCall(contract, method, params)
|
|
75
|
+
```
|
|
76
|
+
<br>
|
|
77
|
+
|
|
78
|
+
### createContractAddress(owner: `string`, code: `string`, params: `array`)
|
|
79
|
+
`owner`: address of the deployer<br>
|
|
80
|
+
`code`: contract as a string<br>
|
|
81
|
+
`params`: contract constructor params<br>
|
|
82
|
+
|
|
83
|
+
```js
|
|
84
|
+
const address = await client.createContractAddress(owner, code, params)
|
|
85
|
+
```
|
|
86
|
+
<br>
|
|
87
|
+
|
|
88
|
+
### deployContract(code: `string`, params: `array`)
|
|
89
|
+
`code`: contract as a string<br>
|
|
90
|
+
`params`: contract constructor params<br>
|
|
91
|
+
|
|
92
|
+
```js
|
|
93
|
+
const tx = await client.deployContract(code, params)
|
|
94
|
+
```
|
|
95
|
+
<br>
|
|
96
|
+
|
|
97
|
+
### accounts()
|
|
98
|
+
```js
|
|
99
|
+
await client.accounts()
|
|
100
|
+
```
|
|
101
|
+
<br>
|
|
102
|
+
|
|
103
|
+
### hasTransactionToHandle()
|
|
104
|
+
```js
|
|
105
|
+
await client.hasTransactionToHandle()
|
|
106
|
+
```
|
|
107
|
+
<br>
|
|
108
|
+
|
|
109
|
+
### balances()
|
|
110
|
+
> returns all balances
|
|
111
|
+
```js
|
|
112
|
+
await client.balances()
|
|
113
|
+
```
|
|
114
|
+
<br>
|
|
115
|
+
|
|
116
|
+
### balancOf(address: `string`, format: `boolean`)
|
|
117
|
+
`address`: The address to check<br>
|
|
118
|
+
`format`: Wether or not to format<br>
|
|
119
|
+
> returns the balance of given address as BigNumber or string (when format is true)
|
|
120
|
+
```js
|
|
121
|
+
await client.balanceOf(address, true)
|
|
122
|
+
```
|
|
123
|
+
<br>
|
|
124
|
+
|
|
125
|
+
### selectedAccount()
|
|
126
|
+
```js
|
|
127
|
+
await client.selectedAccount()
|
|
128
|
+
```
|
|
129
|
+
<br>
|
|
130
|
+
|
|
131
|
+
### peerId()
|
|
132
|
+
```js
|
|
133
|
+
await client.peerId()
|
|
134
|
+
```
|
|
135
|
+
<br>
|
|
136
|
+
|
|
137
|
+
### peers()
|
|
138
|
+
```js
|
|
139
|
+
await client.peers()
|
|
140
|
+
```
|
|
141
|
+
<br>
|
|
142
|
+
|
|
143
|
+
### validators()
|
|
144
|
+
```js
|
|
145
|
+
await client.validators()
|
|
146
|
+
```
|
|
147
|
+
<br>
|
|
148
|
+
|
|
149
|
+
### nativeBurns()
|
|
150
|
+
```js
|
|
151
|
+
await client.nativeBurns()
|
|
152
|
+
```
|
|
153
|
+
<br>
|
|
154
|
+
|
|
155
|
+
### contracts()
|
|
156
|
+
```js
|
|
157
|
+
await client.contracts()
|
|
158
|
+
```
|
|
159
|
+
<br>
|
|
160
|
+
|
|
161
|
+
### nativeMints()
|
|
162
|
+
```js
|
|
163
|
+
await client.nativeMints()
|
|
164
|
+
```
|
|
165
|
+
<br>
|
|
166
|
+
|
|
167
|
+
### nativeToken()
|
|
168
|
+
```js
|
|
169
|
+
await client.nativeToken()
|
|
170
|
+
```
|
|
171
|
+
<br>
|
|
172
|
+
|
|
173
|
+
### nativeTransfers()
|
|
174
|
+
```js
|
|
175
|
+
await client. nativeTransfers()
|
|
176
|
+
```
|
|
177
|
+
<br>
|
|
178
|
+
|
|
179
|
+
### totalSize()
|
|
180
|
+
```js
|
|
181
|
+
await client.totalSize()
|
|
182
|
+
```
|
|
183
|
+
<br>
|
|
184
|
+
|
|
185
|
+
### totalTransactions()
|
|
186
|
+
```js
|
|
187
|
+
await client.totalTransactions()
|
|
188
|
+
```
|
|
189
|
+
<br>
|
|
190
|
+
|
|
191
|
+
### totalBlocks()
|
|
192
|
+
```js
|
|
193
|
+
await client.totalBlocks()
|
|
194
|
+
```
|
|
195
|
+
<br>
|
|
196
|
+
|
|
197
|
+
### nativeCalls()
|
|
198
|
+
```js
|
|
199
|
+
await client.nativeCalls()
|
|
200
|
+
```
|
|
201
|
+
<br>
|
|
202
|
+
|
|
203
|
+
### participating()
|
|
204
|
+
```js
|
|
205
|
+
await client.participating()
|
|
206
|
+
```
|
|
207
|
+
<br>
|
package/exports/http.js
CHANGED
package/package.json
CHANGED
package/test/index.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { needsImplementations } from './spec.js';
|
|
2
|
+
import WsClient from './../exports/ws.js'
|
|
3
|
+
import HttpClient from './../exports/http.js'
|
|
4
|
+
|
|
5
|
+
try {
|
|
6
|
+
const wsNeeds = needsImplementations(new WsClient())
|
|
7
|
+
if (wsNeeds.length > 0) throw new Error(`ws: missing implementations ${wsNeeds.length > 2 ? wsNeeds.join(', ') : wsNeeds.join(' & ')}`)
|
|
8
|
+
|
|
9
|
+
const httpNeeds = needsImplementations(new HttpClient())
|
|
10
|
+
if (httpNeeds.length > 0) throw new Error(`http: missing implementations ${httpNeeds.length > 2 ? httpNeeds.join(', ') : httpNeeds.join(' & ')}`)
|
|
11
|
+
} catch (error) {
|
|
12
|
+
console.error(error);
|
|
13
|
+
}
|
package/test/spec.js
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
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
|
+
]
|
|
31
|
+
|
|
32
|
+
export const needsImplementations = (client) => {
|
|
33
|
+
const needs = []
|
|
34
|
+
for (const key of implementations) {
|
|
35
|
+
try {
|
|
36
|
+
if (!client[key] && key === 'pubsub' && !client.isHttpClient) needs.push(key)
|
|
37
|
+
} catch (error) {
|
|
38
|
+
if (error.message !== "Cannot read properties of undefined (reading 'pubsub')") throw new Error(error)
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
}
|
|
42
|
+
return needs
|
|
43
|
+
}
|