@dashevo/dapi-client 0.25.8 → 0.25.10
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/lib/methods/platform/PlatformMethodsFacade.js +6 -0
- package/lib/methods/platform/getConsensusParams/getConsensusParamsFactory.js +10 -2
- package/lib/methods/platform/getConsensusParams/getConsensusParamsResponse.js +2 -2
- package/lib/methods/platform/getDataContract/GetDataContractResponse.js +1 -1
- package/lib/methods/platform/getDataContract/getDataContractFactory.js +6 -2
- package/lib/methods/platform/getDataContractHistory/GetDataContractHistoryResponse.js +1 -1
- package/lib/methods/platform/getDataContractHistory/getDataContractHistoryFactory.js +9 -5
- package/lib/methods/platform/getDocuments/GetDocumentsResponse.js +1 -1
- package/lib/methods/platform/getDocuments/getDocumentsFactory.js +12 -8
- package/lib/methods/platform/getEpochsInfo/EpochInfo.js +54 -0
- package/lib/methods/platform/getEpochsInfo/GetEpochsInfoResponse.js +59 -0
- package/lib/methods/platform/getEpochsInfo/getEpochsInfoFactory.js +69 -0
- package/lib/methods/platform/getIdentitiesByPublicKeyHashes/GetIdentitiesByPublicKeyHashesResponse.js +8 -2
- package/lib/methods/platform/getIdentitiesByPublicKeyHashes/getIdentitiesByPublicKeyHashesFactory.js +6 -3
- package/lib/methods/platform/getIdentity/GetIdentityResponse.js +2 -2
- package/lib/methods/platform/getIdentity/getIdentityFactory.js +6 -2
- package/lib/methods/platform/getVersionUpgradeState/GetVersionUpgradeStateResponse.js +56 -0
- package/lib/methods/platform/getVersionUpgradeState/VersionEntry.js +26 -0
- package/lib/methods/platform/getVersionUpgradeState/getVersionUpgradeStateFactory.js +63 -0
- package/lib/methods/platform/getVersionUpgradeVoteStatus/GetVersionUpgradeVoteStatusResponse.js +56 -0
- package/lib/methods/platform/getVersionUpgradeVoteStatus/VersionSignal.js +26 -0
- package/lib/methods/platform/getVersionUpgradeVoteStatus/getVersionUpgradeVoteStatusFactory.js +67 -0
- package/lib/methods/platform/response/AbstractResponse.js +2 -2
- package/lib/methods/platform/waitForStateTransitionResult/WaitForStateTransitionResultResponse.js +8 -7
- package/lib/methods/platform/waitForStateTransitionResult/waitForStateTransitionResultFactory.js +6 -3
- package/lib/test/bootstrap.js +5 -0
- package/package.json +6 -7
|
@@ -6,6 +6,9 @@ const getIdentityFactory = require('./getIdentity/getIdentityFactory');
|
|
|
6
6
|
const getIdentitiesByPublicKeyHashesFactory = require('./getIdentitiesByPublicKeyHashes/getIdentitiesByPublicKeyHashesFactory');
|
|
7
7
|
const waitForStateTransitionResultFactory = require('./waitForStateTransitionResult/waitForStateTransitionResultFactory');
|
|
8
8
|
const getConsensusParamsFactory = require('./getConsensusParams/getConsensusParamsFactory');
|
|
9
|
+
const getEpochsInfoFactory = require('./getEpochsInfo/getEpochsInfoFactory');
|
|
10
|
+
const getVersionUpgradeVoteStatusFactory = require('./getVersionUpgradeVoteStatus/getVersionUpgradeVoteStatusFactory');
|
|
11
|
+
const getVersionUpgradeStateFactory = require('./getVersionUpgradeState/getVersionUpgradeStateFactory');
|
|
9
12
|
|
|
10
13
|
class PlatformMethodsFacade {
|
|
11
14
|
/**
|
|
@@ -20,6 +23,9 @@ class PlatformMethodsFacade {
|
|
|
20
23
|
this.getIdentitiesByPublicKeyHashes = getIdentitiesByPublicKeyHashesFactory(grpcTransport);
|
|
21
24
|
this.waitForStateTransitionResult = waitForStateTransitionResultFactory(grpcTransport);
|
|
22
25
|
this.getConsensusParams = getConsensusParamsFactory(grpcTransport);
|
|
26
|
+
this.getEpochsInfo = getEpochsInfoFactory(grpcTransport);
|
|
27
|
+
this.getVersionUpgradeVoteStatus = getVersionUpgradeVoteStatusFactory(grpcTransport);
|
|
28
|
+
this.getVersionUpgradeState = getVersionUpgradeStateFactory(grpcTransport);
|
|
23
29
|
}
|
|
24
30
|
}
|
|
25
31
|
|
|
@@ -7,6 +7,10 @@ const {
|
|
|
7
7
|
const InvalidResponseError = require('../response/errors/InvalidResponseError');
|
|
8
8
|
const GetConsensusParamsResponse = require('./getConsensusParamsResponse');
|
|
9
9
|
|
|
10
|
+
const {
|
|
11
|
+
GetConsensusParamsRequestV0,
|
|
12
|
+
} = GetConsensusParamsRequest;
|
|
13
|
+
|
|
10
14
|
/**
|
|
11
15
|
* @param {GrpcTransport} grpcTransport
|
|
12
16
|
* @returns {getConsensusParams}
|
|
@@ -22,11 +26,15 @@ function getConsensusParamsFactory(grpcTransport) {
|
|
|
22
26
|
*/
|
|
23
27
|
async function getConsensusParams(height = undefined, options = {}) {
|
|
24
28
|
const getConsensusParamsRequest = new GetConsensusParamsRequest();
|
|
29
|
+
getConsensusParamsRequest.setV0(
|
|
30
|
+
new GetConsensusParamsRequestV0(),
|
|
31
|
+
);
|
|
32
|
+
|
|
25
33
|
if (height !== undefined) {
|
|
26
|
-
getConsensusParamsRequest.setHeight(height);
|
|
34
|
+
getConsensusParamsRequest.getV0().setHeight(height);
|
|
27
35
|
}
|
|
28
36
|
|
|
29
|
-
getConsensusParamsRequest.setProve(!!options.prove);
|
|
37
|
+
getConsensusParamsRequest.getV0().setProve(!!options.prove);
|
|
30
38
|
|
|
31
39
|
let lastError;
|
|
32
40
|
|
|
@@ -32,8 +32,8 @@ class GetConsensusParamsResponse {
|
|
|
32
32
|
* @returns {GetConsensusParamsResponse}
|
|
33
33
|
*/
|
|
34
34
|
static createFromProto(proto) {
|
|
35
|
-
const protoBlock = proto.getBlock();
|
|
36
|
-
const protoEvidence = proto.getEvidence();
|
|
35
|
+
const protoBlock = proto.getV0().getBlock();
|
|
36
|
+
const protoEvidence = proto.getV0().getEvidence();
|
|
37
37
|
|
|
38
38
|
if (!protoBlock && !protoEvidence) {
|
|
39
39
|
throw new InvalidResponseError('Consensus params are not defined');
|
|
@@ -25,7 +25,7 @@ class GetDataContractResponse extends AbstractResponse {
|
|
|
25
25
|
* @returns {GetDataContractResponse}
|
|
26
26
|
*/
|
|
27
27
|
static createFromProto(proto) {
|
|
28
|
-
const dataContract = proto.getDataContract();
|
|
28
|
+
const dataContract = proto.getV0().getDataContract();
|
|
29
29
|
const { metadata, proof } = AbstractResponse.createMetadataAndProofFromProto(proto);
|
|
30
30
|
|
|
31
31
|
if (!dataContract && !proof) {
|
|
@@ -22,6 +22,7 @@ function getDataContractFactory(grpcTransport) {
|
|
|
22
22
|
* @returns {Promise<GetDataContractResponse>}
|
|
23
23
|
*/
|
|
24
24
|
async function getDataContract(contractId, options = {}) {
|
|
25
|
+
const { GetDataContractRequestV0 } = GetDataContractRequest;
|
|
25
26
|
const getDataContractRequest = new GetDataContractRequest();
|
|
26
27
|
|
|
27
28
|
// need to convert objects inherited from Buffer to pure buffer as google protobuf
|
|
@@ -32,8 +33,11 @@ function getDataContractFactory(grpcTransport) {
|
|
|
32
33
|
contractId = Buffer.from(contractId);
|
|
33
34
|
}
|
|
34
35
|
|
|
35
|
-
getDataContractRequest.
|
|
36
|
-
|
|
36
|
+
getDataContractRequest.setV0(
|
|
37
|
+
new GetDataContractRequestV0()
|
|
38
|
+
.setId(contractId)
|
|
39
|
+
.setProve(!!options.prove),
|
|
40
|
+
);
|
|
37
41
|
|
|
38
42
|
let lastError;
|
|
39
43
|
|
|
@@ -26,7 +26,7 @@ class GetDataContractHistoryResponse extends AbstractResponse {
|
|
|
26
26
|
*/
|
|
27
27
|
static createFromProto(proto) {
|
|
28
28
|
// History is something that we need to call a method to get a list of entries on
|
|
29
|
-
const dataContractHistory = proto.getDataContractHistory();
|
|
29
|
+
const dataContractHistory = proto.getV0().getDataContractHistory();
|
|
30
30
|
const { metadata, proof } = AbstractResponse.createMetadataAndProofFromProto(proto);
|
|
31
31
|
|
|
32
32
|
if (!dataContractHistory && !proof) {
|
|
@@ -32,6 +32,7 @@ function getDataContractHistoryFactory(grpcTransport) {
|
|
|
32
32
|
offset = 0,
|
|
33
33
|
options = {},
|
|
34
34
|
) {
|
|
35
|
+
const { GetDataContractHistoryRequestV0 } = GetDataContractHistoryRequest;
|
|
35
36
|
const getDataContractHistoryRequest = new GetDataContractHistoryRequest();
|
|
36
37
|
|
|
37
38
|
// need to convert objects inherited from Buffer to pure buffer as google protobuf
|
|
@@ -42,11 +43,14 @@ function getDataContractHistoryFactory(grpcTransport) {
|
|
|
42
43
|
contractId = Buffer.from(contractId);
|
|
43
44
|
}
|
|
44
45
|
|
|
45
|
-
getDataContractHistoryRequest.
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
46
|
+
getDataContractHistoryRequest.setV0(
|
|
47
|
+
new GetDataContractHistoryRequestV0()
|
|
48
|
+
.setId(contractId)
|
|
49
|
+
.setStartAtMs(startAtMs)
|
|
50
|
+
.setLimit(new UInt32Value([limit]))
|
|
51
|
+
.setOffset(new UInt32Value([offset]))
|
|
52
|
+
.setProve(!!options.prove),
|
|
53
|
+
);
|
|
50
54
|
|
|
51
55
|
let lastError;
|
|
52
56
|
|
|
@@ -26,7 +26,7 @@ class GetDocumentsResponse extends AbstractResponse {
|
|
|
26
26
|
static createFromProto(proto) {
|
|
27
27
|
const { metadata, proof } = AbstractResponse.createMetadataAndProofFromProto(proto);
|
|
28
28
|
|
|
29
|
-
const documents = proto.getDocuments();
|
|
29
|
+
const documents = proto.getV0().getDocuments();
|
|
30
30
|
|
|
31
31
|
return new GetDocumentsResponse(
|
|
32
32
|
documents !== undefined
|
|
@@ -43,6 +43,7 @@ function getDocumentsFactory(grpcTransport) {
|
|
|
43
43
|
orderBySerialized = cbor.encode(orderBy);
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
+
const { GetDocumentsRequestV0 } = GetDocumentsRequest;
|
|
46
47
|
const getDocumentsRequest = new GetDocumentsRequest();
|
|
47
48
|
// need to convert Identifier to pure buffer as google protobuf doesn't support extended buffers
|
|
48
49
|
// https://github.com/protocolbuffers/protobuf/blob/master/js/binary/utils.js#L1049
|
|
@@ -55,14 +56,17 @@ function getDocumentsFactory(grpcTransport) {
|
|
|
55
56
|
contractId = Buffer.from(contractId);
|
|
56
57
|
}
|
|
57
58
|
|
|
58
|
-
getDocumentsRequest.
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
59
|
+
getDocumentsRequest.setV0(
|
|
60
|
+
new GetDocumentsRequestV0()
|
|
61
|
+
.setDataContractId(contractId)
|
|
62
|
+
.setDocumentType(type)
|
|
63
|
+
.setWhere(whereSerialized)
|
|
64
|
+
.setOrderBy(orderBySerialized)
|
|
65
|
+
.setLimit(limit)
|
|
66
|
+
.setStartAfter(startAfter)
|
|
67
|
+
.setStartAt(startAt)
|
|
68
|
+
.setProve(!!options.prove),
|
|
69
|
+
);
|
|
66
70
|
|
|
67
71
|
let lastError;
|
|
68
72
|
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
class EpochInfo {
|
|
2
|
+
/**
|
|
3
|
+
*
|
|
4
|
+
* @param {number} number
|
|
5
|
+
* @param {number} firstBlockHeight
|
|
6
|
+
* @param {number} firstCoreBlockHeight
|
|
7
|
+
* @param {number} startTime
|
|
8
|
+
* @param {number} feeMultiplier
|
|
9
|
+
*/
|
|
10
|
+
constructor(number, firstBlockHeight, firstCoreBlockHeight, startTime, feeMultiplier) {
|
|
11
|
+
this.number = number;
|
|
12
|
+
this.firstBlockHeight = firstBlockHeight;
|
|
13
|
+
this.firstCoreBlockHeight = firstCoreBlockHeight;
|
|
14
|
+
this.startTime = startTime;
|
|
15
|
+
this.feeMultiplier = feeMultiplier;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* @returns {number}
|
|
20
|
+
*/
|
|
21
|
+
getNumber() {
|
|
22
|
+
return this.number;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* @returns {number}
|
|
27
|
+
*/
|
|
28
|
+
getFirstBlockHeight() {
|
|
29
|
+
return this.firstBlockHeight;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* @returns {number}
|
|
34
|
+
*/
|
|
35
|
+
getFirstCoreBlockHeight() {
|
|
36
|
+
return this.firstCoreBlockHeight;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* @returns {number}
|
|
41
|
+
*/
|
|
42
|
+
getStartTime() {
|
|
43
|
+
return this.startTime;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* @returns {number}
|
|
48
|
+
*/
|
|
49
|
+
getFeeMultiplier() {
|
|
50
|
+
return this.feeMultiplier;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
module.exports = EpochInfo;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
const AbstractResponse = require('../response/AbstractResponse');
|
|
2
|
+
const EpochInfo = require('./EpochInfo');
|
|
3
|
+
const InvalidResponseError = require('../response/errors/InvalidResponseError');
|
|
4
|
+
|
|
5
|
+
class GetEpochsInfoResponse extends AbstractResponse {
|
|
6
|
+
/**
|
|
7
|
+
* @param {EpochInfo[]} epochsInfo
|
|
8
|
+
* @param {Metadata} metadata
|
|
9
|
+
* @param {Proof} [proof]
|
|
10
|
+
*/
|
|
11
|
+
constructor(epochsInfo, metadata, proof = undefined) {
|
|
12
|
+
super(metadata, proof);
|
|
13
|
+
|
|
14
|
+
this.epochsInfo = epochsInfo;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* @returns {EpochInfo[]}
|
|
19
|
+
*/
|
|
20
|
+
getEpochsInfo() {
|
|
21
|
+
return this.epochsInfo;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* @param proto
|
|
26
|
+
* @returns {GetEpochsInfoResponse}
|
|
27
|
+
*/
|
|
28
|
+
static createFromProto(proto) {
|
|
29
|
+
const epochs = proto.getV0().getEpochs();
|
|
30
|
+
const { metadata, proof } = AbstractResponse.createMetadataAndProofFromProto(
|
|
31
|
+
proto,
|
|
32
|
+
);
|
|
33
|
+
|
|
34
|
+
if (!epochs && !proof) {
|
|
35
|
+
throw new InvalidResponseError('Epochs are not defined');
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
let epochsInfo = [];
|
|
39
|
+
|
|
40
|
+
const epochsInfoList = epochs && epochs.getEpochInfosList();
|
|
41
|
+
if (epochsInfoList) {
|
|
42
|
+
epochsInfo = epochsInfoList.map((epoch) => new EpochInfo(
|
|
43
|
+
epoch.getNumber(),
|
|
44
|
+
epoch.getFirstBlockHeight(),
|
|
45
|
+
epoch.getFirstCoreBlockHeight(),
|
|
46
|
+
epoch.getStartTime(),
|
|
47
|
+
epoch.getFeeMultiplier(),
|
|
48
|
+
));
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return new GetEpochsInfoResponse(
|
|
52
|
+
epochsInfo,
|
|
53
|
+
metadata,
|
|
54
|
+
proof,
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
module.exports = GetEpochsInfoResponse;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
const {
|
|
2
|
+
v0: {
|
|
3
|
+
PlatformPromiseClient,
|
|
4
|
+
GetEpochsInfoRequest,
|
|
5
|
+
},
|
|
6
|
+
} = require('@dashevo/dapi-grpc');
|
|
7
|
+
|
|
8
|
+
const { UInt32Value } = require('google-protobuf/google/protobuf/wrappers_pb');
|
|
9
|
+
|
|
10
|
+
const GetEpochsInfoResponse = require('./GetEpochsInfoResponse');
|
|
11
|
+
const InvalidResponseError = require('../response/errors/InvalidResponseError');
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* @param {GrpcTransport} grpcTransport
|
|
15
|
+
* @returns {getEpochsInfo}
|
|
16
|
+
*/
|
|
17
|
+
function getEpochsInfoFactory(grpcTransport) {
|
|
18
|
+
/**
|
|
19
|
+
* Fetch the epoch info
|
|
20
|
+
*
|
|
21
|
+
* @typedef {getEpochsInfo}
|
|
22
|
+
* @param {number} startEpoch
|
|
23
|
+
* @param {number} count
|
|
24
|
+
* @param {DAPIClientOptions & {prove: boolean, ascending: boolean}} [options]
|
|
25
|
+
* @returns {Promise<GetEpochsInfoResponse>}
|
|
26
|
+
*/
|
|
27
|
+
async function getEpochsInfo(startEpoch, count, options = {}) {
|
|
28
|
+
const { GetEpochsInfoRequestV0 } = GetEpochsInfoRequest;
|
|
29
|
+
const getEpochInfosRequest = new GetEpochsInfoRequest();
|
|
30
|
+
getEpochInfosRequest.setV0(
|
|
31
|
+
new GetEpochsInfoRequestV0()
|
|
32
|
+
.setStartEpoch(new UInt32Value([startEpoch]))
|
|
33
|
+
.setCount(count)
|
|
34
|
+
.setAscending(!!options.ascending)
|
|
35
|
+
.setProve(!!options.prove),
|
|
36
|
+
);
|
|
37
|
+
|
|
38
|
+
let lastError;
|
|
39
|
+
|
|
40
|
+
// TODO: simple retry before the dapi versioning is properly implemented
|
|
41
|
+
for (let i = 0; i < 3; i += 1) {
|
|
42
|
+
try {
|
|
43
|
+
// eslint-disable-next-line no-await-in-loop
|
|
44
|
+
const getEpochsInfoResponse = await grpcTransport.request(
|
|
45
|
+
PlatformPromiseClient,
|
|
46
|
+
'getEpochsInfo',
|
|
47
|
+
getEpochInfosRequest,
|
|
48
|
+
options,
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
return GetEpochsInfoResponse.createFromProto(getEpochsInfoResponse);
|
|
52
|
+
} catch (e) {
|
|
53
|
+
if (e instanceof InvalidResponseError) {
|
|
54
|
+
lastError = e;
|
|
55
|
+
} else {
|
|
56
|
+
throw e;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// If we made it past the cycle it means that the retry didn't work,
|
|
62
|
+
// and we're throwing the last error encountered
|
|
63
|
+
throw lastError;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return getEpochsInfo;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
module.exports = getEpochsInfoFactory;
|
|
@@ -26,11 +26,17 @@ class GetIdentitiesByPublicKeyHashesResponse extends AbstractResponse {
|
|
|
26
26
|
static createFromProto(proto) {
|
|
27
27
|
const { metadata, proof } = AbstractResponse.createMetadataAndProofFromProto(proto);
|
|
28
28
|
|
|
29
|
-
const identitiesList = proto.getIdentities();
|
|
29
|
+
const identitiesList = proto.getV0().getIdentities();
|
|
30
30
|
|
|
31
31
|
return new GetIdentitiesByPublicKeyHashesResponse(
|
|
32
32
|
identitiesList !== undefined
|
|
33
|
-
? identitiesList.
|
|
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
|
+
: [],
|
|
34
40
|
metadata,
|
|
35
41
|
proof,
|
|
36
42
|
);
|
package/lib/methods/platform/getIdentitiesByPublicKeyHashes/getIdentitiesByPublicKeyHashesFactory.js
CHANGED
|
@@ -22,11 +22,14 @@ function getIdentitiesByPublicKeyHashesFactory(grpcTransport) {
|
|
|
22
22
|
* @returns {Promise<GetIdentitiesByPublicKeyHashesResponse>}
|
|
23
23
|
*/
|
|
24
24
|
async function getIdentitiesByPublicKeyHashes(publicKeyHashes, options = {}) {
|
|
25
|
+
const { GetIdentitiesByPublicKeyHashesRequestV0 } = GetIdentitiesByPublicKeyHashesRequest;
|
|
25
26
|
const getIdentitiesByPublicKeyHashesRequest = new GetIdentitiesByPublicKeyHashesRequest();
|
|
26
|
-
getIdentitiesByPublicKeyHashesRequest.
|
|
27
|
-
|
|
27
|
+
getIdentitiesByPublicKeyHashesRequest.setV0(
|
|
28
|
+
new GetIdentitiesByPublicKeyHashesRequestV0()
|
|
29
|
+
.setPublicKeyHashesList(
|
|
30
|
+
publicKeyHashes,
|
|
31
|
+
).setProve(!!options.prove),
|
|
28
32
|
);
|
|
29
|
-
getIdentitiesByPublicKeyHashesRequest.setProve(!!options.prove);
|
|
30
33
|
|
|
31
34
|
let lastError;
|
|
32
35
|
|
|
@@ -25,7 +25,7 @@ class GetIdentityResponse extends AbstractResponse {
|
|
|
25
25
|
* @returns {GetIdentityResponse}
|
|
26
26
|
*/
|
|
27
27
|
static createFromProto(proto) {
|
|
28
|
-
const identity = proto.getIdentity();
|
|
28
|
+
const identity = proto.getV0().getIdentity();
|
|
29
29
|
const { metadata, proof } = AbstractResponse.createMetadataAndProofFromProto(proto);
|
|
30
30
|
|
|
31
31
|
if (!identity && !proof) {
|
|
@@ -33,7 +33,7 @@ class GetIdentityResponse extends AbstractResponse {
|
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
return new GetIdentityResponse(
|
|
36
|
-
Buffer.from(proto.getIdentity()),
|
|
36
|
+
Buffer.from(proto.getV0().getIdentity()),
|
|
37
37
|
metadata,
|
|
38
38
|
proof,
|
|
39
39
|
);
|
|
@@ -22,6 +22,7 @@ function getIdentityFactory(grpcTransport) {
|
|
|
22
22
|
* @returns {Promise<GetIdentityResponse>}
|
|
23
23
|
*/
|
|
24
24
|
async function getIdentity(id, options = {}) {
|
|
25
|
+
const { GetIdentityRequestV0 } = GetIdentityRequest;
|
|
25
26
|
const getIdentityRequest = new GetIdentityRequest();
|
|
26
27
|
// need to convert objects inherited from Buffer to pure buffer as google protobuf
|
|
27
28
|
// doesn't support extended buffers
|
|
@@ -31,8 +32,11 @@ function getIdentityFactory(grpcTransport) {
|
|
|
31
32
|
id = Buffer.from(id);
|
|
32
33
|
}
|
|
33
34
|
|
|
34
|
-
getIdentityRequest.
|
|
35
|
-
|
|
35
|
+
getIdentityRequest.setV0(
|
|
36
|
+
new GetIdentityRequestV0()
|
|
37
|
+
.setId(id)
|
|
38
|
+
.setProve(!!options.prove),
|
|
39
|
+
);
|
|
36
40
|
|
|
37
41
|
let lastError;
|
|
38
42
|
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
const AbstractResponse = require('../response/AbstractResponse');
|
|
2
|
+
const VersionEntry = require('./VersionEntry');
|
|
3
|
+
const InvalidResponseError = require('../response/errors/InvalidResponseError');
|
|
4
|
+
|
|
5
|
+
class GetVersionUpgradeStateResponse extends AbstractResponse {
|
|
6
|
+
/**
|
|
7
|
+
* @param {VersionEntry[]} versionEntries
|
|
8
|
+
* @param {Metadata} metadata
|
|
9
|
+
* @param {Proof} [proof]
|
|
10
|
+
*/
|
|
11
|
+
constructor(versionEntries, metadata, proof = undefined) {
|
|
12
|
+
super(metadata, proof);
|
|
13
|
+
|
|
14
|
+
this.versionEntries = versionEntries;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* @returns {VersionEntry[]}
|
|
19
|
+
*/
|
|
20
|
+
getVersionEntries() {
|
|
21
|
+
return this.versionEntries;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* @param proto
|
|
26
|
+
* @returns {GetVersionUpgradeStateResponse}
|
|
27
|
+
*/
|
|
28
|
+
static createFromProto(proto) {
|
|
29
|
+
const versions = proto.getV0().getVersions();
|
|
30
|
+
const { metadata, proof } = AbstractResponse.createMetadataAndProofFromProto(
|
|
31
|
+
proto,
|
|
32
|
+
);
|
|
33
|
+
|
|
34
|
+
if (!versions && !proof) {
|
|
35
|
+
throw new InvalidResponseError('Version upgrade state is not defined');
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
let versionEntries = [];
|
|
39
|
+
|
|
40
|
+
const versionsList = versions && versions.getVersionsList();
|
|
41
|
+
if (versionsList) {
|
|
42
|
+
versionEntries = versionsList.map((versionSignal) => new VersionEntry(
|
|
43
|
+
versionSignal.getVersionNumber(),
|
|
44
|
+
versionSignal.getVoteCount(),
|
|
45
|
+
));
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return new GetVersionUpgradeStateResponse(
|
|
49
|
+
versionEntries,
|
|
50
|
+
metadata,
|
|
51
|
+
proof,
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
module.exports = GetVersionUpgradeStateResponse;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
class VersionEntry {
|
|
2
|
+
/**
|
|
3
|
+
* @param {number} versionNumber
|
|
4
|
+
* @param {number} voteCount
|
|
5
|
+
*/
|
|
6
|
+
constructor(versionNumber, voteCount) {
|
|
7
|
+
this.versionNumber = versionNumber;
|
|
8
|
+
this.voteCount = voteCount;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* @returns {number}
|
|
13
|
+
*/
|
|
14
|
+
getVersionNumber() {
|
|
15
|
+
return this.versionNumber;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* @returns {number}
|
|
20
|
+
*/
|
|
21
|
+
getVoteCount() {
|
|
22
|
+
return this.voteCount;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
module.exports = VersionEntry;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
const {
|
|
2
|
+
v0: {
|
|
3
|
+
PlatformPromiseClient,
|
|
4
|
+
GetVersionUpgradeStateRequest,
|
|
5
|
+
},
|
|
6
|
+
} = require('@dashevo/dapi-grpc');
|
|
7
|
+
|
|
8
|
+
const GetVersionUpgradeStateResponse = require('./GetVersionUpgradeStateResponse');
|
|
9
|
+
const InvalidResponseError = require('../response/errors/InvalidResponseError');
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* @param {GrpcTransport} grpcTransport
|
|
13
|
+
* @returns {getVersionUpgradeState}
|
|
14
|
+
*/
|
|
15
|
+
function getVersionUpgradeStateFactory(grpcTransport) {
|
|
16
|
+
/**
|
|
17
|
+
* Fetch the version upgrade state
|
|
18
|
+
*
|
|
19
|
+
* @typedef {getVersionUpgradeState}
|
|
20
|
+
* @param {DAPIClientOptions & {prove: boolean}} [options]
|
|
21
|
+
* @returns {Promise<GetVersionUpgradeStateResponse>}
|
|
22
|
+
*/
|
|
23
|
+
async function getVersionUpgradeState(options = {}) {
|
|
24
|
+
const { GetVersionUpgradeStateRequestV0 } = GetVersionUpgradeStateRequest;
|
|
25
|
+
const getVersionUpgradeStateRequest = new GetVersionUpgradeStateRequest();
|
|
26
|
+
getVersionUpgradeStateRequest.setV0(
|
|
27
|
+
new GetVersionUpgradeStateRequestV0()
|
|
28
|
+
.setProve(!!options.prove),
|
|
29
|
+
);
|
|
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 getVersionUpgradeStateResponse = await grpcTransport.request(
|
|
38
|
+
PlatformPromiseClient,
|
|
39
|
+
'getVersionUpgradeState',
|
|
40
|
+
getVersionUpgradeStateRequest,
|
|
41
|
+
options,
|
|
42
|
+
);
|
|
43
|
+
|
|
44
|
+
return GetVersionUpgradeStateResponse
|
|
45
|
+
.createFromProto(getVersionUpgradeStateResponse);
|
|
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 getVersionUpgradeState;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
module.exports = getVersionUpgradeStateFactory;
|
package/lib/methods/platform/getVersionUpgradeVoteStatus/GetVersionUpgradeVoteStatusResponse.js
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
const AbstractResponse = require('../response/AbstractResponse');
|
|
2
|
+
const VersionSignal = require('./VersionSignal');
|
|
3
|
+
const InvalidResponseError = require('../response/errors/InvalidResponseError');
|
|
4
|
+
|
|
5
|
+
class GetVersionUpgradeVoteStatusResponse extends AbstractResponse {
|
|
6
|
+
/**
|
|
7
|
+
* @param {VersionSignal[]} versionSignals
|
|
8
|
+
* @param {Metadata} metadata
|
|
9
|
+
* @param {Proof} [proof]
|
|
10
|
+
*/
|
|
11
|
+
constructor(versionSignals, metadata, proof = undefined) {
|
|
12
|
+
super(metadata, proof);
|
|
13
|
+
|
|
14
|
+
this.versionSignals = versionSignals;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* @returns {VersionSignal[]}
|
|
19
|
+
*/
|
|
20
|
+
getVersionSignals() {
|
|
21
|
+
return this.versionSignals;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* @param proto
|
|
26
|
+
* @returns {GetVersionUpgradeVoteStatusResponse}
|
|
27
|
+
*/
|
|
28
|
+
static createFromProto(proto) {
|
|
29
|
+
const versions = proto.getV0().getVersions();
|
|
30
|
+
const { metadata, proof } = AbstractResponse.createMetadataAndProofFromProto(
|
|
31
|
+
proto,
|
|
32
|
+
);
|
|
33
|
+
|
|
34
|
+
if (!versions && !proof) {
|
|
35
|
+
throw new InvalidResponseError('Version upgrade vote status is not defined');
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
let versionSignals = [];
|
|
39
|
+
|
|
40
|
+
const versionSignalsList = versions && versions.getVersionSignalsList();
|
|
41
|
+
if (versionSignalsList) {
|
|
42
|
+
versionSignals = versionSignalsList.map((versionSignal) => new VersionSignal(
|
|
43
|
+
Buffer.from(versionSignal.getProTxHash()).toString('hex'),
|
|
44
|
+
versionSignal.getVersion(),
|
|
45
|
+
));
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return new GetVersionUpgradeVoteStatusResponse(
|
|
49
|
+
versionSignals,
|
|
50
|
+
metadata,
|
|
51
|
+
proof,
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
module.exports = GetVersionUpgradeVoteStatusResponse;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
class VersionSignal {
|
|
2
|
+
/**
|
|
3
|
+
* @param {string} proTxHash
|
|
4
|
+
* @param {number} version
|
|
5
|
+
*/
|
|
6
|
+
constructor(proTxHash, version) {
|
|
7
|
+
this.proTxHash = proTxHash;
|
|
8
|
+
this.version = version;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* @returns {string}
|
|
13
|
+
*/
|
|
14
|
+
getProTxHash() {
|
|
15
|
+
return this.proTxHash;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* @returns {number}
|
|
20
|
+
*/
|
|
21
|
+
getVersion() {
|
|
22
|
+
return this.version;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
module.exports = VersionSignal;
|
package/lib/methods/platform/getVersionUpgradeVoteStatus/getVersionUpgradeVoteStatusFactory.js
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
const {
|
|
2
|
+
v0: {
|
|
3
|
+
PlatformPromiseClient,
|
|
4
|
+
GetVersionUpgradeVoteStatusRequest,
|
|
5
|
+
},
|
|
6
|
+
} = require('@dashevo/dapi-grpc');
|
|
7
|
+
|
|
8
|
+
const GetVersionUpgradeVoteStatusResponse = require('./GetVersionUpgradeVoteStatusResponse');
|
|
9
|
+
const InvalidResponseError = require('../response/errors/InvalidResponseError');
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* @param {GrpcTransport} grpcTransport
|
|
13
|
+
* @returns {getVersionUpgradeVoteStatus}
|
|
14
|
+
*/
|
|
15
|
+
function getVersionUpgradeVoteStatusFactory(grpcTransport) {
|
|
16
|
+
/**
|
|
17
|
+
* Fetch the version upgrade vote status
|
|
18
|
+
*
|
|
19
|
+
* @typedef {getVersionUpgradeVoteStatus}
|
|
20
|
+
* @param {string} startProTxHash
|
|
21
|
+
* @param {number} count
|
|
22
|
+
* @param {DAPIClientOptions & {prove: boolean}} [options]
|
|
23
|
+
* @returns {Promise<GetVersionUpgradeVoteStatusResponse>}
|
|
24
|
+
*/
|
|
25
|
+
async function getVersionUpgradeVoteStatus(startProTxHash, count, options = {}) {
|
|
26
|
+
const { GetVersionUpgradeVoteStatusRequestV0 } = GetVersionUpgradeVoteStatusRequest;
|
|
27
|
+
const getVersionUpgradeVoteStatusRequest = new GetVersionUpgradeVoteStatusRequest();
|
|
28
|
+
getVersionUpgradeVoteStatusRequest.setV0(
|
|
29
|
+
new GetVersionUpgradeVoteStatusRequestV0()
|
|
30
|
+
.setStartProTxHash(Buffer.from(startProTxHash, 'hex'))
|
|
31
|
+
.setCount(count)
|
|
32
|
+
.setProve(!!options.prove),
|
|
33
|
+
);
|
|
34
|
+
|
|
35
|
+
let lastError;
|
|
36
|
+
|
|
37
|
+
// TODO: simple retry before the dapi versioning is properly implemented
|
|
38
|
+
for (let i = 0; i < 3; i += 1) {
|
|
39
|
+
try {
|
|
40
|
+
// eslint-disable-next-line no-await-in-loop
|
|
41
|
+
const getVersionUpgradeVoteStatusResponse = await grpcTransport.request(
|
|
42
|
+
PlatformPromiseClient,
|
|
43
|
+
'getVersionUpgradeVoteStatus',
|
|
44
|
+
getVersionUpgradeVoteStatusRequest,
|
|
45
|
+
options,
|
|
46
|
+
);
|
|
47
|
+
|
|
48
|
+
return GetVersionUpgradeVoteStatusResponse
|
|
49
|
+
.createFromProto(getVersionUpgradeVoteStatusResponse);
|
|
50
|
+
} catch (e) {
|
|
51
|
+
if (e instanceof InvalidResponseError) {
|
|
52
|
+
lastError = e;
|
|
53
|
+
} else {
|
|
54
|
+
throw e;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// If we made it past the cycle it means that the retry didn't work,
|
|
60
|
+
// and we're throwing the last error encountered
|
|
61
|
+
throw lastError;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return getVersionUpgradeVoteStatus;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
module.exports = getVersionUpgradeVoteStatusFactory;
|
|
@@ -37,13 +37,13 @@ class AbstractResponse {
|
|
|
37
37
|
* @throws {InvalidResponseError}
|
|
38
38
|
*/
|
|
39
39
|
static createMetadataAndProofFromProto(proto) {
|
|
40
|
-
const metadata = proto.getMetadata();
|
|
40
|
+
const metadata = proto.getV0().getMetadata();
|
|
41
41
|
|
|
42
42
|
if (metadata === undefined) {
|
|
43
43
|
throw new InvalidResponseError('Metadata is not defined');
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
-
const rawProof = proto.getProof();
|
|
46
|
+
const rawProof = proto.getV0().getProof();
|
|
47
47
|
|
|
48
48
|
let proof;
|
|
49
49
|
if (rawProof) {
|
package/lib/methods/platform/waitForStateTransitionResult/WaitForStateTransitionResultResponse.js
CHANGED
|
@@ -32,25 +32,26 @@ class WaitForStateTransitionResultResponse extends AbstractResponse {
|
|
|
32
32
|
let error;
|
|
33
33
|
let proof;
|
|
34
34
|
|
|
35
|
-
if (proto.getProof()) {
|
|
36
|
-
proof = Proof.createFromProto(proto.getProof());
|
|
35
|
+
if (proto.getV0().getProof()) {
|
|
36
|
+
proof = Proof.createFromProto(proto.getV0().getProof());
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
-
if (proto.getError()) {
|
|
39
|
+
if (proto.getV0().getError()) {
|
|
40
40
|
let data;
|
|
41
|
-
const rawData = proto.getError().getData();
|
|
41
|
+
const rawData = proto.getV0().getError().getData();
|
|
42
42
|
if (rawData) {
|
|
43
43
|
data = cbor.decode(Buffer.from(rawData));
|
|
44
44
|
}
|
|
45
45
|
|
|
46
46
|
error = new ErrorResult(
|
|
47
|
-
proto.getError().getCode(),
|
|
48
|
-
proto.getError().getMessage(),
|
|
47
|
+
proto.getV0().getError().getCode(),
|
|
48
|
+
proto.getV0().getError().getMessage(),
|
|
49
49
|
data,
|
|
50
50
|
);
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
-
const metadata = proto.
|
|
53
|
+
const metadata = proto.getV0().getMetadata()
|
|
54
|
+
? new Metadata(proto.getV0().getMetadata().toObject()) : null;
|
|
54
55
|
|
|
55
56
|
return new WaitForStateTransitionResultResponse(
|
|
56
57
|
metadata,
|
package/lib/methods/platform/waitForStateTransitionResult/waitForStateTransitionResultFactory.js
CHANGED
|
@@ -31,10 +31,13 @@ function waitForStateTransitionResultFactory(grpcTransport) {
|
|
|
31
31
|
...options,
|
|
32
32
|
};
|
|
33
33
|
|
|
34
|
+
const { WaitForStateTransitionResultRequestV0 } = WaitForStateTransitionResultRequest;
|
|
34
35
|
const waitForStateTransitionResultRequest = new WaitForStateTransitionResultRequest();
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
36
|
+
waitForStateTransitionResultRequest.setV0(
|
|
37
|
+
new WaitForStateTransitionResultRequestV0()
|
|
38
|
+
.setStateTransitionHash(stateTransitionHash)
|
|
39
|
+
.setProve(options.prove),
|
|
40
|
+
);
|
|
38
41
|
|
|
39
42
|
let lastError;
|
|
40
43
|
|
package/lib/test/bootstrap.js
CHANGED
|
@@ -6,11 +6,16 @@ const sinon = require('sinon');
|
|
|
6
6
|
const sinonChai = require('sinon-chai');
|
|
7
7
|
const dirtyChai = require('dirty-chai');
|
|
8
8
|
const chaiAsPromised = require('chai-as-promised');
|
|
9
|
+
const { default: loadDpp } = require('@dashevo/wasm-dpp');
|
|
9
10
|
|
|
10
11
|
use(sinonChai);
|
|
11
12
|
use(chaiAsPromised);
|
|
12
13
|
use(dirtyChai);
|
|
13
14
|
|
|
15
|
+
before(async () => {
|
|
16
|
+
await loadDpp();
|
|
17
|
+
});
|
|
18
|
+
|
|
14
19
|
beforeEach(function beforeEach() {
|
|
15
20
|
if (!this.sinon) {
|
|
16
21
|
this.sinon = sinon.createSandbox();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dashevo/dapi-client",
|
|
3
|
-
"version": "0.25.
|
|
3
|
+
"version": "0.25.10",
|
|
4
4
|
"description": "Client library used to access Dash DAPI endpoints",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"contributors": [
|
|
@@ -26,12 +26,11 @@
|
|
|
26
26
|
}
|
|
27
27
|
],
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@dashevo/dapi-grpc": "0.25.
|
|
30
|
-
"@dashevo/dash-spv": "0.25.
|
|
31
|
-
"@dashevo/dashcore-lib": "~0.
|
|
32
|
-
"@dashevo/
|
|
33
|
-
"@dashevo/
|
|
34
|
-
"@dashevo/wasm-dpp": "0.25.8",
|
|
29
|
+
"@dashevo/dapi-grpc": "0.25.10",
|
|
30
|
+
"@dashevo/dash-spv": "0.25.10",
|
|
31
|
+
"@dashevo/dashcore-lib": "~0.21.0",
|
|
32
|
+
"@dashevo/grpc-common": "0.25.10",
|
|
33
|
+
"@dashevo/wasm-dpp": "0.25.10",
|
|
35
34
|
"bs58": "^4.0.1",
|
|
36
35
|
"cbor": "^8.0.0",
|
|
37
36
|
"google-protobuf": "^3.12.2",
|