@dashevo/dapi-client 1.0.0-pr.1825.9 → 1.0.0-pr.1883.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/docs/_sidebar.md +3 -1
- package/docs/usage/application/core/getBestBlockHeight.md +10 -0
- package/docs/usage/application/core/subscribeToBlockHeadersWithChainLocks.md +39 -0
- package/docs/usage/application/core/subscribeToMasternodeList.md +24 -0
- package/docs/usage/{utils → application/core}/subscribeToTransactionsWithProofs.md +13 -10
- package/lib/BlockHeadersProvider/createBlockHeadersProviderFromOptions.js +4 -2
- package/lib/DAPIClient.js +19 -1
- package/lib/SimplifiedMasternodeListProvider/SimplifiedMasternodeListProvider.js +174 -65
- package/lib/SimplifiedMasternodeListProvider/createMasternodeListStreamFactory.js +49 -0
- package/lib/dapiAddressProvider/createDAPIAddressProviderFromOptions.js +4 -9
- package/lib/methods/core/CoreMethodsFacade.js +6 -4
- package/lib/methods/core/getBestBlockHeightFactory.js +34 -0
- package/lib/methods/core/subscribeToMasternodeListFactory.js +46 -0
- package/lib/methods/core/subscribeToTransactionsWithProofsFactory.js +1 -1
- package/lib/methods/platform/PlatformMethodsFacade.js +4 -2
- package/lib/methods/platform/getIdentitiesContractKeys/GetIdentitiesContractKeysResponse.js +65 -0
- package/lib/methods/platform/getIdentitiesContractKeys/getIdentitiesContractKeysFactory.js +93 -0
- package/lib/methods/platform/getIdentityByPublicKeyHash/GetIdentityByPublicKeyHashResponse.js +40 -0
- package/lib/methods/platform/getIdentityByPublicKeyHash/getIdentityByPublicKeyHashFactory.js +64 -0
- package/lib/transport/GrpcTransport/GrpcTransport.js +7 -1
- package/lib/transport/ReconnectableStream.js +48 -6
- package/package.json +7 -7
- package/docs/usage/application/core/generateToAddress.md +0 -13
- package/docs/usage/application/core/getMnListDiff.md +0 -12
- package/lib/methods/core/generateToAddressFactory.js +0 -25
- package/lib/methods/core/getMnListDiffFactory.js +0 -21
- package/lib/methods/platform/getIdentitiesByPublicKeyHashes/GetIdentitiesByPublicKeyHashesResponse.js +0 -46
- package/lib/methods/platform/getIdentitiesByPublicKeyHashes/getIdentitiesByPublicKeyHashesFactory.js +0 -65
|
@@ -29,7 +29,7 @@ function subscribeToTransactionsWithProofsFactory(grpcTransport) {
|
|
|
29
29
|
* EventEmitter|!grpc.web.ClientReadableStream<!TransactionsWithProofsResponse>
|
|
30
30
|
* }
|
|
31
31
|
*/
|
|
32
|
-
async function subscribeToTransactionsWithProofs(bloomFilter, options = {
|
|
32
|
+
async function subscribeToTransactionsWithProofs(bloomFilter, options = {}) {
|
|
33
33
|
// eslint-disable-next-line no-param-reassign
|
|
34
34
|
options = {
|
|
35
35
|
count: 0,
|
|
@@ -3,7 +3,8 @@ const getDataContractFactory = require('./getDataContract/getDataContractFactory
|
|
|
3
3
|
const getDataContractHistoryFactory = require('./getDataContractHistory/getDataContractHistoryFactory');
|
|
4
4
|
const getDocumentsFactory = require('./getDocuments/getDocumentsFactory');
|
|
5
5
|
const getIdentityFactory = require('./getIdentity/getIdentityFactory');
|
|
6
|
-
const
|
|
6
|
+
const getIdentityByPublicKeyHashFactory = require('./getIdentityByPublicKeyHash/getIdentityByPublicKeyHashFactory');
|
|
7
|
+
const getIdentitiesContractKeysFactory = require('./getIdentitiesContractKeys/getIdentitiesContractKeysFactory');
|
|
7
8
|
const waitForStateTransitionResultFactory = require('./waitForStateTransitionResult/waitForStateTransitionResultFactory');
|
|
8
9
|
const getConsensusParamsFactory = require('./getConsensusParams/getConsensusParamsFactory');
|
|
9
10
|
const getEpochsInfoFactory = require('./getEpochsInfo/getEpochsInfoFactory');
|
|
@@ -23,7 +24,8 @@ class PlatformMethodsFacade {
|
|
|
23
24
|
this.getDataContractHistory = getDataContractHistoryFactory(grpcTransport);
|
|
24
25
|
this.getDocuments = getDocumentsFactory(grpcTransport);
|
|
25
26
|
this.getIdentity = getIdentityFactory(grpcTransport);
|
|
26
|
-
this.
|
|
27
|
+
this.getIdentityByPublicKeyHash = getIdentityByPublicKeyHashFactory(grpcTransport);
|
|
28
|
+
this.getIdentitiesContractKeys = getIdentitiesContractKeysFactory(grpcTransport);
|
|
27
29
|
this.waitForStateTransitionResult = waitForStateTransitionResultFactory(grpcTransport);
|
|
28
30
|
this.getConsensusParams = getConsensusParamsFactory(grpcTransport);
|
|
29
31
|
this.getEpochsInfo = getEpochsInfoFactory(grpcTransport);
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
const { Identifier } = require('@dashevo/wasm-dpp');
|
|
2
|
+
const AbstractResponse = require('../response/AbstractResponse');
|
|
3
|
+
|
|
4
|
+
class GetIdentitiesContractKeysResponse extends AbstractResponse {
|
|
5
|
+
/**
|
|
6
|
+
* @param {object} identitiesKeys
|
|
7
|
+
* @param {Metadata} metadata
|
|
8
|
+
* @param {Proof} [proof]
|
|
9
|
+
*/
|
|
10
|
+
constructor(identitiesKeys, metadata, proof = undefined) {
|
|
11
|
+
super(metadata, proof);
|
|
12
|
+
|
|
13
|
+
this.identitiesKeys = identitiesKeys;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* @returns {object}
|
|
18
|
+
*/
|
|
19
|
+
getIdentitiesKeys() {
|
|
20
|
+
return this.identitiesKeys;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* @param proto
|
|
25
|
+
* @returns {GetIdentitiesContractKeysResponse}
|
|
26
|
+
*/
|
|
27
|
+
static createFromProto(proto) {
|
|
28
|
+
const { metadata, proof } = AbstractResponse.createMetadataAndProofFromProto(proto);
|
|
29
|
+
|
|
30
|
+
const identitiesKeys = proto.getV0().getIdentitiesKeys();
|
|
31
|
+
|
|
32
|
+
let identitiesKeysMap = {};
|
|
33
|
+
if (identitiesKeys) {
|
|
34
|
+
const keysEntries = identitiesKeys.getEntriesList();
|
|
35
|
+
|
|
36
|
+
identitiesKeysMap = keysEntries.reduce((acc, entry) => {
|
|
37
|
+
const identityId = Identifier.from(Buffer.from(entry.getIdentityId())).toString();
|
|
38
|
+
if (!acc[identityId]) {
|
|
39
|
+
acc[identityId] = {};
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
entry.getKeysList().forEach((key) => {
|
|
43
|
+
const purpose = key.getPurpose();
|
|
44
|
+
if (!acc[identityId][purpose]) {
|
|
45
|
+
// eslint-disable-next-line no-param-reassign
|
|
46
|
+
acc[identityId][purpose] = [];
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// eslint-disable-next-line no-param-reassign
|
|
50
|
+
acc[identityId][purpose] = acc[identityId][purpose].concat(key.getKeysBytesList());
|
|
51
|
+
}, {});
|
|
52
|
+
|
|
53
|
+
return acc;
|
|
54
|
+
}, {});
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return new GetIdentitiesContractKeysResponse(
|
|
58
|
+
identitiesKeysMap,
|
|
59
|
+
metadata,
|
|
60
|
+
proof,
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
module.exports = GetIdentitiesContractKeysResponse;
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
const {
|
|
2
|
+
v0: {
|
|
3
|
+
PlatformPromiseClient,
|
|
4
|
+
GetIdentitiesContractKeysRequest,
|
|
5
|
+
},
|
|
6
|
+
} = require('@dashevo/dapi-grpc');
|
|
7
|
+
const { IdentityPublicKey } = require('@dashevo/wasm-dpp');
|
|
8
|
+
|
|
9
|
+
const GetIdentitiesContractKeysResponse = require('./GetIdentitiesContractKeysResponse');
|
|
10
|
+
const InvalidResponseError = require('../response/errors/InvalidResponseError');
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* @param {GrpcTransport} grpcTransport
|
|
14
|
+
* @returns {getIdentitiesContractKeys}
|
|
15
|
+
*/
|
|
16
|
+
function getIdentitiesContractKeysFactory(grpcTransport) {
|
|
17
|
+
/**
|
|
18
|
+
* Fetch the identities by public key hashes
|
|
19
|
+
* @typedef {getIdentitiesContractKeys}
|
|
20
|
+
* @param {Buffer[]} identitiesIds
|
|
21
|
+
* @param {Buffer} contractId
|
|
22
|
+
* @param {IdentityPublicKey.PURPOSES[]} keyPurposes
|
|
23
|
+
* @param {string | null} documentTypeName
|
|
24
|
+
* @param {DAPIClientOptions & {prove: boolean}} [options]
|
|
25
|
+
* @returns {Promise<GetIdentitiesContractKeysResponse>}
|
|
26
|
+
*/
|
|
27
|
+
async function getIdentitiesContractKeys(
|
|
28
|
+
identitiesIds,
|
|
29
|
+
contractId,
|
|
30
|
+
keyPurposes,
|
|
31
|
+
documentTypeName = null,
|
|
32
|
+
options = {},
|
|
33
|
+
) {
|
|
34
|
+
const { GetIdentitiesContractKeysRequestV0 } = GetIdentitiesContractKeysRequest;
|
|
35
|
+
const getIdentitiesContractKeysRequest = new GetIdentitiesContractKeysRequest();
|
|
36
|
+
|
|
37
|
+
// eslint-disable-next-line no-param-reassign
|
|
38
|
+
identitiesIds = identitiesIds.map((id) => {
|
|
39
|
+
if (Buffer.isBuffer(id)) {
|
|
40
|
+
// eslint-disable-next-line no-param-reassign
|
|
41
|
+
id = Buffer.from(id);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return id;
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
if (Buffer.isBuffer(contractId)) {
|
|
48
|
+
// eslint-disable-next-line no-param-reassign
|
|
49
|
+
contractId = Buffer.from(contractId);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
getIdentitiesContractKeysRequest.setV0(
|
|
53
|
+
new GetIdentitiesContractKeysRequestV0()
|
|
54
|
+
.setProve(!!options.prove)
|
|
55
|
+
.setIdentitiesIdsList(identitiesIds)
|
|
56
|
+
.setContractId(contractId)
|
|
57
|
+
.setPurposesList(keyPurposes)
|
|
58
|
+
.setDocumentTypeName(documentTypeName),
|
|
59
|
+
);
|
|
60
|
+
|
|
61
|
+
let lastError;
|
|
62
|
+
|
|
63
|
+
// TODO: simple retry before the dapi versioning is properly implemented
|
|
64
|
+
for (let i = 0; i < 3; i += 1) {
|
|
65
|
+
try {
|
|
66
|
+
// eslint-disable-next-line no-await-in-loop
|
|
67
|
+
const getIdentitiesContractKeysResponse = await grpcTransport.request(
|
|
68
|
+
PlatformPromiseClient,
|
|
69
|
+
'getIdentitiesContractKeys',
|
|
70
|
+
getIdentitiesContractKeysRequest,
|
|
71
|
+
options,
|
|
72
|
+
);
|
|
73
|
+
|
|
74
|
+
return GetIdentitiesContractKeysResponse
|
|
75
|
+
.createFromProto(getIdentitiesContractKeysResponse);
|
|
76
|
+
} catch (e) {
|
|
77
|
+
if (e instanceof InvalidResponseError) {
|
|
78
|
+
lastError = e;
|
|
79
|
+
} else {
|
|
80
|
+
throw e;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// If we made it past the cycle it means that the retry didn't work,
|
|
86
|
+
// and we're throwing the last error encountered
|
|
87
|
+
throw lastError;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
return getIdentitiesContractKeys;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
module.exports = getIdentitiesContractKeysFactory;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
const AbstractResponse = require('../response/AbstractResponse');
|
|
2
|
+
|
|
3
|
+
class GetIdentityByPublicKeyHashResponse extends AbstractResponse {
|
|
4
|
+
/**
|
|
5
|
+
* @param {Buffer} identities
|
|
6
|
+
* @param identity
|
|
7
|
+
* @param {Metadata} metadata
|
|
8
|
+
* @param {Proof} [proof]
|
|
9
|
+
*/
|
|
10
|
+
constructor(identity, metadata, proof = undefined) {
|
|
11
|
+
super(metadata, proof);
|
|
12
|
+
|
|
13
|
+
this.identity = identity;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* @returns {Buffer[]}
|
|
18
|
+
*/
|
|
19
|
+
getIdentity() {
|
|
20
|
+
return this.identity;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* @param proto
|
|
25
|
+
* @returns {GetIdentityByPublicKeyHashResponse}
|
|
26
|
+
*/
|
|
27
|
+
static createFromProto(proto) {
|
|
28
|
+
const { metadata, proof } = AbstractResponse.createMetadataAndProofFromProto(proto);
|
|
29
|
+
|
|
30
|
+
const identity = proto.getV0().getIdentity();
|
|
31
|
+
|
|
32
|
+
return new GetIdentityByPublicKeyHashResponse(
|
|
33
|
+
Buffer.from(identity),
|
|
34
|
+
metadata,
|
|
35
|
+
proof,
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
module.exports = GetIdentityByPublicKeyHashResponse;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
const {
|
|
2
|
+
v0: {
|
|
3
|
+
PlatformPromiseClient,
|
|
4
|
+
GetIdentityByPublicKeyHashRequest,
|
|
5
|
+
},
|
|
6
|
+
} = require('@dashevo/dapi-grpc');
|
|
7
|
+
|
|
8
|
+
const GetIdentityByPublicKeyHashResponse = require('./GetIdentityByPublicKeyHashResponse');
|
|
9
|
+
const InvalidResponseError = require('../response/errors/InvalidResponseError');
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* @param {GrpcTransport} grpcTransport
|
|
13
|
+
* @returns {getIdentityByPublicKeyHash}
|
|
14
|
+
*/
|
|
15
|
+
function getIdentityByPublicKeyHashFactory(grpcTransport) {
|
|
16
|
+
/**
|
|
17
|
+
* Fetch the identity by public key hash
|
|
18
|
+
* @typedef {getIdentityByPublicKeyHash}
|
|
19
|
+
* @param {Buffer} publicKeyHash
|
|
20
|
+
* @param {DAPIClientOptions & {prove: boolean}} [options]
|
|
21
|
+
* @returns {Promise<GetIdentityByPublicKeyHashResponse>}
|
|
22
|
+
*/
|
|
23
|
+
async function getIdentityByPublicKeyHash(publicKeyHash, options = {}) {
|
|
24
|
+
const { GetIdentityByPublicKeyHashRequestV0 } = GetIdentityByPublicKeyHashRequest;
|
|
25
|
+
const getIdentityByPublicKeyHashRequest = new GetIdentityByPublicKeyHashRequest();
|
|
26
|
+
getIdentityByPublicKeyHashRequest.setV0(
|
|
27
|
+
new GetIdentityByPublicKeyHashRequestV0()
|
|
28
|
+
.setPublicKeyHash(publicKeyHash)
|
|
29
|
+
.setProve(!!options.prove),
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
let lastError;
|
|
33
|
+
|
|
34
|
+
// TODO: simple retry before the dapi versioning is properly implemented
|
|
35
|
+
for (let i = 0; i < 3; i += 1) {
|
|
36
|
+
try {
|
|
37
|
+
// eslint-disable-next-line no-await-in-loop
|
|
38
|
+
const getIdentityByPublicKeyHashResponse = await grpcTransport.request(
|
|
39
|
+
PlatformPromiseClient,
|
|
40
|
+
'getIdentityByPublicKeyHash',
|
|
41
|
+
getIdentityByPublicKeyHashRequest,
|
|
42
|
+
options,
|
|
43
|
+
);
|
|
44
|
+
|
|
45
|
+
return GetIdentityByPublicKeyHashResponse
|
|
46
|
+
.createFromProto(getIdentityByPublicKeyHashResponse);
|
|
47
|
+
} catch (e) {
|
|
48
|
+
if (e instanceof InvalidResponseError) {
|
|
49
|
+
lastError = e;
|
|
50
|
+
} else {
|
|
51
|
+
throw e;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// If we made it past the cycle it means that the retry didn't work,
|
|
57
|
+
// and we're throwing the last error encountered
|
|
58
|
+
throw lastError;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return getIdentityByPublicKeyHash;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
module.exports = getIdentityByPublicKeyHashFactory;
|
|
@@ -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
|
-
|
|
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) {
|
|
@@ -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
|
-
|
|
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
|
-
|
|
190
|
-
this.stream
|
|
191
|
-
this.
|
|
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": "1.0.0-pr.
|
|
3
|
+
"version": "1.0.0-pr.1883.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": "1.0.0-pr.
|
|
30
|
-
"@dashevo/dash-spv": "1.0.0-pr.
|
|
29
|
+
"@dashevo/dapi-grpc": "1.0.0-pr.1883.1",
|
|
30
|
+
"@dashevo/dash-spv": "1.0.0-pr.1883.1",
|
|
31
31
|
"@dashevo/dashcore-lib": "~0.21.1",
|
|
32
|
-
"@dashevo/grpc-common": "1.0.0-pr.
|
|
33
|
-
"@dashevo/wasm-dpp": "1.0.0-pr.
|
|
32
|
+
"@dashevo/grpc-common": "1.0.0-pr.1883.1",
|
|
33
|
+
"@dashevo/wasm-dpp": "1.0.0-pr.1883.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.
|
|
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
|
+
"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,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;
|
package/lib/methods/platform/getIdentitiesByPublicKeyHashes/getIdentitiesByPublicKeyHashesFactory.js
DELETED
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
const {
|
|
2
|
-
v0: {
|
|
3
|
-
PlatformPromiseClient,
|
|
4
|
-
GetIdentitiesByPublicKeyHashesRequest,
|
|
5
|
-
},
|
|
6
|
-
} = require('@dashevo/dapi-grpc');
|
|
7
|
-
|
|
8
|
-
const GetIdentitiesByPublicKeyHashesResponse = require('./GetIdentitiesByPublicKeyHashesResponse');
|
|
9
|
-
const InvalidResponseError = require('../response/errors/InvalidResponseError');
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* @param {GrpcTransport} grpcTransport
|
|
13
|
-
* @returns {getIdentitiesByPublicKeyHashes}
|
|
14
|
-
*/
|
|
15
|
-
function getIdentitiesByPublicKeyHashesFactory(grpcTransport) {
|
|
16
|
-
/**
|
|
17
|
-
* Fetch the identities by public key hashes
|
|
18
|
-
* @typedef {getIdentitiesByPublicKeyHashes}
|
|
19
|
-
* @param {Buffer[]} publicKeyHashes
|
|
20
|
-
* @param {DAPIClientOptions & {prove: boolean}} [options]
|
|
21
|
-
* @returns {Promise<GetIdentitiesByPublicKeyHashesResponse>}
|
|
22
|
-
*/
|
|
23
|
-
async function getIdentitiesByPublicKeyHashes(publicKeyHashes, options = {}) {
|
|
24
|
-
const { GetIdentitiesByPublicKeyHashesRequestV0 } = GetIdentitiesByPublicKeyHashesRequest;
|
|
25
|
-
const getIdentitiesByPublicKeyHashesRequest = new GetIdentitiesByPublicKeyHashesRequest();
|
|
26
|
-
getIdentitiesByPublicKeyHashesRequest.setV0(
|
|
27
|
-
new GetIdentitiesByPublicKeyHashesRequestV0()
|
|
28
|
-
.setPublicKeyHashesList(
|
|
29
|
-
publicKeyHashes,
|
|
30
|
-
).setProve(!!options.prove),
|
|
31
|
-
);
|
|
32
|
-
|
|
33
|
-
let lastError;
|
|
34
|
-
|
|
35
|
-
// TODO: simple retry before the dapi versioning is properly implemented
|
|
36
|
-
for (let i = 0; i < 3; i += 1) {
|
|
37
|
-
try {
|
|
38
|
-
// eslint-disable-next-line no-await-in-loop
|
|
39
|
-
const getIdentitiesByPublicKeyHashesResponse = await grpcTransport.request(
|
|
40
|
-
PlatformPromiseClient,
|
|
41
|
-
'getIdentitiesByPublicKeyHashes',
|
|
42
|
-
getIdentitiesByPublicKeyHashesRequest,
|
|
43
|
-
options,
|
|
44
|
-
);
|
|
45
|
-
|
|
46
|
-
return GetIdentitiesByPublicKeyHashesResponse
|
|
47
|
-
.createFromProto(getIdentitiesByPublicKeyHashesResponse);
|
|
48
|
-
} catch (e) {
|
|
49
|
-
if (e instanceof InvalidResponseError) {
|
|
50
|
-
lastError = e;
|
|
51
|
-
} else {
|
|
52
|
-
throw e;
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
// If we made it past the cycle it means that the retry didn't work,
|
|
58
|
-
// and we're throwing the last error encountered
|
|
59
|
-
throw lastError;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
return getIdentitiesByPublicKeyHashes;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
module.exports = getIdentitiesByPublicKeyHashesFactory;
|