File tree Expand file tree Collapse file tree 5 files changed +30
-1
lines changed
Expand file tree Collapse file tree 5 files changed +30
-1
lines changed Original file line number Diff line number Diff line change @@ -7,3 +7,5 @@ tests/tmp/**
77.vscode /* .json
88/0g-storage-contracts-dev
99/run /.env
10+
11+ ** .bin
Original file line number Diff line number Diff line change @@ -32,6 +32,7 @@ parking_lot = "0.12.3"
3232tonic = { version = " 0.9.2" , features = [" transport" ] }
3333prost = " 0.11.9"
3434prost-types = " 0.11.9"
35+ tonic-reflection = " 0.9.2"
3536
3637[build-dependencies ]
3738tonic-build = " 0.9.2"
Original file line number Diff line number Diff line change 11fn 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}
Original file line number Diff line number Diff line change @@ -34,6 +34,9 @@ pub use admin::RpcClient as ZgsAdminRpcClient;
3434pub use config:: Config as RPCConfig ;
3535pub use miner:: RpcClient as ZgsMinerRpcClient ;
3636pub use zgs:: RpcClient as ZgsRPCClient ;
37+ // bring in the reflection-builder
38+ use tonic_reflection:: server:: Builder as ReflectionBuilder ;
39+
3740
3841pub mod zgs_grpc_proto {
3942 tonic:: include_proto!( "zgs_grpc" ) ;
@@ -43,6 +46,8 @@ mod zgs_grpc;
4346
4447use 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
147152pub 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 ( ( ) )
You can’t perform that action at this time.
0 commit comments