@dashevo/dapi-grpc 1.0.0-dev.3 → 1.0.0-dev.5

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-dev.3"
4
+ version = "1.0.0-dev.5"
5
5
  authors = [
6
6
  "Samuel Westrich <sam@dash.org>",
7
7
  "Igor Markin <igor.markin@dash.org>",
@@ -21,6 +21,7 @@ platform = []
21
21
  tenderdash-proto = []
22
22
  client = ["tonic/channel", "tonic/tls", "tonic/tls-roots", "platform"]
23
23
  serde = ["dep:serde", "dep:serde_bytes"]
24
+ mocks = ["dep:serde_json"]
24
25
 
25
26
  [dependencies]
26
27
  prost = { version = "0.11.9" }
@@ -30,7 +31,8 @@ tonic = { version = "0.9.2", features = [
30
31
  ], default-features = false }
31
32
  serde = { version = "1.0.171", optional = true, features = ["derive"] }
32
33
  serde_bytes = { version = "0.11.12", optional = true }
33
- tenderdash-proto = { git = "https://github.com/dashpay/rs-tenderdash-abci" }
34
+ serde_json = { version = "1.0", optional = true }
35
+ tenderdash-proto = { git = "https://github.com/dashpay/rs-tenderdash-abci", version = "0.14.0-dev.6" }
34
36
  dapi-grpc-macros = { path = "../rs-dapi-grpc-macros" }
35
37
  platform-version = { path = "../rs-platform-version" }
36
38
 
package/build.rs CHANGED
@@ -6,7 +6,21 @@ 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
+ configure_core(core)
14
+ .generate()
15
+ .expect("generate core proto");
16
+
17
+ let platform = MappingConfig::new(
18
+ PathBuf::from("protos/platform/v0/platform.proto"),
19
+ PathBuf::from("src/platform/proto"),
20
+ );
21
+ configure_platform(platform)
22
+ .generate()
23
+ .expect("generate platform proto");
10
24
 
11
25
  println!("cargo:rerun-if-changed=./protos");
12
26
  println!("cargo:rerun-if-env-changed=CARGO_FEATURE_SERDE");
@@ -18,29 +32,20 @@ struct MappingConfig {
18
32
  builder: Builder,
19
33
  proto_includes: Vec<PathBuf>,
20
34
  }
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
35
 
36
+ fn configure_platform(mut platform: MappingConfig) -> MappingConfig {
34
37
  // Derive features for versioned messages
35
38
  //
36
39
  // "GetConsensusParamsRequest" is excluded as this message does not support proofs
37
- const VERSIONED_REQUESTS: [&str; 15] = [
40
+ const VERSIONED_REQUESTS: [&str; 17] = [
38
41
  "GetDataContractHistoryRequest",
39
42
  "GetDataContractRequest",
40
43
  "GetDataContractsRequest",
41
44
  "GetDocumentsRequest",
42
45
  "GetIdentitiesByPublicKeyHashesRequest",
43
46
  "GetIdentitiesRequest",
47
+ "GetIdentityNonceRequest",
48
+ "GetIdentityContractNonceRequest",
44
49
  "GetIdentityBalanceAndRevisionRequest",
45
50
  "GetIdentityBalanceRequest",
46
51
  "GetIdentityByPublicKeyHashRequest",
@@ -53,7 +58,7 @@ pub fn generate() -> Result<(), std::io::Error> {
53
58
  ];
54
59
 
55
60
  // "GetConsensusParamsResponse" is excluded as this message does not support proofs
56
- const VERSIONED_RESPONSES: [&str; 16] = [
61
+ const VERSIONED_RESPONSES: [&str; 18] = [
57
62
  "GetDataContractHistoryResponse",
58
63
  "GetDataContractResponse",
59
64
  "GetDataContractsResponse",
@@ -62,6 +67,8 @@ pub fn generate() -> Result<(), std::io::Error> {
62
67
  "GetIdentitiesResponse",
63
68
  "GetIdentityBalanceAndRevisionResponse",
64
69
  "GetIdentityBalanceResponse",
70
+ "GetIdentityNonceResponse",
71
+ "GetIdentityContractNonceResponse",
65
72
  "GetIdentityByPublicKeyHashResponse",
66
73
  "GetIdentityKeysResponse",
67
74
  "GetIdentityResponse",
@@ -92,6 +99,9 @@ pub fn generate() -> Result<(), std::io::Error> {
92
99
  .message_attribute(msg, r#"#[grpc_versions(0)]"#);
93
100
  }
94
101
 
102
+ // All messages can be mocked.
103
+ platform = platform.message_attribute(".", r#"#[derive( ::dapi_grpc_macros::Mockable)]"#);
104
+
95
105
  #[cfg(feature = "serde")]
96
106
  let platform = platform
97
107
  .type_attribute(
@@ -132,9 +142,21 @@ pub fn generate() -> Result<(), std::io::Error> {
132
142
  .field_attribute("Proof.signature", r#"#[serde(with = "serde_bytes")]"#)
133
143
  .field_attribute("Proof.block_id_hash", r#"#[serde(with = "serde_bytes")]"#);
134
144
 
135
- platform.generate().unwrap();
145
+ platform
146
+ }
147
+
148
+ fn configure_core(mut core: MappingConfig) -> MappingConfig {
149
+ // All messages can be mocked.
150
+ core = core.message_attribute(".", r#"#[derive( ::dapi_grpc_macros::Mockable)]"#);
151
+
152
+ // Serde support
153
+ #[cfg(feature = "serde")]
154
+ let core = core.type_attribute(
155
+ ".",
156
+ r#"#[derive(::serde::Serialize, ::serde::Deserialize)]"#,
157
+ );
136
158
 
137
- Ok(())
159
+ core
138
160
  }
139
161
 
140
162
  impl MappingConfig {
@@ -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,10 @@ const {
48
48
  PBJSGetProtocolVersionUpgradeVoteStatusResponse,
49
49
  GetProtocolVersionUpgradeStateRequest: PBJSGetProtocolVersionUpgradeStateRequest,
50
50
  GetProtocolVersionUpgradeStateResponse: PBJSGetProtocolVersionUpgradeStateResponse,
51
+ GetIdentityContractNonceRequest: PBJSGetIdentityContractNonceRequest,
52
+ GetIdentityContractNonceResponse: PBJSGetIdentityContractNonceResponse,
53
+ GetIdentityNonceRequest: PBJSGetIdentityNonceRequest,
54
+ GetIdentityNonceResponse: PBJSGetIdentityNonceResponse,
51
55
  },
52
56
  },
53
57
  },
@@ -67,6 +71,8 @@ const {
67
71
  GetEpochsInfoResponse: ProtocGetEpochsInfoResponse,
68
72
  GetProtocolVersionUpgradeVoteStatusResponse: ProtocGetProtocolVersionUpgradeVoteStatusResponse,
69
73
  GetProtocolVersionUpgradeStateResponse: ProtocGetProtocolVersionUpgradeStateResponse,
74
+ GetIdentityContractNonceResponse: ProtocGetIdentityContractNonceResponse,
75
+ GetIdentityNonceResponse: ProtocGetIdentityNonceResponse,
70
76
  } = require('./platform_protoc');
71
77
 
72
78
  const getPlatformDefinition = require('../../../../lib/getPlatformDefinition');
@@ -137,6 +143,14 @@ class PlatformPromiseClient {
137
143
  this.client.getProtocolVersionUpgradeState.bind(this.client),
138
144
  );
139
145
 
146
+ this.client.getIdentityContractNonce = promisify(
147
+ this.client.getIdentityContractNonce.bind(this.client),
148
+ );
149
+
150
+ this.client.getIdentityNonce = promisify(
151
+ this.client.getIdentityNonce.bind(this.client),
152
+ );
153
+
140
154
  this.protocolVersion = undefined;
141
155
  }
142
156
 
@@ -496,6 +510,70 @@ class PlatformPromiseClient {
496
510
  );
497
511
  }
498
512
 
513
+ /**
514
+ * @param {!PBJSGetIdentityContractNonceRequest} getIdentityContractNonceRequest
515
+ * @param {?Object<string, string>} metadata
516
+ * @param {CallOptions} [options={}]
517
+ * @return {Promise<!GetIdentityContractNonceResponse>}
518
+ */
519
+ getIdentityContractNonce(
520
+ getIdentityContractNonceRequest,
521
+ metadata = {},
522
+ options = {},
523
+ ) {
524
+ if (!isObject(metadata)) {
525
+ throw new Error('metadata must be an object');
526
+ }
527
+
528
+ return this.client.getIdentityContractNonce(
529
+ getIdentityContractNonceRequest,
530
+ convertObjectToMetadata(metadata),
531
+ {
532
+ interceptors: [
533
+ jsonToProtobufInterceptorFactory(
534
+ jsonToProtobufFactory(
535
+ ProtocGetIdentityContractNonceResponse,
536
+ PBJSGetIdentityContractNonceResponse,
537
+ ),
538
+ protobufToJsonFactory(
539
+ PBJSGetIdentityContractNonceRequest,
540
+ ),
541
+ ),
542
+ ],
543
+ ...options,
544
+ },
545
+ );
546
+ }
547
+
548
+ getIdentityNonce(
549
+ getIdentityNonceRequest,
550
+ metadata = {},
551
+ options = {},
552
+ ) {
553
+ if (!isObject(metadata)) {
554
+ throw new Error('metadata must be an object');
555
+ }
556
+
557
+ return this.client.getIdentityNonce(
558
+ getIdentityNonceRequest,
559
+ convertObjectToMetadata(metadata),
560
+ {
561
+ interceptors: [
562
+ jsonToProtobufInterceptorFactory(
563
+ jsonToProtobufFactory(
564
+ ProtocGetIdentityNonceResponse,
565
+ PBJSGetIdentityNonceResponse,
566
+ ),
567
+ protobufToJsonFactory(
568
+ PBJSGetIdentityNonceRequest,
569
+ ),
570
+ ),
571
+ ],
572
+ ...options,
573
+ },
574
+ );
575
+ }
576
+
499
577
  /**
500
578
  * @param {string} protocolVersion
501
579
  */