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::{
|
use quartz_cw::{
|
||||||
msg::{execute::attested::HasUserData, instantiate::CoreInstantiate},
|
msg::{execute::attested::HasUserData, instantiate::CoreInstantiate},
|
||||||
state::{Config, UserData},
|
state::{Config, UserData},
|
||||||
};
|
};
|
||||||
use quartz_proto::quartz::{
|
use quartz_proto::quartz::{
|
||||||
core_server::Core, InstantiateRequest, InstantiateResponse, SessionCreateRequest,
|
core_server::Core, InstantiateRequest as RawInstantiateRequest,
|
||||||
SessionCreateResponse,
|
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 tonic::{Request, Response, Status};
|
||||||
|
|
||||||
|
use crate::types::InstantiateResponse;
|
||||||
|
|
||||||
|
type TonicResult<T> = Result<T, Status>;
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct CoreService {
|
pub struct CoreService {
|
||||||
config: Config,
|
config: Config,
|
||||||
|
@ -28,20 +32,20 @@ impl CoreService {
|
||||||
impl Core for CoreService {
|
impl Core for CoreService {
|
||||||
async fn instantiate(
|
async fn instantiate(
|
||||||
&self,
|
&self,
|
||||||
request: Request<InstantiateRequest>,
|
_request: Request<RawInstantiateRequest>,
|
||||||
) -> Result<Response<InstantiateResponse>, Status> {
|
) -> TonicResult<Response<RawInstantiateResponse>> {
|
||||||
println!("Got a request: {:?}", request);
|
let core_instantiate_msg = CoreInstantiate::new(self.config.clone());
|
||||||
|
|
||||||
let reply = InstantiateResponse {
|
let user_data = core_instantiate_msg.user_data();
|
||||||
message: "Hello!".to_string(),
|
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(
|
async fn session_create(
|
||||||
&self,
|
&self,
|
||||||
request: Request<SessionCreateRequest>,
|
request: Request<SessionCreateRequest>,
|
||||||
) -> Result<Response<SessionCreateResponse>, Status> {
|
) -> TonicResult<Response<SessionCreateResponse>> {
|
||||||
println!("Got a request: {:?}", request);
|
println!("Got a request: {:?}", request);
|
||||||
|
|
||||||
let reply = SessionCreateResponse {
|
let reply = SessionCreateResponse {
|
||||||
|
|
Loading…
Reference in a new issue