Impl instantiate handler correctly
This commit is contained in:
parent
092c221d48
commit
089b1eac4d
1 changed files with 18 additions and 14 deletions
|
@ -1,18 +1,22 @@
|
|||
use std::time::Duration;
|
||||
use std::{
|
||||
fs::{read, File},
|
||||
io::{Result as IoResult, Write},
|
||||
};
|
||||
|
||||
use quartz_cw::{
|
||||
msg::{execute::attested::HasUserData, instantiate::CoreInstantiate},
|
||||
state::{Config, UserData},
|
||||
};
|
||||
use quartz_proto::quartz::{
|
||||
core_server::Core, InstantiateRequest, InstantiateResponse, SessionCreateRequest,
|
||||
SessionCreateResponse,
|
||||
core_server::Core, InstantiateRequest as RawInstantiateRequest,
|
||||
InstantiateResponse as RawInstantiateResponse, SessionCreateRequest, SessionCreateResponse,
|
||||
};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use tendermint::Hash;
|
||||
use tendermint_light_client::types::{Height, TrustThreshold};
|
||||
use tonic::{Request, Response, Status};
|
||||
|
||||
use crate::types::InstantiateResponse;
|
||||
|
||||
type TonicResult<T> = Result<T, Status>;
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct CoreService {
|
||||
config: Config,
|
||||
|
@ -28,20 +32,20 @@ impl CoreService {
|
|||
impl Core for CoreService {
|
||||
async fn instantiate(
|
||||
&self,
|
||||
request: Request<InstantiateRequest>,
|
||||
) -> Result<Response<InstantiateResponse>, Status> {
|
||||
println!("Got a request: {:?}", request);
|
||||
_request: Request<RawInstantiateRequest>,
|
||||
) -> TonicResult<Response<RawInstantiateResponse>> {
|
||||
let core_instantiate_msg = CoreInstantiate::new(self.config.clone());
|
||||
|
||||
let reply = InstantiateResponse {
|
||||
message: "Hello!".to_string(),
|
||||
};
|
||||
let user_data = core_instantiate_msg.user_data();
|
||||
let quote = attestion_quote(user_data).map_err(|e| Status::internal(e.to_string()))?;
|
||||
|
||||
Ok(Response::new(reply))
|
||||
let response = InstantiateResponse::new(self.config.clone(), quote);
|
||||
Ok(Response::new(response.into()))
|
||||
}
|
||||
async fn session_create(
|
||||
&self,
|
||||
request: Request<SessionCreateRequest>,
|
||||
) -> Result<Response<SessionCreateResponse>, Status> {
|
||||
) -> TonicResult<Response<SessionCreateResponse>> {
|
||||
println!("Got a request: {:?}", request);
|
||||
|
||||
let reply = SessionCreateResponse {
|
||||
|
|
Loading…
Reference in a new issue