cycles-quartz/enclaves/quartz/src/server.rs

63 lines
1.6 KiB
Rust
Raw Normal View History

2024-02-22 20:48:13 +00:00
use std::time::Duration;
2024-02-23 20:51:20 +00:00
use quartz_cw::{
msg::{execute::attested::HasUserData, instantiate::CoreInstantiate},
state::{Config, UserData},
};
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)]
2024-02-23 20:51:20 +00:00
pub struct CoreService {
config: Config,
}
impl CoreService {
pub fn new(config: Config) -> Self {
Self { 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
2024-02-23 20:51:20 +00:00
pub fn attestion_quote(user_data: UserData) -> IoResult<Vec<u8>> {
let mut user_report_data = File::create("/dev/attestation/user_report_data")?;
user_report_data.write_all(user_data.as_slice())?;
user_report_data.flush()?;
2024-02-22 20:48:13 +00:00
2024-02-23 20:51:20 +00:00
let quote = read("/dev/attestation/quote")?;
Ok(quote)
2024-02-22 20:48:13 +00:00
}