@dashevo/dapi-grpc 0.25.0-dev.9 → 0.25.0
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 +44 -0
- package/build.rs +69 -0
- package/clients/core/v0/rust/README.md +3 -0
- package/clients/core/v0/rust/core_example.rs +14 -0
- package/clients/platform/v0/nodejs/PlatformPromiseClient.js +39 -0
- package/clients/platform/v0/nodejs/platform_pbjs.js +13976 -1484
- package/clients/platform/v0/nodejs/platform_protoc.js +11116 -1468
- package/clients/platform/v0/rust/README.md +3 -0
- package/clients/platform/v0/rust/platform_example.rs +15 -0
- package/clients/platform/v0/web/PlatformPromiseClient.js +15 -0
- package/clients/platform/v0/web/platform_pb.d.ts +1278 -22
- package/clients/platform/v0/web/platform_pb.js +11116 -1468
- package/clients/platform/v0/web/platform_pb_service.d.ts +152 -0
- package/clients/platform/v0/web/platform_pb_service.js +320 -0
- package/package.json +16 -4
- package/protos/platform/v0/platform.proto +274 -16
- package/scripts/build.sh +91 -115
- package/scripts/patch-protobuf-js.sh +10 -9
- package/src/core/proto/org.dash.platform.dapi.v0.rs +666 -0
- package/src/lib.rs +15 -0
- package/src/platform/proto/org.dash.platform.dapi.v0.rs +1324 -0
- package/clients/core/v0/rust/core.rs +0 -4956
- package/clients/core/v0/rust/core_grpc.rs +0 -223
- package/clients/core/v0/rust/mod.rs +0 -3
- package/clients/platform/v0/rust/mod.rs +0 -3
- package/clients/platform/v0/rust/platform.rs +0 -3555
- package/clients/platform/v0/rust/platform_grpc.rs +0 -223
package/Cargo.toml
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
[package]
|
|
2
|
+
name = "dapi-grpc"
|
|
3
|
+
description = "GRPC client for Dash Platform"
|
|
4
|
+
version = "0.25.0"
|
|
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>",
|
|
11
|
+
]
|
|
12
|
+
edition = "2021"
|
|
13
|
+
license = "MIT"
|
|
14
|
+
|
|
15
|
+
[dependencies]
|
|
16
|
+
prost = { version = "0.11.9" }
|
|
17
|
+
prost-types = { version = "0.11.9" }
|
|
18
|
+
tonic = { version = "0.9.2", features = [
|
|
19
|
+
"codegen",
|
|
20
|
+
"prost",
|
|
21
|
+
], default-features = false }
|
|
22
|
+
|
|
23
|
+
[build-dependencies]
|
|
24
|
+
tonic-build = { version = "0.9.2" }
|
|
25
|
+
|
|
26
|
+
[features]
|
|
27
|
+
default = ["core", "platform", "client"]
|
|
28
|
+
core = ["core_v0"]
|
|
29
|
+
platform = ["platform_v0"]
|
|
30
|
+
client = ["tonic/channel", "tonic/tls", "tonic/tls-roots", "platform"]
|
|
31
|
+
|
|
32
|
+
core_v0 = []
|
|
33
|
+
platform_v0 = []
|
|
34
|
+
|
|
35
|
+
[lib]
|
|
36
|
+
|
|
37
|
+
[[example]]
|
|
38
|
+
name = "core_example"
|
|
39
|
+
path = "clients/core/v0/rust/core_example.rs"
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
[[example]]
|
|
43
|
+
name = "platform_example"
|
|
44
|
+
path = "clients/platform/v0/rust/platform_example.rs"
|
package/build.rs
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
use std::{
|
|
2
|
+
collections::HashMap,
|
|
3
|
+
fs::{create_dir_all, remove_dir_all},
|
|
4
|
+
path::PathBuf,
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
fn main() {
|
|
8
|
+
generate().expect("failed to compile protobuf definitions");
|
|
9
|
+
|
|
10
|
+
println!("cargo:rerun-if-changed=./protos");
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/// Generate Rust definitions from Protobuf definitions
|
|
14
|
+
pub fn generate() -> Result<(), std::io::Error> {
|
|
15
|
+
// Mapping between protobuf files => output directory
|
|
16
|
+
let mut input = HashMap::<PathBuf, PathBuf>::new();
|
|
17
|
+
input.insert(
|
|
18
|
+
PathBuf::from("protos/core/v0/core.proto"),
|
|
19
|
+
PathBuf::from("src/core/proto"),
|
|
20
|
+
);
|
|
21
|
+
input.insert(
|
|
22
|
+
PathBuf::from("protos/platform/v0/platform.proto"),
|
|
23
|
+
PathBuf::from("src/platform/proto"),
|
|
24
|
+
);
|
|
25
|
+
|
|
26
|
+
let proto_includes = vec![abs_path(&PathBuf::from("protos"))];
|
|
27
|
+
|
|
28
|
+
for (proto, dest) in input {
|
|
29
|
+
let proto = abs_path(&proto);
|
|
30
|
+
let dest = abs_path(&dest);
|
|
31
|
+
// Remove old compiled files; ignore errors
|
|
32
|
+
if dest.exists() {
|
|
33
|
+
remove_dir_all(&dest)?;
|
|
34
|
+
}
|
|
35
|
+
create_dir_all(&dest)?;
|
|
36
|
+
|
|
37
|
+
generate1(&[proto], &proto_includes, &dest)?;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
Ok(())
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/// Run single generation process.
|
|
44
|
+
///
|
|
45
|
+
/// All paths must be absolute
|
|
46
|
+
fn generate1(
|
|
47
|
+
files: &[PathBuf],
|
|
48
|
+
proto_includes: &[PathBuf],
|
|
49
|
+
out_dir: &PathBuf,
|
|
50
|
+
) -> Result<(), std::io::Error> {
|
|
51
|
+
let pb = tonic_build::configure()
|
|
52
|
+
.build_server(false)
|
|
53
|
+
.out_dir(out_dir)
|
|
54
|
+
.protoc_arg("--experimental_allow_proto3_optional");
|
|
55
|
+
#[cfg(feature = "client")]
|
|
56
|
+
let pb = pb.build_client(true).build_transport(true);
|
|
57
|
+
#[cfg(not(feature = "client"))]
|
|
58
|
+
let pb = pb.build_client(false).build_transport(false);
|
|
59
|
+
|
|
60
|
+
pb.compile(files, proto_includes)
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
fn abs_path(path: &PathBuf) -> PathBuf {
|
|
64
|
+
if path.is_absolute() {
|
|
65
|
+
return path.to_owned();
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
PathBuf::from(env!("CARGO_MANIFEST_DIR")).join(path)
|
|
69
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
use dapi_grpc::core::v0 as core;
|
|
2
|
+
use prost::Message;
|
|
3
|
+
|
|
4
|
+
fn main() {
|
|
5
|
+
let request = core::GetBlockRequest {
|
|
6
|
+
block: Some(core::get_block_request::Block::Height(123)),
|
|
7
|
+
};
|
|
8
|
+
let mut buffer = Vec::<u8>::new();
|
|
9
|
+
request.encode(&mut buffer).expect("failed to encode data");
|
|
10
|
+
|
|
11
|
+
let decoded = core::GetBlockRequest::decode(buffer.as_ref()).expect("failed to decode data");
|
|
12
|
+
|
|
13
|
+
assert_eq!(request, decoded);
|
|
14
|
+
}
|
|
@@ -30,6 +30,8 @@ const {
|
|
|
30
30
|
GetIdentityResponse: PBJSGetIdentityResponse,
|
|
31
31
|
GetDataContractRequest: PBJSGetDataContractRequest,
|
|
32
32
|
GetDataContractResponse: PBJSGetDataContractResponse,
|
|
33
|
+
GetDataContractHistoryRequest: PBJSGetDataContractHistoryRequest,
|
|
34
|
+
GetDataContractHistoryResponse: PBJSGetDataContractHistoryResponse,
|
|
33
35
|
GetDocumentsRequest: PBJSGetDocumentsRequest,
|
|
34
36
|
GetDocumentsResponse: PBJSGetDocumentsResponse,
|
|
35
37
|
GetIdentitiesByPublicKeyHashesRequest: PBJSGetIdentitiesByPublicKeyHashesRequest,
|
|
@@ -49,6 +51,7 @@ const {
|
|
|
49
51
|
BroadcastStateTransitionResponse: ProtocBroadcastStateTransitionResponse,
|
|
50
52
|
GetIdentityResponse: ProtocGetIdentityResponse,
|
|
51
53
|
GetDataContractResponse: ProtocGetDataContractResponse,
|
|
54
|
+
GetDataContractHistoryResponse: ProtocGetDataContractHistoryResponse,
|
|
52
55
|
GetDocumentsResponse: ProtocGetDocumentsResponse,
|
|
53
56
|
GetIdentitiesByPublicKeyHashesResponse: ProtocGetIdentitiesByPublicKeyHashesResponse,
|
|
54
57
|
WaitForStateTransitionResultResponse: ProtocWaitForStateTransitionResultResponse,
|
|
@@ -91,6 +94,10 @@ class PlatformPromiseClient {
|
|
|
91
94
|
this.client.getDataContract.bind(this.client),
|
|
92
95
|
);
|
|
93
96
|
|
|
97
|
+
this.client.getDataContractHistory = promisify(
|
|
98
|
+
this.client.getDataContractHistory.bind(this.client),
|
|
99
|
+
);
|
|
100
|
+
|
|
94
101
|
this.client.getDocuments = promisify(
|
|
95
102
|
this.client.getDocuments.bind(this.client),
|
|
96
103
|
);
|
|
@@ -204,6 +211,38 @@ class PlatformPromiseClient {
|
|
|
204
211
|
);
|
|
205
212
|
}
|
|
206
213
|
|
|
214
|
+
/**
|
|
215
|
+
*
|
|
216
|
+
* @param {!GetDataContractHistoryRequest} getDataContractHistoryRequest
|
|
217
|
+
* @param {?Object<string, string>} metadata
|
|
218
|
+
* @param {CallOptions} [options={}]
|
|
219
|
+
* @returns {Promise<!GetDataContractResponse>}
|
|
220
|
+
*/
|
|
221
|
+
getDataContractHistory(getDataContractHistoryRequest, metadata = {}, options = {}) {
|
|
222
|
+
if (!isObject(metadata)) {
|
|
223
|
+
throw new Error('metadata must be an object');
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
return this.client.getDataContractHistory(
|
|
227
|
+
getDataContractHistoryRequest,
|
|
228
|
+
convertObjectToMetadata(metadata),
|
|
229
|
+
{
|
|
230
|
+
interceptors: [
|
|
231
|
+
jsonToProtobufInterceptorFactory(
|
|
232
|
+
jsonToProtobufFactory(
|
|
233
|
+
ProtocGetDataContractHistoryResponse,
|
|
234
|
+
PBJSGetDataContractHistoryResponse,
|
|
235
|
+
),
|
|
236
|
+
protobufToJsonFactory(
|
|
237
|
+
PBJSGetDataContractHistoryRequest,
|
|
238
|
+
),
|
|
239
|
+
),
|
|
240
|
+
],
|
|
241
|
+
...options,
|
|
242
|
+
},
|
|
243
|
+
);
|
|
244
|
+
}
|
|
245
|
+
|
|
207
246
|
/**
|
|
208
247
|
*
|
|
209
248
|
* @param {!GetDocumentsRequest} getDocumentsRequest
|