@dashevo/dapi-client 1.0.0-pr.1545.8 → 1.0.0-pr.1621.0

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.
Files changed (42) hide show
  1. package/lib/BlockHeadersProvider/BlockHeadersProvider.js +2 -3
  2. package/lib/BlockHeadersProvider/BlockHeadersReader.js +3 -9
  3. package/lib/DAPIClient.js +6 -1
  4. package/lib/SimplifiedMasternodeListProvider/SimplifiedMasternodeListProvider.js +1 -6
  5. package/lib/dapiAddressProvider/DAPIAddress.js +1 -9
  6. package/lib/dapiAddressProvider/ListDAPIAddressProvider.js +0 -5
  7. package/lib/dapiAddressProvider/SimplifiedMasternodeListDAPIAddressProvider.js +0 -2
  8. package/lib/logger/index.js +5 -1
  9. package/lib/methods/core/broadcastTransactionFactory.js +0 -1
  10. package/lib/methods/core/generateToAddressFactory.js +0 -1
  11. package/lib/methods/core/getBestBlockHashFactory.js +0 -1
  12. package/lib/methods/core/getBlockByHashFactory.js +0 -1
  13. package/lib/methods/core/getBlockByHeightFactory.js +0 -1
  14. package/lib/methods/core/getBlockHashFactory.js +0 -1
  15. package/lib/methods/core/getMnListDiffFactory.js +0 -1
  16. package/lib/methods/core/getStatusFactory.js +0 -1
  17. package/lib/methods/core/getTransaction/GetTransactionResponse.js +0 -6
  18. package/lib/methods/core/getTransaction/getTransactionFactory.js +0 -1
  19. package/lib/methods/platform/broadcastStateTransition/broadcastStateTransitionFactory.js +0 -1
  20. package/lib/methods/platform/getConsensusParams/getConsensusParamsFactory.js +0 -1
  21. package/lib/methods/platform/getDataContract/getDataContractFactory.js +0 -1
  22. package/lib/methods/platform/getDataContractHistory/getDataContractHistoryFactory.js +0 -1
  23. package/lib/methods/platform/getDocuments/getDocumentsFactory.js +0 -1
  24. package/lib/methods/platform/getEpochsInfo/getEpochsInfoFactory.js +0 -1
  25. package/lib/methods/platform/getIdentitiesByPublicKeyHashes/getIdentitiesByPublicKeyHashesFactory.js +0 -1
  26. package/lib/methods/platform/getIdentity/getIdentityFactory.js +0 -1
  27. package/lib/methods/platform/getProtocolVersionUpgradeState/getProtocolVersionUpgradeStateFactory.js +0 -1
  28. package/lib/methods/platform/getProtocolVersionUpgradeVoteStatus/getProtocolVersionUpgradeVoteStatusFactory.js +0 -1
  29. package/lib/methods/platform/response/AbstractResponse.js +0 -1
  30. package/lib/methods/platform/response/Metadata.js +3 -5
  31. package/lib/methods/platform/response/Proof.js +0 -1
  32. package/lib/methods/platform/waitForStateTransitionResult/waitForStateTransitionResultFactory.js +1 -1
  33. package/lib/test/bootstrap.js +13 -19
  34. package/lib/test/fixtures/getMNListDiffsFixture.js +0 -1
  35. package/lib/test/karma/bootstrap.js +37 -0
  36. package/lib/test/karma/loader.js +1 -1
  37. package/lib/transport/GrpcTransport/GrpcTransport.js +3 -5
  38. package/lib/transport/JsonRpcTransport/JsonRpcTransport.js +0 -3
  39. package/lib/transport/JsonRpcTransport/errors/JsonRpcError.js +0 -3
  40. package/lib/transport/ReconnectableStream.js +0 -9
  41. package/lib/utils/wait.js +1 -3
  42. package/package.json +17 -17
@@ -39,6 +39,8 @@ class BlockHeadersProvider extends EventEmitter {
39
39
  * @param {Function} [createHistoricalSyncStream]
40
40
  * @param {Function} [createContinuousSyncStream]
41
41
  */
42
+ // TODO move options to as last param
43
+ // eslint-disable-next-line default-param-last
42
44
  constructor(options = {}, createHistoricalSyncStream, createContinuousSyncStream) {
43
45
  super();
44
46
  this.options = {
@@ -102,7 +104,6 @@ class BlockHeadersProvider extends EventEmitter {
102
104
 
103
105
  /**
104
106
  * Initializes SPV chain with a list of headers and a known lastSyncedHeaderHeight
105
- *
106
107
  * @param headers
107
108
  * @param firstHeaderHeight
108
109
  */
@@ -120,7 +121,6 @@ class BlockHeadersProvider extends EventEmitter {
120
121
 
121
122
  /**
122
123
  * Checks whether spv chain has header at specified height and flushes chains if not
123
- *
124
124
  * @private
125
125
  * @param height
126
126
  */
@@ -134,7 +134,6 @@ class BlockHeadersProvider extends EventEmitter {
134
134
 
135
135
  /**
136
136
  * Reads historical block headers
137
- *
138
137
  * @param fromBlockHeight
139
138
  * @param toBlockHeight
140
139
  * @returns {Promise<void>}
@@ -21,6 +21,8 @@ class BlockHeadersReader extends EventEmitter {
21
21
  * @param createHistoricalSyncStream
22
22
  * @param createContinuousSyncStream
23
23
  */
24
+ // TODO move options to as last param
25
+ // eslint-disable-next-line default-param-last
24
26
  constructor(options = {}, createHistoricalSyncStream, createContinuousSyncStream) {
25
27
  super();
26
28
  this.createHistoricalSyncStream = createHistoricalSyncStream;
@@ -31,14 +33,12 @@ class BlockHeadersReader extends EventEmitter {
31
33
 
32
34
  /**
33
35
  * Holds references to the historical streams
34
- *
35
36
  * @type {Stream[]}
36
37
  */
37
38
  this.historicalStreams = [];
38
39
 
39
40
  /**
40
41
  * Holds reference to the continuous sync stream
41
- *
42
42
  * @type {Stream}
43
43
  */
44
44
  this.continuousSyncStream = null;
@@ -46,7 +46,6 @@ class BlockHeadersReader extends EventEmitter {
46
46
 
47
47
  /**
48
48
  * Reads historical block heights using multiple streams
49
- *
50
49
  * @param {number} fromBlockHeight
51
50
  * @param {number} toBlockHeight
52
51
  * @returns {Promise<void>}
@@ -92,7 +91,6 @@ class BlockHeadersReader extends EventEmitter {
92
91
 
93
92
  /**
94
93
  * Subscribes to continuously arriving block headers
95
- *
96
94
  * @param {number} fromBlockHeight
97
95
  * @returns {Promise<ReconnectableStream>}
98
96
  */
@@ -131,7 +129,6 @@ class BlockHeadersReader extends EventEmitter {
131
129
 
132
130
  /**
133
131
  * Kills stream in case of deliberate rejection from the outside
134
- *
135
132
  * @param e
136
133
  */
137
134
  const rejectHeaders = async (e) => {
@@ -187,9 +184,8 @@ class BlockHeadersReader extends EventEmitter {
187
184
  /**
188
185
  * A HOF that returns a function to subscribe to historical block headers and chain locks
189
186
  * and handles retry logic
190
- *
191
187
  * @private
192
- * @param {number} [maxRetries=0] - maximum amount of retries
188
+ * @param {number} [maxRetries] - maximum amount of retries
193
189
  * @returns {function(*, *): Promise<Stream>}
194
190
  */
195
191
  createSubscribeToHistoricalBatch(maxRetries = 0) {
@@ -197,7 +193,6 @@ class BlockHeadersReader extends EventEmitter {
197
193
 
198
194
  /**
199
195
  * Subscribes to the stream of historical data and handles retry logic
200
- *
201
196
  * @param {number} fromBlockHeight
202
197
  * @param {number} count
203
198
  * @returns {Promise<Stream>}
@@ -249,7 +244,6 @@ class BlockHeadersReader extends EventEmitter {
249
244
 
250
245
  /**
251
246
  * Kills stream in case of deliberate rejection from the outside
252
- *
253
247
  * @param e
254
248
  */
255
249
  const rejectHeaders = (e) => {
package/lib/DAPIClient.js CHANGED
@@ -34,6 +34,7 @@ class DAPIClient extends EventEmitter {
34
34
  blockHeadersProviderOptions: BlockHeadersProvider.defaultOptions,
35
35
  loggerOptions: {
36
36
  identifier: '',
37
+ level: undefined,
37
38
  },
38
39
  ...options,
39
40
  };
@@ -57,7 +58,10 @@ class DAPIClient extends EventEmitter {
57
58
 
58
59
  this.core = new CoreMethodsFacade(jsonRpcTransport, grpcTransport);
59
60
  this.platform = new PlatformMethodsFacade(grpcTransport);
60
- this.logger = logger.getForId(this.options.loggerOptions.identifier);
61
+ this.logger = logger.getForId(
62
+ this.options.loggerOptions.identifier,
63
+ this.options.loggerOptions.level,
64
+ );
61
65
 
62
66
  this.initBlockHeadersProvider();
63
67
  }
@@ -89,6 +93,7 @@ DAPIClient.EVENTS = EVENTS;
89
93
  * @property {boolean} [throwDeadlineExceeded]
90
94
  * @property {object} [loggerOptions]
91
95
  * @property {string} [loggerOptions.identifier]
96
+ * @property {string} [loggerOptions.level]
92
97
  * @property {BlockHeadersProvider} [blockHeadersProvider]
93
98
  * @property {BlockHeadersProviderOptions} [blockHeadersProviderOptions]
94
99
  */
@@ -6,7 +6,7 @@ class SimplifiedMasternodeListProvider {
6
6
  *
7
7
  * @param {JsonRpcTransport} jsonRpcTransport - JsonRpcTransport instance
8
8
  * @param {object} [options] - Options
9
- * @param {number} [options.updateInterval=60000]
9
+ * @param {number} [options.updateInterval]
10
10
  * @param {string} [options.network]
11
11
  */
12
12
  constructor(jsonRpcTransport, options = {}) {
@@ -26,7 +26,6 @@ class SimplifiedMasternodeListProvider {
26
26
 
27
27
  /**
28
28
  * Returns simplified masternode list
29
- *
30
29
  * @returns {Promise<SimplifiedMNList>}
31
30
  */
32
31
  async getSimplifiedMNList() {
@@ -39,7 +38,6 @@ class SimplifiedMasternodeListProvider {
39
38
 
40
39
  /**
41
40
  * Checks whether simplified masternode list needs update
42
- *
43
41
  * @private
44
42
  * @returns {boolean}
45
43
  */
@@ -49,7 +47,6 @@ class SimplifiedMasternodeListProvider {
49
47
 
50
48
  /**
51
49
  * Updates simplified masternodes list. No need to call it manually
52
- *
53
50
  * @private
54
51
  */
55
52
  async updateMasternodeList() {
@@ -76,7 +73,6 @@ class SimplifiedMasternodeListProvider {
76
73
 
77
74
  /**
78
75
  * Fetches masternode diff from DAPI
79
- *
80
76
  * @private
81
77
  * @returns {Promise<SimplifiedMNListDiff>}
82
78
  */
@@ -94,7 +90,6 @@ class SimplifiedMasternodeListProvider {
94
90
 
95
91
  /**
96
92
  * Reset simplifiedMNList
97
- *
98
93
  * @private
99
94
  */
100
95
  reset() {
@@ -6,6 +6,7 @@ class DAPIAddress {
6
6
  */
7
7
  constructor(address) {
8
8
  if (address instanceof DAPIAddress) {
9
+ // eslint-disable-next-line no-constructor-return
9
10
  return new DAPIAddress(address.toJSON());
10
11
  }
11
12
 
@@ -37,7 +38,6 @@ class DAPIAddress {
37
38
 
38
39
  /**
39
40
  * Get protocol
40
- *
41
41
  * @returns {string}
42
42
  */
43
43
  getProtocol() {
@@ -46,7 +46,6 @@ class DAPIAddress {
46
46
 
47
47
  /**
48
48
  * Get host
49
- *
50
49
  * @returns {string}
51
50
  */
52
51
  getHost() {
@@ -55,7 +54,6 @@ class DAPIAddress {
55
54
 
56
55
  /**
57
56
  * Set host
58
- *
59
57
  * @param {string} host
60
58
  * @returns {DAPIAddress}
61
59
  */
@@ -67,7 +65,6 @@ class DAPIAddress {
67
65
 
68
66
  /**
69
67
  * Get port
70
- *
71
68
  * @returns {number}
72
69
  */
73
70
  getPort() {
@@ -76,7 +73,6 @@ class DAPIAddress {
76
73
 
77
74
  /**
78
75
  * Set port
79
- *
80
76
  * @param {number} port
81
77
  * @returns {DAPIAddress}
82
78
  */
@@ -88,7 +84,6 @@ class DAPIAddress {
88
84
 
89
85
  /**
90
86
  * Get ProRegTx hash
91
- *
92
87
  * @returns {string}
93
88
  */
94
89
  getProRegTxHash() {
@@ -111,7 +106,6 @@ class DAPIAddress {
111
106
 
112
107
  /**
113
108
  * Mark address as banned
114
- *
115
109
  * @returns {DAPIAddress}
116
110
  */
117
111
  markAsBanned() {
@@ -123,7 +117,6 @@ class DAPIAddress {
123
117
 
124
118
  /**
125
119
  * Mark address as live
126
- *
127
120
  * @returns {DAPIAddress}
128
121
  */
129
122
  markAsLive() {
@@ -149,7 +142,6 @@ class DAPIAddress {
149
142
 
150
143
  /**
151
144
  * Return DAPIAddress as plain object
152
- *
153
145
  * @returns {RawDAPIAddress}
154
146
  */
155
147
  toJSON() {
@@ -17,7 +17,6 @@ class ListDAPIAddressProvider {
17
17
 
18
18
  /**
19
19
  * Get random address
20
- *
21
20
  * @returns {Promise<DAPIAddress|undefined>}
22
21
  */
23
22
  async getLiveAddress() {
@@ -47,7 +46,6 @@ class ListDAPIAddressProvider {
47
46
 
48
47
  /**
49
48
  * Get all addresses
50
- *
51
49
  * @returns {DAPIAddress[]}
52
50
  */
53
51
  getAllAddresses() {
@@ -56,7 +54,6 @@ class ListDAPIAddressProvider {
56
54
 
57
55
  /**
58
56
  * Set addresses
59
- *
60
57
  * @param {DAPIAddress[]} addresses
61
58
  * @returns {ListDAPIAddressProvider}
62
59
  */
@@ -68,7 +65,6 @@ class ListDAPIAddressProvider {
68
65
 
69
66
  /**
70
67
  * Check if we have live addresses left
71
- *
72
68
  * @returns {Promise<boolean>} - True if there are live address left
73
69
  */
74
70
  async hasLiveAddresses() {
@@ -79,7 +75,6 @@ class ListDAPIAddressProvider {
79
75
 
80
76
  /**
81
77
  * Get live addresses
82
- *
83
78
  * @returns {DAPIAddress[]}
84
79
  */
85
80
  getLiveAddresses() {
@@ -14,7 +14,6 @@ class SimplifiedMasternodeListDAPIAddressProvider {
14
14
 
15
15
  /**
16
16
  * Get random live DAPI address from SML
17
- *
18
17
  * @returns {Promise<DAPIAddress>}
19
18
  */
20
19
  async getLiveAddress() {
@@ -66,7 +65,6 @@ class SimplifiedMasternodeListDAPIAddressProvider {
66
65
 
67
66
  /**
68
67
  * Check if we have live addresses left
69
- *
70
68
  * @returns {Promise<boolean>}
71
69
  */
72
70
  async hasLiveAddresses() {
@@ -1,7 +1,9 @@
1
1
  const util = require('util');
2
2
  const winston = require('winston');
3
3
 
4
- const LOG_LEVEL = process.env.LOG_LEVEL || 'info';
4
+ // TODO: Refactor to use params instead on envs
5
+
6
+ const LOG_LEVEL = process.env.LOG_LEVEL || 'silent';
5
7
  const LOG_TO_FILE = process.env.LOG_WALLET_TO_FILE || 'false';
6
8
 
7
9
  // Log levels:
@@ -36,6 +38,7 @@ const createLogger = (formats = [], id = '') => {
36
38
  const transports = [
37
39
  new winston.transports.Console({
38
40
  format,
41
+ silent: LOG_LEVEL === 'silent',
39
42
  }),
40
43
  ];
41
44
 
@@ -44,6 +47,7 @@ const createLogger = (formats = [], id = '') => {
44
47
  new winston.transports.File({
45
48
  filename: `wallet${id !== '' ? `_${id}` : ''}`,
46
49
  format,
50
+ silent: LOG_LEVEL === 'silent',
47
51
  }),
48
52
  );
49
53
  }
@@ -12,7 +12,6 @@ const {
12
12
  function broadcastTransactionFactory(grpcTransport) {
13
13
  /**
14
14
  * Broadcast Transaction
15
- *
16
15
  * @typedef {broadcastTransaction}
17
16
  * @param {Buffer} transaction
18
17
  * @param {DAPIClientOptions & BroadcastTransactionOptions} [options]
@@ -5,7 +5,6 @@
5
5
  function generateToAddressFactory(jsonRpcTransport) {
6
6
  /**
7
7
  * ONLY FOR TESTING PURPOSES WITH REGTEST. WILL NOT WORK ON TESTNET/LIVENET.
8
- *
9
8
  * @typedef {generateToAddress}
10
9
  * @param {number} blocksNumber - Number of blocks to generate
11
10
  * @param {string} address - The address that will receive the newly generated Dash
@@ -6,7 +6,6 @@
6
6
  function getBestBlockHashFactory(jsonRpcTransport) {
7
7
  /**
8
8
  * Returns block hash of chaintip
9
- *
10
9
  * @typedef {getBestBlockHash}
11
10
  * @param {DAPIClientOptions} [options]
12
11
  * @returns {Promise<string>}
@@ -12,7 +12,6 @@ const {
12
12
  function getBlockByHashFactory(grpcTransport) {
13
13
  /**
14
14
  * Get block by hash
15
- *
16
15
  * @typedef {getBlockByHash}
17
16
  * @param {string} hash
18
17
  * @param {DAPIClientOptions} [options]
@@ -12,7 +12,6 @@ const {
12
12
  function getBlockByHeightFactory(grpcTransport) {
13
13
  /**
14
14
  * Get block by height
15
- *
16
15
  * @typedef {getBlockByHeight}
17
16
  * @param {number} height
18
17
  * @param {DAPIClientOptions} [options]
@@ -5,7 +5,6 @@
5
5
  function getBlockHashFactory(jsonRpcTransport) {
6
6
  /**
7
7
  * Returns block hash for the given height
8
- *
9
8
  * @typedef {getBlockHash}
10
9
  * @param {number} height
11
10
  * @param {DAPIClientOptions} [options]
@@ -5,7 +5,6 @@
5
5
  function getMnListDiffFactory(jsonRpcTransport) {
6
6
  /**
7
7
  * Get deterministic masternodelist diff
8
- *
9
8
  * @typedef {getMnListDiff}
10
9
  * @param {string} baseBlockHash - hash or height of start block
11
10
  * @param {string} blockHash - hash or height of end block
@@ -13,7 +13,6 @@ const {
13
13
  function getStatusFactory(grpcTransport) {
14
14
  /**
15
15
  * Get Core chain status
16
- *
17
16
  * @typedef {getStatus}
18
17
  * @param {DAPIClientOptions} [options]
19
18
  * @returns {Promise<object>}
@@ -22,7 +22,6 @@ class GetTransactionResponse {
22
22
 
23
23
  /**
24
24
  * Get transaction
25
- *
26
25
  * @returns {Buffer}
27
26
  */
28
27
  getTransaction() {
@@ -31,7 +30,6 @@ class GetTransactionResponse {
31
30
 
32
31
  /**
33
32
  * Get block hash
34
- *
35
33
  * @returns {Buffer}
36
34
  */
37
35
  getBlockHash() {
@@ -40,7 +38,6 @@ class GetTransactionResponse {
40
38
 
41
39
  /**
42
40
  * Get height
43
- *
44
41
  * @returns {number}
45
42
  */
46
43
  getHeight() {
@@ -49,7 +46,6 @@ class GetTransactionResponse {
49
46
 
50
47
  /**
51
48
  * Get number of confirmations
52
- *
53
49
  * @returns {number}
54
50
  */
55
51
  getConfirmations() {
@@ -58,7 +54,6 @@ class GetTransactionResponse {
58
54
 
59
55
  /**
60
56
  * Is transaction instant locked
61
- *
62
57
  * @returns {boolean}
63
58
  */
64
59
  isInstantLocked() {
@@ -67,7 +62,6 @@ class GetTransactionResponse {
67
62
 
68
63
  /**
69
64
  * Is transaction chain locked
70
- *
71
65
  * @returns {boolean}
72
66
  */
73
67
  isChainLocked() {
@@ -15,7 +15,6 @@ const InvalidResponseError = require('../../platform/response/errors/InvalidResp
15
15
  function getTransactionFactory(grpcTransport) {
16
16
  /**
17
17
  * Get Transaction by ID
18
- *
19
18
  * @typedef {getTransaction}
20
19
  * @param {string} id
21
20
  * @param {DAPIClientOptions} [options]
@@ -14,7 +14,6 @@ const InvalidResponseError = require('../response/errors/InvalidResponseError');
14
14
  function broadcastStateTransitionFactory(grpcTransport) {
15
15
  /**
16
16
  * Broadcast State Transaction
17
- *
18
17
  * @typedef {broadcastStateTransition}
19
18
  * @param {Buffer} stateTransition
20
19
  * @param {DAPIClientOptions} [options]
@@ -18,7 +18,6 @@ const {
18
18
  function getConsensusParamsFactory(grpcTransport) {
19
19
  /**
20
20
  * Fetch Consensus params
21
- *
22
21
  * @typedef getConsensusParams
23
22
  * @param {number} [height]
24
23
  * @param {prove: boolean} [options]
@@ -15,7 +15,6 @@ const InvalidResponseError = require('../response/errors/InvalidResponseError');
15
15
  function getDataContractFactory(grpcTransport) {
16
16
  /**
17
17
  * Fetch Data Contract by id
18
- *
19
18
  * @typedef {getDataContract}
20
19
  * @param {Buffer} contractId
21
20
  * @param {DAPIClientOptions & {prove: boolean}} [options]
@@ -16,7 +16,6 @@ const InvalidResponseError = require('../response/errors/InvalidResponseError');
16
16
  function getDataContractHistoryFactory(grpcTransport) {
17
17
  /**
18
18
  * Fetch Data Contract by id
19
- *
20
19
  * @typedef {getDataContractHistory}
21
20
  * @param {Buffer} contractId
22
21
  * @param {number} [startAtMs]
@@ -17,7 +17,6 @@ const InvalidResponseError = require('../response/errors/InvalidResponseError');
17
17
  function getDocumentsFactory(grpcTransport) {
18
18
  /**
19
19
  * Fetch Documents from Drive
20
- *
21
20
  * @typedef {getDocuments}
22
21
  * @param {Buffer} contractId - Data Contract ID
23
22
  * @param {string} type - Document type
@@ -17,7 +17,6 @@ const InvalidResponseError = require('../response/errors/InvalidResponseError');
17
17
  function getEpochsInfoFactory(grpcTransport) {
18
18
  /**
19
19
  * Fetch the epoch info
20
- *
21
20
  * @typedef {getEpochsInfo}
22
21
  * @param {number} startEpoch
23
22
  * @param {number} count
@@ -15,7 +15,6 @@ const InvalidResponseError = require('../response/errors/InvalidResponseError');
15
15
  function getIdentitiesByPublicKeyHashesFactory(grpcTransport) {
16
16
  /**
17
17
  * Fetch the identities by public key hashes
18
- *
19
18
  * @typedef {getIdentitiesByPublicKeyHashes}
20
19
  * @param {Buffer[]} publicKeyHashes
21
20
  * @param {DAPIClientOptions & {prove: boolean}} [options]
@@ -15,7 +15,6 @@ const InvalidResponseError = require('../response/errors/InvalidResponseError');
15
15
  function getIdentityFactory(grpcTransport) {
16
16
  /**
17
17
  * Fetch the identity by id
18
- *
19
18
  * @typedef {getIdentity}
20
19
  * @param {Buffer} id
21
20
  * @param {DAPIClientOptions & {prove: boolean}} [options]
@@ -15,7 +15,6 @@ const InvalidResponseError = require('../response/errors/InvalidResponseError');
15
15
  function getProtocolVersionUpgradeStateFactory(grpcTransport) {
16
16
  /**
17
17
  * Fetch the version upgrade state
18
- *
19
18
  * @typedef {getProtocolVersionUpgradeState}
20
19
  * @param {DAPIClientOptions & {prove: boolean}} [options]
21
20
  * @returns {Promise<GetProtocolVersionUpgradeStateResponse>}
@@ -15,7 +15,6 @@ const InvalidResponseError = require('../response/errors/InvalidResponseError');
15
15
  function getProtocolVersionUpgradeVoteStatusFactory(grpcTransport) {
16
16
  /**
17
17
  * Fetch the version upgrade vote status
18
- *
19
18
  * @typedef {getProtocolVersionUpgradeVoteStatus}
20
19
  * @param {string} startProTxHash
21
20
  * @param {number} count
@@ -32,7 +32,6 @@ class AbstractResponse {
32
32
  /**
33
33
  *
34
34
  * @param proto
35
- *
36
35
  * @returns{{metadata: Metadata, proof: Proof|undefined}}
37
36
  * @throws {InvalidResponseError}
38
37
  */
@@ -1,6 +1,6 @@
1
1
  class Metadata {
2
2
  /**
3
- * @param {Object} properties
3
+ * @param {object} properties
4
4
  * @param {number} properties.height - block height
5
5
  * @param {number} properties.coreChainLockedHeight - core chain locked height
6
6
  * @param {number} properties.timeMs - block time
@@ -15,7 +15,6 @@ class Metadata {
15
15
 
16
16
  /**
17
17
  * Get height
18
- *
19
18
  * @returns {number} - block height
20
19
  */
21
20
  getHeight() {
@@ -24,7 +23,6 @@ class Metadata {
24
23
 
25
24
  /**
26
25
  * Get core chain locked height
27
- *
28
26
  * @returns {number} - core chain locked height
29
27
  */
30
28
  getCoreChainLockedHeight() {
@@ -33,7 +31,7 @@ class Metadata {
33
31
 
34
32
  /**
35
33
  * Get block time
36
- * @return {number}
34
+ * @returns {number}
37
35
  */
38
36
  getTimeMs() {
39
37
  return this.timeMs;
@@ -41,7 +39,7 @@ class Metadata {
41
39
 
42
40
  /**
43
41
  * Get protocol version
44
- * @return {number}
42
+ * @returns {number}
45
43
  */
46
44
  getProtocolVersion() {
47
45
  return this.protocolVersion;
@@ -44,7 +44,6 @@ class Proof {
44
44
 
45
45
  /**
46
46
  * @param {object} proofProto
47
- *
48
47
  * @returns {Proof}
49
48
  */
50
49
  static createFromProto(proofProto) {
@@ -24,7 +24,7 @@ function waitForStateTransitionResultFactory(grpcTransport) {
24
24
  // eslint-disable-next-line no-param-reassign
25
25
  options = {
26
26
  // Set default timeout
27
- timeout: 120000,
27
+ timeout: 80000,
28
28
  prove: false,
29
29
  retry: 0,
30
30
  throwDeadlineExceeded: true,
@@ -12,26 +12,20 @@ use(sinonChai);
12
12
  use(chaiAsPromised);
13
13
  use(dirtyChai);
14
14
 
15
- before(async () => {
16
- await loadDpp();
17
- });
15
+ exports.mochaHooks = {
16
+ beforeAll: loadDpp,
18
17
 
19
- beforeEach(function beforeEach() {
20
- if (!this.sinon) {
21
- this.sinon = sinon.createSandbox();
22
- } else {
23
- this.sinon.restore();
24
- }
25
- });
26
-
27
- afterEach(function afterEach() {
28
- this.sinon.restore();
29
- });
18
+ beforeEach() {
19
+ if (!this.sinon) {
20
+ this.sinon = sinon.createSandbox();
21
+ } else {
22
+ this.sinon.restore();
23
+ }
24
+ },
30
25
 
31
- before(function before() {
32
- if (!this.sinon) {
33
- this.sinon = sinon.createSandbox();
34
- }
35
- });
26
+ afterEach() {
27
+ this.sinon.restore();
28
+ },
29
+ };
36
30
 
37
31
  global.expect = expect;
@@ -1,6 +1,5 @@
1
1
  /**
2
2
  * Get MN List Diff fixture
3
- *
4
3
  * @returns {object} - MN List Diff object
5
4
  */
6
5
  function getMNListDiffsFixture() {
@@ -0,0 +1,37 @@
1
+ require('../../../polyfills/fetch-polyfill');
2
+ require('setimmediate');
3
+
4
+ const { expect, use } = require('chai');
5
+ const sinon = require('sinon');
6
+ const sinonChai = require('sinon-chai');
7
+ const dirtyChai = require('dirty-chai');
8
+ const chaiAsPromised = require('chai-as-promised');
9
+ const { default: loadDpp } = require('@dashevo/wasm-dpp');
10
+
11
+ use(sinonChai);
12
+ use(chaiAsPromised);
13
+ use(dirtyChai);
14
+
15
+ before(async () => {
16
+ await loadDpp();
17
+ });
18
+
19
+ beforeEach(function beforeEach() {
20
+ if (!this.sinon) {
21
+ this.sinon = sinon.createSandbox();
22
+ } else {
23
+ this.sinon.restore();
24
+ }
25
+ });
26
+
27
+ afterEach(function afterEach() {
28
+ this.sinon.restore();
29
+ });
30
+
31
+ before(function before() {
32
+ if (!this.sinon) {
33
+ this.sinon = sinon.createSandbox();
34
+ }
35
+ });
36
+
37
+ global.expect = expect;
@@ -1,5 +1,5 @@
1
1
  // This file is used for compiling tests with webpack into one file for using with karma
2
- require('../bootstrap');
2
+ require('./bootstrap');
3
3
 
4
4
  // noinspection JSUnresolvedFunction
5
5
  const testsContext = require.context('../../../test', true, /^(?!.*functional).*\.js$/);
@@ -34,12 +34,10 @@ class GrpcTransport {
34
34
 
35
35
  /**
36
36
  * Make request to DAPI node
37
- *
38
37
  * @param {Function} ClientClass
39
38
  * @param {string} method
40
39
  * @param {object} requestMessage
41
40
  * @param {DAPIClientOptions} [options]
42
- *
43
41
  * @returns {Promise<object>}
44
42
  */
45
43
  async request(ClientClass, method, requestMessage, options = { }) {
@@ -100,6 +98,8 @@ class GrpcTransport {
100
98
  throw responseError;
101
99
  }
102
100
 
101
+ // TODO: Shouldn't we call address.markAsBanned() here?
102
+
103
103
  if (options.retries === 0) {
104
104
  throw new MaxRetriesReachedError(responseError);
105
105
  }
@@ -123,7 +123,6 @@ class GrpcTransport {
123
123
 
124
124
  /**
125
125
  * Get last used address
126
- *
127
126
  * @returns {DAPIAddress|null}
128
127
  */
129
128
  getLastUsedAddress() {
@@ -132,8 +131,7 @@ class GrpcTransport {
132
131
 
133
132
  /**
134
133
  *
135
- * Get gRPC url string
136
- *
134
+ *Get gRPC url string
137
135
  * @private
138
136
  * @param {DAPIAddress} address
139
137
  * @returns {string}
@@ -38,11 +38,9 @@ class JsonRpcTransport {
38
38
 
39
39
  /**
40
40
  * Make request to DAPI node
41
- *
42
41
  * @param {string} method
43
42
  * @param {object} [params]
44
43
  * @param {DAPIClientOptions} [options]
45
- *
46
44
  * @returns {Promise<object>}
47
45
  */
48
46
  async request(method, params = {}, options = {}) {
@@ -122,7 +120,6 @@ class JsonRpcTransport {
122
120
 
123
121
  /**
124
122
  * Get last used address
125
- *
126
123
  * @returns {DAPIAddress|null}
127
124
  */
128
125
  getLastUsedAddress() {
@@ -30,7 +30,6 @@ class JsonRpcError extends DAPIClientError {
30
30
 
31
31
  /**
32
32
  * Get error message
33
- *
34
33
  * @returns {string}
35
34
  */
36
35
  getMessage() {
@@ -39,7 +38,6 @@ class JsonRpcError extends DAPIClientError {
39
38
 
40
39
  /**
41
40
  * Get error data
42
- *
43
41
  * @returns {object}
44
42
  */
45
43
  getData() {
@@ -48,7 +46,6 @@ class JsonRpcError extends DAPIClientError {
48
46
 
49
47
  /**
50
48
  * Get original error code
51
- *
52
49
  * @returns {number}
53
50
  */
54
51
  getCode() {
@@ -36,7 +36,6 @@ const EVENTS = {
36
36
  class ReconnectableStream extends EventEmitter {
37
37
  /**
38
38
  * Helper that wraps stream creation function and performs auto connection
39
- *
40
39
  * @param {Function} createStreamFunction - function returning grpc-js/grpc-web stream
41
40
  * @param {ReconnectableStreamOptions} options
42
41
  * @returns {function(...[*]): Promise<ReconnectableStream>}
@@ -61,7 +60,6 @@ class ReconnectableStream extends EventEmitter {
61
60
  /**
62
61
  * Auto-reconnect interval in millisecond
63
62
  * It is needed to automatically reconnect to another DAPI node
64
- *
65
63
  * @type {number}
66
64
  */
67
65
  this.autoReconnectInterval = opts.autoReconnectInterval;
@@ -155,7 +153,6 @@ class ReconnectableStream extends EventEmitter {
155
153
  * Function that adds EventEmitter style listeners
156
154
  * to the stream and also rewires stream cancel function
157
155
  * in order to automatically unsubscribe from events
158
- *
159
156
  * @private
160
157
  */
161
158
  addListeners() {
@@ -178,7 +175,6 @@ class ReconnectableStream extends EventEmitter {
178
175
 
179
176
  /**
180
177
  * stream.on('data') handler
181
- *
182
178
  * @param data
183
179
  */
184
180
  dataHandler(data) {
@@ -187,7 +183,6 @@ class ReconnectableStream extends EventEmitter {
187
183
 
188
184
  /**
189
185
  * stream.on('end') handler
190
- *
191
186
  * @private
192
187
  */
193
188
  endHandler() {
@@ -198,7 +193,6 @@ class ReconnectableStream extends EventEmitter {
198
193
 
199
194
  /**
200
195
  * stream.on('error') handler
201
- *
202
196
  * @private
203
197
  * @param e
204
198
  */
@@ -215,7 +209,6 @@ class ReconnectableStream extends EventEmitter {
215
209
 
216
210
  /**
217
211
  * Manages retry logic
218
- *
219
212
  * @param e
220
213
  */
221
214
  retryOnError(e) {
@@ -256,7 +249,6 @@ class ReconnectableStream extends EventEmitter {
256
249
 
257
250
  /**
258
251
  * Stops auto reconnect timeout
259
- *
260
252
  * @private
261
253
  */
262
254
  stopAutoReconnect() {
@@ -270,7 +262,6 @@ class ReconnectableStream extends EventEmitter {
270
262
  * Cancels stream.
271
263
  * Returns `stream.cancel()` to handle it from parent if needed.
272
264
  * (grpc-js cancel() is asynchronous and grpc-web is synchronous)
273
- *
274
265
  * @returns {*}
275
266
  */
276
267
  cancel() {
package/lib/utils/wait.js CHANGED
@@ -1,12 +1,10 @@
1
1
  /**
2
2
  * Asynchronously wait for a specified number of milliseconds.
3
- *
4
3
  * @param {number} ms - Number of milliseconds to wait.
5
- *
6
4
  * @returns {Promise<void>} The promise to await on.
7
5
  */
8
6
  async function wait(ms) {
9
- return new Promise((resolve) => setTimeout(resolve, ms));
7
+ return new Promise((resolve) => { setTimeout(resolve, ms); });
10
8
  }
11
9
 
12
10
  module.exports = wait;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dashevo/dapi-client",
3
- "version": "1.0.0-pr.1545.8",
3
+ "version": "1.0.0-pr.1621.0",
4
4
  "description": "Client library used to access Dash DAPI endpoints",
5
5
  "main": "lib/index.js",
6
6
  "contributors": [
@@ -26,11 +26,11 @@
26
26
  }
27
27
  ],
28
28
  "dependencies": {
29
- "@dashevo/dapi-grpc": "1.0.0-pr.1545.8",
30
- "@dashevo/dash-spv": "1.0.0-pr.1545.8",
29
+ "@dashevo/dapi-grpc": "1.0.0-pr.1621.0",
30
+ "@dashevo/dash-spv": "1.0.0-pr.1621.0",
31
31
  "@dashevo/dashcore-lib": "~0.21.0",
32
- "@dashevo/grpc-common": "1.0.0-pr.1545.8",
33
- "@dashevo/wasm-dpp": "1.0.0-pr.1545.8",
32
+ "@dashevo/grpc-common": "1.0.0-pr.1621.0",
33
+ "@dashevo/wasm-dpp": "1.0.0-pr.1621.0",
34
34
  "bs58": "^4.0.1",
35
35
  "cbor": "^8.0.0",
36
36
  "google-protobuf": "^3.12.2",
@@ -41,40 +41,40 @@
41
41
  "winston": "^3.2.1"
42
42
  },
43
43
  "devDependencies": {
44
- "@babel/core": "^7.15.5",
44
+ "@babel/core": "^7.23.3",
45
45
  "assert-browserify": "^2.0.0",
46
- "babel-loader": "^8.2.2",
46
+ "babel-loader": "^9.1.3",
47
47
  "browserify-zlib": "^0.2.0",
48
48
  "buffer": "^6.0.3",
49
- "chai": "^4.3.9",
49
+ "chai": "^4.3.10",
50
50
  "chai-as-promised": "^7.1.1",
51
51
  "comment-parser": "^0.7.6",
52
- "core-js": "^3.17.2",
52
+ "core-js": "^3.33.1",
53
53
  "crypto-browserify": "^3.12.0",
54
54
  "dirty-chai": "^2.0.1",
55
- "eslint": "^7.32.0",
56
- "eslint-config-airbnb-base": "^14.2.1",
57
- "eslint-plugin-import": "^2.24.2",
58
- "eslint-plugin-jsdoc": "^27.0.0",
55
+ "eslint": "^8.53.0",
56
+ "eslint-config-airbnb-base": "^15.0.0",
57
+ "eslint-plugin-import": "^2.29.0",
58
+ "eslint-plugin-jsdoc": "^46.9.0",
59
59
  "events": "^3.3.0",
60
60
  "karma": "^6.4.1",
61
61
  "karma-chai": "^0.1.0",
62
62
  "karma-chrome-launcher": "^3.1.0",
63
- "karma-firefox-launcher": "^2.1.1",
63
+ "karma-firefox-launcher": "^2.1.2",
64
64
  "karma-mocha": "^2.0.1",
65
65
  "karma-mocha-reporter": "^2.2.5",
66
66
  "karma-webpack": "^5.0.0",
67
- "mocha": "^9.1.2",
67
+ "mocha": "^10.2.0",
68
68
  "nyc": "^15.1.0",
69
69
  "os-browserify": "^0.3.0",
70
70
  "path-browserify": "^1.0.1",
71
71
  "process": "^0.11.10",
72
72
  "setimmediate": "^1.0.5",
73
- "sinon": "^11.1.2",
73
+ "sinon": "^17.0.1",
74
74
  "sinon-chai": "^3.7.0",
75
75
  "stream-browserify": "^3.0.0",
76
76
  "string_decoder": "^1.3.0",
77
- "url": "^0.11.0",
77
+ "url": "^0.11.3",
78
78
  "util": "^0.12.4",
79
79
  "webpack": "^5.76.1",
80
80
  "webpack-cli": "^4.9.1"