use tonic::transport::{Channel, Endpoint};
use crate::rpc::RpcClientConfig;
pub fn endpoint_from_config(config: &RpcClientConfig) -> Result<Endpoint, tonic::transport::Error> {
Endpoint::from_shared(config.endpoint.clone()).map(|endpoint| {
endpoint
.connect_timeout(config.connect_timeout)
.timeout(config.request_timeout)
})
}
pub async fn connect_channel(config: &RpcClientConfig) -> Result<Channel, tonic::transport::Error> {
endpoint_from_config(config)?.connect().await
}
#[cfg(test)]
mod tests {
use super::endpoint_from_config;
use crate::rpc::RpcClientConfig;
#[test]
fn endpoint_accepts_http_uri() {
let config = RpcClientConfig::new("http://127.0.0.1:50051");
assert!(endpoint_from_config(&config).is_ok());
}
}