@dashevo/dapi-grpc 2.0.0-dev.1 → 2.0.0-rc.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 = "2.0.0-dev.1"
4
+ version = "2.0.0-rc.1"
5
5
  authors = [
6
6
  "Samuel Westrich <sam@dash.org>",
7
7
  "Igor Markin <igor.markin@dash.org>",
@@ -15,6 +15,8 @@ license = "MIT"
15
15
 
16
16
  [features]
17
17
  default = ["core", "platform", "client"]
18
+ # Internal Drive endpoints. Used by DAPI
19
+ drive = ["platform"]
18
20
  core = []
19
21
  platform = []
20
22
  # Re-export Dash Platform protobuf types as `dapi_grpc::platform::proto`
@@ -25,21 +27,28 @@ tenderdash-proto = []
25
27
  client = ["platform"]
26
28
 
27
29
  # Build tonic server code. Includes all client features and adds server-specific dependencies.
28
- server = ["platform", "tenderdash-proto/server", "client"]
30
+ server = [
31
+ "platform",
32
+ "tenderdash-proto/server",
33
+ "client",
34
+ "drive",
35
+ "tonic/router",
36
+ ]
29
37
 
30
38
  serde = ["dep:serde", "dep:serde_bytes", "tenderdash-proto/serde"]
31
39
  mocks = ["serde", "dep:serde_json"]
32
40
 
33
41
  [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 }
42
+ tenderdash-proto = { git = "https://github.com/dashpay/rs-tenderdash-abci", version = "1.4.0", tag = "v1.4.0", default-features = false }
35
43
 
36
44
  prost = { version = "0.13" }
37
45
  futures-core = "0.3.30"
38
- tonic = { version = "0.12.3", features = [
46
+ tonic = { version = "0.13.0", features = [
39
47
  "codegen",
40
48
  "prost",
49
+ "tls-ring",
41
50
  ], default-features = false }
42
- serde = { version = "1.0.197", optional = true, features = ["derive"] }
51
+ serde = { version = "1.0.219", optional = true, features = ["derive"] }
43
52
  serde_bytes = { version = "0.11.12", optional = true }
44
53
  serde_json = { version = "1.0", optional = true }
45
54
  dapi-grpc-macros = { path = "../rs-dapi-grpc-macros" }
@@ -49,18 +58,18 @@ platform-version = { path = "../rs-platform-version" }
49
58
  getrandom = { version = "0.2", features = ["js"] }
50
59
 
51
60
  [target.'cfg(not(target_arch = "wasm32"))'.dependencies]
52
- tonic = { version = "0.12.3", features = [
61
+ tonic = { version = "0.13.0", features = [
53
62
  "codegen",
54
63
  "prost",
55
64
  "channel",
56
65
  "transport",
57
- "tls",
58
- "tls-roots",
66
+ "tls-native-roots",
59
67
  "tls-webpki-roots",
68
+ "tls-ring",
60
69
  ], default-features = false }
61
70
 
62
71
  [build-dependencies]
63
- tonic-build = { version = "0.12.3" }
72
+ tonic-build = { version = "0.13.0" }
64
73
 
65
74
  [lib]
66
75
 
package/build.rs CHANGED
@@ -47,6 +47,16 @@ fn generate_code(typ: ImplType) {
47
47
  .generate()
48
48
  .expect("generate platform proto");
49
49
 
50
+ let drive = MappingConfig::new(
51
+ PathBuf::from("protos/drive/v0/drive.proto"),
52
+ PathBuf::from("src/drive"),
53
+ &typ,
54
+ );
55
+
56
+ configure_drive(drive)
57
+ .generate()
58
+ .expect("generate platform proto");
59
+
50
60
  println!("cargo:rerun-if-changed=./protos");
51
61
  println!("cargo:rerun-if-env-changed=CARGO_FEATURE_SERDE");
52
62
  println!("cargo:rerun-if-env-changed=CARGO_CFG_TARGET_ARCH");
@@ -63,7 +73,7 @@ fn configure_platform(mut platform: MappingConfig) -> MappingConfig {
63
73
  // Derive features for versioned messages
64
74
  //
65
75
  // "GetConsensusParamsRequest" is excluded as this message does not support proofs
66
- const VERSIONED_REQUESTS: [&str; 40] = [
76
+ const VERSIONED_REQUESTS: [&str; 41] = [
67
77
  "GetDataContractHistoryRequest",
68
78
  "GetDataContractRequest",
69
79
  "GetDataContractsRequest",
@@ -75,10 +85,10 @@ fn configure_platform(mut platform: MappingConfig) -> MappingConfig {
75
85
  "GetIdentityContractNonceRequest",
76
86
  "GetIdentityBalanceAndRevisionRequest",
77
87
  "GetIdentityBalanceRequest",
88
+ "GetIdentityByNonUniquePublicKeyHashRequest",
78
89
  "GetIdentityByPublicKeyHashRequest",
79
90
  "GetIdentityKeysRequest",
80
91
  "GetIdentityRequest",
81
- "GetProofsRequest",
82
92
  "WaitForStateTransitionResultRequest",
83
93
  "GetProtocolVersionUpgradeStateRequest",
84
94
  "GetProtocolVersionUpgradeVoteStatusRequest",
@@ -98,6 +108,7 @@ fn configure_platform(mut platform: MappingConfig) -> MappingConfig {
98
108
  "GetIdentitiesTokenBalancesRequest",
99
109
  "GetIdentityTokenInfosRequest",
100
110
  "GetIdentitiesTokenInfosRequest",
111
+ "GetTokenDirectPurchasePricesRequest",
101
112
  "GetTokenStatusesRequest",
102
113
  "GetTokenTotalSupplyRequest",
103
114
  "GetGroupInfoRequest",
@@ -110,6 +121,9 @@ fn configure_platform(mut platform: MappingConfig) -> MappingConfig {
110
121
  // - "GetConsensusParamsResponse"
111
122
  // - "GetStatusResponse"
112
123
  //
124
+ // The following responses are excluded as they need custom proof handling:
125
+ // - "GetIdentityByNonUniquePublicKeyHashResponse"
126
+ //
113
127
  // "GetEvonodesProposedEpochBlocksResponse" is used for 2 Requests
114
128
  const VERSIONED_RESPONSES: [&str; 39] = [
115
129
  "GetDataContractHistoryResponse",
@@ -126,7 +140,6 @@ fn configure_platform(mut platform: MappingConfig) -> MappingConfig {
126
140
  "GetIdentityByPublicKeyHashResponse",
127
141
  "GetIdentityKeysResponse",
128
142
  "GetIdentityResponse",
129
- "GetProofsResponse",
130
143
  "WaitForStateTransitionResultResponse",
131
144
  "GetEpochsInfoResponse",
132
145
  "GetProtocolVersionUpgradeStateResponse",
@@ -145,6 +158,7 @@ fn configure_platform(mut platform: MappingConfig) -> MappingConfig {
145
158
  "GetIdentitiesTokenBalancesResponse",
146
159
  "GetIdentityTokenInfosResponse",
147
160
  "GetIdentitiesTokenInfosResponse",
161
+ "GetTokenDirectPurchasePricesResponse",
148
162
  "GetTokenStatusesResponse",
149
163
  "GetTokenTotalSupplyResponse",
150
164
  "GetGroupInfoResponse",
@@ -210,6 +224,19 @@ fn configure_platform(mut platform: MappingConfig) -> MappingConfig {
210
224
  platform
211
225
  }
212
226
 
227
+ fn configure_drive(drive: MappingConfig) -> MappingConfig {
228
+ drive
229
+ .message_attribute(".", r#"#[derive( ::dapi_grpc_macros::Mockable)]"#)
230
+ .type_attribute(
231
+ ".",
232
+ r#"#[cfg_attr(feature = "serde", derive(::serde::Serialize, ::serde::Deserialize))]"#,
233
+ )
234
+ .type_attribute(
235
+ ".",
236
+ r#"#[cfg_attr(feature = "serde", serde(rename_all = "snake_case"))]"#,
237
+ )
238
+ }
239
+
213
240
  /// Check for duplicate messages in the list.
214
241
  fn check_unique(messages: &[&'static str]) -> Result<(), String> {
215
242
  let mut hashset: HashSet<&'static str> = HashSet::new();
@@ -322,6 +349,14 @@ impl MappingConfig {
322
349
  self
323
350
  }
324
351
 
352
+ #[allow(unused)]
353
+ fn includes(mut self, includes: &[PathBuf]) -> Self {
354
+ for include in includes {
355
+ self.proto_includes.push(abs_path(include));
356
+ }
357
+ self
358
+ }
359
+
325
360
  #[allow(unused)]
326
361
  fn field_attribute(mut self, path: &str, attribute: &str) -> Self {
327
362
  self.builder = self.builder.field_attribute(path, attribute);
@@ -0,0 +1,111 @@
1
+ const grpc = require('@grpc/grpc-js');
2
+ const { promisify } = require('util');
3
+
4
+ const {
5
+ convertObjectToMetadata,
6
+ utils: {
7
+ isObject,
8
+ },
9
+ client: {
10
+ interceptors: {
11
+ jsonToProtobufInterceptorFactory,
12
+ },
13
+ converters: {
14
+ jsonToProtobufFactory,
15
+ protobufToJsonFactory,
16
+ },
17
+ },
18
+ } = require('@dashevo/grpc-common');
19
+
20
+ const { URL } = require('url');
21
+ const {
22
+ org: {
23
+ dash: {
24
+ platform: {
25
+ drive: {
26
+ v0: {
27
+ GetProofsRequest: PBJSGetProofsRequest,
28
+ GetProofsResponse: PBJSGetProofsResponse,
29
+ },
30
+ },
31
+ },
32
+ },
33
+ },
34
+ } = require('./drive_pbjs');
35
+
36
+ const {
37
+ GetProofsResponse: ProtocGetProofsResponse,
38
+ } = require('./drive_protoc');
39
+
40
+ const getDriveDefinition = require('../../../../lib/getDriveDefinition');
41
+
42
+ const DriveNodeJSClient = getDriveDefinition(0);
43
+
44
+ class DrivePromiseClient {
45
+ /**
46
+ * @param {string} hostname
47
+ * @param {?Object} credentials
48
+ * @param {?Object} options
49
+ */
50
+ constructor(hostname, credentials, options = {}) {
51
+ if (credentials !== undefined) {
52
+ throw new Error('"credentials" option is not supported yet');
53
+ }
54
+
55
+ const url = new URL(hostname);
56
+ const { protocol, host: strippedHostname } = url;
57
+
58
+ // See this issue https://github.com/nodejs/node/issues/3176
59
+ // eslint-disable-next-line no-param-reassign
60
+ credentials = protocol.replace(':', '') === 'https' ? grpc.credentials.createSsl() : grpc.credentials.createInsecure();
61
+
62
+ this.client = new DriveNodeJSClient(strippedHostname, credentials, options);
63
+
64
+ this.client.getProofs = promisify(
65
+ this.client.getProofs.bind(this.client),
66
+ );
67
+
68
+ this.protocolVersion = undefined;
69
+ }
70
+
71
+ /**
72
+ *
73
+ * @param {!GetProofsRequest} request
74
+ * @param {?Object<string, string>} metadata
75
+ * @param {CallOptions} [options={}]
76
+ * @returns {Promise<!GetProofsResponse>}
77
+ */
78
+ getProofs(request, metadata = {}, options = {}) {
79
+ if (!isObject(metadata)) {
80
+ throw new Error('metadata must be an object');
81
+ }
82
+
83
+ return this.client.getProofs(
84
+ request,
85
+ convertObjectToMetadata(metadata),
86
+ {
87
+ interceptors: [
88
+ jsonToProtobufInterceptorFactory(
89
+ jsonToProtobufFactory(
90
+ ProtocGetProofsResponse,
91
+ PBJSGetProofsResponse,
92
+ ),
93
+ protobufToJsonFactory(
94
+ PBJSGetProofsRequest,
95
+ ),
96
+ ),
97
+ ],
98
+ ...options,
99
+ },
100
+ );
101
+ }
102
+
103
+ /**
104
+ * @param {string} protocolVersion
105
+ */
106
+ setProtocolVersion(protocolVersion) {
107
+ this.protocolVersion = protocolVersion;
108
+ }
109
+ }
110
+
111
+ module.exports = DrivePromiseClient;