@dashevo/dapi-client 1.0.2 → 1.1.0-dev.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.
@@ -0,0 +1,46 @@
1
+ const AbstractResponse = require('../response/AbstractResponse');
2
+ const InvalidResponseError = require('../response/errors/InvalidResponseError');
3
+
4
+ class GetTotalCreditsOnPlatformResponse extends AbstractResponse {
5
+ /**
6
+ * @param {number} totalCreditsOnPlatform
7
+ * @param {Metadata} metadata
8
+ * @param {Proof} [proof]
9
+ */
10
+ constructor(totalCreditsOnPlatform, metadata, proof = undefined) {
11
+ super(metadata, proof);
12
+
13
+ this.totalCreditsOnPlatform = totalCreditsOnPlatform;
14
+ }
15
+
16
+ /**
17
+ * @returns {number}
18
+ */
19
+ getTotalCreditsOnPlatform() {
20
+ return this.totalCreditsOnPlatform;
21
+ }
22
+
23
+ /**
24
+ * @param proto
25
+ * @returns {GetTotalCreditsOnPlatformResponse}
26
+ */
27
+ static createFromProto(proto) {
28
+ // eslint-disable-next-line
29
+ const totalCreditsOnPlatform = proto.getV0().getTotalCreditsOnPlatform();
30
+ const { metadata, proof } = AbstractResponse.createMetadataAndProofFromProto(
31
+ proto,
32
+ );
33
+
34
+ if ((typeof totalCreditsOnPlatform === 'undefined' || totalCreditsOnPlatform === null) && !proof) {
35
+ throw new InvalidResponseError('Total Credits on Platform data is not defined');
36
+ }
37
+
38
+ return new GetTotalCreditsOnPlatformResponse(
39
+ totalCreditsOnPlatform,
40
+ metadata,
41
+ proof,
42
+ );
43
+ }
44
+ }
45
+
46
+ module.exports = GetTotalCreditsOnPlatformResponse;
@@ -0,0 +1,67 @@
1
+ const {
2
+ v0: {
3
+ PlatformPromiseClient,
4
+ GetTotalCreditsOnPlatformRequest,
5
+ },
6
+ } = require('@dashevo/dapi-grpc');
7
+
8
+ const GetTotalCreditsOnPlatformResponse = require('./GetTotalCreditsOnPlatformResponse');
9
+ const InvalidResponseError = require('../response/errors/InvalidResponseError');
10
+
11
+ /**
12
+ * @param {GrpcTransport} grpcTransport
13
+ * @returns {getTotalCreditsOnPlatform}
14
+ */
15
+ function getTotalCreditsOnPlatformFactory(grpcTransport) {
16
+ /**
17
+ * Fetch the version upgrade votes status
18
+ * @typedef {getTotalCreditsOnPlatform}
19
+ * @param {DAPIClientOptions & {prove: boolean}} [options]
20
+ * @returns {Promise<GetTotalCreditsOnPlatformResponse>}
21
+ */
22
+ async function getTotalCreditsOnPlatform(options = {}) {
23
+ const {
24
+ GetTotalCreditsOnPlatformRequestV0,
25
+ } = GetTotalCreditsOnPlatformRequest;
26
+
27
+ // eslint-disable-next-line max-len
28
+ const getTotalCreditsOnPlatformRequest = new GetTotalCreditsOnPlatformRequest();
29
+
30
+ getTotalCreditsOnPlatformRequest.setV0(
31
+ new GetTotalCreditsOnPlatformRequestV0()
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 getTotalCreditsOnPlatformResponse = await grpcTransport.request(
42
+ PlatformPromiseClient,
43
+ 'getTotalCreditsOnPlatform',
44
+ getTotalCreditsOnPlatformRequest,
45
+ options,
46
+ );
47
+
48
+ return GetTotalCreditsOnPlatformResponse
49
+ .createFromProto(getTotalCreditsOnPlatformResponse);
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 getTotalCreditsOnPlatform;
65
+ }
66
+
67
+ module.exports = getTotalCreditsOnPlatformFactory;
@@ -24,7 +24,7 @@ function waitForStateTransitionResultFactory(grpcTransport) {
24
24
  // eslint-disable-next-line no-param-reassign
25
25
  options = {
26
26
  // Set default timeout
27
- timeout: 80000,
27
+ timeout: 120000,
28
28
  prove: false,
29
29
  retry: 0,
30
30
  throwDeadlineExceeded: true,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dashevo/dapi-client",
3
- "version": "1.0.2",
3
+ "version": "1.1.0-dev.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.2",
30
- "@dashevo/dash-spv": "2.0.2",
29
+ "@dashevo/dapi-grpc": "1.1.0-dev.1",
30
+ "@dashevo/dash-spv": "2.1.0-dev.1",
31
31
  "@dashevo/dashcore-lib": "~0.21.3",
32
- "@dashevo/grpc-common": "1.0.2",
33
- "@dashevo/wasm-dpp": "1.0.2",
32
+ "@dashevo/grpc-common": "1.1.0-dev.1",
33
+ "@dashevo/wasm-dpp": "1.1.0-dev.1",
34
34
  "bs58": "^4.0.1",
35
35
  "cbor": "^8.0.0",
36
36
  "google-protobuf": "^3.12.2",