Skip to content

Commit cb18ffd

Browse files
committed
add reflection
1 parent a4b0bc1 commit cb18ffd

File tree

5 files changed

+30
-1
lines changed

5 files changed

+30
-1
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,5 @@ tests/tmp/**
77
.vscode/*.json
88
/0g-storage-contracts-dev
99
/run/.env
10+
11+
**.bin

Cargo.lock

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node/rpc/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ parking_lot = "0.12.3"
3232
tonic = { version = "0.9.2", features = ["transport"] }
3333
prost = "0.11.9"
3434
prost-types = "0.11.9"
35+
tonic-reflection = "0.9.2"
3536

3637
[build-dependencies]
3738
tonic-build = "0.9.2"

node/rpc/build.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
fn main() -> Result<(), Box<dyn std::error::Error>> {
22
// Compile proto/my_service.proto
3-
tonic_build::compile_protos("proto/zgs_grpc.proto")?;
3+
tonic_build::configure()
4+
.file_descriptor_set_path("proto/zgs_grpc_descriptor.bin")
5+
.compile(&["proto/zgs_grpc.proto"], &["proto"])?;
46
Ok(())
57
}

node/rpc/src/lib.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ pub use admin::RpcClient as ZgsAdminRpcClient;
3434
pub use config::Config as RPCConfig;
3535
pub use miner::RpcClient as ZgsMinerRpcClient;
3636
pub use zgs::RpcClient as ZgsRPCClient;
37+
// bring in the reflection-builder
38+
use tonic_reflection::server::Builder as ReflectionBuilder;
39+
3740

3841
pub mod zgs_grpc_proto {
3942
tonic::include_proto!("zgs_grpc");
@@ -43,6 +46,8 @@ mod zgs_grpc;
4346

4447
use tonic::transport::Server;
4548

49+
const DESCRIPTOR_SET: &[u8] = include_bytes!("../proto/zgs_grpc_descriptor.bin");
50+
4651
/// A wrapper around all the items required to spawn the HTTP server.
4752
///
4853
/// The server will gracefully handle the case where any fields are `None`.
@@ -146,9 +151,14 @@ async fn run_server_public_private(
146151

147152
pub async fn run_grpc_server(ctx: Context) -> Result<(), Box<dyn Error>> {
148153
let grpc_addr = ctx.config.listen_address_grpc;
154+
let reflection = ReflectionBuilder::configure()
155+
.register_encoded_file_descriptor_set(DESCRIPTOR_SET)
156+
.build()?;
157+
149158
let server = ZgsGrpcServiceServer::new(ZgsGrpcServiceImpl { ctx });
150159
Server::builder()
151160
.add_service(server)
161+
.add_service(reflection)
152162
.serve(grpc_addr)
153163
.await?;
154164
Ok(())

0 commit comments

Comments
 (0)