@dashevo/dapi-client 1.1.0-pr.1713.2 → 1.1.0-pr.2012.3
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 +2 -0
- package/lib/methods/platform/getTotalCreditsInPlatform/GetTotalCreditsInPlatformResponse.js +46 -0
- package/lib/methods/platform/getTotalCreditsInPlatform/getTotalCreditsInPlatformFactory.js +67 -0
- package/lib/methods/platform/waitForStateTransitionResult/waitForStateTransitionResultFactory.js +1 -1
- package/package.json +5 -5
|
@@ -13,6 +13,7 @@ const getProtocolVersionUpgradeStateFactory = require('./getProtocolVersionUpgra
|
|
|
13
13
|
const getIdentityContractNonceFactory = require('./getIdentityContractNonce/getIdentityContractNonceFactory');
|
|
14
14
|
const getIdentityNonceFactory = require('./getIdentityNonce/getIdentityNonceFactory');
|
|
15
15
|
const getIdentityKeysFactory = require('./getIdentityKeys/getIdentityKeysFactory');
|
|
16
|
+
const getTotalCreditsInPlatformFactory = require('./getTotalCreditsInPlatform/getTotalCreditsInPlatformFactory');
|
|
16
17
|
|
|
17
18
|
class PlatformMethodsFacade {
|
|
18
19
|
/**
|
|
@@ -36,6 +37,7 @@ class PlatformMethodsFacade {
|
|
|
36
37
|
this.getIdentityContractNonce = getIdentityContractNonceFactory(grpcTransport);
|
|
37
38
|
this.getIdentityNonce = getIdentityNonceFactory(grpcTransport);
|
|
38
39
|
this.getIdentityKeys = getIdentityKeysFactory(grpcTransport);
|
|
40
|
+
this.getTotalCreditsInPlatform = getTotalCreditsInPlatformFactory(grpcTransport);
|
|
39
41
|
}
|
|
40
42
|
}
|
|
41
43
|
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
const AbstractResponse = require('../response/AbstractResponse');
|
|
2
|
+
const InvalidResponseError = require('../response/errors/InvalidResponseError');
|
|
3
|
+
|
|
4
|
+
class GetTotalCreditsInPlatformResponse extends AbstractResponse {
|
|
5
|
+
/**
|
|
6
|
+
* @param {number} totalCreditsInPlatform
|
|
7
|
+
* @param {Metadata} metadata
|
|
8
|
+
* @param {Proof} [proof]
|
|
9
|
+
*/
|
|
10
|
+
constructor(totalCreditsInPlatform, metadata, proof = undefined) {
|
|
11
|
+
super(metadata, proof);
|
|
12
|
+
|
|
13
|
+
this.totalCreditsInPlatform = totalCreditsInPlatform;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* @returns {number}
|
|
18
|
+
*/
|
|
19
|
+
getTotalCreditsInPlatform() {
|
|
20
|
+
return this.totalCreditsInPlatform;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* @param proto
|
|
25
|
+
* @returns {GetTotalCreditsInPlatformResponse}
|
|
26
|
+
*/
|
|
27
|
+
static createFromProto(proto) {
|
|
28
|
+
// eslint-disable-next-line
|
|
29
|
+
const totalCreditsInPlatform = proto.getV0().getCredits();
|
|
30
|
+
const { metadata, proof } = AbstractResponse.createMetadataAndProofFromProto(
|
|
31
|
+
proto,
|
|
32
|
+
);
|
|
33
|
+
|
|
34
|
+
if ((typeof totalCreditsInPlatform === 'undefined' || totalCreditsInPlatform === null) && !proof) {
|
|
35
|
+
throw new InvalidResponseError('Total Credits on Platform data is not defined');
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return new GetTotalCreditsInPlatformResponse(
|
|
39
|
+
totalCreditsInPlatform,
|
|
40
|
+
metadata,
|
|
41
|
+
proof,
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
module.exports = GetTotalCreditsInPlatformResponse;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
const {
|
|
2
|
+
v0: {
|
|
3
|
+
PlatformPromiseClient,
|
|
4
|
+
GetTotalCreditsInPlatformRequest,
|
|
5
|
+
},
|
|
6
|
+
} = require('@dashevo/dapi-grpc');
|
|
7
|
+
|
|
8
|
+
const GetTotalCreditsInPlatformResponse = require('./GetTotalCreditsInPlatformResponse');
|
|
9
|
+
const InvalidResponseError = require('../response/errors/InvalidResponseError');
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* @param {GrpcTransport} grpcTransport
|
|
13
|
+
* @returns {getTotalCreditsInPlatform}
|
|
14
|
+
*/
|
|
15
|
+
function getTotalCreditsInPlatformFactory(grpcTransport) {
|
|
16
|
+
/**
|
|
17
|
+
* Fetch the version upgrade votes status
|
|
18
|
+
* @typedef {getTotalCreditsInPlatform}
|
|
19
|
+
* @param {DAPIClientOptions & {prove: boolean}} [options]
|
|
20
|
+
* @returns {Promise<GetTotalCreditsInPlatformResponse>}
|
|
21
|
+
*/
|
|
22
|
+
async function getTotalCreditsInPlatform(options = {}) {
|
|
23
|
+
const {
|
|
24
|
+
GetTotalCreditsInPlatformRequestV0,
|
|
25
|
+
} = GetTotalCreditsInPlatformRequest;
|
|
26
|
+
|
|
27
|
+
// eslint-disable-next-line max-len
|
|
28
|
+
const getTotalCreditsInPlatformRequest = new GetTotalCreditsInPlatformRequest();
|
|
29
|
+
|
|
30
|
+
getTotalCreditsInPlatformRequest.setV0(
|
|
31
|
+
new GetTotalCreditsInPlatformRequestV0()
|
|
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 getTotalCreditsInPlatformResponse = await grpcTransport.request(
|
|
42
|
+
PlatformPromiseClient,
|
|
43
|
+
'getTotalCreditsInPlatform',
|
|
44
|
+
getTotalCreditsInPlatformRequest,
|
|
45
|
+
options,
|
|
46
|
+
);
|
|
47
|
+
|
|
48
|
+
return GetTotalCreditsInPlatformResponse
|
|
49
|
+
.createFromProto(getTotalCreditsInPlatformResponse);
|
|
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 getTotalCreditsInPlatform;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
module.exports = getTotalCreditsInPlatformFactory;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dashevo/dapi-client",
|
|
3
|
-
"version": "1.1.0-pr.
|
|
3
|
+
"version": "1.1.0-pr.2012.3",
|
|
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.1.0-pr.
|
|
30
|
-
"@dashevo/dash-spv": "2.1.0-
|
|
29
|
+
"@dashevo/dapi-grpc": "1.1.0-pr.2012.3",
|
|
30
|
+
"@dashevo/dash-spv": "2.1.0-dev.1",
|
|
31
31
|
"@dashevo/dashcore-lib": "~0.21.3",
|
|
32
|
-
"@dashevo/grpc-common": "1.1.0-pr.
|
|
33
|
-
"@dashevo/wasm-dpp": "1.1.0-pr.
|
|
32
|
+
"@dashevo/grpc-common": "1.1.0-pr.2012.3",
|
|
33
|
+
"@dashevo/wasm-dpp": "1.1.0-pr.2012.3",
|
|
34
34
|
"bs58": "^4.0.1",
|
|
35
35
|
"cbor": "^8.0.0",
|
|
36
36
|
"google-protobuf": "^3.12.2",
|