@dashevo/dapi-grpc 0.25.22 → 1.0.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.
package/Cargo.toml CHANGED
@@ -1,36 +1,45 @@
1
1
  [package]
2
2
  name = "dapi-grpc"
3
3
  description = "GRPC client for Dash Platform"
4
- version = "0.25.22"
4
+ version = "1.0.0-dev.10"
5
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>",
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
11
  ]
12
12
  edition = "2021"
13
- rust-version = "1.73"
13
+ rust-version = "1.76"
14
14
  license = "MIT"
15
15
 
16
16
  [features]
17
- default = ["core", "platform", "client", "serde"]
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"]
18
21
  core = []
19
22
  platform = []
20
23
  # Re-export Dash Platform protobuf types as `dapi_grpc::platform::proto`
21
24
  tenderdash-proto = []
22
25
  client = ["tonic/channel", "tonic/tls", "tonic/tls-roots", "platform"]
26
+ server = ["tonic/channel", "tonic/tls", "tonic/tls-roots", "platform"]
23
27
  serde = ["dep:serde", "dep:serde_bytes"]
28
+ mocks = ["dep:serde_json"]
24
29
 
25
30
  [dependencies]
26
- prost = { version = "0.11.9" }
27
- tonic = { version = "0.9.2", features = [
28
- "codegen",
29
- "prost",
31
+ prost = { version = "0.12.3" }
32
+ futures-core = "0.3.30"
33
+ tonic = { version = "0.11", features = [
34
+ "codegen",
35
+ "prost",
30
36
  ], default-features = false }
31
37
  serde = { version = "1.0.171", optional = true, features = ["derive"] }
32
38
  serde_bytes = { version = "0.11.12", optional = true }
33
- tenderdash-proto = { git = "https://github.com/dashpay/rs-tenderdash-abci" }
39
+ serde_json = { version = "1.0", optional = true }
40
+ tenderdash-proto = { git = "https://github.com/dashpay/rs-tenderdash-abci", version = "0.14.0-dev.11", features = [
41
+ "grpc",
42
+ ] }
34
43
  dapi-grpc-macros = { path = "../rs-dapi-grpc-macros" }
35
44
  platform-version = { path = "../rs-platform-version" }
36
45
 
package/build.rs CHANGED
@@ -6,7 +6,23 @@ use std::{
6
6
  use tonic_build::Builder;
7
7
 
8
8
  fn main() {
9
- generate().expect("failed to compile protobuf definitions");
9
+ let core = MappingConfig::new(
10
+ PathBuf::from("protos/core/v0/core.proto"),
11
+ PathBuf::from("src/core/proto"),
12
+ );
13
+
14
+ configure_core(core)
15
+ .generate()
16
+ .expect("generate core proto");
17
+
18
+ let platform = MappingConfig::new(
19
+ PathBuf::from("protos/platform/v0/platform.proto"),
20
+ PathBuf::from("src/platform/proto"),
21
+ );
22
+
23
+ configure_platform(platform)
24
+ .generate()
25
+ .expect("generate platform proto");
10
26
 
11
27
  println!("cargo:rerun-if-changed=./protos");
12
28
  println!("cargo:rerun-if-env-changed=CARGO_FEATURE_SERDE");
@@ -18,29 +34,20 @@ struct MappingConfig {
18
34
  builder: Builder,
19
35
  proto_includes: Vec<PathBuf>,
20
36
  }
21
- /// Generate Rust definitions from Protobuf definitions
22
- pub fn generate() -> Result<(), std::io::Error> {
23
- let core = MappingConfig::new(
24
- PathBuf::from("protos/core/v0/core.proto"),
25
- PathBuf::from("src/core/proto"),
26
- );
27
- core.generate().unwrap();
28
-
29
- let mut platform = MappingConfig::new(
30
- PathBuf::from("protos/platform/v0/platform.proto"),
31
- PathBuf::from("src/platform/proto"),
32
- );
33
37
 
38
+ fn configure_platform(mut platform: MappingConfig) -> MappingConfig {
34
39
  // Derive features for versioned messages
35
40
  //
36
41
  // "GetConsensusParamsRequest" is excluded as this message does not support proofs
37
- const VERSIONED_REQUESTS: [&str; 15] = [
42
+ const VERSIONED_REQUESTS: [&str; 17] = [
38
43
  "GetDataContractHistoryRequest",
39
44
  "GetDataContractRequest",
40
45
  "GetDataContractsRequest",
41
46
  "GetDocumentsRequest",
42
47
  "GetIdentitiesByPublicKeyHashesRequest",
43
48
  "GetIdentitiesRequest",
49
+ "GetIdentityNonceRequest",
50
+ "GetIdentityContractNonceRequest",
44
51
  "GetIdentityBalanceAndRevisionRequest",
45
52
  "GetIdentityBalanceRequest",
46
53
  "GetIdentityByPublicKeyHashRequest",
@@ -53,7 +60,7 @@ pub fn generate() -> Result<(), std::io::Error> {
53
60
  ];
54
61
 
55
62
  // "GetConsensusParamsResponse" is excluded as this message does not support proofs
56
- const VERSIONED_RESPONSES: [&str; 16] = [
63
+ const VERSIONED_RESPONSES: [&str; 18] = [
57
64
  "GetDataContractHistoryResponse",
58
65
  "GetDataContractResponse",
59
66
  "GetDataContractsResponse",
@@ -62,6 +69,8 @@ pub fn generate() -> Result<(), std::io::Error> {
62
69
  "GetIdentitiesResponse",
63
70
  "GetIdentityBalanceAndRevisionResponse",
64
71
  "GetIdentityBalanceResponse",
72
+ "GetIdentityNonceResponse",
73
+ "GetIdentityContractNonceResponse",
65
74
  "GetIdentityByPublicKeyHashResponse",
66
75
  "GetIdentityKeysResponse",
67
76
  "GetIdentityResponse",
@@ -92,6 +101,9 @@ pub fn generate() -> Result<(), std::io::Error> {
92
101
  .message_attribute(msg, r#"#[grpc_versions(0)]"#);
93
102
  }
94
103
 
104
+ // All messages can be mocked.
105
+ platform = platform.message_attribute(".", r#"#[derive( ::dapi_grpc_macros::Mockable)]"#);
106
+
95
107
  #[cfg(feature = "serde")]
96
108
  let platform = platform
97
109
  .type_attribute(
@@ -132,9 +144,21 @@ pub fn generate() -> Result<(), std::io::Error> {
132
144
  .field_attribute("Proof.signature", r#"#[serde(with = "serde_bytes")]"#)
133
145
  .field_attribute("Proof.block_id_hash", r#"#[serde(with = "serde_bytes")]"#);
134
146
 
135
- platform.generate().unwrap();
147
+ platform
148
+ }
136
149
 
137
- Ok(())
150
+ fn configure_core(mut core: MappingConfig) -> MappingConfig {
151
+ // All messages can be mocked.
152
+ core = core.message_attribute(".", r#"#[derive( ::dapi_grpc_macros::Mockable)]"#);
153
+
154
+ // Serde support
155
+ #[cfg(feature = "serde")]
156
+ let core = core.type_attribute(
157
+ ".",
158
+ r#"#[derive(::serde::Serialize, ::serde::Deserialize)]"#,
159
+ );
160
+
161
+ core
138
162
  }
139
163
 
140
164
  impl MappingConfig {
@@ -142,16 +166,16 @@ impl MappingConfig {
142
166
  let protobuf_file = abs_path(&protobuf_file);
143
167
  let out_dir = abs_path(&out_dir);
144
168
 
169
+ let build_server = cfg!(feature = "server");
170
+ let build_client = cfg!(feature = "client");
171
+
145
172
  let builder = tonic_build::configure()
146
- .build_server(false)
173
+ .build_server(build_server)
174
+ .build_client(build_client)
175
+ .build_transport(build_server || build_client)
147
176
  .out_dir(out_dir.clone())
148
177
  .protoc_arg("--experimental_allow_proto3_optional");
149
178
 
150
- #[cfg(feature = "client")]
151
- let builder = builder.build_client(true).build_transport(true);
152
- #[cfg(not(feature = "client"))]
153
- let builder = builder.build_client(false).build_transport(false);
154
-
155
179
  Self {
156
180
  protobuf_file,
157
181
  out_dir,
@@ -1,5 +1,5 @@
1
1
  use dapi_grpc::core::v0 as core;
2
- use prost::Message;
2
+ use dapi_grpc::Message;
3
3
 
4
4
  fn main() {
5
5
  let request = core::GetBlockRequest {
@@ -48,6 +48,14 @@ const {
48
48
  PBJSGetProtocolVersionUpgradeVoteStatusResponse,
49
49
  GetProtocolVersionUpgradeStateRequest: PBJSGetProtocolVersionUpgradeStateRequest,
50
50
  GetProtocolVersionUpgradeStateResponse: PBJSGetProtocolVersionUpgradeStateResponse,
51
+ GetProofsRequest: PBJSGetProofsRequest,
52
+ GetProofsResponse: PBJSGetProofsResponse,
53
+ GetIdentityContractNonceRequest: PBJSGetIdentityContractNonceRequest,
54
+ GetIdentityContractNonceResponse: PBJSGetIdentityContractNonceResponse,
55
+ GetIdentityNonceRequest: PBJSGetIdentityNonceRequest,
56
+ GetIdentityNonceResponse: PBJSGetIdentityNonceResponse,
57
+ GetIdentityKeysRequest: PBJSGetIdentityKeysRequest,
58
+ GetIdentityKeysResponse: PBJSGetIdentityKeysResponse,
51
59
  },
52
60
  },
53
61
  },
@@ -67,6 +75,10 @@ const {
67
75
  GetEpochsInfoResponse: ProtocGetEpochsInfoResponse,
68
76
  GetProtocolVersionUpgradeVoteStatusResponse: ProtocGetProtocolVersionUpgradeVoteStatusResponse,
69
77
  GetProtocolVersionUpgradeStateResponse: ProtocGetProtocolVersionUpgradeStateResponse,
78
+ GetProofsResponse: ProtocGetProofsResponse,
79
+ GetIdentityContractNonceResponse: ProtocGetIdentityContractNonceResponse,
80
+ GetIdentityNonceResponse: ProtocGetIdentityNonceResponse,
81
+ GetIdentityKeysResponse: ProtocGetIdentityKeysResponse,
70
82
  } = require('./platform_protoc');
71
83
 
72
84
  const getPlatformDefinition = require('../../../../lib/getPlatformDefinition');
@@ -137,6 +149,22 @@ class PlatformPromiseClient {
137
149
  this.client.getProtocolVersionUpgradeState.bind(this.client),
138
150
  );
139
151
 
152
+ this.client.getProofs = promisify(
153
+ this.client.getProofs.bind(this.client),
154
+ );
155
+
156
+ this.client.getIdentityContractNonce = promisify(
157
+ this.client.getIdentityContractNonce.bind(this.client),
158
+ );
159
+
160
+ this.client.getIdentityNonce = promisify(
161
+ this.client.getIdentityNonce.bind(this.client),
162
+ );
163
+
164
+ this.client.getIdentityKeys = promisify(
165
+ this.client.getIdentityKeys.bind(this.client),
166
+ );
167
+
140
168
  this.protocolVersion = undefined;
141
169
  }
142
170
 
@@ -496,6 +524,131 @@ class PlatformPromiseClient {
496
524
  );
497
525
  }
498
526
 
527
+ /**
528
+ *
529
+ * @param {!GetProofsRequest} request
530
+ * @param {?Object<string, string>} metadata
531
+ * @param {CallOptions} [options={}]
532
+ * @returns {Promise<!GetProofsResponse>}
533
+ */
534
+ getProofs(request, metadata = {}, options = {}) {
535
+ if (!isObject(metadata)) {
536
+ throw new Error('metadata must be an object');
537
+ }
538
+
539
+ return this.client.getProofs(
540
+ request,
541
+ convertObjectToMetadata(metadata),
542
+ {
543
+ interceptors: [
544
+ jsonToProtobufInterceptorFactory(
545
+ jsonToProtobufFactory(
546
+ ProtocGetProofsResponse,
547
+ PBJSGetProofsResponse,
548
+ ),
549
+ protobufToJsonFactory(
550
+ PBJSGetProofsRequest,
551
+ ),
552
+ ),
553
+ ],
554
+ ...options,
555
+ },
556
+ );
557
+ }
558
+
559
+ /**
560
+ * @param {!PBJSGetIdentityContractNonceRequest} getIdentityContractNonceRequest
561
+ * @param {?Object<string, string>} metadata
562
+ * @param {CallOptions} [options={}]
563
+ * @return {Promise<!GetIdentityContractNonceResponse>}
564
+ */
565
+ getIdentityContractNonce(
566
+ getIdentityContractNonceRequest,
567
+ metadata = {},
568
+ options = {},
569
+ ) {
570
+ if (!isObject(metadata)) {
571
+ throw new Error('metadata must be an object');
572
+ }
573
+
574
+ return this.client.getIdentityContractNonce(
575
+ getIdentityContractNonceRequest,
576
+ convertObjectToMetadata(metadata),
577
+ {
578
+ interceptors: [
579
+ jsonToProtobufInterceptorFactory(
580
+ jsonToProtobufFactory(
581
+ ProtocGetIdentityContractNonceResponse,
582
+ PBJSGetIdentityContractNonceResponse,
583
+ ),
584
+ protobufToJsonFactory(
585
+ PBJSGetIdentityContractNonceRequest,
586
+ ),
587
+ ),
588
+ ],
589
+ ...options,
590
+ },
591
+ );
592
+ }
593
+
594
+ getIdentityNonce(
595
+ getIdentityNonceRequest,
596
+ metadata = {},
597
+ options = {},
598
+ ) {
599
+ if (!isObject(metadata)) {
600
+ throw new Error('metadata must be an object');
601
+ }
602
+
603
+ return this.client.getIdentityNonce(
604
+ getIdentityNonceRequest,
605
+ convertObjectToMetadata(metadata),
606
+ {
607
+ interceptors: [
608
+ jsonToProtobufInterceptorFactory(
609
+ jsonToProtobufFactory(
610
+ ProtocGetIdentityNonceResponse,
611
+ PBJSGetIdentityNonceResponse,
612
+ ),
613
+ protobufToJsonFactory(
614
+ PBJSGetIdentityNonceRequest,
615
+ ),
616
+ ),
617
+ ],
618
+ ...options,
619
+ },
620
+ );
621
+ }
622
+
623
+ getIdentityKeys(
624
+ getIdentityKeysRequest,
625
+ metadata = {},
626
+ options = {},
627
+ ) {
628
+ if (!isObject(metadata)) {
629
+ throw new Error('metadata must be an object');
630
+ }
631
+
632
+ return this.client.getIdentityKeys(
633
+ getIdentityKeysRequest,
634
+ convertObjectToMetadata(metadata),
635
+ {
636
+ interceptors: [
637
+ jsonToProtobufInterceptorFactory(
638
+ jsonToProtobufFactory(
639
+ ProtocGetIdentityKeysResponse,
640
+ PBJSGetIdentityKeysResponse,
641
+ ),
642
+ protobufToJsonFactory(
643
+ PBJSGetIdentityKeysRequest,
644
+ ),
645
+ ),
646
+ ],
647
+ ...options,
648
+ },
649
+ );
650
+ }
651
+
499
652
  /**
500
653
  * @param {string} protocolVersion
501
654
  */