@dashevo/dapi-client 0.21.1 → 0.21.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/lib/dapiAddressProvider/ListDAPIAddressProvider.js +5 -1
- package/lib/dapiAddressProvider/createDAPIAddressProviderFromOptions.js +7 -1
- package/lib/transport/JsonRpcTransport/createJsonTransportError.js +1 -1
- package/lib/transport/JsonRpcTransport/errors/WrongHttpCodeError.js +3 -3
- package/lib/transport/JsonRpcTransport/requestJsonRpc.js +16 -6
- package/package.json +25 -19
|
@@ -18,13 +18,17 @@ class ListDAPIAddressProvider {
|
|
|
18
18
|
/**
|
|
19
19
|
* Get random address
|
|
20
20
|
*
|
|
21
|
-
* @returns {Promise<DAPIAddress>}
|
|
21
|
+
* @returns {Promise<DAPIAddress|undefined>}
|
|
22
22
|
*/
|
|
23
23
|
async getLiveAddress() {
|
|
24
24
|
const liveAddresses = this.getLiveAddresses();
|
|
25
25
|
|
|
26
26
|
const liveAddress = sample(liveAddresses);
|
|
27
27
|
|
|
28
|
+
if (liveAddress === undefined) {
|
|
29
|
+
return liveAddress;
|
|
30
|
+
}
|
|
31
|
+
|
|
28
32
|
// This is a temporary fix for a localhost masternode.
|
|
29
33
|
// On mac os, internal docker IP is used to register masternode, and it's
|
|
30
34
|
// not really possible to bind to that address, so that workaround is introduced.
|
|
@@ -67,7 +67,13 @@ function createDAPIAddressProviderFromOptions(options) {
|
|
|
67
67
|
// Since we don't have PoSe atm, 3rd party masternodes sometimes provide wrong data
|
|
68
68
|
// that breaks test suite and application logic. Temporary solution is to hardcode
|
|
69
69
|
// reliable DCG testnet masternodes to connect. Should be removed when PoSe is introduced.
|
|
70
|
-
|
|
70
|
+
const network = networks.get(options.network);
|
|
71
|
+
let isRegtest = false;
|
|
72
|
+
if (network) {
|
|
73
|
+
isRegtest = network.regtestEnabled;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
if (options.network === 'testnet' && dapiAddressesWhiteList.length === 0 && !isRegtest) {
|
|
71
77
|
dapiAddressesWhiteList = networkConfigs.testnet.dapiAddressesWhiteList;
|
|
72
78
|
}
|
|
73
79
|
|
|
@@ -13,7 +13,7 @@ const RetriableResponseError = require('../errors/response/RetriableResponseErro
|
|
|
13
13
|
function createJsonTransportError(error, dapiAddress) {
|
|
14
14
|
if (error instanceof WrongHttpCodeError) {
|
|
15
15
|
return new ServerError(
|
|
16
|
-
error.
|
|
16
|
+
error.getCode(),
|
|
17
17
|
error.message,
|
|
18
18
|
{},
|
|
19
19
|
dapiAddress,
|
|
@@ -16,7 +16,7 @@ class WrongHttpCodeError extends DAPIClientError {
|
|
|
16
16
|
super(`DAPI JSON RPC wrong http code: ${statusMessage}`);
|
|
17
17
|
|
|
18
18
|
this.requestInfo = requestInfo;
|
|
19
|
-
this.
|
|
19
|
+
this.code = statusCode;
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
/**
|
|
@@ -30,8 +30,8 @@ class WrongHttpCodeError extends DAPIClientError {
|
|
|
30
30
|
*
|
|
31
31
|
* @returns {number}
|
|
32
32
|
*/
|
|
33
|
-
|
|
34
|
-
return this.
|
|
33
|
+
getCode() {
|
|
34
|
+
return this.code;
|
|
35
35
|
}
|
|
36
36
|
}
|
|
37
37
|
|
|
@@ -29,12 +29,6 @@ async function requestJsonRpc(host, port, method, params, options = {}) {
|
|
|
29
29
|
postOptions.timeout = options.timeout;
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
const response = await axios.post(
|
|
33
|
-
url,
|
|
34
|
-
payload,
|
|
35
|
-
{ timeout: options.timeout },
|
|
36
|
-
);
|
|
37
|
-
|
|
38
32
|
const requestInfo = {
|
|
39
33
|
host,
|
|
40
34
|
port,
|
|
@@ -43,6 +37,22 @@ async function requestJsonRpc(host, port, method, params, options = {}) {
|
|
|
43
37
|
options,
|
|
44
38
|
};
|
|
45
39
|
|
|
40
|
+
let response;
|
|
41
|
+
|
|
42
|
+
try {
|
|
43
|
+
response = await axios.post(
|
|
44
|
+
url,
|
|
45
|
+
payload,
|
|
46
|
+
{ timeout: options.timeout },
|
|
47
|
+
);
|
|
48
|
+
} catch (error) {
|
|
49
|
+
if (error.response && error.response.status >= 500) {
|
|
50
|
+
throw new WrongHttpCodeError(requestInfo, error.response.status, error.response.statusText);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
throw error;
|
|
54
|
+
}
|
|
55
|
+
|
|
46
56
|
if (response.status !== 200) {
|
|
47
57
|
throw new WrongHttpCodeError(requestInfo, response.status, response.statusMessage);
|
|
48
58
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dashevo/dapi-client",
|
|
3
|
-
"version": "0.21.
|
|
3
|
+
"version": "0.21.5",
|
|
4
4
|
"description": "Client library used to access Dash DAPI endpoints",
|
|
5
5
|
"main": "lib/DAPIClient.js",
|
|
6
6
|
"contributors": [
|
|
@@ -26,30 +26,31 @@
|
|
|
26
26
|
}
|
|
27
27
|
],
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@dashevo/dapi-grpc": "~0.21.
|
|
30
|
-
"@dashevo/dashcore-lib": "~0.19.
|
|
31
|
-
"@dashevo/dpp": "~0.21.
|
|
32
|
-
"@dashevo/grpc-common": "~0.5
|
|
29
|
+
"@dashevo/dapi-grpc": "~0.21.5",
|
|
30
|
+
"@dashevo/dashcore-lib": "~0.19.28",
|
|
31
|
+
"@dashevo/dpp": "~0.21.5",
|
|
32
|
+
"@dashevo/grpc-common": "~0.21.5",
|
|
33
33
|
"@grpc/grpc-js": "^1.3.7",
|
|
34
34
|
"axios": "^0.21.1",
|
|
35
35
|
"bs58": "^4.0.1",
|
|
36
|
-
"cbor": "^
|
|
36
|
+
"cbor": "^8.0.0",
|
|
37
37
|
"lodash.sample": "^4.2.1",
|
|
38
|
-
"node-inspect-extracted": "^1.0.
|
|
38
|
+
"node-inspect-extracted": "^1.0.8"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
|
-
"@babel/core": "^7.
|
|
41
|
+
"@babel/core": "^7.15.5",
|
|
42
42
|
"assert-browserify": "^2.0.0",
|
|
43
|
-
"babel-loader": "^8.
|
|
43
|
+
"babel-loader": "^8.2.2",
|
|
44
44
|
"buffer": "^6.0.3",
|
|
45
|
-
"chai": "^4.
|
|
45
|
+
"chai": "^4.3.4",
|
|
46
46
|
"chai-as-promised": "^7.1.1",
|
|
47
|
-
"
|
|
47
|
+
"comment-parser": "^0.7.6",
|
|
48
|
+
"core-js": "^3.17.2",
|
|
48
49
|
"crypto-browserify": "^3.12.0",
|
|
49
50
|
"dirty-chai": "^2.0.1",
|
|
50
|
-
"eslint": "^
|
|
51
|
-
"eslint-config-airbnb-base": "^14.1
|
|
52
|
-
"eslint-plugin-import": "^2.
|
|
51
|
+
"eslint": "^7.32.0",
|
|
52
|
+
"eslint-config-airbnb-base": "^14.2.1",
|
|
53
|
+
"eslint-plugin-import": "^2.24.2",
|
|
53
54
|
"eslint-plugin-jsdoc": "^27.0.0",
|
|
54
55
|
"karma": "^6.3.4",
|
|
55
56
|
"karma-chai": "^0.1.0",
|
|
@@ -58,7 +59,7 @@
|
|
|
58
59
|
"karma-mocha": "^2.0.1",
|
|
59
60
|
"karma-mocha-reporter": "^2.2.5",
|
|
60
61
|
"karma-webpack": "^5.0.0",
|
|
61
|
-
"mocha": "^9.1.
|
|
62
|
+
"mocha": "^9.1.2",
|
|
62
63
|
"nyc": "^15.1.0",
|
|
63
64
|
"path-browserify": "^1.0.1",
|
|
64
65
|
"process": "^0.11.10",
|
|
@@ -66,15 +67,15 @@
|
|
|
66
67
|
"sinon-chai": "^3.7.0",
|
|
67
68
|
"stream-browserify": "^3.0.0",
|
|
68
69
|
"url": "^0.11.0",
|
|
69
|
-
"webpack": "^5.
|
|
70
|
-
"webpack-cli": "^4.
|
|
70
|
+
"webpack": "^5.59.1",
|
|
71
|
+
"webpack-cli": "^4.9.1"
|
|
71
72
|
},
|
|
72
73
|
"files": [
|
|
73
74
|
"docs",
|
|
74
75
|
"lib"
|
|
75
76
|
],
|
|
76
77
|
"scripts": {
|
|
77
|
-
"build": "webpack",
|
|
78
|
+
"build:web": "webpack",
|
|
78
79
|
"lint": "eslint .",
|
|
79
80
|
"test": "npm run test:coverage && npm run test:browsers",
|
|
80
81
|
"test:unit": "mocha './test/unit/**/*.spec.js'",
|
|
@@ -82,7 +83,12 @@
|
|
|
82
83
|
"test:node": "NODE_ENV=test mocha",
|
|
83
84
|
"test:browsers": "karma start ./karma.conf.js --single-run",
|
|
84
85
|
"test:coverage": "NODE_ENV=test nyc --check-coverage --stmts=98 --branch=98 --funcs=98 --lines=95 mocha 'test/unit/**/*.spec.js' 'test/integration/**/*.spec.js'",
|
|
85
|
-
"prepublishOnly": "npm run build"
|
|
86
|
+
"prepublishOnly": "npm run build:web"
|
|
87
|
+
},
|
|
88
|
+
"ultra": {
|
|
89
|
+
"concurrent": [
|
|
90
|
+
"clean"
|
|
91
|
+
]
|
|
86
92
|
},
|
|
87
93
|
"license": "MIT"
|
|
88
94
|
}
|