@dashevo/dapi-grpc 1.0.0-pr.1825.8 → 1.0.0-pr.1875.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.
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.1825.8"
4
+ version = "1.0.0-pr.1875.1"
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" }
@@ -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)
@@ -39,7 +46,7 @@ fn configure_platform(mut platform: MappingConfig) -> MappingConfig {
39
46
  // Derive features for versioned messages
40
47
  //
41
48
  // "GetConsensusParamsRequest" is excluded as this message does not support proofs
42
- const VERSIONED_REQUESTS: [&str; 18] = [
49
+ const VERSIONED_REQUESTS: [&str; 19] = [
43
50
  "GetDataContractHistoryRequest",
44
51
  "GetDataContractRequest",
45
52
  "GetDataContractsRequest",
@@ -58,10 +65,11 @@ fn configure_platform(mut platform: MappingConfig) -> MappingConfig {
58
65
  "GetProtocolVersionUpgradeStateRequest",
59
66
  "GetProtocolVersionUpgradeVoteStatusRequest",
60
67
  "GetPathElementsRequest",
68
+ "GetIdentitiesContractKeysRequest",
61
69
  ];
62
70
 
63
71
  // "GetConsensusParamsResponse" is excluded as this message does not support proofs
64
- const VERSIONED_RESPONSES: [&str; 19] = [
72
+ const VERSIONED_RESPONSES: [&str; 20] = [
65
73
  "GetDataContractHistoryResponse",
66
74
  "GetDataContractResponse",
67
75
  "GetDataContractsResponse",
@@ -81,6 +89,7 @@ fn configure_platform(mut platform: MappingConfig) -> MappingConfig {
81
89
  "GetProtocolVersionUpgradeStateResponse",
82
90
  "GetProtocolVersionUpgradeVoteStatusResponse",
83
91
  "GetPathElementsResponse",
92
+ "GetIdentitiesContractKeysResponse",
84
93
  ];
85
94
 
86
95
  // Derive VersionedGrpcMessage on requests
@@ -104,73 +113,83 @@ fn configure_platform(mut platform: MappingConfig) -> MappingConfig {
104
113
  }
105
114
 
106
115
  // All messages can be mocked.
107
- platform = platform.message_attribute(".", r#"#[derive( ::dapi_grpc_macros::Mockable)]"#);
116
+ let platform = platform.message_attribute(".", r#"#[derive( ::dapi_grpc_macros::Mockable)]"#);
108
117
 
109
- #[cfg(feature = "serde")]
110
118
  let platform = platform
111
119
  .type_attribute(
112
120
  ".",
113
- r#"#[derive(::serde::Serialize, ::serde::Deserialize)]"#,
114
- )
115
- .type_attribute(".", r#"#[serde(rename_all = "snake_case")]"#)
116
- .field_attribute("id", r#"#[serde(with = "serde_bytes")]"#)
117
- .field_attribute("identity_id", r#"#[serde(with = "serde_bytes")]"#)
118
- .field_attribute(
119
- "ids",
120
- r#"#[serde(with = "crate::deserialization::vec_base64string")]"#,
121
- )
122
- .field_attribute(
123
- "ResponseMetadata.height",
124
- r#"#[serde(with = "crate::deserialization::from_to_string")]"#,
125
- )
126
- .field_attribute(
127
- "ResponseMetadata.time_ms",
128
- r#"#[serde(with = "crate::deserialization::from_to_string")]"#,
121
+ r#"#[cfg_attr(feature = "serde", derive(::serde::Serialize, ::serde::Deserialize))]"#,
129
122
  )
130
- .field_attribute(
131
- "start_at_ms",
132
- r#"#[serde(with = "crate::deserialization::from_to_string")]"#,
133
- )
134
- .field_attribute("public_key_hash", r#"#[serde(with = "serde_bytes")]"#)
135
- .field_attribute(
136
- "public_key_hashes",
137
- r#"#[serde(with = "crate::deserialization::vec_base64string")]"#,
123
+ .type_attribute(
124
+ ".",
125
+ r#"#[cfg_attr(feature = "serde", serde(rename_all = "snake_case"))]"#,
138
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)
139
135
  // Get documents fields
140
- .field_attribute("data_contract_id", r#"#[serde(with = "serde_bytes")]"#)
141
- .field_attribute("where", r#"#[serde(with = "serde_bytes")]"#)
142
- .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)
143
139
  // Proof fields
144
- .field_attribute("Proof.grovedb_proof", r#"#[serde(with = "serde_bytes")]"#)
145
- .field_attribute("Proof.quorum_hash", r#"#[serde(with = "serde_bytes")]"#)
146
- .field_attribute("Proof.signature", r#"#[serde(with = "serde_bytes")]"#)
147
- .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);
148
144
 
145
+ #[allow(clippy::let_and_return)]
149
146
  platform
150
147
  }
151
148
 
152
- fn configure_core(mut core: MappingConfig) -> MappingConfig {
149
+ fn configure_core(core: MappingConfig) -> MappingConfig {
153
150
  // All messages can be mocked.
154
- core = core.message_attribute(".", r#"#[derive( ::dapi_grpc_macros::Mockable)]"#);
151
+ let core = core.message_attribute(".", r#"#[derive(::dapi_grpc_macros::Mockable)]"#);
155
152
 
156
153
  // Serde support
157
- #[cfg(feature = "serde")]
158
154
  let core = core.type_attribute(
159
155
  ".",
160
- r#"#[derive(::serde::Serialize, ::serde::Deserialize)]"#,
156
+ r#"#[cfg_attr(feature = "serde", derive(::serde::Serialize, ::serde::Deserialize))]"#,
161
157
  );
162
158
 
159
+ #[allow(clippy::let_and_return)]
163
160
  core
164
161
  }
165
162
 
166
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`.
167
172
  fn new(protobuf_file: PathBuf, out_dir: PathBuf) -> Self {
168
173
  let protobuf_file = abs_path(&protobuf_file);
169
- let out_dir = abs_path(&out_dir);
170
174
 
171
175
  let build_server = cfg!(feature = "server");
172
176
  let build_client = cfg!(feature = "client");
173
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
+
174
193
  let builder = tonic_build::configure()
175
194
  .build_server(build_server)
176
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,
@@ -51,6 +53,7 @@ const {
51
53
  GetBlockchainStatusResponse: ProtocGetBlockchainStatusResponse,
52
54
  GetMasternodeStatusResponse: ProtocGetMasternodeStatusResponse,
53
55
  GetBlockResponse: ProtocGetBlockResponse,
56
+ GetBestBlockHeightResponse: ProtocGetBestBlockHeightResponse,
54
57
  BroadcastTransactionResponse: ProtocBroadcastTransactionResponse,
55
58
  GetTransactionResponse: ProtocGetTransactionResponse,
56
59
  BlockHeadersWithChainLocksResponse: ProtocBlockHeadersWithChainLocksResponse,
@@ -94,6 +97,10 @@ class CorePromiseClient {
94
97
  this.client.getBlock.bind(this.client),
95
98
  );
96
99
 
100
+ this.client.getBestBlockHeight = promisify(
101
+ this.client.getBestBlockHeight.bind(this.client),
102
+ );
103
+
97
104
  this.client.broadcastTransaction = promisify(
98
105
  this.client.broadcastTransaction.bind(this.client),
99
106
  );
@@ -169,6 +176,37 @@ class CorePromiseClient {
169
176
  );
170
177
  }
171
178
 
179
+ /**
180
+ * @param {!GetBestBlockHeightRequest} getBestBlockHeightRequest
181
+ * @param {?Object<string, string>} metadata
182
+ * @param {CallOptions} [options={}]
183
+ * @return {Promise<!GetBestBlockHeightResponse>}
184
+ */
185
+ getBestBlockHeight(getBestBlockHeightRequest, metadata = {}, options = {}) {
186
+ if (!isObject(metadata)) {
187
+ throw new Error('metadata must be an object');
188
+ }
189
+
190
+ return this.client.getBestBlockHeight(
191
+ getBestBlockHeightRequest,
192
+ convertObjectToMetadata(metadata),
193
+ {
194
+ interceptors: [
195
+ jsonToProtobufInterceptorFactory(
196
+ jsonToProtobufFactory(
197
+ ProtocGetBestBlockHeightResponse,
198
+ PBJSGetBestBlockHeightResponse,
199
+ ),
200
+ protobufToJsonFactory(
201
+ PBJSGetBestBlockHeightRequest,
202
+ ),
203
+ ),
204
+ ],
205
+ ...options,
206
+ },
207
+ );
208
+ }
209
+
172
210
  /**
173
211
  * @param {!GetMasternodeStatusRequest} getMasternodeStatusRequest
174
212
  * @param {?Object<string, string>} metadata