@dashevo/dapi-client 0.25.22 → 1.0.0-beta.1

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 (40) hide show
  1. package/docs/_sidebar.md +3 -1
  2. package/docs/usage/application/core/getBestBlockHeight.md +10 -0
  3. package/docs/usage/application/core/subscribeToBlockHeadersWithChainLocks.md +39 -0
  4. package/docs/usage/application/core/subscribeToMasternodeList.md +24 -0
  5. package/docs/usage/{utils → application/core}/subscribeToTransactionsWithProofs.md +13 -10
  6. package/lib/BlockHeadersProvider/createBlockHeadersProviderFromOptions.js +4 -2
  7. package/lib/DAPIClient.js +19 -1
  8. package/lib/SimplifiedMasternodeListProvider/SimplifiedMasternodeListProvider.js +174 -65
  9. package/lib/SimplifiedMasternodeListProvider/createMasternodeListStreamFactory.js +49 -0
  10. package/lib/dapiAddressProvider/createDAPIAddressProviderFromOptions.js +4 -9
  11. package/lib/methods/core/CoreMethodsFacade.js +10 -6
  12. package/lib/methods/core/getBestBlockHeightFactory.js +34 -0
  13. package/lib/methods/core/getBlockchainStatusFactory.js +59 -0
  14. package/lib/methods/core/getMasternodeStatusFactory.js +45 -0
  15. package/lib/methods/core/subscribeToMasternodeListFactory.js +46 -0
  16. package/lib/methods/core/subscribeToTransactionsWithProofsFactory.js +1 -1
  17. package/lib/methods/platform/PlatformMethodsFacade.js +10 -2
  18. package/lib/methods/platform/getIdentitiesContractKeys/GetIdentitiesContractKeysResponse.js +65 -0
  19. package/lib/methods/platform/getIdentitiesContractKeys/getIdentitiesContractKeysFactory.js +93 -0
  20. package/lib/methods/platform/getIdentityByPublicKeyHash/GetIdentityByPublicKeyHashResponse.js +40 -0
  21. package/lib/methods/platform/getIdentityByPublicKeyHash/getIdentityByPublicKeyHashFactory.js +64 -0
  22. package/lib/methods/platform/getIdentityContractNonce/GetIdentityContractNonceResponse.js +49 -0
  23. package/lib/methods/platform/getIdentityContractNonce/getIdentityContractNonceFactory.js +81 -0
  24. package/lib/methods/platform/getIdentityKeys/GetIdentityKeysResponse.js +52 -0
  25. package/lib/methods/platform/getIdentityKeys/getIdentityKeysFactory.js +78 -0
  26. package/lib/methods/platform/getIdentityNonce/GetIdentityNonceResponse.js +49 -0
  27. package/lib/methods/platform/getIdentityNonce/getIdentityNonceFactory.js +74 -0
  28. package/lib/methods/platform/getProtocolVersionUpgradeVoteStatus/GetProtocolVersionUpgradeVoteStatusResponse.js +1 -1
  29. package/lib/methods/platform/getProtocolVersionUpgradeVoteStatus/getProtocolVersionUpgradeVoteStatusFactory.js +1 -1
  30. package/lib/transport/GrpcTransport/GrpcTransport.js +7 -1
  31. package/lib/transport/GrpcTransport/createGrpcTransportError.js +1 -1
  32. package/lib/transport/ReconnectableStream.js +48 -6
  33. package/package.json +8 -8
  34. package/docs/usage/application/core/generateToAddress.md +0 -13
  35. package/docs/usage/application/core/getMnListDiff.md +0 -12
  36. package/lib/methods/core/generateToAddressFactory.js +0 -25
  37. package/lib/methods/core/getMnListDiffFactory.js +0 -21
  38. package/lib/methods/core/getStatusFactory.js +0 -68
  39. package/lib/methods/platform/getIdentitiesByPublicKeyHashes/GetIdentitiesByPublicKeyHashesResponse.js +0 -46
  40. package/lib/methods/platform/getIdentitiesByPublicKeyHashes/getIdentitiesByPublicKeyHashesFactory.js +0 -65
@@ -0,0 +1,78 @@
1
+ const {
2
+ v0: {
3
+ PlatformPromiseClient,
4
+ GetIdentityKeysRequest,
5
+ KeyRequestType,
6
+ SpecificKeys,
7
+ },
8
+ } = require('@dashevo/dapi-grpc');
9
+ const { UInt32Value } = require('google-protobuf/google/protobuf/wrappers_pb');
10
+
11
+ const GetIdentityKeysResponse = require('./GetIdentityKeysResponse');
12
+ const InvalidResponseError = require('../response/errors/InvalidResponseError');
13
+
14
+ /**
15
+ * @param {GrpcTransport} grpcTransport
16
+ * @returns {getIdentityKeys}
17
+ */
18
+ function getIdentityKeysFactory(grpcTransport) {
19
+ /**
20
+ * Fetch the version upgrade votes status
21
+ * @typedef {getIdentityKeys}
22
+ * @param {Buffer} identityId
23
+ * @param {number[]} keyIds
24
+ * @param {number} limit
25
+ * @param {DAPIClientOptions & {prove: boolean}} [options]
26
+ * @returns {Promise<GetIdentityKeysResponse>}
27
+ */
28
+ async function getIdentityKeys(identityId, keyIds, limit = 100, options = {}) {
29
+ const { GetIdentityKeysRequestV0 } = GetIdentityKeysRequest;
30
+ const getIdentityKeysRequest = new GetIdentityKeysRequest();
31
+
32
+ if (Buffer.isBuffer(identityId)) {
33
+ // eslint-disable-next-line no-param-reassign
34
+ identityId = Buffer.from(identityId);
35
+ }
36
+
37
+ getIdentityKeysRequest.setV0(
38
+ new GetIdentityKeysRequestV0()
39
+ .setIdentityId(identityId)
40
+ .setRequestType(new KeyRequestType()
41
+ .setSpecificKeys(new SpecificKeys().setKeyIdsList(keyIds)))
42
+ .setLimit(new UInt32Value([limit]))
43
+ .setProve(!!options.prove),
44
+ );
45
+
46
+ let lastError;
47
+
48
+ // TODO: simple retry before the dapi versioning is properly implemented
49
+ for (let i = 0; i < 3; i += 1) {
50
+ try {
51
+ // eslint-disable-next-line no-await-in-loop
52
+ const getIdentityKeysResponse = await grpcTransport.request(
53
+ PlatformPromiseClient,
54
+ 'getIdentityKeys',
55
+ getIdentityKeysRequest,
56
+ options,
57
+ );
58
+
59
+ return GetIdentityKeysResponse
60
+ .createFromProto(getIdentityKeysResponse);
61
+ } catch (e) {
62
+ if (e instanceof InvalidResponseError) {
63
+ lastError = e;
64
+ } else {
65
+ throw e;
66
+ }
67
+ }
68
+ }
69
+
70
+ // If we made it past the cycle it means that the retry didn't work,
71
+ // and we're throwing the last error encountered
72
+ throw lastError;
73
+ }
74
+
75
+ return getIdentityKeys;
76
+ }
77
+
78
+ module.exports = getIdentityKeysFactory;
@@ -0,0 +1,49 @@
1
+ const AbstractResponse = require('../response/AbstractResponse');
2
+ const InvalidResponseError = require('../response/errors/InvalidResponseError');
3
+
4
+ const IDENTITY_NONCE_VALUE_FILTER = 0xFFFFFFFFFF;
5
+
6
+ class GetIdentityNonceResponse extends AbstractResponse {
7
+ /**
8
+ * @param {number} identityNonce
9
+ * @param {Metadata} metadata
10
+ * @param {Proof} [proof]
11
+ */
12
+ constructor(identityNonce, metadata, proof = undefined) {
13
+ super(metadata, proof);
14
+
15
+ this.identityNonce = identityNonce;
16
+ }
17
+
18
+ /**
19
+ * @returns {number}
20
+ */
21
+ getIdentityNonce() {
22
+ return this.identityNonce;
23
+ }
24
+
25
+ /**
26
+ * @param proto
27
+ * @returns {GetIdentityNonceResponse}
28
+ */
29
+ static createFromProto(proto) {
30
+ // eslint-disable-next-line
31
+ const identityNonce = proto.getV0()
32
+ .getIdentityNonce() & IDENTITY_NONCE_VALUE_FILTER;
33
+ const { metadata, proof } = AbstractResponse.createMetadataAndProofFromProto(
34
+ proto,
35
+ );
36
+
37
+ if ((typeof identityNonce === 'undefined' || identityNonce === null) && !proof) {
38
+ throw new InvalidResponseError('Nonce data is not defined');
39
+ }
40
+
41
+ return new GetIdentityNonceResponse(
42
+ identityNonce,
43
+ metadata,
44
+ proof,
45
+ );
46
+ }
47
+ }
48
+
49
+ module.exports = GetIdentityNonceResponse;
@@ -0,0 +1,74 @@
1
+ const {
2
+ v0: {
3
+ PlatformPromiseClient,
4
+ GetIdentityNonceRequest,
5
+ },
6
+ } = require('@dashevo/dapi-grpc');
7
+
8
+ const GetIdentityNonceResponse = require('./GetIdentityNonceResponse');
9
+ const InvalidResponseError = require('../response/errors/InvalidResponseError');
10
+
11
+ /**
12
+ * @param {GrpcTransport} grpcTransport
13
+ * @returns {getIdentityNonce}
14
+ */
15
+ function getIdentityNonceFactory(grpcTransport) {
16
+ /**
17
+ * Fetch the version upgrade votes status
18
+ * @typedef {getIdentityNonce}
19
+ * @param {Buffer} identityId
20
+ * @param {DAPIClientOptions & {prove: boolean}} [options]
21
+ * @returns {Promise<GetIdentityNonceResponse>}
22
+ */
23
+ async function getIdentityNonce(identityId, options = {}) {
24
+ const {
25
+ GetIdentityNonceRequestV0,
26
+ } = GetIdentityNonceRequest;
27
+
28
+ // eslint-disable-next-line max-len
29
+ const getIdentityNonceRequest = new GetIdentityNonceRequest();
30
+
31
+ if (Buffer.isBuffer(identityId)) {
32
+ // eslint-disable-next-line no-param-reassign
33
+ identityId = Buffer.from(identityId);
34
+ }
35
+
36
+ getIdentityNonceRequest.setV0(
37
+ new GetIdentityNonceRequestV0()
38
+ .setIdentityId(identityId)
39
+ .setProve(!!options.prove),
40
+ );
41
+
42
+ let lastError;
43
+
44
+ // TODO: simple retry before the dapi versioning is properly implemented
45
+ for (let i = 0; i < 3; i += 1) {
46
+ try {
47
+ // eslint-disable-next-line no-await-in-loop
48
+ const getIdentityNonceResponse = await grpcTransport.request(
49
+ PlatformPromiseClient,
50
+ 'getIdentityNonce',
51
+ getIdentityNonceRequest,
52
+ options,
53
+ );
54
+
55
+ return GetIdentityNonceResponse
56
+ .createFromProto(getIdentityNonceResponse);
57
+ } catch (e) {
58
+ if (e instanceof InvalidResponseError) {
59
+ lastError = e;
60
+ } else {
61
+ throw e;
62
+ }
63
+ }
64
+ }
65
+
66
+ // If we made it past the cycle it means that the retry didn't work,
67
+ // and we're throwing the last error encountered
68
+ throw lastError;
69
+ }
70
+
71
+ return getIdentityNonce;
72
+ }
73
+
74
+ module.exports = getIdentityNonceFactory;
@@ -32,7 +32,7 @@ class GetProtocolVersionUpgradeVoteStatusResponse extends AbstractResponse {
32
32
  );
33
33
 
34
34
  if (!versions && !proof) {
35
- throw new InvalidResponseError('Version upgrade vote status is not defined');
35
+ throw new InvalidResponseError('Version upgrade votes status is not defined');
36
36
  }
37
37
 
38
38
  let versionSignals = [];
@@ -14,7 +14,7 @@ const InvalidResponseError = require('../response/errors/InvalidResponseError');
14
14
  */
15
15
  function getProtocolVersionUpgradeVoteStatusFactory(grpcTransport) {
16
16
  /**
17
- * Fetch the version upgrade vote status
17
+ * Fetch the version upgrade votes status
18
18
  * @typedef {getProtocolVersionUpgradeVoteStatus}
19
19
  * @param {string} startProTxHash
20
20
  * @param {number} count
@@ -1,3 +1,4 @@
1
+ const GrpcErrorCodes = require('@dashevo/grpc-common/lib/server/error/GrpcErrorCodes');
1
2
  const logger = require('../../logger');
2
3
 
3
4
  const MaxRetriesReachedError = require('../errors/response/MaxRetriesReachedError');
@@ -81,7 +82,12 @@ class GrpcTransport {
81
82
  } catch (error) {
82
83
  this.lastUsedAddress = address;
83
84
 
84
- this.logger.error(`GRPC Request ${method} to ${address.toString()} failed with error: ${error.message}`);
85
+ // Show NOT_FOUND errors only in debug mode
86
+ if (error.code !== GrpcErrorCodes.NOT_FOUND) {
87
+ this.logger.error(`GRPC Request ${method} to ${address.toString()} failed with error: ${error.message}`);
88
+ } else {
89
+ this.logger.debug(`GRPC Request ${method} to ${address.toString()} failed with error: ${error.message}`);
90
+ }
85
91
 
86
92
  // for unknown errors
87
93
  if (error.code === undefined) {
@@ -118,7 +118,7 @@ async function createGrpcTransportError(grpcError, dapiAddress) {
118
118
  }
119
119
 
120
120
  // DPP consensus errors
121
- if (code >= 1000 && code < 5000) {
121
+ if (code >= 10000 && code < 50000) {
122
122
  const consensusError = deserializeConsensusError(data.serializedError || []);
123
123
 
124
124
  delete data.serializedError;
@@ -12,8 +12,7 @@ const wait = require('../utils/wait');
12
12
  * delay in MS to perform retry after an error
13
13
  */
14
14
  const defaultOptions = {
15
- // TODO: manage timeout according to the Nginx setting of the node
16
- autoReconnectInterval: 50000,
15
+ autoReconnectInterval: 600000,
17
16
  maxRetriesOnError: 10,
18
17
  retryOnErrorDelay: 1000,
19
18
  };
@@ -57,6 +56,8 @@ class ReconnectableStream extends EventEmitter {
57
56
 
58
57
  const opts = { ...defaultOptions, ...options };
59
58
 
59
+ this.logger = opts.logger || { debug: () => {} };
60
+
60
61
  /**
61
62
  * Auto-reconnect interval in millisecond
62
63
  * It is needed to automatically reconnect to another DAPI node
@@ -109,6 +110,8 @@ class ReconnectableStream extends EventEmitter {
109
110
  }
110
111
 
111
112
  async connect(...args) {
113
+ // eslint-disable-next-line no-unused-expressions
114
+ this.logger.debug('[ReconnectableStream] Connecting to stream');
112
115
  // Memorize current stream args (which can be altered by beforeReconnect logic)
113
116
  this.args = args;
114
117
 
@@ -127,6 +130,8 @@ class ReconnectableStream extends EventEmitter {
127
130
  if (this.reconnectTimeout) {
128
131
  throw new Error('Auto reconnect timeout is already running.');
129
132
  }
133
+ // eslint-disable-next-line no-unused-expressions
134
+ this.logger.debug('[ReconnectableStream] Setting reconnect timeout');
130
135
  this.reconnectTimeout = this.setTimeout(
131
136
  this.reconnect,
132
137
  this.autoReconnectInterval,
@@ -134,6 +139,8 @@ class ReconnectableStream extends EventEmitter {
134
139
  }
135
140
 
136
141
  reconnect() {
142
+ // eslint-disable-next-line no-unused-expressions
143
+ this.logger.debug('[ReconnectableStream] Try reconnecting to stream');
137
144
  if (this.reconnectTimeout) {
138
145
  this.reconnectTimeout = null;
139
146
  this.stream.cancel();
@@ -146,6 +153,8 @@ class ReconnectableStream extends EventEmitter {
146
153
  this.emit(EVENTS.BEFORE_RECONNECT, updateArgs);
147
154
  this.connect(...newArgs)
148
155
  .catch((connectError) => this.emit(EVENTS.ERROR, connectError));
156
+ // eslint-disable-next-line no-unused-expressions
157
+ this.logger.debug('[ReconnectableStream] Reconnected to stream');
149
158
  }
150
159
  }
151
160
 
@@ -186,9 +195,13 @@ class ReconnectableStream extends EventEmitter {
186
195
  * @private
187
196
  */
188
197
  endHandler() {
189
- this.stopAutoReconnect();
190
- this.stream = null;
191
- this.emit(EVENTS.END);
198
+ // eslint-disable-next-line no-unused-expressions
199
+ this.logger.debug('[ReconnectableStream] End handler, stream exists:', !!this.stream);
200
+ if (this.stream) {
201
+ this.stopAutoReconnect();
202
+ this.stream = null;
203
+ this.emit(EVENTS.END);
204
+ }
192
205
  }
193
206
 
194
207
  /**
@@ -197,9 +210,21 @@ class ReconnectableStream extends EventEmitter {
197
210
  * @param e
198
211
  */
199
212
  errorHandler(e) {
213
+ // eslint-disable-next-line no-unused-expressions
214
+ this.logger.debug(`[ReconnectableStream] Error in stream, code ${e.code}, e:`, e);
215
+
200
216
  // In case of cancellation nothing has to happen.
217
+ // Do not retry UNKNOWN error code - HACH for grpc-web that ignores following error that happens
218
+ // in a while after stream cancellation
219
+ // Error message:
220
+ // "Response closed without grpc-status (Headers only) {
221
+ // [Error: Response closed without grpc-status (Headers only)]"
201
222
  // TODO: do we need to propagate GrpcErrorCodes.CANCELLED further?
202
- if (e.code === GrpcErrorCodes.CANCELLED) {
223
+ if (e.code === GrpcErrorCodes.CANCELLED
224
+ || (e.code === GrpcErrorCodes.UNKNOWN && this.stream === null)
225
+ ) {
226
+ // e.code
227
+ this.logger.debug(`[ReconnectableStream] Returning from error handler without restart, error code ${e.code}, e:`);
203
228
  return;
204
229
  }
205
230
 
@@ -212,6 +237,8 @@ class ReconnectableStream extends EventEmitter {
212
237
  * @param e
213
238
  */
214
239
  retryOnError(e) {
240
+ // eslint-disable-next-line no-unused-expressions
241
+ this.logger.debug('[ReconnectableStream] Error handler', e);
215
242
  // Stop reconnect timeout if there is one
216
243
  this.stopAutoReconnect();
217
244
 
@@ -252,9 +279,13 @@ class ReconnectableStream extends EventEmitter {
252
279
  * @private
253
280
  */
254
281
  stopAutoReconnect() {
282
+ // eslint-disable-next-line no-unused-expressions
283
+ this.logger.debug('[ReconnectableStream] Stopping auto reconnect');
255
284
  if (this.reconnectTimeout) {
256
285
  this.clearTimeout(this.reconnectTimeout);
257
286
  this.reconnectTimeout = null;
287
+ // eslint-disable-next-line no-unused-expressions
288
+ this.logger.debug('[ReconnectableStream] Stoped auto reconnect');
258
289
  }
259
290
  }
260
291
 
@@ -265,7 +296,18 @@ class ReconnectableStream extends EventEmitter {
265
296
  * @returns {*}
266
297
  */
267
298
  cancel() {
299
+ // eslint-disable-next-line no-unused-expressions
300
+ this.logger.debug('[ReconnectableStream] Canceling streams');
268
301
  this.stopAutoReconnect();
302
+ // Hack for browsers to properly unsubscribe from ERROR event.
303
+ // (It will continue propagating despite of calling cancel)
304
+ // Ref to unsubscribe from ERROR event
305
+ const { stream } = this;
306
+ setTimeout(() => {
307
+ stream.removeListener(EVENTS.ERROR, this.errorHandler);
308
+ // endHandler
309
+ this.stream = null;
310
+ }, 1000);
269
311
  return this.stream.cancel();
270
312
  }
271
313
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dashevo/dapi-client",
3
- "version": "0.25.22",
3
+ "version": "1.0.0-beta.1",
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": "0.25.22",
30
- "@dashevo/dash-spv": "0.25.22",
31
- "@dashevo/dashcore-lib": "~0.21.0",
32
- "@dashevo/grpc-common": "0.25.22",
33
- "@dashevo/wasm-dpp": "0.25.22",
29
+ "@dashevo/dapi-grpc": "1.0.0-beta.1",
30
+ "@dashevo/dash-spv": "1.0.0-beta.1",
31
+ "@dashevo/dashcore-lib": "~0.21.2",
32
+ "@dashevo/grpc-common": "1.0.0-beta.1",
33
+ "@dashevo/wasm-dpp": "1.0.0-beta.1",
34
34
  "bs58": "^4.0.1",
35
35
  "cbor": "^8.0.0",
36
36
  "google-protobuf": "^3.12.2",
@@ -57,7 +57,7 @@
57
57
  "eslint-plugin-import": "^2.29.0",
58
58
  "eslint-plugin-jsdoc": "^46.9.0",
59
59
  "events": "^3.3.0",
60
- "karma": "^6.4.1",
60
+ "karma": "^6.4.3",
61
61
  "karma-chai": "^0.1.0",
62
62
  "karma-chrome-launcher": "^3.1.0",
63
63
  "karma-firefox-launcher": "^2.1.2",
@@ -92,7 +92,7 @@
92
92
  "test:integration": "mocha './test/integration/**/*.spec.js'",
93
93
  "test:node": "NODE_ENV=test mocha",
94
94
  "test:browsers": "karma start ./karma.conf.js --single-run",
95
- "test:coverage": "NODE_ENV=test nyc --check-coverage --stmts=98 --branch=98 --funcs=98 --lines=95 yarn run mocha 'test/unit/**/*.spec.js' 'test/integration/**/*.spec.js'",
95
+ "test:coverage": "NODE_ENV=test nyc --check-coverage --stmts=98 --branch=98 --funcs=98 --lines=90 yarn run mocha 'test/unit/**/*.spec.js' 'test/integration/**/*.spec.js'",
96
96
  "prepublishOnly": "yarn run build:web"
97
97
  },
98
98
  "ultra": {
@@ -1,13 +0,0 @@
1
- **Usage**: `await client.core.generateToAddress(blockMumber, address, options)`
2
- **Description**: Allow to broadcast a valid **signed** transaction to the network.
3
- **Notes**: Will only works on regtest.
4
-
5
- Parameters:
6
-
7
- | parameters | type | required | Description |
8
- |---------------------------|---------------------|----------------| ------------------------------------------------------------------------------------------------ |
9
- | **blocksNumber** | Number | yes | A number of block to see generated on the regtest network |
10
- | **address** | String | yes | The address that will receive the newly generated Dash |
11
- | **options** | DAPIClientOptions | no | |
12
-
13
- Returns : {Promise<string[]>} - a set of generated blockhashes.
@@ -1,12 +0,0 @@
1
- **Usage**: `await client.core.getMnListDiff(baseBlockHash, blockHash, options)`
2
- **Description**: Allow to fetch a specific block hash from its height
3
-
4
- Parameters:
5
-
6
- | parameters | type | required | Description |
7
- |---------------------------|---------------------|----------------| ------------------------------------------------------------------------------------------------ |
8
- | **baseBlockHash** | String | yes | hash or height of start block |
9
- | **blockHash** | String | yes | hash or height of end block |
10
- | **options** | DAPIClientOptions | no | |
11
-
12
- Returns : {Promise<object>} - The Masternode List Diff of the specified period
@@ -1,25 +0,0 @@
1
- /**
2
- * @param {JsonRpcTransport} jsonRpcTransport
3
- * @returns {generateToAddress}
4
- */
5
- function generateToAddressFactory(jsonRpcTransport) {
6
- /**
7
- * ONLY FOR TESTING PURPOSES WITH REGTEST. WILL NOT WORK ON TESTNET/LIVENET.
8
- * @typedef {generateToAddress}
9
- * @param {number} blocksNumber - Number of blocks to generate
10
- * @param {string} address - The address that will receive the newly generated Dash
11
- * @param {DAPIClientOptions} [options]
12
- * @returns {Promise<string[]>} - block hashes
13
- */
14
- function generateToAddress(blocksNumber, address, options = {}) {
15
- return jsonRpcTransport.request(
16
- 'generateToAddress',
17
- { blocksNumber, address },
18
- options,
19
- );
20
- }
21
-
22
- return generateToAddress;
23
- }
24
-
25
- module.exports = generateToAddressFactory;
@@ -1,21 +0,0 @@
1
- /**
2
- * @param {JsonRpcTransport} jsonRpcTransport
3
- * @returns {getMnListDiff}
4
- */
5
- function getMnListDiffFactory(jsonRpcTransport) {
6
- /**
7
- * Get deterministic masternodelist diff
8
- * @typedef {getMnListDiff}
9
- * @param {string} baseBlockHash - hash or height of start block
10
- * @param {string} blockHash - hash or height of end block
11
- * @param {DAPIClientOptions} [options]
12
- * @returns {Promise<object>}
13
- */
14
- function getMnListDiff(baseBlockHash, blockHash, options = {}) {
15
- return jsonRpcTransport.request('getMnListDiff', { baseBlockHash, blockHash }, options);
16
- }
17
-
18
- return getMnListDiff;
19
- }
20
-
21
- module.exports = getMnListDiffFactory;
@@ -1,68 +0,0 @@
1
- const {
2
- v0: {
3
- GetStatusRequest,
4
- GetStatusResponse,
5
- CorePromiseClient,
6
- },
7
- } = require('@dashevo/dapi-grpc');
8
-
9
- /**
10
- * @param {GrpcTransport} grpcTransport
11
- * @returns {getStatus}
12
- */
13
- function getStatusFactory(grpcTransport) {
14
- /**
15
- * Get Core chain status
16
- * @typedef {getStatus}
17
- * @param {DAPIClientOptions} [options]
18
- * @returns {Promise<object>}
19
- */
20
- async function getStatus(options = {}) {
21
- const getStatusRequest = new GetStatusRequest();
22
-
23
- const response = await grpcTransport.request(
24
- CorePromiseClient,
25
- 'getStatus',
26
- getStatusRequest,
27
- options,
28
- );
29
-
30
- const responseObject = response.toObject();
31
-
32
- // Respond with Buffers instead of base64 for binary fields
33
-
34
- if (response.getChain()) {
35
- if (response.getChain().getBestBlockHash()) {
36
- responseObject.chain.bestBlockHash = Buffer.from(response.getChain().getBestBlockHash());
37
- }
38
-
39
- if (response.getChain().getChainWork()) {
40
- responseObject.chain.chainWork = Buffer.from(response.getChain().getChainWork());
41
- }
42
- }
43
-
44
- if (response.getMasternode()) {
45
- if (response.getMasternode().getProTxHash()) {
46
- responseObject.masternode.proTxHash = Buffer.from(response.getMasternode().getProTxHash());
47
- }
48
- }
49
-
50
- // Respond with constant names instead of constant values
51
-
52
- responseObject.status = Object.keys(GetStatusResponse.Status)
53
- .find((key) => GetStatusResponse.Status[key] === responseObject.status);
54
-
55
- if (responseObject.masternode) {
56
- responseObject.masternode.status = Object.keys(GetStatusResponse.Masternode.Status)
57
- .find((key) => (
58
- GetStatusResponse.Masternode.Status[key] === responseObject.masternode.status
59
- ));
60
- }
61
-
62
- return responseObject;
63
- }
64
-
65
- return getStatus;
66
- }
67
-
68
- module.exports = getStatusFactory;
@@ -1,46 +0,0 @@
1
- const AbstractResponse = require('../response/AbstractResponse');
2
-
3
- class GetIdentitiesByPublicKeyHashesResponse extends AbstractResponse {
4
- /**
5
- * @param {Buffer[]} identities
6
- * @param {Metadata} metadata
7
- * @param {Proof} [proof]
8
- */
9
- constructor(identities, metadata, proof = undefined) {
10
- super(metadata, proof);
11
-
12
- this.identities = identities;
13
- }
14
-
15
- /**
16
- * @returns {Buffer[]}
17
- */
18
- getIdentities() {
19
- return this.identities;
20
- }
21
-
22
- /**
23
- * @param proto
24
- * @returns {GetIdentitiesByPublicKeyHashesResponse}
25
- */
26
- static createFromProto(proto) {
27
- const { metadata, proof } = AbstractResponse.createMetadataAndProofFromProto(proto);
28
-
29
- const identitiesList = proto.getV0().getIdentities();
30
-
31
- return new GetIdentitiesByPublicKeyHashesResponse(
32
- identitiesList !== undefined
33
- ? identitiesList.getIdentityEntriesList()
34
- .map((identity) => {
35
- const value = identity.getValue();
36
- // TODO: rework to return whole `identity.getValue()` instead of inner getValue()
37
- return value && Buffer.from(value.getValue());
38
- })
39
- : [],
40
- metadata,
41
- proof,
42
- );
43
- }
44
- }
45
-
46
- module.exports = GetIdentitiesByPublicKeyHashesResponse;