@dashevo/dapi-client 0.22.0-dev.3 → 0.22.0-dev.7
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/README.md +3 -3
- package/lib/methods/core/CoreMethodsFacade.js +4 -0
- package/lib/methods/core/subscribeToBlockHeadersWithChainLocksFactory.js +69 -0
- package/lib/methods/platform/getIdentitiesByPublicKeyHashes/GetIdentitiesByPublicKeyHashesResponse.js +10 -3
- package/lib/methods/platform/getIdentityIdsByPublicKeyHashes/GetIdentityIdsByPublicKeyHashesResponse.js +10 -3
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -12,7 +12,7 @@ Platform via the decentralized API ([DAPI](https://github.com/dashevo/dapi))
|
|
|
12
12
|
hosted on Dash masternodes.
|
|
13
13
|
|
|
14
14
|
- `DAPI-Client` provides automatic server (masternode) discovery using either a default seed node or a user-supplied one
|
|
15
|
-
- `DAPI-Client` maps to DAPI's [RPC](https://github.com/dashevo/
|
|
15
|
+
- `DAPI-Client` maps to DAPI's [RPC](https://github.com/dashevo/platform/tree/master/packages/dapi/lib/rpcServer/commands) and [gRPC](https://github.com/dashevo/platform/tree/master/packages/dapi/lib/grpcServer/handlers) endpoints
|
|
16
16
|
|
|
17
17
|
## Table of Contents
|
|
18
18
|
- [Install](#install)
|
|
@@ -101,12 +101,12 @@ client.core.getBestBlockHash(options).then((r) => {
|
|
|
101
101
|
|
|
102
102
|
## Documentation
|
|
103
103
|
|
|
104
|
-
More extensive documentation available at https://dashevo.github.io/
|
|
104
|
+
More extensive documentation available at https://dashevo.github.io/platform/DAPI-Client/.
|
|
105
105
|
|
|
106
106
|
|
|
107
107
|
## Contributing
|
|
108
108
|
|
|
109
|
-
Feel free to dive in! [Open an issue](https://github.com/dashevo/
|
|
109
|
+
Feel free to dive in! [Open an issue](https://github.com/dashevo/platform/issues/new/choose) or submit PRs.
|
|
110
110
|
|
|
111
111
|
## License
|
|
112
112
|
|
|
@@ -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;
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
const cbor = require('cbor');
|
|
2
|
+
|
|
1
3
|
const AbstractResponse = require('../response/AbstractResponse');
|
|
2
4
|
|
|
3
5
|
class GetIdentitiesByPublicKeyHashesResponse extends AbstractResponse {
|
|
@@ -13,7 +15,7 @@ class GetIdentitiesByPublicKeyHashesResponse extends AbstractResponse {
|
|
|
13
15
|
}
|
|
14
16
|
|
|
15
17
|
/**
|
|
16
|
-
* @returns {Buffer[]}
|
|
18
|
+
* @returns {Array<Buffer[]>}
|
|
17
19
|
*/
|
|
18
20
|
getIdentities() {
|
|
19
21
|
return this.identities;
|
|
@@ -27,8 +29,13 @@ class GetIdentitiesByPublicKeyHashesResponse extends AbstractResponse {
|
|
|
27
29
|
const { metadata, proof } = AbstractResponse.createMetadataAndProofFromProto(proto);
|
|
28
30
|
|
|
29
31
|
return new GetIdentitiesByPublicKeyHashesResponse(
|
|
30
|
-
proto.getIdentitiesList()
|
|
31
|
-
|
|
32
|
+
proto.getIdentitiesList().map((identitiesSerialized) => {
|
|
33
|
+
const identities = cbor.decode(identitiesSerialized);
|
|
34
|
+
|
|
35
|
+
return identities.map((identity) => (
|
|
36
|
+
(identity.length > 0 ? Buffer.from(identity) : null)
|
|
37
|
+
));
|
|
38
|
+
}),
|
|
32
39
|
metadata,
|
|
33
40
|
proof,
|
|
34
41
|
);
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
const cbor = require('cbor');
|
|
2
|
+
|
|
1
3
|
const AbstractResponse = require('../response/AbstractResponse');
|
|
2
4
|
|
|
3
5
|
class GetIdentityIdsByPublicKeyHashesResponse extends AbstractResponse {
|
|
@@ -13,7 +15,7 @@ class GetIdentityIdsByPublicKeyHashesResponse extends AbstractResponse {
|
|
|
13
15
|
}
|
|
14
16
|
|
|
15
17
|
/**
|
|
16
|
-
* @returns {Buffer[]}
|
|
18
|
+
* @returns {Array<Buffer[]>}
|
|
17
19
|
*/
|
|
18
20
|
getIdentityIds() {
|
|
19
21
|
return this.identityIds;
|
|
@@ -27,8 +29,13 @@ class GetIdentityIdsByPublicKeyHashesResponse extends AbstractResponse {
|
|
|
27
29
|
const { metadata, proof } = AbstractResponse.createMetadataAndProofFromProto(proto);
|
|
28
30
|
|
|
29
31
|
return new GetIdentityIdsByPublicKeyHashesResponse(
|
|
30
|
-
proto.getIdentityIdsList()
|
|
31
|
-
|
|
32
|
+
proto.getIdentityIdsList().map((identityIdsSerialized) => {
|
|
33
|
+
const identityIds = cbor.decode(identityIdsSerialized);
|
|
34
|
+
|
|
35
|
+
return identityIds.map((identityId) => (
|
|
36
|
+
(identityId.length > 0 ? Buffer.from(identityId) : null)
|
|
37
|
+
));
|
|
38
|
+
}),
|
|
32
39
|
metadata,
|
|
33
40
|
proof,
|
|
34
41
|
);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dashevo/dapi-client",
|
|
3
|
-
"version": "0.22.0-dev.
|
|
3
|
+
"version": "0.22.0-dev.7",
|
|
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.
|
|
30
|
-
"@dashevo/dashcore-lib": "~0.19.
|
|
31
|
-
"@dashevo/dpp": "~0.22.0-dev.
|
|
32
|
-
"@dashevo/grpc-common": "~0.22.0-dev.
|
|
29
|
+
"@dashevo/dapi-grpc": "~0.22.0-dev.7",
|
|
30
|
+
"@dashevo/dashcore-lib": "~0.19.29",
|
|
31
|
+
"@dashevo/dpp": "~0.22.0-dev.7",
|
|
32
|
+
"@dashevo/grpc-common": "~0.22.0-dev.7",
|
|
33
33
|
"@grpc/grpc-js": "^1.3.7",
|
|
34
34
|
"axios": "^0.21.1",
|
|
35
35
|
"bs58": "^4.0.1",
|