@leofcoin/endpoint-clients 0.2.2 → 0.2.3

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/http.js CHANGED
@@ -1,4 +1,6 @@
1
1
  class http {
2
+ url;
3
+ networkVersion;
2
4
  get isHttpClient() {
3
5
  return true;
4
6
  }
@@ -6,10 +8,19 @@ class http {
6
8
  this.url = url;
7
9
  this.networkVersion = networkVersion;
8
10
  }
9
- async _fetch(method, params) {
11
+ async _fetch(method, params, type = 'json') {
10
12
  params = new URLSearchParams(params).toString();
11
13
  const response = await fetch(`${this.url}/${method}?${params}`);
12
- return response.json();
14
+ return response[type]();
15
+ }
16
+ async _fetchString(method, params) {
17
+ return String(await this._fetch(method, params, 'text'));
18
+ }
19
+ async _fetchNumber(method, params) {
20
+ return Number(await this._fetchString(method, params));
21
+ }
22
+ async _fetchBoolean(method, params) {
23
+ return Boolean((await this._fetchString(method, params)) === 'true');
13
24
  }
14
25
  balances() {
15
26
  return this._fetch('balances');
@@ -18,7 +29,7 @@ class http {
18
29
  return this._fetch(`balanceOf`, { address, format });
19
30
  }
20
31
  selectedAccount() {
21
- return this._fetch('selectedAccount');
32
+ return this._fetchString('selectedAccount');
22
33
  }
23
34
  selectAccount(address) {
24
35
  return this._fetch('selectAccount', { address });
@@ -27,7 +38,7 @@ class http {
27
38
  return this._fetch('accounts');
28
39
  }
29
40
  hasTransactionToHandle() {
30
- return this._fetch('hasTransactionToHandle');
41
+ return this._fetchBoolean('hasTransactionToHandle');
31
42
  }
32
43
  getBlock(index) {
33
44
  return this._fetch('getBlock', { index });
@@ -39,7 +50,7 @@ class http {
39
50
  return this._fetch('sendTransaction', transaction);
40
51
  }
41
52
  peerId() {
42
- return this._fetch('peerId');
53
+ return this._fetchString('peerId');
43
54
  }
44
55
  peers() {
45
56
  return this._fetch('peers');
@@ -54,34 +65,34 @@ class http {
54
65
  return this._fetch('staticCall', { contract, method, params });
55
66
  }
56
67
  nativeBurns() {
57
- return this._fetch('nativeBurns');
68
+ return this._fetchNumber('nativeBurns');
58
69
  }
59
70
  contracts() {
60
71
  return this._fetch('contracts');
61
72
  }
62
73
  nativeMints() {
63
- return this._fetch('nativeMints');
74
+ return this._fetchNumber('nativeMints');
64
75
  }
65
76
  nativeToken() {
66
- return this._fetch('nativeToken');
77
+ return this._fetchString('nativeToken');
67
78
  }
68
79
  nativeTransfers() {
69
- return this._fetch('nativeTransfers');
80
+ return this._fetchNumber('nativeTransfers');
70
81
  }
71
82
  totalSize() {
72
- return this._fetch('totalSize');
83
+ return this._fetchNumber('totalSize');
73
84
  }
74
85
  totalTransactions() {
75
- return this._fetch('totalTransactions');
86
+ return this._fetchNumber('totalTransactions');
76
87
  }
77
88
  totalBlocks() {
78
- return this._fetch('totalBlocks');
89
+ return this._fetchNumber('totalBlocks');
79
90
  }
80
91
  nativeCalls() {
81
- return this._fetch('nativeCalls');
92
+ return this._fetchNumber('nativeCalls');
82
93
  }
83
94
  participating() {
84
- return this._fetch('participating');
95
+ return this._fetchBoolean('participating');
85
96
  }
86
97
  participate(address) {
87
98
  return this._fetch('participate', { address });
package/exports/index.js CHANGED
@@ -1,2 +1,3 @@
1
1
  export { default as ws } from './ws.js';
2
2
  export { default as http } from './http.js';
3
+ import 'socket-request-client';
@@ -1,32 +1,40 @@
1
+ type responseType = 'json' | 'text' | 'arrayBuffer' | 'clone' | 'formData' | 'blob';
2
+ type networkVersion = 'peach' | string;
1
3
  export default class {
4
+ url: URL;
5
+ networkVersion: networkVersion;
2
6
  get isHttpClient(): boolean;
3
7
  constructor(url: any, networkVersion: any);
4
- _fetch(method: any, params: any): Promise<any>;
8
+ _fetch(method: any, params?: any, type?: responseType): Promise<any>;
9
+ _fetchString(method: string, params?: any): Promise<string>;
10
+ _fetchNumber(method: string, params?: any): Promise<number>;
11
+ _fetchBoolean(method: string, params?: any): Promise<boolean>;
5
12
  balances(): Promise<any>;
6
13
  balanceOf(address: any, format: any): Promise<any>;
7
- selectedAccount(): Promise<any>;
14
+ selectedAccount(): Promise<string>;
8
15
  selectAccount(address: any): Promise<any>;
9
16
  accounts(): Promise<any>;
10
- hasTransactionToHandle(): Promise<any>;
17
+ hasTransactionToHandle(): Promise<boolean>;
11
18
  getBlock(index: any): Promise<any>;
12
19
  blocks(amount: any): Promise<any>;
13
20
  sendTransaction(transaction: any): Promise<any>;
14
- peerId(): Promise<any>;
21
+ peerId(): Promise<string>;
15
22
  peers(): Promise<any>;
16
23
  validators(): Promise<any>;
17
24
  lookup(name: any): Promise<any>;
18
25
  staticCall(contract: any, method: any, params: any): Promise<any>;
19
- nativeBurns(): Promise<any>;
26
+ nativeBurns(): Promise<number>;
20
27
  contracts(): Promise<any>;
21
- nativeMints(): Promise<any>;
22
- nativeToken(): Promise<any>;
23
- nativeTransfers(): Promise<any>;
24
- totalSize(): Promise<any>;
25
- totalTransactions(): Promise<any>;
26
- totalBlocks(): Promise<any>;
27
- nativeCalls(): Promise<any>;
28
- participating(): Promise<any>;
28
+ nativeMints(): Promise<number>;
29
+ nativeToken(): Promise<string>;
30
+ nativeTransfers(): Promise<number>;
31
+ totalSize(): Promise<number>;
32
+ totalTransactions(): Promise<number>;
33
+ totalBlocks(): Promise<number>;
34
+ nativeCalls(): Promise<number>;
35
+ participating(): Promise<boolean>;
29
36
  participate(address: any): Promise<any>;
30
37
  createContractAddress(owner: any, code: any, params: any): Promise<any>;
31
38
  deployContract(code: any, params: any): Promise<any>;
32
39
  }
40
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leofcoin/endpoint-clients",
3
- "version": "0.2.2",
3
+ "version": "0.2.3",
4
4
  "description": "",
5
5
  "exports": {
6
6
  "./ws": "./exports/ws.js",
package/src/http.ts CHANGED
@@ -1,16 +1,36 @@
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
+
1
6
  export default class {
7
+ url: URL;
8
+ networkVersion: networkVersion;
2
9
  get isHttpClient() {
3
10
  return true
4
11
  }
12
+
5
13
  constructor(url, networkVersion) {
6
14
  this.url = url
7
15
  this.networkVersion = networkVersion
8
16
  }
9
17
 
10
- async _fetch(method, params) {
18
+ async _fetch(method, params?, type: responseType = 'json') {
11
19
  params = new URLSearchParams(params).toString()
12
20
  const response = await fetch(`${this.url}/${method}?${params}`)
13
- return response.json()
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')
14
34
  }
15
35
 
16
36
  balances() {
@@ -22,7 +42,7 @@ export default class {
22
42
  }
23
43
 
24
44
  selectedAccount() {
25
- return this._fetch('selectedAccount')
45
+ return this._fetchString('selectedAccount')
26
46
  }
27
47
 
28
48
  selectAccount(address) {
@@ -34,7 +54,7 @@ export default class {
34
54
  }
35
55
 
36
56
  hasTransactionToHandle() {
37
- return this._fetch('hasTransactionToHandle')
57
+ return this._fetchBoolean('hasTransactionToHandle')
38
58
  }
39
59
 
40
60
  getBlock(index) {
@@ -48,7 +68,7 @@ export default class {
48
68
  return this._fetch('sendTransaction', transaction)
49
69
  }
50
70
  peerId() {
51
- return this._fetch('peerId')
71
+ return this._fetchString('peerId')
52
72
  }
53
73
  peers() {
54
74
  return this._fetch('peers')
@@ -64,34 +84,34 @@ export default class {
64
84
  return this._fetch('staticCall', {contract, method, params})
65
85
  }
66
86
  nativeBurns() {
67
- return this._fetch('nativeBurns')
87
+ return this._fetchNumber('nativeBurns')
68
88
  }
69
89
  contracts() {
70
90
  return this._fetch('contracts')
71
91
  }
72
92
  nativeMints() {
73
- return this._fetch('nativeMints')
93
+ return this._fetchNumber('nativeMints')
74
94
  }
75
95
  nativeToken() {
76
- return this._fetch('nativeToken')
96
+ return this._fetchString('nativeToken')
77
97
  }
78
98
  nativeTransfers() {
79
- return this._fetch('nativeTransfers')
99
+ return this._fetchNumber('nativeTransfers')
80
100
  }
81
101
  totalSize() {
82
- return this._fetch('totalSize')
102
+ return this._fetchNumber('totalSize')
83
103
  }
84
104
  totalTransactions() {
85
- return this._fetch('totalTransactions')
105
+ return this._fetchNumber('totalTransactions')
86
106
  }
87
107
  totalBlocks() {
88
- return this._fetch('totalBlocks')
108
+ return this._fetchNumber('totalBlocks')
89
109
  }
90
110
  nativeCalls() {
91
- return this._fetch('nativeCalls')
111
+ return this._fetchNumber('nativeCalls')
92
112
  }
93
113
  participating() {
94
- return this._fetch('participating')
114
+ return this._fetchBoolean('participating')
95
115
  }
96
116
  participate(address) {
97
117
  return this._fetch('participate', { address })