@dashevo/dapi-grpc 0.24.0-dev.3 → 0.24.0-dev.30

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 CHANGED
@@ -1,8 +1,8 @@
1
1
  # DAPI GRPC
2
2
 
3
- [![Build Status](https://github.com/dashevo/platform/actions/workflows/release.yml/badge.svg)](https://github.com/dashevo/platform/actions/workflows/release.yml)
3
+ [![Build Status](https://github.com/dashpay/platform/actions/workflows/release.yml/badge.svg)](https://github.com/dashpay/platform/actions/workflows/release.yml)
4
4
  [![NPM version](https://img.shields.io/npm/v/@dashevo/dapi-grpc.svg)](https://npmjs.org/package/@dashevo/dapi-grpc)
5
- [![Release Date](https://img.shields.io/github/release-date/dashevo/platform)](https://github.com/dashevo/platform/releases/latest)
5
+ [![Release Date](https://img.shields.io/github/release-date/dashpay/platform)](https://github.com/dashpay/platform/releases/latest)
6
6
  [![license](https://img.shields.io/github/license/dashevo/dapi-grpc.svg)](LICENSE)
7
7
 
8
8
  Decentralized API GRPC definition files and generated clients
@@ -135,7 +135,7 @@ Available methods :
135
135
 
136
136
  ## Contributing
137
137
 
138
- Feel free to dive in! [Open an issue](https://github.com/dashevo/platform/issues/new/choose) or submit PRs.
138
+ Feel free to dive in! [Open an issue](https://github.com/dashpay/platform/issues/new/choose) or submit PRs.
139
139
 
140
140
  ## License
141
141
 
package/browser.js CHANGED
@@ -1,10 +1,18 @@
1
- const core = require('./clients/core/v0/web/core_grpc_web_pb');
2
- const platform = require('./clients/platform/v0/web/platform_grpc_web_pb');
1
+ const { grpc: { Metadata } } = require('@improbable-eng/grpc-web');
2
+ const CorePromiseClient = require('./clients/core/v0/web/CorePromiseClient');
3
+ const PlatformPromiseClient = require('./clients/platform/v0/web/PlatformPromiseClient');
4
+
5
+ const coreMessages = require('./clients/core/v0/web/core_pb');
6
+ const platformMessages = require('./clients/platform/v0/web/platform_pb');
7
+ const parseMetadata = require('./lib/utils/parseMetadata');
3
8
 
4
9
  module.exports = {
5
10
  v0: {
6
-
7
- ...core,
8
- ...platform,
11
+ ...coreMessages,
12
+ ...platformMessages,
13
+ CorePromiseClient,
14
+ PlatformPromiseClient,
9
15
  },
16
+ parseMetadata,
17
+ Metadata,
10
18
  };
@@ -73,8 +73,9 @@ class CorePromiseClient {
73
73
  const url = new URL(hostname);
74
74
  const { protocol, host: strippedHostname } = url;
75
75
 
76
+ // See this issue https://github.com/nodejs/node/issues/3176
76
77
  // eslint-disable-next-line no-param-reassign
77
- credentials = protocol === 'https' ? grpc.credentials.createSsl() : grpc.credentials.createInsecure();
78
+ credentials = protocol.replace(':', '') === 'https' ? grpc.credentials.createSsl() : grpc.credentials.createInsecure();
78
79
 
79
80
  this.client = new CoreNodeJSClient(strippedHostname, credentials, options);
80
81
 
@@ -13,39 +13,39 @@
13
13
 
14
14
  var jspb = require('google-protobuf');
15
15
  var goog = jspb;
16
- var global = Function('return this')();
17
-
18
- goog.exportSymbol('proto.org.dash.platform.dapi.v0.BlockHeaders', null, global);
19
- goog.exportSymbol('proto.org.dash.platform.dapi.v0.BlockHeadersWithChainLocksRequest', null, global);
20
- goog.exportSymbol('proto.org.dash.platform.dapi.v0.BlockHeadersWithChainLocksRequest.FromBlockCase', null, global);
21
- goog.exportSymbol('proto.org.dash.platform.dapi.v0.BlockHeadersWithChainLocksResponse', null, global);
22
- goog.exportSymbol('proto.org.dash.platform.dapi.v0.BlockHeadersWithChainLocksResponse.ResponsesCase', null, global);
23
- goog.exportSymbol('proto.org.dash.platform.dapi.v0.BloomFilter', null, global);
24
- goog.exportSymbol('proto.org.dash.platform.dapi.v0.BroadcastTransactionRequest', null, global);
25
- goog.exportSymbol('proto.org.dash.platform.dapi.v0.BroadcastTransactionResponse', null, global);
26
- goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetBlockRequest', null, global);
27
- goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetBlockRequest.BlockCase', null, global);
28
- goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetBlockResponse', null, global);
29
- goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEstimatedTransactionFeeRequest', null, global);
30
- goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEstimatedTransactionFeeResponse', null, global);
31
- goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetStatusRequest', null, global);
32
- goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetStatusResponse', null, global);
33
- goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetStatusResponse.Chain', null, global);
34
- goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetStatusResponse.Masternode', null, global);
35
- goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetStatusResponse.Masternode.Status', null, global);
36
- goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetStatusResponse.Network', null, global);
37
- goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetStatusResponse.NetworkFee', null, global);
38
- goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetStatusResponse.Status', null, global);
39
- goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetStatusResponse.Time', null, global);
40
- goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetStatusResponse.Version', null, global);
41
- goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTransactionRequest', null, global);
42
- goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTransactionResponse', null, global);
43
- goog.exportSymbol('proto.org.dash.platform.dapi.v0.InstantSendLockMessages', null, global);
44
- goog.exportSymbol('proto.org.dash.platform.dapi.v0.RawTransactions', null, global);
45
- goog.exportSymbol('proto.org.dash.platform.dapi.v0.TransactionsWithProofsRequest', null, global);
46
- goog.exportSymbol('proto.org.dash.platform.dapi.v0.TransactionsWithProofsRequest.FromBlockCase', null, global);
47
- goog.exportSymbol('proto.org.dash.platform.dapi.v0.TransactionsWithProofsResponse', null, global);
48
- goog.exportSymbol('proto.org.dash.platform.dapi.v0.TransactionsWithProofsResponse.ResponsesCase', null, global);
16
+ const proto = {};
17
+
18
+ goog.exportSymbol('proto.org.dash.platform.dapi.v0.BlockHeaders', null, { proto });
19
+ goog.exportSymbol('proto.org.dash.platform.dapi.v0.BlockHeadersWithChainLocksRequest', null, { proto });
20
+ goog.exportSymbol('proto.org.dash.platform.dapi.v0.BlockHeadersWithChainLocksRequest.FromBlockCase', null, { proto });
21
+ goog.exportSymbol('proto.org.dash.platform.dapi.v0.BlockHeadersWithChainLocksResponse', null, { proto });
22
+ goog.exportSymbol('proto.org.dash.platform.dapi.v0.BlockHeadersWithChainLocksResponse.ResponsesCase', null, { proto });
23
+ goog.exportSymbol('proto.org.dash.platform.dapi.v0.BloomFilter', null, { proto });
24
+ goog.exportSymbol('proto.org.dash.platform.dapi.v0.BroadcastTransactionRequest', null, { proto });
25
+ goog.exportSymbol('proto.org.dash.platform.dapi.v0.BroadcastTransactionResponse', null, { proto });
26
+ goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetBlockRequest', null, { proto });
27
+ goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetBlockRequest.BlockCase', null, { proto });
28
+ goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetBlockResponse', null, { proto });
29
+ goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEstimatedTransactionFeeRequest', null, { proto });
30
+ goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetEstimatedTransactionFeeResponse', null, { proto });
31
+ goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetStatusRequest', null, { proto });
32
+ goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetStatusResponse', null, { proto });
33
+ goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetStatusResponse.Chain', null, { proto });
34
+ goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetStatusResponse.Masternode', null, { proto });
35
+ goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetStatusResponse.Masternode.Status', null, { proto });
36
+ goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetStatusResponse.Network', null, { proto });
37
+ goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetStatusResponse.NetworkFee', null, { proto });
38
+ goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetStatusResponse.Status', null, { proto });
39
+ goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetStatusResponse.Time', null, { proto });
40
+ goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetStatusResponse.Version', null, { proto });
41
+ goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTransactionRequest', null, { proto });
42
+ goog.exportSymbol('proto.org.dash.platform.dapi.v0.GetTransactionResponse', null, { proto });
43
+ goog.exportSymbol('proto.org.dash.platform.dapi.v0.InstantSendLockMessages', null, { proto });
44
+ goog.exportSymbol('proto.org.dash.platform.dapi.v0.RawTransactions', null, { proto });
45
+ goog.exportSymbol('proto.org.dash.platform.dapi.v0.TransactionsWithProofsRequest', null, { proto });
46
+ goog.exportSymbol('proto.org.dash.platform.dapi.v0.TransactionsWithProofsRequest.FromBlockCase', null, { proto });
47
+ goog.exportSymbol('proto.org.dash.platform.dapi.v0.TransactionsWithProofsResponse', null, { proto });
48
+ goog.exportSymbol('proto.org.dash.platform.dapi.v0.TransactionsWithProofsResponse.ResponsesCase', null, { proto });
49
49
  /**
50
50
  * Generated by JsPbCodeGenerator.
51
51
  * @param {Array=} opt_data Optional initial data array, typically from a
@@ -0,0 +1,159 @@
1
+ const { promisify } = require('util');
2
+ const GrpcError = require('@dashevo/grpc-common/lib/server/error/GrpcError');
3
+
4
+ const { CoreClient } = require('./core_pb_service');
5
+
6
+ /**
7
+ * Function rewires @imporbable-eng/grpc-web stream
8
+ * to comply with the EventEmitter interface
9
+ * @param stream
10
+ * @return {!grpc.web.ClientReadableStream}
11
+ */
12
+ const rewireStream = (stream) => {
13
+ const defaultOnFunction = stream.on.bind(stream);
14
+
15
+ // Rewire default on function to comply with EventEmitter interface
16
+ stream.on = ((type, handler) => {
17
+ if (type === 'error') { // Handle `error` event using `end` event
18
+ return stream.on('end', (payload) => {
19
+ if (payload) {
20
+ const { code, details, metadata } = payload;
21
+ if (code !== 0) {
22
+ const error = new GrpcError(code, details);
23
+ // It is important to assign metadata to the error object
24
+ // instead of passing it as GrpcError constructor argument
25
+ // Otherwise it will be converted to grpc-js metadata
26
+ // Which is not compatible with web
27
+ error.metadata = metadata;
28
+ handler(error);
29
+ }
30
+ }
31
+ });
32
+ } else {
33
+ // `data` event could be processed normally
34
+ return defaultOnFunction(type, handler);
35
+ }
36
+ });
37
+
38
+ // Assign an empty function to `once` method
39
+ // because @imporbable-eng/grpc-web doesn't expose it and
40
+ // stream cancellation detaches all handlers internally
41
+ stream.removeListener = () => {}
42
+ }
43
+
44
+ class CorePromiseClient {
45
+ /**
46
+ * @param {string} hostname
47
+ * @param {?Object} credentials
48
+ * @param {?Object} options
49
+ */
50
+ constructor(hostname, credentials , options = {}) {
51
+ this.client = new CoreClient(hostname, options)
52
+ }
53
+
54
+ /**
55
+ * @param {!GetStatusRequest} getStatusRequest
56
+ * @param {?Object<string, string>} metadata
57
+ * @return {Promise<!GetStatusResponse>}
58
+ */
59
+ getStatus(getStatusRequest, metadata = {}) {
60
+ return promisify(
61
+ this.client.getStatus.bind(this.client),
62
+ )(
63
+ getStatusRequest,
64
+ metadata,
65
+ );
66
+ }
67
+
68
+ /**
69
+ * @param {!GetBlockRequest} getBlockRequest
70
+ * @param {?Object<string, string>} metadata
71
+ * @return {Promise<!GetBlockResponse>}
72
+ */
73
+ getBlock(getBlockRequest, metadata = {}) {
74
+ return promisify(
75
+ this.client.getBlock.bind(this.client),
76
+ )(
77
+ getBlockRequest,
78
+ metadata,
79
+ );
80
+ }
81
+
82
+ /**
83
+ * @param {!BroadcastTransactionRequest} broadcastTransactionRequest
84
+ * @param {?Object<string, string>} metadata
85
+ * @return {Promise<!BroadcastTransactionResponse>}
86
+ */
87
+ broadcastTransaction(broadcastTransactionRequest, metadata = {}) {
88
+ return promisify(
89
+ this.client.broadcastTransaction.bind(this.client),
90
+ )(
91
+ broadcastTransactionRequest,
92
+ metadata,
93
+ );
94
+ }
95
+
96
+ /**
97
+ * @param {!GetTransactionRequest} getTransactionRequest
98
+ * @param {?Object<string, string>} metadata
99
+ * @return {Promise<!GetTransactionResponse>}
100
+ */
101
+ getTransaction(getTransactionRequest, metadata = {}) {
102
+ return promisify(
103
+ this.client.getTransaction.bind(this.client),
104
+ )(
105
+ getTransactionRequest,
106
+ metadata,
107
+ );
108
+ }
109
+
110
+ /**
111
+ * @param {!GetEstimatedTransactionFeeRequest} getEstimatedTransactionFeeRequest
112
+ * @param {?Object<string, string>} metadata
113
+ * @returns {Promise<!GetEstimatedTransactionFeeResponse>}
114
+ */
115
+ getEstimatedTransactionFee(getEstimatedTransactionFeeRequest, metadata = {}) {
116
+ return promisify(
117
+ this.client.getEstimatedTransactionFee.bind(this.client),
118
+ )(
119
+ getEstimatedTransactionFeeRequest,
120
+ metadata,
121
+ );
122
+ }
123
+
124
+ /**
125
+ * @param {!BlockHeadersWithChainLocksRequest} blockHeadersWithChainLocksRequest
126
+ * @param {?Object<string, string>} metadata
127
+ * @return {!grpc.web.ClientReadableStream<!BlockHeadersWithChainLocksResponse>|undefined}
128
+ */
129
+ subscribeToBlockHeadersWithChainLocks(
130
+ blockHeadersWithChainLocksRequest,
131
+ metadata = {},
132
+ ) {
133
+ const stream = this.client.subscribeToBlockHeadersWithChainLocks(
134
+ blockHeadersWithChainLocksRequest,
135
+ metadata,
136
+ )
137
+
138
+ rewireStream(stream);
139
+
140
+ return stream;
141
+ }
142
+
143
+ /**
144
+ * @param {TransactionsWithProofsRequest} transactionsWithProofsRequest The request proto
145
+ * @param {?Object<string, string>} metadata User defined call metadata
146
+ * @return {!grpc.web.ClientReadableStream<!TransactionsWithProofsResponse>|undefined}
147
+ */
148
+ subscribeToTransactionsWithProofs(transactionsWithProofsRequest, metadata = {}) {
149
+ const stream = this.client.subscribeToTransactionsWithProofs(
150
+ transactionsWithProofsRequest,
151
+ metadata
152
+ )
153
+
154
+ rewireStream(stream);
155
+ return stream;
156
+ }
157
+ }
158
+
159
+ module.exports = CorePromiseClient;