@dashevo/dapi-client 0.22.0-dev.5 → 0.22.0-dev.6

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.
@@ -8,6 +8,7 @@ const getMnListDiffFactory = require('./getMnListDiffFactory');
8
8
  const getStatusFactory = require('./getStatusFactory');
9
9
  const getTransactionFactory = require('./getTransaction/getTransactionFactory');
10
10
  const subscribeToTransactionsWithProofsFactory = require('./subscribeToTransactionsWithProofsFactory');
11
+ const subscribeToBlockHeadersWithChainLocksFactory = require('./subscribeToBlockHeadersWithChainLocksFactory');
11
12
 
12
13
  class CoreMethodsFacade {
13
14
  /**
@@ -27,6 +28,9 @@ class CoreMethodsFacade {
27
28
  this.subscribeToTransactionsWithProofs = subscribeToTransactionsWithProofsFactory(
28
29
  grpcTransport,
29
30
  );
31
+ this.subscribeToBlockHeadersWithChainLocks = subscribeToBlockHeadersWithChainLocksFactory(
32
+ grpcTransport,
33
+ );
30
34
  }
31
35
  }
32
36
 
@@ -0,0 +1,69 @@
1
+ const {
2
+ v0: {
3
+ BlockHeadersWithChainLocksRequest,
4
+ CorePromiseClient,
5
+ },
6
+ } = require('@dashevo/dapi-grpc');
7
+
8
+ const DAPIClientError = require('../../errors/DAPIClientError');
9
+
10
+ /**
11
+ * @param {GrpcTransport} grpcTransport
12
+ * @returns {subscribeToBlockHeadersWithChainLocks}
13
+ */
14
+ function subscribeToBlockHeadersWithChainLocksFactory(grpcTransport) {
15
+ /**
16
+ * @typedef {subscribeToBlockHeadersWithChainLocks}
17
+ * @param {DAPIClientOptions & subscribeToBlockHeadersWithChainLocksOptions} [options]
18
+ * @returns {
19
+ * EventEmitter|!grpc.web.ClientReadableStream<!BlockHeadersWithChainLocksResponse>
20
+ * }
21
+ */
22
+ async function subscribeToBlockHeadersWithChainLocks(options = { }) {
23
+ // eslint-disable-next-line no-param-reassign
24
+ options = {
25
+ count: 0,
26
+ // Override global timeout option
27
+ // and timeout for this method by default
28
+ timeout: undefined,
29
+ ...options,
30
+ };
31
+
32
+ if (options.fromBlockHeight === 0) {
33
+ throw new DAPIClientError('Invalid argument: minimum value for `fromBlockHeight` is 1');
34
+ }
35
+
36
+ const request = new BlockHeadersWithChainLocksRequest();
37
+
38
+ if (options.fromBlockHeight !== undefined) {
39
+ request.setFromBlockHeight(options.fromBlockHeight);
40
+ }
41
+
42
+ if (options.fromBlockHash) {
43
+ request.setFromBlockHash(
44
+ Buffer.from(options.fromBlockHash, 'hex'),
45
+ );
46
+ }
47
+
48
+ request.setCount(options.count);
49
+
50
+ return grpcTransport.request(
51
+ CorePromiseClient,
52
+ 'subscribeToBlockHeadersWithChainLocks',
53
+ request,
54
+ options,
55
+ );
56
+ }
57
+
58
+ return subscribeToBlockHeadersWithChainLocks;
59
+ }
60
+
61
+ /**
62
+ * @typedef {object} subscribeToBlockHeadersWithChainLocksOptions
63
+ * @property {string} [fromBlockHash] - Specifies block hash to start syncing from
64
+ * @property {number} [fromBlockHeight] - Specifies block height to start syncing from
65
+ * @property {number} [count=0] - Number of blocks to sync,
66
+ * if set to 0 syncing is continuously sends new data as well
67
+ */
68
+
69
+ module.exports = subscribeToBlockHeadersWithChainLocksFactory;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dashevo/dapi-client",
3
- "version": "0.22.0-dev.5",
3
+ "version": "0.22.0-dev.6",
4
4
  "description": "Client library used to access Dash DAPI endpoints",
5
5
  "main": "lib/DAPIClient.js",
6
6
  "contributors": [
@@ -26,10 +26,10 @@
26
26
  }
27
27
  ],
28
28
  "dependencies": {
29
- "@dashevo/dapi-grpc": "~0.22.0-dev.5",
29
+ "@dashevo/dapi-grpc": "~0.22.0-dev.6",
30
30
  "@dashevo/dashcore-lib": "~0.19.28",
31
- "@dashevo/dpp": "~0.22.0-dev.5",
32
- "@dashevo/grpc-common": "~0.22.0-dev.5",
31
+ "@dashevo/dpp": "~0.22.0-dev.6",
32
+ "@dashevo/grpc-common": "~0.22.0-dev.6",
33
33
  "@grpc/grpc-js": "^1.3.7",
34
34
  "axios": "^0.21.1",
35
35
  "bs58": "^4.0.1",