@dashevo/dapi-client 0.21.0 → 0.21.4

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/DAPIClient.js CHANGED
@@ -47,7 +47,8 @@ class DAPIClient {
47
47
  * @typedef {DAPIClientOptions} DAPIClientOptions
48
48
  * @property {DAPIAddressProvider} [dapiAddressProvider]
49
49
  * @property {Array<RawDAPIAddress|DAPIAddress|string>} [dapiAddresses]
50
- * @property {string[]|RawDAPIAddress[]} [seeds]
50
+ * @property {Array<RawDAPIAddress|DAPIAddress|string>} [seeds]
51
+ * @property {Array<RawDAPIAddress|DAPIAddress|string>} [dapiAddressesWhiteList]
51
52
  * @property {string|Network} [network=testnet]
52
53
  * @property {number} [timeout=2000]
53
54
  * @property {number} [retries=3]
@@ -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.
@@ -2,13 +2,14 @@ const DAPIAddress = require('./DAPIAddress');
2
2
 
3
3
  class SimplifiedMasternodeListDAPIAddressProvider {
4
4
  /**
5
- *
6
5
  * @param {SimplifiedMasternodeListProvider} smlProvider
7
6
  * @param {ListDAPIAddressProvider} listDAPIAddressProvider
7
+ * @param {DAPIAddress[]} addressWhiteList
8
8
  */
9
- constructor(smlProvider, listDAPIAddressProvider) {
9
+ constructor(smlProvider, listDAPIAddressProvider, addressWhiteList) {
10
10
  this.smlProvider = smlProvider;
11
11
  this.listDAPIAddressProvider = listDAPIAddressProvider;
12
+ this.addressWhiteStrings = addressWhiteList.map((dapiAddress) => dapiAddress.toString());
12
13
  }
13
14
 
14
15
  /**
@@ -44,7 +45,14 @@ class SimplifiedMasternodeListDAPIAddressProvider {
44
45
  return address;
45
46
  });
46
47
 
47
- this.listDAPIAddressProvider.setAddresses(updatedAddresses);
48
+ let filteredAddresses = updatedAddresses;
49
+ if (this.addressWhiteStrings.length > 0) {
50
+ filteredAddresses = updatedAddresses.filter((dapiAddress) => (
51
+ this.addressWhiteStrings.includes(dapiAddress.toString())
52
+ ));
53
+ }
54
+
55
+ this.listDAPIAddressProvider.setAddresses(filteredAddresses);
48
56
 
49
57
  return this.listDAPIAddressProvider.getLiveAddress();
50
58
  }
@@ -39,6 +39,10 @@ function createDAPIAddressProviderFromOptions(options) {
39
39
  throw new DAPIClientError("Can't use 'seeds' with 'dapiAddressProvider' option");
40
40
  }
41
41
 
42
+ if (options.dapiAddressesWhiteList) {
43
+ throw new DAPIClientError("Can't use 'dapiAddressesWhiteList' with 'dapiAddressProvider' option");
44
+ }
45
+
42
46
  return options.dapiAddressProvider;
43
47
  }
44
48
 
@@ -47,6 +51,10 @@ function createDAPIAddressProviderFromOptions(options) {
47
51
  throw new DAPIClientError("Can't use 'seeds' with 'dapiAddresses' option");
48
52
  }
49
53
 
54
+ if (options.dapiAddressesWhiteList) {
55
+ throw new DAPIClientError("Can't use 'dapiAddressesWhiteList' with 'dapiAddresses' option");
56
+ }
57
+
50
58
  return new ListDAPIAddressProvider(
51
59
  options.dapiAddresses.map((rawAddress) => new DAPIAddress(rawAddress)),
52
60
  options,
@@ -54,6 +62,21 @@ function createDAPIAddressProviderFromOptions(options) {
54
62
  }
55
63
 
56
64
  if (options.seeds) {
65
+ let dapiAddressesWhiteList = options.dapiAddressesWhiteList || [];
66
+
67
+ // Since we don't have PoSe atm, 3rd party masternodes sometimes provide wrong data
68
+ // that breaks test suite and application logic. Temporary solution is to hardcode
69
+ // reliable DCG testnet masternodes to connect. Should be removed when PoSe is introduced.
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) {
77
+ dapiAddressesWhiteList = networkConfigs.testnet.dapiAddressesWhiteList;
78
+ }
79
+
57
80
  const listDAPIAddressProvider = new ListDAPIAddressProvider(
58
81
  options.seeds.map((rawAddress) => new DAPIAddress(rawAddress)),
59
82
  options,
@@ -72,7 +95,11 @@ function createDAPIAddressProviderFromOptions(options) {
72
95
  { network: options.network },
73
96
  );
74
97
 
75
- return new SimplifiedMasternodeListDAPIAddressProvider(smlProvider, listDAPIAddressProvider);
98
+ return new SimplifiedMasternodeListDAPIAddressProvider(
99
+ smlProvider,
100
+ listDAPIAddressProvider,
101
+ dapiAddressesWhiteList.map((rawAddress) => new DAPIAddress(rawAddress)),
102
+ );
76
103
  }
77
104
 
78
105
  if (options.network) {
@@ -8,6 +8,161 @@ module.exports = {
8
8
  'seed-5.testnet.networks.dash.org',
9
9
  ],
10
10
  network: 'testnet',
11
+ // Since we don't have PoSe atm, 3rd party masternodes sometimes provide wrong data
12
+ // that breaks test suite and application logic. Temporary solution is to hardcode
13
+ // reliable DCG testnet masternodes to connect. Should be removed when PoSe is introduced.
14
+ dapiAddressesWhiteList: [
15
+ '52.11.85.154',
16
+ '52.38.248.133',
17
+ '34.212.231.240',
18
+ '54.185.249.226',
19
+ '34.215.57.86',
20
+ '54.190.73.116',
21
+ '34.214.2.219',
22
+ '54.212.84.164',
23
+ '35.164.96.124',
24
+ '34.219.81.129',
25
+ '34.221.42.205',
26
+ '34.208.88.128',
27
+ '54.189.162.193',
28
+ '34.220.124.90',
29
+ '54.201.242.241',
30
+ '54.68.10.46',
31
+ '34.210.81.39',
32
+ '18.237.47.243',
33
+ '54.187.229.6',
34
+ '34.214.102.160',
35
+ '34.219.93.145',
36
+ '35.165.37.186',
37
+ '54.202.157.120',
38
+ '34.215.144.176',
39
+ '52.13.119.69',
40
+ '34.220.12.188',
41
+ '18.237.5.33',
42
+ '54.191.32.70',
43
+ '54.213.219.155',
44
+ '35.167.25.157',
45
+ '54.213.89.75',
46
+ '52.32.232.156',
47
+ '34.212.226.44',
48
+ '35.160.140.37',
49
+ '52.11.133.244',
50
+ '54.201.189.185',
51
+ '34.216.200.22',
52
+ '34.220.144.226',
53
+ '34.216.195.19',
54
+ '54.185.1.69',
55
+ '35.166.29.155',
56
+ '18.237.147.160',
57
+ '34.220.228.214',
58
+ '54.212.75.8',
59
+ '35.163.152.74',
60
+ '18.236.78.191',
61
+ '54.148.106.179',
62
+ '34.211.46.222',
63
+ '35.160.13.25',
64
+ '34.220.17.107',
65
+ '34.212.65.137',
66
+ '54.185.249.172',
67
+ '54.70.65.199',
68
+ '54.69.210.42',
69
+ '18.236.160.247',
70
+ '54.245.197.173',
71
+ '54.187.11.213',
72
+ '54.218.70.46',
73
+ '35.165.207.13',
74
+ '34.211.49.3',
75
+ '34.219.36.94',
76
+ '34.222.127.158',
77
+ '34.222.242.228',
78
+ '52.26.220.40',
79
+ '52.36.244.225',
80
+ '34.222.225.76',
81
+ '18.236.169.114',
82
+ '54.201.236.212',
83
+ '54.203.241.214',
84
+ '34.221.254.29',
85
+ '54.187.50.120',
86
+ '54.184.140.221',
87
+ '34.215.192.133',
88
+ '35.164.180.39',
89
+ '54.184.183.20',
90
+ '52.43.197.215',
91
+ '54.201.42.245',
92
+ '54.218.113.88',
93
+ '54.244.141.192',
94
+ '34.217.98.54',
95
+ '34.222.168.33',
96
+ '52.32.143.49',
97
+ '54.187.224.80',
98
+ '54.189.87.145',
99
+ '52.39.164.105',
100
+ '54.70.55.164',
101
+ '54.214.68.206',
102
+ '54.201.239.109',
103
+ '34.215.146.162',
104
+ '18.236.233.120',
105
+ '54.190.217.178',
106
+ '34.220.41.134',
107
+ '34.212.178.215',
108
+ '34.219.169.55',
109
+ '54.218.251.43',
110
+ '18.236.216.191',
111
+ '54.188.17.60',
112
+ '54.191.227.118',
113
+ '34.213.5.102',
114
+ '35.166.79.235',
115
+ '54.71.107.225',
116
+ '54.201.162.86',
117
+ '52.34.141.75',
118
+ '34.217.43.189',
119
+ '52.38.77.105',
120
+ '52.11.252.174',
121
+ '54.191.221.246',
122
+ '54.218.107.83',
123
+ '54.212.18.218',
124
+ '34.220.53.77',
125
+ '54.244.41.15',
126
+ '34.222.135.203',
127
+ '54.191.110.152',
128
+ '34.208.190.130',
129
+ '34.222.6.55',
130
+ '54.184.7.184',
131
+ '52.12.47.86',
132
+ '34.217.28.248',
133
+ '54.149.252.146',
134
+ '54.149.80.193',
135
+ '34.215.55.0',
136
+ '34.220.74.48',
137
+ '34.209.124.112',
138
+ '34.217.23.70',
139
+ '34.222.102.137',
140
+ '34.209.166.42',
141
+ '18.236.128.49',
142
+ '35.163.99.20',
143
+ '34.215.67.224',
144
+ '34.211.244.117',
145
+ '18.236.199.232',
146
+ '54.191.237.52',
147
+ '34.223.226.224',
148
+ '54.149.133.143',
149
+ '52.41.198.242',
150
+ '54.148.215.161',
151
+ '54.188.193.70',
152
+ '54.218.104.194',
153
+ '34.209.73.208',
154
+ '34.220.88.70',
155
+ '52.40.101.104',
156
+ '18.236.68.153',
157
+ '34.218.76.179',
158
+ '34.219.94.178',
159
+ '54.218.127.128',
160
+ '52.27.198.246',
161
+ '18.237.204.153',
162
+ '35.166.57.113',
163
+ '54.191.15.3',
164
+ '18.237.128.46',
165
+ ],
11
166
  },
12
167
  evonet: {
13
168
  seeds: [
@@ -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.statusCode,
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.statusCode = statusCode;
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
- getStatusCode() {
34
- return this.statusCode;
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.0",
3
+ "version": "0.21.4",
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.0",
30
- "@dashevo/dashcore-lib": "~0.19.26",
31
- "@dashevo/dpp": "~0.21.0-dev.5",
32
- "@dashevo/grpc-common": "~0.5.4",
29
+ "@dashevo/dapi-grpc": "~0.21.4",
30
+ "@dashevo/dashcore-lib": "~0.19.27",
31
+ "@dashevo/dpp": "~0.21.4",
32
+ "@dashevo/grpc-common": "~0.21.4",
33
33
  "@grpc/grpc-js": "^1.3.7",
34
34
  "axios": "^0.21.1",
35
35
  "bs58": "^4.0.1",
36
- "cbor": "^7.0.5",
36
+ "cbor": "^8.0.0",
37
37
  "lodash.sample": "^4.2.1",
38
- "node-inspect-extracted": "^1.0.7"
38
+ "node-inspect-extracted": "^1.0.8"
39
39
  },
40
40
  "devDependencies": {
41
- "@babel/core": "^7.10.2",
41
+ "@babel/core": "^7.15.5",
42
42
  "assert-browserify": "^2.0.0",
43
- "babel-loader": "^8.0.6",
43
+ "babel-loader": "^8.2.2",
44
44
  "buffer": "^6.0.3",
45
- "chai": "^4.2.0",
45
+ "chai": "^4.3.4",
46
46
  "chai-as-promised": "^7.1.1",
47
- "core-js": "^3.6.4",
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": "^6.8.0",
51
- "eslint-config-airbnb-base": "^14.1.0",
52
- "eslint-plugin-import": "^2.20.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.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.52.1",
70
- "webpack-cli": "^4.8.0"
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
  }