@dashevo/dapi-grpc 1.8.0-rc.2 → 2.0.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.
package/.eslintrc CHANGED
@@ -1,5 +1,8 @@
1
1
  {
2
2
  "extends": "airbnb-base",
3
+ "env": {
4
+ "es2020": true
5
+ },
3
6
  "rules": {
4
7
  "import/no-extraneous-dependencies": ["error", { "packageDir": "." }],
5
8
  "no-plusplus": 0,
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.8.0-rc.2"
4
+ version = "2.0.0-dev.1"
5
5
  authors = [
6
6
  "Samuel Westrich <sam@dash.org>",
7
7
  "Igor Markin <igor.markin@dash.org>",
@@ -20,19 +20,19 @@ platform = []
20
20
  # Re-export Dash Platform protobuf types as `dapi_grpc::platform::proto`
21
21
  # Note: client needs tls and tls-roots to connect to testnet which uses TLS.
22
22
  tenderdash-proto = []
23
- client = [
24
- "tonic/channel",
25
- "tonic/transport",
26
- "tonic/tls",
27
- "tonic/tls-roots",
28
- "tonic/tls-webpki-roots",
29
- "platform",
30
- ]
31
- server = ["tonic/channel", "tonic/transport", "platform"]
32
- serde = ["dep:serde", "dep:serde_bytes"]
23
+
24
+ # Client support.
25
+ client = ["platform"]
26
+
27
+ # Build tonic server code. Includes all client features and adds server-specific dependencies.
28
+ server = ["platform", "tenderdash-proto/server", "client"]
29
+
30
+ serde = ["dep:serde", "dep:serde_bytes", "tenderdash-proto/serde"]
33
31
  mocks = ["serde", "dep:serde_json"]
34
32
 
35
33
  [dependencies]
34
+ tenderdash-proto = { git = "https://github.com/dashpay/rs-tenderdash-abci", version = "1.3.0", tag = "v1.3.0+1.3.0", default-features = false }
35
+
36
36
  prost = { version = "0.13" }
37
37
  futures-core = "0.3.30"
38
38
  tonic = { version = "0.12.3", features = [
@@ -42,12 +42,23 @@ tonic = { version = "0.12.3", features = [
42
42
  serde = { version = "1.0.197", optional = true, features = ["derive"] }
43
43
  serde_bytes = { version = "0.11.12", optional = true }
44
44
  serde_json = { version = "1.0", optional = true }
45
- tenderdash-proto = { git = "https://github.com/dashpay/rs-tenderdash-abci", version = "1.2.1", tag = "v1.2.1+1.3.0", default-features = false, features = [
46
- "grpc",
47
- ] }
48
45
  dapi-grpc-macros = { path = "../rs-dapi-grpc-macros" }
49
46
  platform-version = { path = "../rs-platform-version" }
50
47
 
48
+ [target.'cfg(target_arch = "wasm32")'.dependencies]
49
+ getrandom = { version = "0.2", features = ["js"] }
50
+
51
+ [target.'cfg(not(target_arch = "wasm32"))'.dependencies]
52
+ tonic = { version = "0.12.3", features = [
53
+ "codegen",
54
+ "prost",
55
+ "channel",
56
+ "transport",
57
+ "tls",
58
+ "tls-roots",
59
+ "tls-webpki-roots",
60
+ ], default-features = false }
61
+
51
62
  [build-dependencies]
52
63
  tonic-build = { version = "0.12.3" }
53
64
 
package/build.rs CHANGED
@@ -2,7 +2,6 @@ use std::{
2
2
  collections::HashSet,
3
3
  fs::{create_dir_all, remove_dir_all},
4
4
  path::PathBuf,
5
- process::exit,
6
5
  };
7
6
 
8
7
  use tonic_build::Builder;
@@ -14,9 +13,24 @@ const SERDE_WITH_STRING: &str =
14
13
  r#"#[cfg_attr(feature = "serde", serde(with = "crate::deserialization::from_to_string"))]"#;
15
14
 
16
15
  fn main() {
16
+ #[cfg(feature = "server")]
17
+ generate_code(ImplType::Server);
18
+ #[cfg(feature = "client")]
19
+ generate_code(ImplType::Client);
20
+
21
+ if std::env::var("CARGO_CFG_TARGET_ARCH")
22
+ .unwrap_or_default()
23
+ .eq("wasm32")
24
+ {
25
+ generate_code(ImplType::Wasm);
26
+ }
27
+ }
28
+
29
+ fn generate_code(typ: ImplType) {
17
30
  let core = MappingConfig::new(
18
31
  PathBuf::from("protos/core/v0/core.proto"),
19
32
  PathBuf::from("src/core"),
33
+ &typ,
20
34
  );
21
35
 
22
36
  configure_core(core)
@@ -26,6 +40,7 @@ fn main() {
26
40
  let platform = MappingConfig::new(
27
41
  PathBuf::from("protos/platform/v0/platform.proto"),
28
42
  PathBuf::from("src/platform"),
43
+ &typ,
29
44
  );
30
45
 
31
46
  configure_platform(platform)
@@ -34,6 +49,7 @@ fn main() {
34
49
 
35
50
  println!("cargo:rerun-if-changed=./protos");
36
51
  println!("cargo:rerun-if-env-changed=CARGO_FEATURE_SERDE");
52
+ println!("cargo:rerun-if-env-changed=CARGO_CFG_TARGET_ARCH");
37
53
  }
38
54
 
39
55
  struct MappingConfig {
@@ -47,7 +63,7 @@ fn configure_platform(mut platform: MappingConfig) -> MappingConfig {
47
63
  // Derive features for versioned messages
48
64
  //
49
65
  // "GetConsensusParamsRequest" is excluded as this message does not support proofs
50
- const VERSIONED_REQUESTS: [&str; 30] = [
66
+ const VERSIONED_REQUESTS: [&str; 40] = [
51
67
  "GetDataContractHistoryRequest",
52
68
  "GetDataContractRequest",
53
69
  "GetDataContractsRequest",
@@ -78,6 +94,16 @@ fn configure_platform(mut platform: MappingConfig) -> MappingConfig {
78
94
  "GetEvonodesProposedEpochBlocksByIdsRequest",
79
95
  "GetEvonodesProposedEpochBlocksByRangeRequest",
80
96
  "GetStatusRequest",
97
+ "GetIdentityTokenBalancesRequest",
98
+ "GetIdentitiesTokenBalancesRequest",
99
+ "GetIdentityTokenInfosRequest",
100
+ "GetIdentitiesTokenInfosRequest",
101
+ "GetTokenStatusesRequest",
102
+ "GetTokenTotalSupplyRequest",
103
+ "GetGroupInfoRequest",
104
+ "GetGroupInfosRequest",
105
+ "GetGroupActionsRequest",
106
+ "GetGroupActionSignersRequest",
81
107
  ];
82
108
 
83
109
  // The following responses are excluded as they don't support proofs:
@@ -85,7 +111,7 @@ fn configure_platform(mut platform: MappingConfig) -> MappingConfig {
85
111
  // - "GetStatusResponse"
86
112
  //
87
113
  // "GetEvonodesProposedEpochBlocksResponse" is used for 2 Requests
88
- const VERSIONED_RESPONSES: [&str; 29] = [
114
+ const VERSIONED_RESPONSES: [&str; 39] = [
89
115
  "GetDataContractHistoryResponse",
90
116
  "GetDataContractResponse",
91
117
  "GetDataContractsResponse",
@@ -115,6 +141,16 @@ fn configure_platform(mut platform: MappingConfig) -> MappingConfig {
115
141
  "GetVotePollsByEndDateResponse",
116
142
  "GetTotalCreditsInPlatformResponse",
117
143
  "GetEvonodesProposedEpochBlocksResponse",
144
+ "GetIdentityTokenBalancesResponse",
145
+ "GetIdentitiesTokenBalancesResponse",
146
+ "GetIdentityTokenInfosResponse",
147
+ "GetIdentitiesTokenInfosResponse",
148
+ "GetTokenStatusesResponse",
149
+ "GetTokenTotalSupplyResponse",
150
+ "GetGroupInfoResponse",
151
+ "GetGroupInfosResponse",
152
+ "GetGroupActionsResponse",
153
+ "GetGroupActionSignersResponse",
118
154
  ];
119
155
 
120
156
  check_unique(&VERSIONED_REQUESTS).expect("VERSIONED_REQUESTS");
@@ -210,6 +246,43 @@ fn configure_core(core: MappingConfig) -> MappingConfig {
210
246
  core
211
247
  }
212
248
 
249
+ #[allow(unused)]
250
+ enum ImplType {
251
+ Server,
252
+ Client,
253
+ Wasm,
254
+ }
255
+
256
+ impl ImplType {
257
+ // Configure the builder based on the implementation type.
258
+ pub fn configure(&self, builder: Builder) -> Builder {
259
+ match self {
260
+ Self::Server => builder
261
+ .build_client(true)
262
+ .build_server(true)
263
+ .build_transport(true),
264
+ Self::Client => builder
265
+ .build_client(true)
266
+ .build_server(false)
267
+ .build_transport(true),
268
+ Self::Wasm => builder
269
+ .build_client(true)
270
+ .build_server(false)
271
+ .build_transport(false),
272
+ }
273
+ }
274
+
275
+ /// Get the directory name for the implementation type.
276
+ fn dirname(&self) -> String {
277
+ match self {
278
+ Self::Server => "server",
279
+ Self::Client => "client",
280
+ Self::Wasm => "wasm",
281
+ }
282
+ .to_string()
283
+ }
284
+ }
285
+
213
286
  impl MappingConfig {
214
287
  /// Create a new MappingConfig instance.
215
288
  ///
@@ -220,31 +293,18 @@ impl MappingConfig {
220
293
  ///
221
294
  /// Depending on the features, either `client`, `server` or `client_server` subdirectory
222
295
  /// will be created inside `out_dir`.
223
- fn new(protobuf_file: PathBuf, out_dir: PathBuf) -> Self {
296
+ fn new(protobuf_file: PathBuf, out_dir: PathBuf, typ: &ImplType) -> Self {
224
297
  let protobuf_file = abs_path(&protobuf_file);
225
298
 
226
- let build_server = cfg!(feature = "server");
227
- let build_client = cfg!(feature = "client");
228
-
229
299
  // Depending on the features, we need to build the server, client or both.
230
300
  // We save these artifacts in separate directories to avoid overwriting the generated files
231
301
  // when another crate requires different features.
232
- let out_dir_suffix = match (build_server, build_client) {
233
- (true, true) => "client_server",
234
- (true, false) => "server",
235
- (false, true) => "client",
236
- (false, false) => {
237
- println!("WARNING: At least one of the features 'server' or 'client' must be enabled; dapi-grpc will not generate any files.");
238
- exit(0)
239
- }
240
- };
302
+ let out_dir_suffix = typ.dirname();
241
303
 
242
304
  let out_dir = abs_path(&out_dir.join(out_dir_suffix));
243
305
 
244
- let builder = tonic_build::configure()
245
- .build_server(build_server)
246
- .build_client(build_client)
247
- .build_transport(build_server || build_client)
306
+ let builder = typ
307
+ .configure(tonic_build::configure())
248
308
  .out_dir(out_dir.clone())
249
309
  .protoc_arg("--experimental_allow_proto3_optional");
250
310