@dashevo/dapi-grpc 0.24.0-dev.6 → 0.25.0-dev.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.
Files changed (32) hide show
  1. package/Cargo.toml +39 -0
  2. package/README.md +3 -3
  3. package/browser.js +13 -5
  4. package/build.rs +65 -0
  5. package/clients/core/v0/nodejs/CorePromiseClient.js +2 -1
  6. package/clients/core/v0/nodejs/core_protoc.js +33 -33
  7. package/clients/core/v0/rust/README.md +3 -0
  8. package/clients/core/v0/rust/core_example.rs +14 -0
  9. package/clients/core/v0/web/CorePromiseClient.js +159 -0
  10. package/clients/core/v0/web/core_pb.d.ts +783 -0
  11. package/clients/core/v0/web/core_pb.js +33 -33
  12. package/clients/core/v0/web/core_pb_service.d.ts +161 -0
  13. package/clients/core/v0/web/core_pb_service.js +317 -0
  14. package/clients/platform/v0/nodejs/PlatformPromiseClient.js +2 -1
  15. package/clients/platform/v0/nodejs/platform_pbjs.js +10012 -1472
  16. package/clients/platform/v0/nodejs/platform_protoc.js +6811 -1243
  17. package/clients/platform/v0/rust/README.md +3 -0
  18. package/clients/platform/v0/rust/platform_example.rs +15 -0
  19. package/clients/platform/v0/web/PlatformPromiseClient.js +130 -0
  20. package/clients/platform/v0/web/platform_pb.d.ts +1312 -0
  21. package/clients/platform/v0/web/platform_pb.js +6811 -1243
  22. package/clients/platform/v0/web/platform_pb_service.d.ts +272 -0
  23. package/clients/platform/v0/web/platform_pb_service.js +501 -0
  24. package/lib/utils/parseMetadata.js +27 -0
  25. package/node.js +4 -0
  26. package/package.json +15 -3
  27. package/protos/platform/v0/platform.proto +157 -8
  28. package/scripts/build.sh +85 -79
  29. package/scripts/patch-protobuf-js.sh +31 -0
  30. package/src/lib.rs +15 -0
  31. package/clients/core/v0/web/core_grpc_web_pb.js +0 -499
  32. package/clients/platform/v0/web/platform_grpc_web_pb.js +0 -509
package/Cargo.toml ADDED
@@ -0,0 +1,39 @@
1
+ [package]
2
+ name = "dapi-grpc"
3
+ description = "GRPC client for Dash Platform"
4
+ version = "0.25.0-dev.6"
5
+ authors = [
6
+ "Samuel Westrich <sam@dash.org>",
7
+ "Igor Markin <igor.markin@dash.org>",
8
+ "Łukasz Klimek <lukasz.klimek@dash.org>",
9
+ "Anton Suprunchuk <anton.suprunchuk@dash.org>",
10
+ "Ivan Shumkov <shumkov@dash.org>",
11
+ ]
12
+ edition = "2021"
13
+ license = "MIT"
14
+
15
+ [dependencies]
16
+ prost = { version = "0.11.9" }
17
+ prost-types = { version = "0.11.9" }
18
+
19
+ [build-dependencies]
20
+ prost-build = { version = "0.11" }
21
+
22
+ [features]
23
+ default = ["core", "platform"]
24
+ core = ["core_v0"]
25
+ platform = ["platform_v0"]
26
+
27
+ core_v0 = []
28
+ platform_v0 = []
29
+
30
+ [lib]
31
+
32
+ [[example]]
33
+ name = "core_example"
34
+ path = "clients/core/v0/rust/core_example.rs"
35
+
36
+
37
+ [[example]]
38
+ name = "platform_example"
39
+ path = "clients/platform/v0/rust/platform_example.rs"
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
  };
package/build.rs ADDED
@@ -0,0 +1,65 @@
1
+ use std::{
2
+ collections::HashMap,
3
+ fs::{create_dir_all, remove_dir_all},
4
+ path::PathBuf,
5
+ };
6
+
7
+ fn main() {
8
+ generate().expect("failed to compile protobuf definitions");
9
+
10
+ println!("cargo:rerun-if-changed=./protos");
11
+ println!("cargo:rerun-if-changed=./src/core/proto");
12
+ println!("cargo:rerun-if-changed=./src/platform/proto");
13
+ }
14
+
15
+ /// Generate Rust definitions from Protobuf definitions
16
+ pub fn generate() -> Result<(), std::io::Error> {
17
+ // Mapping between protobuf files => output directory
18
+ let mut input = HashMap::<PathBuf, PathBuf>::new();
19
+ input.insert(
20
+ PathBuf::from("protos/core/v0/core.proto"),
21
+ PathBuf::from("src/core/proto"),
22
+ );
23
+ input.insert(
24
+ PathBuf::from("protos/platform/v0/platform.proto"),
25
+ PathBuf::from("src/platform/proto"),
26
+ );
27
+
28
+ let proto_includes = vec![abs_path(&PathBuf::from("protos"))];
29
+
30
+ for (proto, dest) in input {
31
+ let proto = abs_path(&proto);
32
+ let dest = abs_path(&dest);
33
+ // Remove old compiled files; ignore errors
34
+ if dest.exists() {
35
+ remove_dir_all(&dest)?;
36
+ }
37
+ create_dir_all(&dest)?;
38
+
39
+ generate1(&[proto], &proto_includes, &dest)?;
40
+ }
41
+
42
+ Ok(())
43
+ }
44
+
45
+ /// Run single generation process.
46
+ ///
47
+ /// All paths must be absolute
48
+ fn generate1(
49
+ files: &[PathBuf],
50
+ proto_includes: &[PathBuf],
51
+ out_dir: &PathBuf,
52
+ ) -> Result<(), std::io::Error> {
53
+ let mut pb = prost_build::Config::new();
54
+ pb.out_dir(out_dir);
55
+ pb.format(true);
56
+ pb.compile_protos(files, proto_includes)
57
+ }
58
+
59
+ fn abs_path(path: &PathBuf) -> PathBuf {
60
+ if path.is_absolute() {
61
+ return path.to_owned();
62
+ }
63
+
64
+ PathBuf::from(env!("CARGO_MANIFEST_DIR")).join(path)
65
+ }
@@ -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,3 @@
1
+ # Rust bindings
2
+
3
+ Rust definitions can be found in [dapi-grpc/src](../../../../src/) directory.
@@ -0,0 +1,14 @@
1
+ use dapi_grpc::core::v0 as core;
2
+ use prost::Message;
3
+
4
+ fn main() {
5
+ let request = core::GetBlockRequest {
6
+ block: Some(core::get_block_request::Block::Height(123)),
7
+ };
8
+ let mut buffer = Vec::<u8>::new();
9
+ request.encode(&mut buffer).expect("failed to encode data");
10
+
11
+ let decoded = core::GetBlockRequest::decode(buffer.as_ref()).expect("failed to decode data");
12
+
13
+ assert_eq!(request, decoded);
14
+ }
@@ -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;