@dashevo/dapi-grpc 1.0.0-pr.1825.9 → 1.0.0-pr.1883.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 +9 -7
- package/build.rs +61 -42
- package/clients/core/v0/nodejs/CorePromiseClient.js +73 -0
- package/clients/core/v0/nodejs/core_pbjs.js +783 -14
- package/clients/core/v0/nodejs/core_protoc.js +574 -0
- package/clients/core/v0/web/CorePromiseClient.js +30 -0
- package/clients/core/v0/web/core_pb.d.ts +74 -0
- package/clients/core/v0/web/core_pb.js +574 -0
- package/clients/core/v0/web/core_pb_service.d.ts +30 -0
- package/clients/core/v0/web/core_pb_service.js +88 -0
- package/clients/platform/v0/nodejs/PlatformPromiseClient.js +55 -14
- package/clients/platform/v0/nodejs/platform_pbjs.js +7193 -8354
- package/clients/platform/v0/nodejs/platform_protoc.js +3175 -4286
- package/clients/platform/v0/web/PlatformPromiseClient.js +22 -8
- package/clients/platform/v0/web/platform_pb.d.ts +231 -372
- package/clients/platform/v0/web/platform_pb.js +3175 -4286
- package/clients/platform/v0/web/platform_pb_service.d.ts +16 -35
- package/clients/platform/v0/web/platform_pb_service.js +12 -52
- package/package.json +2 -2
- package/protos/core/v0/core.proto +18 -0
- package/protos/platform/v0/platform.proto +49 -64
- package/src/lib.rs +19 -2
- package/test/unit/clients/platform/v0/nodejs/PlatformPromiseClient.spec.js +21 -0
- package/src/core/proto/org.dash.platform.dapi.v0.rs +0 -1338
- package/src/platform/proto/org.dash.platform.dapi.v0.rs +0 -4208
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.
|
|
4
|
+
version = "1.0.0-pr.1883.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
|
-
|
|
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 = [
|
|
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
|
|
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
|
|
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;
|
|
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;
|
|
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
|
-
.
|
|
131
|
-
"
|
|
132
|
-
r#"#[serde(
|
|
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",
|
|
141
|
-
.field_attribute("where",
|
|
142
|
-
.field_attribute("order_by",
|
|
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",
|
|
145
|
-
.field_attribute("Proof.quorum_hash",
|
|
146
|
-
.field_attribute("Proof.signature",
|
|
147
|
-
.field_attribute("Proof.block_id_hash",
|
|
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(
|
|
149
|
+
fn configure_core(core: MappingConfig) -> MappingConfig {
|
|
153
150
|
// All messages can be mocked.
|
|
154
|
-
core = core.message_attribute(".", r#"#[derive(
|
|
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,
|
|
@@ -40,6 +42,8 @@ const {
|
|
|
40
42
|
GetEstimatedTransactionFeeResponse: PBJSGetEstimatedTransactionFeeResponse,
|
|
41
43
|
TransactionsWithProofsRequest: PBJSTransactionsWithProofsRequest,
|
|
42
44
|
TransactionsWithProofsResponse: PBJSTransactionsWithProofsResponse,
|
|
45
|
+
MasternodeListRequest: PBJSMasternodeListRequest,
|
|
46
|
+
MasternodeListResponse: PBJSMasternodeListResponse,
|
|
43
47
|
},
|
|
44
48
|
},
|
|
45
49
|
},
|
|
@@ -51,11 +55,13 @@ const {
|
|
|
51
55
|
GetBlockchainStatusResponse: ProtocGetBlockchainStatusResponse,
|
|
52
56
|
GetMasternodeStatusResponse: ProtocGetMasternodeStatusResponse,
|
|
53
57
|
GetBlockResponse: ProtocGetBlockResponse,
|
|
58
|
+
GetBestBlockHeightResponse: ProtocGetBestBlockHeightResponse,
|
|
54
59
|
BroadcastTransactionResponse: ProtocBroadcastTransactionResponse,
|
|
55
60
|
GetTransactionResponse: ProtocGetTransactionResponse,
|
|
56
61
|
BlockHeadersWithChainLocksResponse: ProtocBlockHeadersWithChainLocksResponse,
|
|
57
62
|
GetEstimatedTransactionFeeResponse: ProtocGetEstimatedTransactionFeeResponse,
|
|
58
63
|
TransactionsWithProofsResponse: ProtocTransactionsWithProofsResponse,
|
|
64
|
+
MasternodeListResponse: ProtocMasternodeListResponse,
|
|
59
65
|
} = require('./core_protoc');
|
|
60
66
|
|
|
61
67
|
const getCoreDefinition = require('../../../../lib/getCoreDefinition');
|
|
@@ -94,6 +100,10 @@ class CorePromiseClient {
|
|
|
94
100
|
this.client.getBlock.bind(this.client),
|
|
95
101
|
);
|
|
96
102
|
|
|
103
|
+
this.client.getBestBlockHeight = promisify(
|
|
104
|
+
this.client.getBestBlockHeight.bind(this.client),
|
|
105
|
+
);
|
|
106
|
+
|
|
97
107
|
this.client.broadcastTransaction = promisify(
|
|
98
108
|
this.client.broadcastTransaction.bind(this.client),
|
|
99
109
|
);
|
|
@@ -169,6 +179,37 @@ class CorePromiseClient {
|
|
|
169
179
|
);
|
|
170
180
|
}
|
|
171
181
|
|
|
182
|
+
/**
|
|
183
|
+
* @param {!GetBestBlockHeightRequest} getBestBlockHeightRequest
|
|
184
|
+
* @param {?Object<string, string>} metadata
|
|
185
|
+
* @param {CallOptions} [options={}]
|
|
186
|
+
* @return {Promise<!GetBestBlockHeightResponse>}
|
|
187
|
+
*/
|
|
188
|
+
getBestBlockHeight(getBestBlockHeightRequest, metadata = {}, options = {}) {
|
|
189
|
+
if (!isObject(metadata)) {
|
|
190
|
+
throw new Error('metadata must be an object');
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
return this.client.getBestBlockHeight(
|
|
194
|
+
getBestBlockHeightRequest,
|
|
195
|
+
convertObjectToMetadata(metadata),
|
|
196
|
+
{
|
|
197
|
+
interceptors: [
|
|
198
|
+
jsonToProtobufInterceptorFactory(
|
|
199
|
+
jsonToProtobufFactory(
|
|
200
|
+
ProtocGetBestBlockHeightResponse,
|
|
201
|
+
PBJSGetBestBlockHeightResponse,
|
|
202
|
+
),
|
|
203
|
+
protobufToJsonFactory(
|
|
204
|
+
PBJSGetBestBlockHeightRequest,
|
|
205
|
+
),
|
|
206
|
+
),
|
|
207
|
+
],
|
|
208
|
+
...options,
|
|
209
|
+
},
|
|
210
|
+
);
|
|
211
|
+
}
|
|
212
|
+
|
|
172
213
|
/**
|
|
173
214
|
* @param {!GetMasternodeStatusRequest} getMasternodeStatusRequest
|
|
174
215
|
* @param {?Object<string, string>} metadata
|
|
@@ -360,6 +401,38 @@ class CorePromiseClient {
|
|
|
360
401
|
},
|
|
361
402
|
);
|
|
362
403
|
}
|
|
404
|
+
|
|
405
|
+
/**
|
|
406
|
+
* @param {MasternodeListRequest} masternodeListRequest The request proto
|
|
407
|
+
* @param {?Object<string, string>} metadata User defined call metadata
|
|
408
|
+
* @param {CallOptions} [options={}]
|
|
409
|
+
* @return {!grpc.web.ClientReadableStream<!MasternodeListResponse>|undefined}
|
|
410
|
+
* The XHR Node Readable Stream
|
|
411
|
+
*/
|
|
412
|
+
subscribeToMasternodeList(masternodeListRequest, metadata = {}, options = {}) {
|
|
413
|
+
if (!isObject(metadata)) {
|
|
414
|
+
throw new Error('metadata must be an object');
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
return this.client.subscribeToMasternodeList(
|
|
418
|
+
masternodeListRequest,
|
|
419
|
+
convertObjectToMetadata(metadata),
|
|
420
|
+
{
|
|
421
|
+
interceptors: [
|
|
422
|
+
jsonToProtobufInterceptorFactory(
|
|
423
|
+
jsonToProtobufFactory(
|
|
424
|
+
ProtocMasternodeListResponse,
|
|
425
|
+
PBJSMasternodeListResponse,
|
|
426
|
+
),
|
|
427
|
+
protobufToJsonFactory(
|
|
428
|
+
PBJSMasternodeListRequest,
|
|
429
|
+
),
|
|
430
|
+
),
|
|
431
|
+
],
|
|
432
|
+
...options,
|
|
433
|
+
},
|
|
434
|
+
);
|
|
435
|
+
}
|
|
363
436
|
}
|
|
364
437
|
|
|
365
438
|
module.exports = CorePromiseClient;
|