@dashevo/dapi-client 0.24.0-dev.11 → 0.24.0-dev.13
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 +3 -4
- package/lib/dapiAddressProvider/DAPIAddress.js +14 -40
- package/lib/dapiAddressProvider/ListDAPIAddressProvider.js +1 -2
- package/lib/index.js +2 -0
- package/lib/test/bootstrap.js +2 -0
- package/lib/transport/GrpcTransport/GrpcTransport.js +4 -9
- package/lib/transport/JsonRpcTransport/JsonRpcTransport.js +1 -1
- package/lib/transport/JsonRpcTransport/requestJsonRpc.js +22 -25
- package/package.json +8 -7
- package/polyfills/fetch-polyfill.js +10 -0
package/README.md
CHANGED
|
@@ -50,8 +50,7 @@ const DAPIClient = require('@dashevo/dapi-client');
|
|
|
50
50
|
var client = new DAPIClient({
|
|
51
51
|
seeds: [{
|
|
52
52
|
host: 'seed-1.evonet.networks.dash.org',
|
|
53
|
-
|
|
54
|
-
grpcPort: 3010,
|
|
53
|
+
port: 3000,
|
|
55
54
|
}],
|
|
56
55
|
});
|
|
57
56
|
|
|
@@ -71,8 +70,8 @@ const DAPIClient = require('@dashevo/dapi-client');
|
|
|
71
70
|
|
|
72
71
|
var client = new DAPIClient({
|
|
73
72
|
dapiAddresses: [
|
|
74
|
-
'127.0.0.1:3000
|
|
75
|
-
'127.0.0.2:3000
|
|
73
|
+
'127.0.0.1:3000',
|
|
74
|
+
'127.0.0.2:3000',
|
|
76
75
|
],
|
|
77
76
|
});
|
|
78
77
|
|
|
@@ -10,13 +10,12 @@ class DAPIAddress {
|
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
if (typeof address === 'string') {
|
|
13
|
-
const [host,
|
|
13
|
+
const [host, port, ssl] = address.split(':');
|
|
14
14
|
|
|
15
15
|
// eslint-disable-next-line no-param-reassign
|
|
16
16
|
address = {
|
|
17
17
|
host,
|
|
18
|
-
|
|
19
|
-
grpcPort: grpcPort ? parseInt(grpcPort, 10) : DAPIAddress.DEFAULT_GRPC_PORT,
|
|
18
|
+
port: port ? parseInt(port, 10) : DAPIAddress.DEFAULT_PORT,
|
|
20
19
|
protocol: ssl === 'no-ssl' ? 'http' : DAPIAddress.DEFAULT_PROTOCOL,
|
|
21
20
|
allowSelfSignedCertificate: ssl === 'self-signed',
|
|
22
21
|
};
|
|
@@ -28,8 +27,7 @@ class DAPIAddress {
|
|
|
28
27
|
|
|
29
28
|
this.protocol = address.protocol || DAPIAddress.DEFAULT_PROTOCOL;
|
|
30
29
|
this.host = address.host;
|
|
31
|
-
this.
|
|
32
|
-
this.grpcPort = address.grpcPort || DAPIAddress.DEFAULT_GRPC_PORT;
|
|
30
|
+
this.port = address.port || DAPIAddress.DEFAULT_PORT;
|
|
33
31
|
this.proRegTxHash = address.proRegTxHash;
|
|
34
32
|
this.allowSelfSignedCertificate = address.allowSelfSignedCertificate || false;
|
|
35
33
|
|
|
@@ -68,43 +66,22 @@ class DAPIAddress {
|
|
|
68
66
|
}
|
|
69
67
|
|
|
70
68
|
/**
|
|
71
|
-
* Get
|
|
69
|
+
* Get port
|
|
72
70
|
*
|
|
73
71
|
* @returns {number}
|
|
74
72
|
*/
|
|
75
|
-
|
|
76
|
-
return this.
|
|
73
|
+
getPort() {
|
|
74
|
+
return this.port;
|
|
77
75
|
}
|
|
78
76
|
|
|
79
77
|
/**
|
|
80
|
-
* Set
|
|
78
|
+
* Set port
|
|
81
79
|
*
|
|
82
80
|
* @param {number} port
|
|
83
81
|
* @returns {DAPIAddress}
|
|
84
82
|
*/
|
|
85
|
-
|
|
86
|
-
this.
|
|
87
|
-
|
|
88
|
-
return this;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
/**
|
|
92
|
-
* Get gRPC port
|
|
93
|
-
*
|
|
94
|
-
* @returns {number}
|
|
95
|
-
*/
|
|
96
|
-
getGrpcPort() {
|
|
97
|
-
return this.grpcPort;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
/**
|
|
101
|
-
* Set gRPC port
|
|
102
|
-
*
|
|
103
|
-
* @param {number} port
|
|
104
|
-
* @returns {DAPIAddress}
|
|
105
|
-
*/
|
|
106
|
-
setGrpcPort(port) {
|
|
107
|
-
this.grpcPort = port;
|
|
83
|
+
setPort(port) {
|
|
84
|
+
this.port = port;
|
|
108
85
|
|
|
109
86
|
return this;
|
|
110
87
|
}
|
|
@@ -179,28 +156,25 @@ class DAPIAddress {
|
|
|
179
156
|
return {
|
|
180
157
|
protocol: this.getProtocol(),
|
|
181
158
|
host: this.getHost(),
|
|
182
|
-
|
|
183
|
-
grpcPort: this.getGrpcPort(),
|
|
159
|
+
port: this.getPort(),
|
|
184
160
|
proRegTxHash: this.getProRegTxHash(),
|
|
185
161
|
allowSelfSignedCertificate: this.isSelfSignedCertificateAllowed(),
|
|
186
162
|
};
|
|
187
163
|
}
|
|
188
164
|
|
|
189
165
|
toString() {
|
|
190
|
-
return `${this.getProtocol()}://${this.getHost()}:${this.
|
|
166
|
+
return `${this.getProtocol()}://${this.getHost()}:${this.getPort()}`;
|
|
191
167
|
}
|
|
192
168
|
}
|
|
193
169
|
|
|
194
|
-
DAPIAddress.
|
|
195
|
-
DAPIAddress.
|
|
196
|
-
DAPIAddress.DEFAULT_PROTOCOL = 'http';
|
|
170
|
+
DAPIAddress.DEFAULT_PORT = 3000;
|
|
171
|
+
DAPIAddress.DEFAULT_PROTOCOL = 'https';
|
|
197
172
|
|
|
198
173
|
/**
|
|
199
174
|
* @typedef {object} RawDAPIAddress
|
|
200
175
|
* @property {string} protocol
|
|
201
176
|
* @property {string} host
|
|
202
|
-
* @property {number} [
|
|
203
|
-
* @property {number} [grpcPort=3010]
|
|
177
|
+
* @property {number} [port=3000]
|
|
204
178
|
* @property {string} [proRegTxHash]
|
|
205
179
|
* @property {bool} [selfSigned]
|
|
206
180
|
*/
|
|
@@ -39,8 +39,7 @@ class ListDAPIAddressProvider {
|
|
|
39
39
|
liveAddress.protocol = 'https';
|
|
40
40
|
liveAddress.host = '127.0.0.1';
|
|
41
41
|
liveAddress.allowSelfSignedCertificate = true;
|
|
42
|
-
liveAddress.
|
|
43
|
-
liveAddress.grpcPort = 3010 + randomNodeIndex * 100;
|
|
42
|
+
liveAddress.port = 3000 + randomNodeIndex * 100;
|
|
44
43
|
}
|
|
45
44
|
|
|
46
45
|
return liveAddress;
|
package/lib/index.js
CHANGED
package/lib/test/bootstrap.js
CHANGED
|
@@ -133,20 +133,15 @@ class GrpcTransport {
|
|
|
133
133
|
*/
|
|
134
134
|
makeGrpcUrlFromAddress(address) {
|
|
135
135
|
let protocol = address.getProtocol();
|
|
136
|
-
let port = address.getHttpPort();
|
|
137
|
-
|
|
138
136
|
// For NodeJS Client
|
|
139
137
|
if (typeof process !== 'undefined'
|
|
140
138
|
&& process.versions != null
|
|
141
|
-
&& process.versions.node != null
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
if (address.isSelfSignedCertificateAllowed()) {
|
|
145
|
-
protocol = 'http';
|
|
146
|
-
}
|
|
139
|
+
&& process.versions.node != null
|
|
140
|
+
&& address.isSelfSignedCertificateAllowed()) {
|
|
141
|
+
protocol = 'http';
|
|
147
142
|
}
|
|
148
143
|
|
|
149
|
-
return `${protocol}://${address.getHost()}:${
|
|
144
|
+
return `${protocol}://${address.getHost()}:${address.getPort()}`;
|
|
150
145
|
}
|
|
151
146
|
}
|
|
152
147
|
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
const axios = require('axios');
|
|
2
1
|
const https = require('https');
|
|
3
|
-
|
|
4
2
|
const JsonRpcError = require('./errors/JsonRpcError');
|
|
5
3
|
const WrongHttpCodeError = require('./errors/WrongHttpCodeError');
|
|
6
4
|
|
|
@@ -25,11 +23,6 @@ async function requestJsonRpc(protocol, host, port, selfSigned, method, params,
|
|
|
25
23
|
id: 1,
|
|
26
24
|
};
|
|
27
25
|
|
|
28
|
-
const postOptions = {};
|
|
29
|
-
if (options.timeout !== undefined) {
|
|
30
|
-
postOptions.timeout = options.timeout;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
26
|
const requestInfo = {
|
|
34
27
|
protocol,
|
|
35
28
|
host,
|
|
@@ -40,40 +33,44 @@ async function requestJsonRpc(protocol, host, port, selfSigned, method, params,
|
|
|
40
33
|
options,
|
|
41
34
|
};
|
|
42
35
|
|
|
43
|
-
|
|
36
|
+
const requestOptions = {
|
|
37
|
+
method: 'POST',
|
|
38
|
+
body: JSON.stringify(payload),
|
|
39
|
+
headers: {
|
|
40
|
+
'Content-Type': 'application/json',
|
|
41
|
+
},
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
let requestTimeoutId;
|
|
45
|
+
if (options.timeout) {
|
|
46
|
+
const controller = new AbortController();
|
|
47
|
+
requestTimeoutId = setTimeout(() => controller.abort(), options.timeout);
|
|
48
|
+
Object.assign(requestOptions, { signal: controller.signal });
|
|
49
|
+
}
|
|
44
50
|
|
|
45
|
-
const config = { timeout: options.timeout };
|
|
46
51
|
// For NodeJS Client
|
|
47
52
|
if (typeof process !== 'undefined'
|
|
48
53
|
&& process.versions != null
|
|
49
54
|
&& process.versions.node != null
|
|
50
55
|
&& protocol === 'https'
|
|
51
56
|
&& selfSigned) {
|
|
52
|
-
|
|
57
|
+
requestOptions.agent = new https.Agent({
|
|
53
58
|
rejectUnauthorized: false,
|
|
54
59
|
});
|
|
55
60
|
}
|
|
56
61
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
url,
|
|
60
|
-
payload,
|
|
61
|
-
config,
|
|
62
|
-
);
|
|
63
|
-
} catch (error) {
|
|
64
|
-
if (error.response && error.response.status >= 500) {
|
|
65
|
-
throw new WrongHttpCodeError(requestInfo, error.response.status, error.response.statusText);
|
|
66
|
-
}
|
|
62
|
+
// eslint-disable-next-line
|
|
63
|
+
const response = await fetch(url, requestOptions);
|
|
67
64
|
|
|
68
|
-
|
|
65
|
+
if (typeof requestTimeoutId !== 'undefined') {
|
|
66
|
+
clearTimeout(requestTimeoutId);
|
|
69
67
|
}
|
|
68
|
+
const data = await response.json();
|
|
70
69
|
|
|
71
|
-
if (response.
|
|
72
|
-
throw new WrongHttpCodeError(requestInfo, response.status, response.
|
|
70
|
+
if (!response.ok) {
|
|
71
|
+
throw new WrongHttpCodeError(requestInfo, response.status, response.statusText);
|
|
73
72
|
}
|
|
74
73
|
|
|
75
|
-
const { data } = response;
|
|
76
|
-
|
|
77
74
|
if (data.error) {
|
|
78
75
|
throw new JsonRpcError(requestInfo, data.error);
|
|
79
76
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dashevo/dapi-client",
|
|
3
|
-
"version": "0.24.0-dev.
|
|
3
|
+
"version": "0.24.0-dev.13",
|
|
4
4
|
"description": "Client library used to access Dash DAPI endpoints",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"contributors": [
|
|
@@ -26,15 +26,15 @@
|
|
|
26
26
|
}
|
|
27
27
|
],
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@dashevo/dapi-grpc": "0.24.0-dev.
|
|
30
|
-
"@dashevo/dash-spv": "0.24.0-dev.
|
|
29
|
+
"@dashevo/dapi-grpc": "0.24.0-dev.13",
|
|
30
|
+
"@dashevo/dash-spv": "0.24.0-dev.13",
|
|
31
31
|
"@dashevo/dashcore-lib": "~0.19.44",
|
|
32
|
-
"@dashevo/dpp": "0.24.0-dev.
|
|
33
|
-
"@dashevo/grpc-common": "0.24.0-dev.
|
|
34
|
-
"axios": "^0.27.2",
|
|
32
|
+
"@dashevo/dpp": "0.24.0-dev.13",
|
|
33
|
+
"@dashevo/grpc-common": "0.24.0-dev.13",
|
|
35
34
|
"bs58": "^4.0.1",
|
|
36
35
|
"cbor": "^8.0.0",
|
|
37
36
|
"lodash": "^4.17.21",
|
|
37
|
+
"node-fetch": "^2.6.7",
|
|
38
38
|
"node-inspect-extracted": "^1.0.8",
|
|
39
39
|
"wasm-x11-hash": "~0.0.2"
|
|
40
40
|
},
|
|
@@ -77,7 +77,8 @@
|
|
|
77
77
|
},
|
|
78
78
|
"files": [
|
|
79
79
|
"docs",
|
|
80
|
-
"lib"
|
|
80
|
+
"lib",
|
|
81
|
+
"polyfills"
|
|
81
82
|
],
|
|
82
83
|
"scripts": {
|
|
83
84
|
"build:web": "webpack",
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/* eslint-disable */
|
|
2
|
+
|
|
3
|
+
const { default: fetch, Headers, Request, Response } = require('node-fetch');
|
|
4
|
+
|
|
5
|
+
if (!globalThis.fetch) {
|
|
6
|
+
globalThis.fetch = fetch;
|
|
7
|
+
globalThis.Headers = Headers;
|
|
8
|
+
globalThis.Request = Request;
|
|
9
|
+
globalThis.Response = Response;
|
|
10
|
+
}
|