@dashevo/dapi-client 0.22.15 → 0.23.0-alpha.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.
- package/README.md +2 -2
- package/lib/dapiAddressProvider/ListDAPIAddressProvider.js +5 -1
- package/lib/methods/platform/PlatformMethodsFacade.js +0 -2
- package/lib/methods/platform/getIdentitiesByPublicKeyHashes/GetIdentitiesByPublicKeyHashesResponse.js +2 -10
- package/lib/transport/GrpcTransport/createGrpcTransportError.js +25 -32
- package/lib/transport/JsonRpcTransport/JsonRpcTransport.js +2 -2
- package/package.json +8 -8
- package/lib/methods/platform/getIdentityIdsByPublicKeyHashes/GetIdentityIdsByPublicKeyHashesResponse.js +0 -45
- package/lib/methods/platform/getIdentityIdsByPublicKeyHashes/getIdentityIdsByPublicKeyHashesFactory.js +0 -63
package/README.md
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
# DAPI Client
|
|
2
2
|
|
|
3
3
|
[](https://www.npmjs.com/package/@dashevo/dapi-client)
|
|
4
|
-
[](https://github.com/dashevo/platform/actions/workflows/release.yml)
|
|
5
|
+
[](https://github.com/dashevo/platform/releases/latest)
|
|
6
6
|
[](https://github.com/RichardLitt/standard-readme)
|
|
7
7
|
|
|
8
8
|
Client library used to access Dash DAPI endpoints
|
|
@@ -26,7 +26,7 @@ class ListDAPIAddressProvider {
|
|
|
26
26
|
const liveAddress = sample(liveAddresses);
|
|
27
27
|
|
|
28
28
|
if (liveAddress === undefined) {
|
|
29
|
-
return
|
|
29
|
+
return undefined;
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
// This is a temporary fix for a localhost masternode.
|
|
@@ -34,7 +34,11 @@ class ListDAPIAddressProvider {
|
|
|
34
34
|
// not really possible to bind to that address, so that workaround is introduced.
|
|
35
35
|
const network = networks.get(this.options.network);
|
|
36
36
|
if (network && network.regtestEnabled) {
|
|
37
|
+
const randomNodeIndex = Math.floor(Math.random() * liveAddresses.length);
|
|
38
|
+
|
|
37
39
|
liveAddress.host = '127.0.0.1';
|
|
40
|
+
liveAddress.httpPort = 3000 + randomNodeIndex * 100;
|
|
41
|
+
liveAddress.grpcPort = 3010 + randomNodeIndex * 100;
|
|
38
42
|
}
|
|
39
43
|
|
|
40
44
|
return liveAddress;
|
|
@@ -2,7 +2,6 @@ const broadcastStateTransitionFactory = require('./broadcastStateTransition/broa
|
|
|
2
2
|
const getDataContractFactory = require('./getDataContract/getDataContractFactory');
|
|
3
3
|
const getDocumentsFactory = require('./getDocuments/getDocumentsFactory');
|
|
4
4
|
const getIdentityFactory = require('./getIdentity/getIdentityFactory');
|
|
5
|
-
const getIdentityIdsByPublicKeyHashesFactory = require('./getIdentityIdsByPublicKeyHashes/getIdentityIdsByPublicKeyHashesFactory');
|
|
6
5
|
const getIdentitiesByPublicKeyHashesFactory = require('./getIdentitiesByPublicKeyHashes/getIdentitiesByPublicKeyHashesFactory');
|
|
7
6
|
const waitForStateTransitionResultFactory = require('./waitForStateTransitionResult/waitForStateTransitionResultFactory');
|
|
8
7
|
const getConsensusParamsFactory = require('./getConsensusParams/getConsensusParamsFactory');
|
|
@@ -16,7 +15,6 @@ class PlatformMethodsFacade {
|
|
|
16
15
|
this.getDataContract = getDataContractFactory(grpcTransport);
|
|
17
16
|
this.getDocuments = getDocumentsFactory(grpcTransport);
|
|
18
17
|
this.getIdentity = getIdentityFactory(grpcTransport);
|
|
19
|
-
this.getIdentityIdsByPublicKeyHashes = getIdentityIdsByPublicKeyHashesFactory(grpcTransport);
|
|
20
18
|
this.getIdentitiesByPublicKeyHashes = getIdentitiesByPublicKeyHashesFactory(grpcTransport);
|
|
21
19
|
this.waitForStateTransitionResult = waitForStateTransitionResultFactory(grpcTransport);
|
|
22
20
|
this.getConsensusParams = getConsensusParamsFactory(grpcTransport);
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
const cbor = require('cbor');
|
|
2
|
-
|
|
3
1
|
const AbstractResponse = require('../response/AbstractResponse');
|
|
4
2
|
|
|
5
3
|
class GetIdentitiesByPublicKeyHashesResponse extends AbstractResponse {
|
|
@@ -15,7 +13,7 @@ class GetIdentitiesByPublicKeyHashesResponse extends AbstractResponse {
|
|
|
15
13
|
}
|
|
16
14
|
|
|
17
15
|
/**
|
|
18
|
-
* @returns {
|
|
16
|
+
* @returns {Buffer[]}
|
|
19
17
|
*/
|
|
20
18
|
getIdentities() {
|
|
21
19
|
return this.identities;
|
|
@@ -29,13 +27,7 @@ class GetIdentitiesByPublicKeyHashesResponse extends AbstractResponse {
|
|
|
29
27
|
const { metadata, proof } = AbstractResponse.createMetadataAndProofFromProto(proto);
|
|
30
28
|
|
|
31
29
|
return new GetIdentitiesByPublicKeyHashesResponse(
|
|
32
|
-
proto.
|
|
33
|
-
const identities = cbor.decode(identitiesSerialized);
|
|
34
|
-
|
|
35
|
-
return identities.map((identity) => (
|
|
36
|
-
(identity.length > 0 ? Buffer.from(identity) : null)
|
|
37
|
-
));
|
|
38
|
-
}),
|
|
30
|
+
proto.getIdentitiesList_asU8().map((identity) => Buffer.from(identity)),
|
|
39
31
|
metadata,
|
|
40
32
|
proof,
|
|
41
33
|
);
|
|
@@ -47,37 +47,37 @@ function createGrpcTransportError(grpcError, dapiAddress) {
|
|
|
47
47
|
// Extract error code and data
|
|
48
48
|
let data = {};
|
|
49
49
|
let { code } = grpcError;
|
|
50
|
+
|
|
50
51
|
const message = grpcError.details || grpcError.message;
|
|
51
52
|
|
|
52
|
-
|
|
53
|
-
let encodedData;
|
|
53
|
+
let metadata = {};
|
|
54
54
|
|
|
55
|
+
if (grpcError.metadata) {
|
|
56
|
+
// In cases of gRPC-Web client we get plain map instead of Metadata instance
|
|
57
|
+
metadata = grpcError.metadata;
|
|
55
58
|
if (grpcError.metadata instanceof Metadata) {
|
|
56
|
-
|
|
57
|
-
if (cboredMetaData && cboredMetaData.length > 0) {
|
|
58
|
-
[encodedData] = cboredMetaData;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
// since gRPC doesn't allow to use custom error codes
|
|
62
|
-
// DAPI pass them as a part of metadata
|
|
63
|
-
const metaCode = grpcError.metadata.get('code');
|
|
64
|
-
if (metaCode && metaCode.length > 0) {
|
|
65
|
-
[code] = metaCode;
|
|
66
|
-
}
|
|
67
|
-
} else {
|
|
68
|
-
if (grpcError.metadata['drive-error-data-bin']) {
|
|
69
|
-
encodedData = Buffer.from(grpcError.metadata['drive-error-data-bin'], 'base64');
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
const metaCode = grpcError.metadata.code;
|
|
73
|
-
if (metaCode !== undefined) {
|
|
74
|
-
code = Number(metaCode);
|
|
75
|
-
}
|
|
59
|
+
metadata = grpcError.metadata.getMap();
|
|
76
60
|
}
|
|
61
|
+
}
|
|
77
62
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
63
|
+
// Error data
|
|
64
|
+
const driveErrorData = metadata['drive-error-data-bin'];
|
|
65
|
+
if (driveErrorData) {
|
|
66
|
+
const encodedData = Buffer.from(driveErrorData, 'base64');
|
|
67
|
+
data = cbor.decode(encodedData);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// Error code
|
|
71
|
+
const driveErrorCode = metadata.code;
|
|
72
|
+
if (driveErrorCode) {
|
|
73
|
+
code = Number(driveErrorCode);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// Error stack
|
|
77
|
+
const driveErrorStack = metadata['stack-bin'];
|
|
78
|
+
if (driveErrorStack) {
|
|
79
|
+
const encodedStack = Buffer.from(driveErrorStack, 'base64');
|
|
80
|
+
data.stack = cbor.decode(encodedStack);
|
|
81
81
|
}
|
|
82
82
|
|
|
83
83
|
// Specialized classes
|
|
@@ -102,13 +102,6 @@ function createGrpcTransportError(grpcError, dapiAddress) {
|
|
|
102
102
|
}
|
|
103
103
|
|
|
104
104
|
if (code === GrpcErrorCodes.INTERNAL) {
|
|
105
|
-
if (grpcError.metadata) {
|
|
106
|
-
const metaStack = grpcError.metadata.get('stack-bin');
|
|
107
|
-
if (metaStack && metaStack.length > 0) {
|
|
108
|
-
data.stack = cbor.decode(metaStack[0]);
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
|
|
112
105
|
return new InternalServerError(
|
|
113
106
|
code,
|
|
114
107
|
message,
|
|
@@ -84,14 +84,14 @@ class JsonRpcTransport {
|
|
|
84
84
|
throw error;
|
|
85
85
|
}
|
|
86
86
|
|
|
87
|
-
address.markAsBanned();
|
|
88
|
-
|
|
89
87
|
const responseError = this.createJsonTransportError(error, address);
|
|
90
88
|
|
|
91
89
|
if (!(responseError instanceof RetriableResponseError)) {
|
|
92
90
|
throw responseError;
|
|
93
91
|
}
|
|
94
92
|
|
|
93
|
+
address.markAsBanned();
|
|
94
|
+
|
|
95
95
|
if (options.retries === 0) {
|
|
96
96
|
throw new MaxRetriesReachedError(responseError);
|
|
97
97
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dashevo/dapi-client",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.23.0-alpha.1",
|
|
4
4
|
"description": "Client library used to access Dash DAPI endpoints",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"contributors": [
|
|
@@ -26,13 +26,13 @@
|
|
|
26
26
|
}
|
|
27
27
|
],
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@dashevo/dapi-grpc": "~0.
|
|
30
|
-
"@dashevo/dash-spv": "~
|
|
31
|
-
"@dashevo/dashcore-lib": "~0.19.
|
|
32
|
-
"@dashevo/dpp": "~0.
|
|
33
|
-
"@dashevo/grpc-common": "~0.
|
|
29
|
+
"@dashevo/dapi-grpc": "~0.23.0-alpha.1",
|
|
30
|
+
"@dashevo/dash-spv": "~0.23.0-alpha.1",
|
|
31
|
+
"@dashevo/dashcore-lib": "~0.19.44",
|
|
32
|
+
"@dashevo/dpp": "~0.23.0-alpha.1",
|
|
33
|
+
"@dashevo/grpc-common": "~0.23.0-alpha.1",
|
|
34
34
|
"@grpc/grpc-js": "^1.3.7",
|
|
35
|
-
"axios": "^0.
|
|
35
|
+
"axios": "^0.27.2",
|
|
36
36
|
"bs58": "^4.0.1",
|
|
37
37
|
"cbor": "^8.0.0",
|
|
38
38
|
"lodash.sample": "^4.2.1",
|
|
@@ -54,7 +54,7 @@
|
|
|
54
54
|
"eslint-plugin-import": "^2.24.2",
|
|
55
55
|
"eslint-plugin-jsdoc": "^27.0.0",
|
|
56
56
|
"events": "^3.3.0",
|
|
57
|
-
"karma": "^6.
|
|
57
|
+
"karma": "^6.4.1",
|
|
58
58
|
"karma-chai": "^0.1.0",
|
|
59
59
|
"karma-chrome-launcher": "^3.1.0",
|
|
60
60
|
"karma-firefox-launcher": "^2.1.1",
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
const cbor = require('cbor');
|
|
2
|
-
|
|
3
|
-
const AbstractResponse = require('../response/AbstractResponse');
|
|
4
|
-
|
|
5
|
-
class GetIdentityIdsByPublicKeyHashesResponse extends AbstractResponse {
|
|
6
|
-
/**
|
|
7
|
-
* @param {Buffer[]} identityIds
|
|
8
|
-
* @param {Metadata} metadata
|
|
9
|
-
* @param {Proof} [proof]
|
|
10
|
-
*/
|
|
11
|
-
constructor(identityIds, metadata, proof = undefined) {
|
|
12
|
-
super(metadata, proof);
|
|
13
|
-
|
|
14
|
-
this.identityIds = identityIds;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* @returns {Array<Buffer[]>}
|
|
19
|
-
*/
|
|
20
|
-
getIdentityIds() {
|
|
21
|
-
return this.identityIds;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* @param proto
|
|
26
|
-
* @returns {GetIdentityIdsByPublicKeyHashesResponse}
|
|
27
|
-
*/
|
|
28
|
-
static createFromProto(proto) {
|
|
29
|
-
const { metadata, proof } = AbstractResponse.createMetadataAndProofFromProto(proto);
|
|
30
|
-
|
|
31
|
-
return new GetIdentityIdsByPublicKeyHashesResponse(
|
|
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
|
-
}),
|
|
39
|
-
metadata,
|
|
40
|
-
proof,
|
|
41
|
-
);
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
module.exports = GetIdentityIdsByPublicKeyHashesResponse;
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
const {
|
|
2
|
-
v0: {
|
|
3
|
-
PlatformPromiseClient,
|
|
4
|
-
GetIdentityIdsByPublicKeyHashesRequest,
|
|
5
|
-
},
|
|
6
|
-
} = require('@dashevo/dapi-grpc');
|
|
7
|
-
|
|
8
|
-
const GetIdentityIdsByPublicKeyHashesResponse = require('./GetIdentityIdsByPublicKeyHashesResponse');
|
|
9
|
-
const InvalidResponseError = require('../response/errors/InvalidResponseError');
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* @param {GrpcTransport} grpcTransport
|
|
13
|
-
* @returns {getIdentityIdsByPublicKeyHashes}
|
|
14
|
-
*/
|
|
15
|
-
function getIdentityIdsByPublicKeyHashesFactory(grpcTransport) {
|
|
16
|
-
/**
|
|
17
|
-
* Fetch the identities by public key hashes
|
|
18
|
-
*
|
|
19
|
-
* @typedef {getIdentityIdsByPublicKeyHashes}
|
|
20
|
-
* @param {Buffer[]} publicKeyHashes
|
|
21
|
-
* @param {DAPIClientOptions & {prove: boolean}} [options]
|
|
22
|
-
* @returns {Promise<GetIdentityIdsByPublicKeyHashesResponse>}
|
|
23
|
-
*/
|
|
24
|
-
async function getIdentityIdsByPublicKeyHashes(publicKeyHashes, options = {}) {
|
|
25
|
-
const getIdentityIdsByPublicKeyHashesRequest = new GetIdentityIdsByPublicKeyHashesRequest();
|
|
26
|
-
getIdentityIdsByPublicKeyHashesRequest.setPublicKeyHashesList(
|
|
27
|
-
publicKeyHashes,
|
|
28
|
-
);
|
|
29
|
-
getIdentityIdsByPublicKeyHashesRequest.setProve(!!options.prove);
|
|
30
|
-
|
|
31
|
-
let lastError;
|
|
32
|
-
|
|
33
|
-
// TODO: simple retry before the dapi versioning is properly implemented
|
|
34
|
-
for (let i = 0; i < 3; i += 1) {
|
|
35
|
-
try {
|
|
36
|
-
// eslint-disable-next-line no-await-in-loop
|
|
37
|
-
const getIdentityIdsByPublicKeyHashesResponse = await grpcTransport.request(
|
|
38
|
-
PlatformPromiseClient,
|
|
39
|
-
'getIdentityIdsByPublicKeyHashes',
|
|
40
|
-
getIdentityIdsByPublicKeyHashesRequest,
|
|
41
|
-
options,
|
|
42
|
-
);
|
|
43
|
-
|
|
44
|
-
return GetIdentityIdsByPublicKeyHashesResponse
|
|
45
|
-
.createFromProto(getIdentityIdsByPublicKeyHashesResponse);
|
|
46
|
-
} catch (e) {
|
|
47
|
-
if (e instanceof InvalidResponseError) {
|
|
48
|
-
lastError = e;
|
|
49
|
-
} else {
|
|
50
|
-
throw e;
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
// If we made it past the cycle it means that the retry didn't work,
|
|
56
|
-
// and we're throwing the last error encountered
|
|
57
|
-
throw lastError;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
return getIdentityIdsByPublicKeyHashes;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
module.exports = getIdentityIdsByPublicKeyHashesFactory;
|