@leofcoin/endpoint-clients 0.3.7 → 0.3.8

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/src/http.ts CHANGED
@@ -1,160 +1,159 @@
1
-
2
- // see https://developer.mozilla.org/en-US/docs/Web/API/Response#instance_methods
3
- type responseType = 'json' | 'text' | 'arrayBuffer' | 'clone' | 'formData' | 'blob';
4
- type networkVersion = 'peach' | string;
5
-
6
- export default class Client {
7
- url: string;
8
- networkVersion: networkVersion;
9
- get isHttpClient() {
10
- return true
11
- }
12
-
13
- constructor(url, networkVersion) {
14
- this.url = url
15
- this.networkVersion = networkVersion
16
- }
17
-
18
- async _fetch(method: string, params?, type: responseType = 'json') {
19
- params = new URLSearchParams(params).toString()
20
- const response = await fetch(`${this.url}/${method}?${params}`)
21
- return response[type]()
22
- }
23
-
24
- async _fetchString(method: string, params?) {
25
- return String(await this._fetch(method, params, 'text'))
26
- }
27
-
28
- async _fetchNumber(method: string, params?) {
29
- return Number(await this._fetchString(method, params))
30
- }
31
-
32
- async _fetchBoolean(method: string, params?) {
33
- return Boolean((await this._fetchString(method, params)) === 'true')
34
- }
35
-
36
- balances() {
37
- return this._fetch('balances')
38
- }
39
-
40
- balanceOf(address, format) {
41
- return this._fetch(`balanceOf`, {address, format})
42
- }
43
-
44
- selectedAccount() {
45
- return this._fetchString('selectedAccount')
46
- }
47
-
48
- selectAccount(address) {
49
- return this._fetch('selectAccount', {address})
50
- }
51
-
52
- accounts() {
53
- return this._fetch('accounts')
54
- }
55
-
56
- hasTransactionToHandle() {
57
- return this._fetchBoolean('hasTransactionToHandle')
58
- }
59
-
60
- getBlock(index) {
61
- return this._fetch('getBlock', { index })
62
- }
63
- blocks(amount) {
64
- return this._fetch('blocks', {amount})
65
- }
66
-
67
- sendTransaction(transaction) {
68
- return this._fetch('sendTransaction', transaction)
69
- }
70
- peerId() {
71
- return this._fetchString('peerId')
72
- }
73
- peers() {
74
- return this._fetch('peers')
75
- }
76
- validators() {
77
- return this._fetch('validators')
78
- }
79
- lookup(name) {
80
- return this._fetch('lookup', { name })
81
- }
82
-
83
- staticCall(contract, method, params) {
84
- return this._fetch('staticCall', {contract, method, params})
85
- }
86
- nativeBurns() {
87
- return this._fetchNumber('nativeBurns')
88
- }
89
- contracts() {
90
- return this._fetch('contracts')
91
- }
92
- nativeMints() {
93
- return this._fetchNumber('nativeMints')
94
- }
95
- nativeToken() {
96
- return this._fetchString('nativeToken')
97
- }
98
- nativeTransfers() {
99
- return this._fetchNumber('nativeTransfers')
100
- }
101
- totalSize() {
102
- return this._fetchNumber('totalSize')
103
- }
104
- totalTransactions() {
105
- return this._fetchNumber('totalTransactions')
106
- }
107
- poolTransactions() {
108
- return this._fetch('poolTransactions')
109
- }
110
- transactionsInPool() {
111
- return this._fetchNumber('transactionsInPool')
112
- }
113
- transactionPoolSize() {
114
- return this._fetchNumber('transactionPoolSize')
115
- }
116
- totalBlocks() {
117
- return this._fetchNumber('totalBlocks')
118
- }
119
- nativeCalls() {
120
- return this._fetchNumber('nativeCalls')
121
- }
122
- participating() {
123
- return this._fetchBoolean('participating')
124
- }
125
- participate(address) {
126
- return this._fetch('participate', { address })
127
- }
128
-
129
- createContractAddress(owner, code, params) {
130
- return this._fetch('createContractAddress', { owner, code, params })
131
- }
132
-
133
- deployContract(code, params) {
134
- return this._fetch('deployContract', { code, params })
135
- }
136
-
137
- network() {
138
- return this._fetch('network')
139
- }
140
-
141
- networkStats(): Promise<{ version: string; peers: {}[]; accounts: number; accountsHolding: number; }> {
142
- return this._fetch('networkStats')
143
- }
144
-
145
- getNonce(address: string) {
146
- return this._fetchNumber('getNonce', { address })
147
- }
148
-
149
- lastBlock() {
150
- return this._fetch('lastBlock')
151
- }
152
-
153
- blockHashMap() {
154
- return this._fetch('blockHashMap')
155
- }
156
-
157
- bootstrap() {
158
- return this._fetch('blockHashMap')
159
- }
160
- }
1
+ // see https://developer.mozilla.org/en-US/docs/Web/API/Response#instance_methods
2
+ type responseType = 'json' | 'text' | 'arrayBuffer' | 'clone' | 'formData' | 'blob'
3
+ type networkVersion = 'peach' | string
4
+
5
+ export default class Client {
6
+ url: string
7
+ networkVersion: networkVersion
8
+ get isHttpClient() {
9
+ return true
10
+ }
11
+
12
+ constructor(url, networkVersion) {
13
+ this.url = url
14
+ this.networkVersion = networkVersion
15
+ }
16
+
17
+ async _fetch(method: string, params?, type: responseType = 'json') {
18
+ params = new URLSearchParams(params).toString()
19
+ const response = await fetch(`${this.url}/${method}?${params}`)
20
+ return response[type]()
21
+ }
22
+
23
+ async _fetchString(method: string, params?) {
24
+ return String(await this._fetch(method, params, 'text'))
25
+ }
26
+
27
+ async _fetchNumber(method: string, params?) {
28
+ return Number(await this._fetchString(method, params))
29
+ }
30
+
31
+ async _fetchBoolean(method: string, params?) {
32
+ return Boolean((await this._fetchString(method, params)) === 'true')
33
+ }
34
+
35
+ balances() {
36
+ return this._fetch('balances')
37
+ }
38
+
39
+ balanceOf(address, format) {
40
+ return this._fetch(`balanceOf`, { address, format })
41
+ }
42
+
43
+ selectedAccount() {
44
+ return this._fetchString('selectedAccount')
45
+ }
46
+
47
+ selectAccount(address) {
48
+ return this._fetch('selectAccount', { address })
49
+ }
50
+
51
+ accounts() {
52
+ return this._fetch('accounts')
53
+ }
54
+
55
+ hasTransactionToHandle() {
56
+ return this._fetchBoolean('hasTransactionToHandle')
57
+ }
58
+
59
+ getBlock(index) {
60
+ return this._fetch('getBlock', { index })
61
+ }
62
+ blocks(amount) {
63
+ return this._fetch('blocks', { amount })
64
+ }
65
+
66
+ sendTransaction(transaction) {
67
+ return this._fetch('sendTransaction', transaction)
68
+ }
69
+ peerId() {
70
+ return this._fetchString('peerId')
71
+ }
72
+ peers() {
73
+ return this._fetch('peers')
74
+ }
75
+ validators() {
76
+ return this._fetch('validators')
77
+ }
78
+ lookup(name) {
79
+ return this._fetch('lookup', { name })
80
+ }
81
+
82
+ staticCall(contract, method, params) {
83
+ return this._fetch('staticCall', { contract, method, params })
84
+ }
85
+ nativeBurns() {
86
+ return this._fetchNumber('nativeBurns')
87
+ }
88
+ contracts() {
89
+ return this._fetch('contracts')
90
+ }
91
+ nativeMints() {
92
+ return this._fetchNumber('nativeMints')
93
+ }
94
+ nativeToken() {
95
+ return this._fetchString('nativeToken')
96
+ }
97
+ nativeTransfers() {
98
+ return this._fetchNumber('nativeTransfers')
99
+ }
100
+ totalSize() {
101
+ return this._fetchNumber('totalSize')
102
+ }
103
+ totalTransactions() {
104
+ return this._fetchNumber('totalTransactions')
105
+ }
106
+ poolTransactions() {
107
+ return this._fetch('poolTransactions')
108
+ }
109
+ transactionsInPool() {
110
+ return this._fetchNumber('transactionsInPool')
111
+ }
112
+ transactionPoolSize() {
113
+ return this._fetchNumber('transactionPoolSize')
114
+ }
115
+ totalBlocks() {
116
+ return this._fetchNumber('totalBlocks')
117
+ }
118
+ nativeCalls() {
119
+ return this._fetchNumber('nativeCalls')
120
+ }
121
+ participating() {
122
+ return this._fetchBoolean('participating')
123
+ }
124
+ participate(address) {
125
+ return this._fetch('participate', { address })
126
+ }
127
+
128
+ createContractAddress(owner, code, params) {
129
+ return this._fetch('createContractAddress', { owner, code, params })
130
+ }
131
+
132
+ deployContract(code, params) {
133
+ return this._fetch('deployContract', { code, params })
134
+ }
135
+
136
+ network() {
137
+ return this._fetch('network')
138
+ }
139
+
140
+ networkStats(): Promise<{ version: string; peers: {}[]; accounts: number; accountsHolding: number }> {
141
+ return this._fetch('networkStats')
142
+ }
143
+
144
+ getNonce(address: string) {
145
+ return this._fetchNumber('getNonce', { address })
146
+ }
147
+
148
+ lastBlock() {
149
+ return this._fetch('lastBlock')
150
+ }
151
+
152
+ blockHashMap() {
153
+ return this._fetch('blockHashMap')
154
+ }
155
+
156
+ bootstrap() {
157
+ return this._fetch('blockHashMap')
158
+ }
159
+ }
package/src/index.ts CHANGED
@@ -1,3 +1,3 @@
1
- export {default as ws} from './ws.js'
2
- export {default as http} from './http.js'
3
- export {default as direct} from './direct.js'
1
+ export { default as ws } from './ws.js'
2
+ export { default as http } from './http.js'
3
+ export { default as direct } from './direct.js'
package/src/ws.ts CHANGED
@@ -1,151 +1,156 @@
1
- import { SocketRequestClient } from 'socket-request-client'
2
- import ClientConnection from 'socket-request-client/connection'
3
-
4
- export default class Client {
5
- url: string
6
- networkVersion: string
7
- client: ClientConnection
8
-
9
- constructor(url = 'ws://localhost:4040', networkVersion = 'leofcoin-peach') {
10
- this.url = url
11
- this.networkVersion = networkVersion
12
- }
13
-
14
- async init() {
15
- const client = new SocketRequestClient(this.url, this.networkVersion)
16
- this.client = await client.init() as ClientConnection
17
- }
18
-
19
- get pubsub() {
20
- return {
21
- publish: this.client.pubsub.publish,
22
- subscribe: this.client.pubsub.subscribe
23
- }
24
- }
25
-
26
- request(url: string, params?: {}) {
27
- return this.client.request({url, params})
28
- }
29
-
30
- balances() {
31
- return this.request('balances')
32
- }
33
-
34
- balanceOf(address: string, format: boolean) {
35
- return this.request('balanceOf', {address, format})
36
- }
37
-
38
- selectedAccount() {
39
- return this.request('selectedAccount')
40
- }
41
-
42
- selectAccount(address: any) {
43
- return this.request('selectAccount', {address})
44
- }
45
-
46
- accounts() {
47
- return this.request('accounts')
48
- }
49
-
50
- hasTransactionToHandle() {
51
- return this.request('hasTransactionToHandle')
52
- }
53
-
54
- getBlock(index: number) {
55
- return this.request('getBlock', { index })
56
- }
57
- blocks(amount: number) {
58
- return this.request('blocks', {amount})
59
- }
60
-
61
- sendTransaction(transaction) {
62
- return this.request('sendTransaction', transaction)
63
- }
64
- peerId() {
65
- return this.request('peerId')
66
- }
67
- peers() {
68
- return this.request('peers')
69
- }
70
- validators() {
71
- return this.request('validators')
72
- }
73
- lookup(name: string) {
74
- return this.request('lookup', { name })
75
- }
76
-
77
- staticCall(contract: string, method: string, params: {}) {
78
- return this.request('staticCall', {contract, method, params})
79
- }
80
- nativeBurns(): Promise<number> {
81
- return this.request('nativeBurns')
82
- }
83
- contracts(): Promise<number> {
84
- return this.request('contracts')
85
- }
86
- nativeMints(): Promise<number> {
87
- return this.request('nativeMints')
88
- }
89
- nativeToken(): Promise<string> {
90
- return this.request('nativeToken')
91
- }
92
- nativeTransfers(): Promise<number> {
93
- return this.request('nativeTransfers')
94
- }
95
- totalSize(): Promise<number> {
96
- return this.request('totalSize')
97
- }
98
- totalTransactions(): Promise<number> {
99
- return this.request('totalTransactions')
100
- }
101
- poolTransactions() {
102
- return this.request('poolTransactions')
103
- }
104
- transactionsInPool() {
105
- return this.request('transactionsInPool')
106
- }
107
- transactionPoolSize() {
108
- return this.request('transactionPoolSize')
109
- }
110
- totalBlocks(): Promise<number> {
111
- return this.request('totalBlocks')
112
- }
113
- nativeCalls(): Promise<number> {
114
- return this.request('nativeCalls')
115
- }
116
- participating(): Promise<boolean> {
117
- return this.request('participating')
118
- }
119
- participate(address: string): {} {
120
- return this.request('participate', { address })
121
- }
122
- createContractAddress(owner: string, code: string, params: {}): {} {
123
- return this.request('createContractAddress', { owner, code, params })
124
- }
125
- deployContract(code: string, params: {}): {} {
126
- return this.request('deployContract', { code, params })
127
- }
128
- network() {
129
- return this.request('network')
130
- }
131
-
132
- networkStats(): Promise<{ version: string; peers: {}[]; accounts: number; accountsHolding: number }> {
133
- return this.request('networkStats')
134
- }
135
-
136
- getNonce(address: string) {
137
- return this.request('getNonce', { address })
138
- }
139
-
140
- lastBlock() {
141
- return this.request('lastBlock')
142
- }
143
-
144
- blockHashMap() {
145
- return this.request('blockHashMap')
146
- }
147
-
148
- bootstrap() {
149
- return this.request('blockHashMap')
150
- }
151
- }
1
+ import { SocketRequestClient } from 'socket-request-client'
2
+ import ClientConnection from 'socket-request-client/connection'
3
+
4
+ export default class Client {
5
+ url: string
6
+ networkVersion: string
7
+ client: ClientConnection
8
+
9
+ constructor(url = 'ws://localhost:4040', networkVersion = 'leofcoin-peach') {
10
+ this.url = url
11
+ this.networkVersion = networkVersion
12
+ }
13
+
14
+ async init() {
15
+ const client = new SocketRequestClient(this.url, this.networkVersion)
16
+ this.client = (await client.init()) as ClientConnection
17
+ }
18
+
19
+ get pubsub() {
20
+ return {
21
+ publish: this.client.pubsub.publish,
22
+ subscribe: this.client.pubsub.subscribe
23
+ }
24
+ }
25
+
26
+ request(url: string, params?: {}) {
27
+ return this.client.request({ url, params })
28
+ }
29
+
30
+ balances() {
31
+ return this.request('balances')
32
+ }
33
+
34
+ balanceOf(address: string, format: boolean) {
35
+ return this.request('balanceOf', { address, format })
36
+ }
37
+
38
+ selectedAccount() {
39
+ return this.request('selectedAccount')
40
+ }
41
+
42
+ selectAccount(address: any) {
43
+ return this.request('selectAccount', { address })
44
+ }
45
+
46
+ accounts() {
47
+ return this.request('accounts')
48
+ }
49
+
50
+ hasTransactionToHandle() {
51
+ return this.request('hasTransactionToHandle')
52
+ }
53
+
54
+ getBlock(index: number) {
55
+ return this.request('getBlock', { index })
56
+ }
57
+ blocks(amount: number) {
58
+ return this.request('blocks', { amount })
59
+ }
60
+
61
+ sendTransaction(transaction) {
62
+ return this.request('sendTransaction', transaction)
63
+ }
64
+ peerId() {
65
+ return this.request('peerId')
66
+ }
67
+ peers() {
68
+ return this.request('peers')
69
+ }
70
+ validators() {
71
+ return this.request('validators')
72
+ }
73
+ lookup(name: string) {
74
+ return this.request('lookup', { name })
75
+ }
76
+
77
+ staticCall(contract: string, method: string, params: {}) {
78
+ return this.request('staticCall', { contract, method, params })
79
+ }
80
+ nativeBurns(): Promise<number> {
81
+ return this.request('nativeBurns')
82
+ }
83
+ contracts(): Promise<number> {
84
+ return this.request('contracts')
85
+ }
86
+ nativeMints(): Promise<number> {
87
+ return this.request('nativeMints')
88
+ }
89
+ nativeToken(): Promise<string> {
90
+ return this.request('nativeToken')
91
+ }
92
+ nativeTransfers(): Promise<number> {
93
+ return this.request('nativeTransfers')
94
+ }
95
+ totalSize(): Promise<number> {
96
+ return this.request('totalSize')
97
+ }
98
+ totalTransactions(): Promise<number> {
99
+ return this.request('totalTransactions')
100
+ }
101
+ poolTransactions() {
102
+ return this.request('poolTransactions')
103
+ }
104
+ transactionsInPool() {
105
+ return this.request('transactionsInPool')
106
+ }
107
+ transactionPoolSize() {
108
+ return this.request('transactionPoolSize')
109
+ }
110
+ totalBlocks(): Promise<number> {
111
+ return this.request('totalBlocks')
112
+ }
113
+ nativeCalls(): Promise<number> {
114
+ return this.request('nativeCalls')
115
+ }
116
+ participating(): Promise<boolean> {
117
+ return this.request('participating')
118
+ }
119
+ participate(address: string): {} {
120
+ return this.request('participate', { address })
121
+ }
122
+ createContractAddress(owner: string, code: string, params: {}): {} {
123
+ return this.request('createContractAddress', { owner, code, params })
124
+ }
125
+ deployContract(code: string, params: {}): {} {
126
+ return this.request('deployContract', { code, params })
127
+ }
128
+ network() {
129
+ return this.request('network')
130
+ }
131
+
132
+ networkStats(): Promise<{
133
+ version: string
134
+ peers: {}[]
135
+ accounts: number
136
+ accountsHolding: number
137
+ }> {
138
+ return this.request('networkStats')
139
+ }
140
+
141
+ getNonce(address: string) {
142
+ return this.request('getNonce', { address })
143
+ }
144
+
145
+ lastBlock() {
146
+ return this.request('lastBlock')
147
+ }
148
+
149
+ blockHashMap() {
150
+ return this.request('blockHashMap')
151
+ }
152
+
153
+ bootstrap() {
154
+ return this.request('blockHashMap')
155
+ }
156
+ }
package/test/index.js CHANGED
@@ -1,17 +1,17 @@
1
- import { needsImplementations } from './spec.js';
2
- import WsClient from './../exports/ws.js'
3
- import HttpClient from './../exports/http.js'
4
- import DirectClient from './../exports/direct.js'
5
-
6
- try {
7
- const wsNeeds = needsImplementations(new WsClient())
8
- if (wsNeeds.length > 0) throw new Error(`ws: missing implementations ${wsNeeds.length > 2 ? wsNeeds.join(', ') : wsNeeds.join(' & ')}`)
9
-
10
- const httpNeeds = needsImplementations(new HttpClient())
11
- if (httpNeeds.length > 0) throw new Error(`http: missing implementations ${httpNeeds.length > 2 ? httpNeeds.join(', ') : httpNeeds.join(' & ')}`)
12
-
13
- const directNeeds = needsImplementations(new DirectClient())
14
- if (directNeeds.length > 0) throw new Error(`direct: missing implementations ${directNeeds.length > 2 ? directNeeds.join(', ') : directNeeds.join(' & ')}`)
15
- } catch (error) {
16
- console.error(error);
1
+ import { needsImplementations } from './spec.js';
2
+ import WsClient from './../exports/ws.js'
3
+ import HttpClient from './../exports/http.js'
4
+ import DirectClient from './../exports/direct.js'
5
+
6
+ try {
7
+ const wsNeeds = needsImplementations(new WsClient())
8
+ if (wsNeeds.length > 0) throw new Error(`ws: missing implementations ${wsNeeds.length > 2 ? wsNeeds.join(', ') : wsNeeds.join(' & ')}`)
9
+
10
+ const httpNeeds = needsImplementations(new HttpClient())
11
+ if (httpNeeds.length > 0) throw new Error(`http: missing implementations ${httpNeeds.length > 2 ? httpNeeds.join(', ') : httpNeeds.join(' & ')}`)
12
+
13
+ const directNeeds = needsImplementations(new DirectClient())
14
+ if (directNeeds.length > 0) throw new Error(`direct: missing implementations ${directNeeds.length > 2 ? directNeeds.join(', ') : directNeeds.join(' & ')}`)
15
+ } catch (error) {
16
+ console.error(error);
17
17
  }