2024-02-22 20:48:13 +00:00
|
|
|
use std::time::Duration;
|
|
|
|
|
2024-02-22 20:09:44 +00:00
|
|
|
use quartz_proto::quartz::{
|
|
|
|
core_server::Core, InstantiateRequest, InstantiateResponse, SessionCreateRequest,
|
|
|
|
SessionCreateResponse,
|
|
|
|
};
|
2024-02-22 20:48:13 +00:00
|
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
use tendermint::Hash;
|
|
|
|
use tendermint_light_client::types::{Height, TrustThreshold};
|
2024-02-20 11:27:10 +00:00
|
|
|
use tonic::{Request, Response, Status};
|
|
|
|
|
2024-02-22 20:48:13 +00:00
|
|
|
#[derive(Clone, Debug)]
|
|
|
|
pub struct CoreService(pub Config);
|
2024-02-20 11:27:10 +00:00
|
|
|
|
|
|
|
#[tonic::async_trait]
|
|
|
|
impl Core for CoreService {
|
2024-02-22 20:09:44 +00:00
|
|
|
async fn instantiate(
|
|
|
|
&self,
|
|
|
|
request: Request<InstantiateRequest>,
|
|
|
|
) -> Result<Response<InstantiateResponse>, Status> {
|
|
|
|
println!("Got a request: {:?}", request);
|
|
|
|
|
|
|
|
let reply = InstantiateResponse {
|
|
|
|
message: "Hello!".to_string(),
|
|
|
|
};
|
|
|
|
|
|
|
|
Ok(Response::new(reply))
|
|
|
|
}
|
2024-02-20 11:27:10 +00:00
|
|
|
async fn session_create(
|
|
|
|
&self,
|
|
|
|
request: Request<SessionCreateRequest>,
|
|
|
|
) -> Result<Response<SessionCreateResponse>, Status> {
|
|
|
|
println!("Got a request: {:?}", request);
|
|
|
|
|
|
|
|
let reply = SessionCreateResponse {
|
|
|
|
message: "Hello!".to_string(),
|
|
|
|
};
|
|
|
|
|
|
|
|
Ok(Response::new(reply))
|
|
|
|
}
|
|
|
|
}
|
2024-02-22 20:48:13 +00:00
|
|
|
|
|
|
|
#[derive(Clone, Debug, Serialize, Deserialize)]
|
|
|
|
pub struct Config {
|
|
|
|
epoch_duration: Duration,
|
|
|
|
light_client_opts: LightClientOpts,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Config {
|
|
|
|
pub fn new(epoch_duration: Duration, light_client_opts: LightClientOpts) -> Self {
|
|
|
|
Self {
|
|
|
|
epoch_duration,
|
|
|
|
light_client_opts,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Clone, Debug, Serialize, Deserialize)]
|
|
|
|
pub struct LightClientOpts {
|
|
|
|
chain_id: String,
|
|
|
|
target_height: Height,
|
|
|
|
trusted_height: Height,
|
|
|
|
trusted_hash: Hash,
|
|
|
|
trust_threshold: TrustThreshold,
|
|
|
|
trusting_period: u64,
|
|
|
|
max_clock_drift: u64,
|
|
|
|
max_block_lag: u64,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl LightClientOpts {
|
|
|
|
#[allow(clippy::too_many_arguments)]
|
|
|
|
pub fn new(
|
|
|
|
chain_id: String,
|
|
|
|
target_height: Height,
|
|
|
|
trusted_height: Height,
|
|
|
|
trusted_hash: Hash,
|
|
|
|
trust_threshold: TrustThreshold,
|
|
|
|
trusting_period: u64,
|
|
|
|
max_clock_drift: u64,
|
|
|
|
max_block_lag: u64,
|
|
|
|
) -> Self {
|
|
|
|
Self {
|
|
|
|
chain_id,
|
|
|
|
target_height,
|
|
|
|
trusted_height,
|
|
|
|
trusted_hash,
|
|
|
|
trust_threshold,
|
|
|
|
trusting_period,
|
|
|
|
max_clock_drift,
|
|
|
|
max_block_lag,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|