@dashevo/dapi-grpc 0.25.0-dev.1 → 0.25.0-dev.11
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 +39 -0
- package/build.rs +65 -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/platform_pbjs.js +9682 -1470
- package/clients/platform/v0/nodejs/platform_protoc.js +6735 -1259
- package/clients/platform/v0/rust/README.md +3 -0
- package/clients/platform/v0/rust/platform_example.rs +15 -0
- package/clients/platform/v0/web/platform_pb.d.ts +709 -5
- package/clients/platform/v0/web/platform_pb.js +6735 -1259
- package/clients/platform/v0/web/platform_pb_service.d.ts +95 -0
- package/clients/platform/v0/web/platform_pb_service.js +200 -0
- package/package.json +15 -3
- package/protos/platform/v0/platform.proto +151 -7
- package/scripts/build.sh +84 -78
- package/scripts/patch-protobuf-js.sh +10 -9
- package/src/lib.rs +15 -0
package/Cargo.toml
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
[package]
|
|
2
|
+
name = "dapi-grpc"
|
|
3
|
+
description = "GRPC client for Dash Platform"
|
|
4
|
+
version = "0.25.0-dev.6"
|
|
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
|
+
|
|
19
|
+
[build-dependencies]
|
|
20
|
+
prost-build = { version = "0.11" }
|
|
21
|
+
|
|
22
|
+
[features]
|
|
23
|
+
default = ["core", "platform"]
|
|
24
|
+
core = ["core_v0"]
|
|
25
|
+
platform = ["platform_v0"]
|
|
26
|
+
|
|
27
|
+
core_v0 = []
|
|
28
|
+
platform_v0 = []
|
|
29
|
+
|
|
30
|
+
[lib]
|
|
31
|
+
|
|
32
|
+
[[example]]
|
|
33
|
+
name = "core_example"
|
|
34
|
+
path = "clients/core/v0/rust/core_example.rs"
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
[[example]]
|
|
38
|
+
name = "platform_example"
|
|
39
|
+
path = "clients/platform/v0/rust/platform_example.rs"
|
package/build.rs
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
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
|
+
println!("cargo:rerun-if-changed=./src/core/proto");
|
|
12
|
+
println!("cargo:rerun-if-changed=./src/platform/proto");
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/// Generate Rust definitions from Protobuf definitions
|
|
16
|
+
pub fn generate() -> Result<(), std::io::Error> {
|
|
17
|
+
// Mapping between protobuf files => output directory
|
|
18
|
+
let mut input = HashMap::<PathBuf, PathBuf>::new();
|
|
19
|
+
input.insert(
|
|
20
|
+
PathBuf::from("protos/core/v0/core.proto"),
|
|
21
|
+
PathBuf::from("src/core/proto"),
|
|
22
|
+
);
|
|
23
|
+
input.insert(
|
|
24
|
+
PathBuf::from("protos/platform/v0/platform.proto"),
|
|
25
|
+
PathBuf::from("src/platform/proto"),
|
|
26
|
+
);
|
|
27
|
+
|
|
28
|
+
let proto_includes = vec![abs_path(&PathBuf::from("protos"))];
|
|
29
|
+
|
|
30
|
+
for (proto, dest) in input {
|
|
31
|
+
let proto = abs_path(&proto);
|
|
32
|
+
let dest = abs_path(&dest);
|
|
33
|
+
// Remove old compiled files; ignore errors
|
|
34
|
+
if dest.exists() {
|
|
35
|
+
remove_dir_all(&dest)?;
|
|
36
|
+
}
|
|
37
|
+
create_dir_all(&dest)?;
|
|
38
|
+
|
|
39
|
+
generate1(&[proto], &proto_includes, &dest)?;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
Ok(())
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/// Run single generation process.
|
|
46
|
+
///
|
|
47
|
+
/// All paths must be absolute
|
|
48
|
+
fn generate1(
|
|
49
|
+
files: &[PathBuf],
|
|
50
|
+
proto_includes: &[PathBuf],
|
|
51
|
+
out_dir: &PathBuf,
|
|
52
|
+
) -> Result<(), std::io::Error> {
|
|
53
|
+
let mut pb = prost_build::Config::new();
|
|
54
|
+
pb.out_dir(out_dir);
|
|
55
|
+
pb.format(true);
|
|
56
|
+
pb.compile_protos(files, proto_includes)
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
fn abs_path(path: &PathBuf) -> PathBuf {
|
|
60
|
+
if path.is_absolute() {
|
|
61
|
+
return path.to_owned();
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
PathBuf::from(env!("CARGO_MANIFEST_DIR")).join(path)
|
|
65
|
+
}
|
|
@@ -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
|
+
}
|