@dashevo/dapi-grpc 1.0.0-pr.1902.1 → 1.0.0-pr.1935.A

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/Cargo.toml CHANGED
@@ -1,7 +1,7 @@
1
1
  [package]
2
2
  name = "dapi-grpc"
3
3
  description = "GRPC client for Dash Platform"
4
- version = "1.0.0-pr.1902.1"
4
+ version = "1.0.0-pr.1935.A"
5
5
  authors = [
6
6
  "Samuel Westrich <sam@dash.org>",
7
7
  "Igor Markin <igor.markin@dash.org>",
@@ -14,10 +14,7 @@ rust-version = "1.76"
14
14
  license = "MIT"
15
15
 
16
16
  [features]
17
- # Enable all features by default, otherwise different crates
18
- # triggier bulding proto with different feature set that overwrites
19
- # previous results and causes build errors
20
- default = ["core", "platform", "client", "serde", "server"]
17
+ default = ["core", "platform", "client"]
21
18
  core = []
22
19
  platform = []
23
20
  # Re-export Dash Platform protobuf types as `dapi_grpc::platform::proto`
@@ -33,7 +30,7 @@ client = [
33
30
  ]
34
31
  server = ["tonic/channel", "tonic/transport", "platform"]
35
32
  serde = ["dep:serde", "dep:serde_bytes"]
36
- mocks = ["dep:serde_json"]
33
+ mocks = ["serde", "dep:serde_json"]
37
34
 
38
35
  [dependencies]
39
36
  prost = { version = "0.12.3" }
@@ -45,7 +42,7 @@ tonic = { version = "0.11", features = [
45
42
  serde = { version = "1.0.197", optional = true, features = ["derive"] }
46
43
  serde_bytes = { version = "0.11.12", optional = true }
47
44
  serde_json = { version = "1.0", optional = true }
48
- tenderdash-proto = { git = "https://github.com/dashpay/rs-tenderdash-abci", version = "0.14.0-dev.12", default-features = false }
45
+ tenderdash-proto = { git = "https://github.com/dashpay/rs-tenderdash-abci", version = "1.0.0", tag = "v1.0.0", default-features = false }
49
46
  dapi-grpc-macros = { path = "../rs-dapi-grpc-macros" }
50
47
  platform-version = { path = "../rs-platform-version" }
51
48
 
@@ -64,4 +61,9 @@ name = "platform_example"
64
61
  path = "clients/platform/v0/rust/platform_example.rs"
65
62
 
66
63
  [package.metadata.cargo-machete]
67
- ignored = ["platform-version", "serde_bytes", "futures-core"]
64
+ ignored = [
65
+ "platform-version",
66
+ "serde_bytes",
67
+ "futures-core",
68
+ "dapi-grpc-macros",
69
+ ]
package/build.rs CHANGED
@@ -1,14 +1,21 @@
1
1
  use std::{
2
2
  fs::{create_dir_all, remove_dir_all},
3
3
  path::PathBuf,
4
+ process::exit,
4
5
  };
5
6
 
6
7
  use tonic_build::Builder;
7
8
 
9
+ const SERDE_WITH_BYTES: &str = r#"#[cfg_attr(feature = "serde", serde(with = "serde_bytes"))]"#;
10
+ const SERDE_WITH_BASE64: &str =
11
+ r#"#[cfg_attr(feature = "serde", serde(with = "crate::deserialization::vec_base64string"))]"#;
12
+ const SERDE_WITH_STRING: &str =
13
+ r#"#[cfg_attr(feature = "serde", serde(with = "crate::deserialization::from_to_string"))]"#;
14
+
8
15
  fn main() {
9
16
  let core = MappingConfig::new(
10
17
  PathBuf::from("protos/core/v0/core.proto"),
11
- PathBuf::from("src/core/proto"),
18
+ PathBuf::from("src/core"),
12
19
  );
13
20
 
14
21
  configure_core(core)
@@ -17,7 +24,7 @@ fn main() {
17
24
 
18
25
  let platform = MappingConfig::new(
19
26
  PathBuf::from("protos/platform/v0/platform.proto"),
20
- PathBuf::from("src/platform/proto"),
27
+ PathBuf::from("src/platform"),
21
28
  );
22
29
 
23
30
  configure_platform(platform)
@@ -106,73 +113,83 @@ fn configure_platform(mut platform: MappingConfig) -> MappingConfig {
106
113
  }
107
114
 
108
115
  // All messages can be mocked.
109
- platform = platform.message_attribute(".", r#"#[derive( ::dapi_grpc_macros::Mockable)]"#);
116
+ let platform = platform.message_attribute(".", r#"#[derive( ::dapi_grpc_macros::Mockable)]"#);
110
117
 
111
- #[cfg(feature = "serde")]
112
118
  let platform = platform
113
119
  .type_attribute(
114
120
  ".",
115
- r#"#[derive(::serde::Serialize, ::serde::Deserialize)]"#,
116
- )
117
- .type_attribute(".", r#"#[serde(rename_all = "snake_case")]"#)
118
- .field_attribute("id", r#"#[serde(with = "serde_bytes")]"#)
119
- .field_attribute("identity_id", r#"#[serde(with = "serde_bytes")]"#)
120
- .field_attribute(
121
- "ids",
122
- r#"#[serde(with = "crate::deserialization::vec_base64string")]"#,
123
- )
124
- .field_attribute(
125
- "ResponseMetadata.height",
126
- r#"#[serde(with = "crate::deserialization::from_to_string")]"#,
127
- )
128
- .field_attribute(
129
- "ResponseMetadata.time_ms",
130
- r#"#[serde(with = "crate::deserialization::from_to_string")]"#,
121
+ r#"#[cfg_attr(feature = "serde", derive(::serde::Serialize, ::serde::Deserialize))]"#,
131
122
  )
132
- .field_attribute(
133
- "start_at_ms",
134
- r#"#[serde(with = "crate::deserialization::from_to_string")]"#,
135
- )
136
- .field_attribute("public_key_hash", r#"#[serde(with = "serde_bytes")]"#)
137
- .field_attribute(
138
- "public_key_hashes",
139
- r#"#[serde(with = "crate::deserialization::vec_base64string")]"#,
123
+ .type_attribute(
124
+ ".",
125
+ r#"#[cfg_attr(feature = "serde", serde(rename_all = "snake_case"))]"#,
140
126
  )
127
+ .field_attribute("id", SERDE_WITH_BYTES)
128
+ .field_attribute("identity_id", SERDE_WITH_BYTES)
129
+ .field_attribute("ids", SERDE_WITH_BASE64)
130
+ .field_attribute("ResponseMetadata.height", SERDE_WITH_STRING)
131
+ .field_attribute("ResponseMetadata.time_ms", SERDE_WITH_STRING)
132
+ .field_attribute("start_at_ms", SERDE_WITH_STRING)
133
+ .field_attribute("public_key_hash", SERDE_WITH_BYTES)
134
+ .field_attribute("public_key_hashes", SERDE_WITH_BASE64)
141
135
  // Get documents fields
142
- .field_attribute("data_contract_id", r#"#[serde(with = "serde_bytes")]"#)
143
- .field_attribute("where", r#"#[serde(with = "serde_bytes")]"#)
144
- .field_attribute("order_by", r#"#[serde(with = "serde_bytes")]"#)
136
+ .field_attribute("data_contract_id", SERDE_WITH_BYTES)
137
+ .field_attribute("where", SERDE_WITH_BYTES)
138
+ .field_attribute("order_by", SERDE_WITH_BYTES)
145
139
  // Proof fields
146
- .field_attribute("Proof.grovedb_proof", r#"#[serde(with = "serde_bytes")]"#)
147
- .field_attribute("Proof.quorum_hash", r#"#[serde(with = "serde_bytes")]"#)
148
- .field_attribute("Proof.signature", r#"#[serde(with = "serde_bytes")]"#)
149
- .field_attribute("Proof.block_id_hash", r#"#[serde(with = "serde_bytes")]"#);
140
+ .field_attribute("Proof.grovedb_proof", SERDE_WITH_BYTES)
141
+ .field_attribute("Proof.quorum_hash", SERDE_WITH_BYTES)
142
+ .field_attribute("Proof.signature", SERDE_WITH_BYTES)
143
+ .field_attribute("Proof.block_id_hash", SERDE_WITH_BYTES);
150
144
 
145
+ #[allow(clippy::let_and_return)]
151
146
  platform
152
147
  }
153
148
 
154
- fn configure_core(mut core: MappingConfig) -> MappingConfig {
149
+ fn configure_core(core: MappingConfig) -> MappingConfig {
155
150
  // All messages can be mocked.
156
- core = core.message_attribute(".", r#"#[derive( ::dapi_grpc_macros::Mockable)]"#);
151
+ let core = core.message_attribute(".", r#"#[derive(::dapi_grpc_macros::Mockable)]"#);
157
152
 
158
153
  // Serde support
159
- #[cfg(feature = "serde")]
160
154
  let core = core.type_attribute(
161
155
  ".",
162
- r#"#[derive(::serde::Serialize, ::serde::Deserialize)]"#,
156
+ r#"#[cfg_attr(feature = "serde", derive(::serde::Serialize, ::serde::Deserialize))]"#,
163
157
  );
164
158
 
159
+ #[allow(clippy::let_and_return)]
165
160
  core
166
161
  }
167
162
 
168
163
  impl MappingConfig {
164
+ /// Create a new MappingConfig instance.
165
+ ///
166
+ /// ## Arguments
167
+ ///
168
+ /// * `protobuf_file` - Path to the protobuf file to use as input.
169
+ /// * `out_dir` - Output directory where subdirectories for generated files will be created.
170
+ /// Depending on the features, either `client`, `server` or `client_server` subdirectory
171
+ /// will be created inside `out_dir`.
169
172
  fn new(protobuf_file: PathBuf, out_dir: PathBuf) -> Self {
170
173
  let protobuf_file = abs_path(&protobuf_file);
171
- let out_dir = abs_path(&out_dir);
172
174
 
173
175
  let build_server = cfg!(feature = "server");
174
176
  let build_client = cfg!(feature = "client");
175
177
 
178
+ // Depending on the features, we need to build the server, client or both.
179
+ // We save these artifacts in separate directories to avoid overwriting the generated files
180
+ // when another crate requires different features.
181
+ let out_dir_suffix = match (build_server, build_client) {
182
+ (true, true) => "client_server",
183
+ (true, false) => "server",
184
+ (false, true) => "client",
185
+ (false, false) => {
186
+ println!("WARNING: At least one of the features 'server' or 'client' must be enabled; dapi-grpc will not generate any files.");
187
+ exit(0)
188
+ }
189
+ };
190
+
191
+ let out_dir = abs_path(&out_dir.join(out_dir_suffix));
192
+
176
193
  let builder = tonic_build::configure()
177
194
  .build_server(build_server)
178
195
  .build_client(build_client)
@@ -30,6 +30,8 @@ const {
30
30
  GetMasternodeStatusResponse: PBJSGetMasternodeStatusResponse,
31
31
  GetBlockRequest: PBJSGetBlockRequest,
32
32
  GetBlockResponse: PBJSGetBlockResponse,
33
+ GetBestBlockHeightRequest: PBJSGetBestBlockHeightRequest,
34
+ GetBestBlockHeightResponse: PBJSGetBestBlockHeightResponse,
33
35
  BroadcastTransactionRequest: PBJSBroadcastTransactionRequest,
34
36
  BroadcastTransactionResponse: PBJSBroadcastTransactionResponse,
35
37
  GetTransactionRequest: PBJSGetTransactionRequest,
@@ -40,6 +42,8 @@ const {
40
42
  GetEstimatedTransactionFeeResponse: PBJSGetEstimatedTransactionFeeResponse,
41
43
  TransactionsWithProofsRequest: PBJSTransactionsWithProofsRequest,
42
44
  TransactionsWithProofsResponse: PBJSTransactionsWithProofsResponse,
45
+ MasternodeListRequest: PBJSMasternodeListRequest,
46
+ MasternodeListResponse: PBJSMasternodeListResponse,
43
47
  },
44
48
  },
45
49
  },
@@ -51,11 +55,13 @@ const {
51
55
  GetBlockchainStatusResponse: ProtocGetBlockchainStatusResponse,
52
56
  GetMasternodeStatusResponse: ProtocGetMasternodeStatusResponse,
53
57
  GetBlockResponse: ProtocGetBlockResponse,
58
+ GetBestBlockHeightResponse: ProtocGetBestBlockHeightResponse,
54
59
  BroadcastTransactionResponse: ProtocBroadcastTransactionResponse,
55
60
  GetTransactionResponse: ProtocGetTransactionResponse,
56
61
  BlockHeadersWithChainLocksResponse: ProtocBlockHeadersWithChainLocksResponse,
57
62
  GetEstimatedTransactionFeeResponse: ProtocGetEstimatedTransactionFeeResponse,
58
63
  TransactionsWithProofsResponse: ProtocTransactionsWithProofsResponse,
64
+ MasternodeListResponse: ProtocMasternodeListResponse,
59
65
  } = require('./core_protoc');
60
66
 
61
67
  const getCoreDefinition = require('../../../../lib/getCoreDefinition');
@@ -94,6 +100,10 @@ class CorePromiseClient {
94
100
  this.client.getBlock.bind(this.client),
95
101
  );
96
102
 
103
+ this.client.getBestBlockHeight = promisify(
104
+ this.client.getBestBlockHeight.bind(this.client),
105
+ );
106
+
97
107
  this.client.broadcastTransaction = promisify(
98
108
  this.client.broadcastTransaction.bind(this.client),
99
109
  );
@@ -169,6 +179,37 @@ class CorePromiseClient {
169
179
  );
170
180
  }
171
181
 
182
+ /**
183
+ * @param {!GetBestBlockHeightRequest} getBestBlockHeightRequest
184
+ * @param {?Object<string, string>} metadata
185
+ * @param {CallOptions} [options={}]
186
+ * @return {Promise<!GetBestBlockHeightResponse>}
187
+ */
188
+ getBestBlockHeight(getBestBlockHeightRequest, metadata = {}, options = {}) {
189
+ if (!isObject(metadata)) {
190
+ throw new Error('metadata must be an object');
191
+ }
192
+
193
+ return this.client.getBestBlockHeight(
194
+ getBestBlockHeightRequest,
195
+ convertObjectToMetadata(metadata),
196
+ {
197
+ interceptors: [
198
+ jsonToProtobufInterceptorFactory(
199
+ jsonToProtobufFactory(
200
+ ProtocGetBestBlockHeightResponse,
201
+ PBJSGetBestBlockHeightResponse,
202
+ ),
203
+ protobufToJsonFactory(
204
+ PBJSGetBestBlockHeightRequest,
205
+ ),
206
+ ),
207
+ ],
208
+ ...options,
209
+ },
210
+ );
211
+ }
212
+
172
213
  /**
173
214
  * @param {!GetMasternodeStatusRequest} getMasternodeStatusRequest
174
215
  * @param {?Object<string, string>} metadata
@@ -360,6 +401,38 @@ class CorePromiseClient {
360
401
  },
361
402
  );
362
403
  }
404
+
405
+ /**
406
+ * @param {MasternodeListRequest} masternodeListRequest The request proto
407
+ * @param {?Object<string, string>} metadata User defined call metadata
408
+ * @param {CallOptions} [options={}]
409
+ * @return {!grpc.web.ClientReadableStream<!MasternodeListResponse>|undefined}
410
+ * The XHR Node Readable Stream
411
+ */
412
+ subscribeToMasternodeList(masternodeListRequest, metadata = {}, options = {}) {
413
+ if (!isObject(metadata)) {
414
+ throw new Error('metadata must be an object');
415
+ }
416
+
417
+ return this.client.subscribeToMasternodeList(
418
+ masternodeListRequest,
419
+ convertObjectToMetadata(metadata),
420
+ {
421
+ interceptors: [
422
+ jsonToProtobufInterceptorFactory(
423
+ jsonToProtobufFactory(
424
+ ProtocMasternodeListResponse,
425
+ PBJSMasternodeListResponse,
426
+ ),
427
+ protobufToJsonFactory(
428
+ PBJSMasternodeListRequest,
429
+ ),
430
+ ),
431
+ ],
432
+ ...options,
433
+ },
434
+ );
435
+ }
363
436
  }
364
437
 
365
438
  module.exports = CorePromiseClient;