2019-02-14 01:09:18 +00:00
|
|
|
mod beacon_block;
|
2019-03-22 02:51:17 +00:00
|
|
|
pub mod beacon_chain;
|
2019-03-22 02:37:24 +00:00
|
|
|
mod beacon_node;
|
2019-03-19 12:47:58 +00:00
|
|
|
pub mod config;
|
2019-02-14 01:09:18 +00:00
|
|
|
mod validator;
|
|
|
|
|
|
|
|
use self::beacon_block::BeaconBlockServiceInstance;
|
2019-03-22 02:51:17 +00:00
|
|
|
use self::beacon_chain::BeaconChain;
|
2019-03-22 02:37:24 +00:00
|
|
|
use self::beacon_node::BeaconNodeServiceInstance;
|
2019-02-14 01:09:18 +00:00
|
|
|
use self::validator::ValidatorServiceInstance;
|
2019-03-19 12:47:58 +00:00
|
|
|
pub use config::Config as RPCConfig;
|
2019-02-14 01:09:18 +00:00
|
|
|
use grpcio::{Environment, Server, ServerBuilder};
|
2019-03-22 02:37:24 +00:00
|
|
|
use protos::services_grpc::{
|
|
|
|
create_beacon_block_service, create_beacon_node_service, create_validator_service,
|
|
|
|
};
|
2019-02-14 01:09:18 +00:00
|
|
|
use std::sync::Arc;
|
|
|
|
|
2019-03-19 12:47:58 +00:00
|
|
|
use slog::{info, o};
|
2019-02-14 01:09:18 +00:00
|
|
|
|
2019-03-22 02:51:17 +00:00
|
|
|
pub fn start_server(
|
2019-03-22 02:37:24 +00:00
|
|
|
config: &RPCConfig,
|
2019-03-22 02:51:17 +00:00
|
|
|
beacon_chain: Arc<BeaconChain>,
|
2019-03-22 02:37:24 +00:00
|
|
|
log: &slog::Logger,
|
2019-03-22 02:51:17 +00:00
|
|
|
) -> Server {
|
2019-03-19 12:47:58 +00:00
|
|
|
let log = log.new(o!("Service"=>"RPC"));
|
2019-02-14 01:09:18 +00:00
|
|
|
let env = Arc::new(Environment::new(1));
|
|
|
|
|
2019-03-22 02:37:24 +00:00
|
|
|
// build the individual rpc services
|
|
|
|
|
|
|
|
let beacon_node_service = {
|
|
|
|
let instance = BeaconNodeServiceInstance {
|
|
|
|
chain: beacon_chain.clone(),
|
|
|
|
log: log.clone(),
|
|
|
|
};
|
|
|
|
create_beacon_node_service(instance)
|
|
|
|
};
|
|
|
|
|
2019-02-14 01:09:18 +00:00
|
|
|
let beacon_block_service = {
|
|
|
|
let instance = BeaconBlockServiceInstance { log: log.clone() };
|
|
|
|
create_beacon_block_service(instance)
|
|
|
|
};
|
|
|
|
let validator_service = {
|
|
|
|
let instance = ValidatorServiceInstance { log: log.clone() };
|
|
|
|
create_validator_service(instance)
|
|
|
|
};
|
|
|
|
|
|
|
|
let mut server = ServerBuilder::new(env)
|
|
|
|
.register_service(beacon_block_service)
|
|
|
|
.register_service(validator_service)
|
2019-03-19 12:47:58 +00:00
|
|
|
.bind(config.listen_address.to_string(), config.port)
|
2019-02-14 01:09:18 +00:00
|
|
|
.build()
|
|
|
|
.unwrap();
|
|
|
|
server.start();
|
|
|
|
for &(ref host, port) in server.bind_addrs() {
|
2019-03-19 12:47:58 +00:00
|
|
|
info!(log, "gRPC listening on {}:{}", host, port);
|
2019-02-14 01:09:18 +00:00
|
|
|
}
|
|
|
|
server
|
|
|
|
}
|