From 83ef846afa7b9b4915fd98f77191e07e84ecfb27 Mon Sep 17 00:00:00 2001 From: hu55a1n1 Date: Fri, 23 Feb 2024 14:27:29 -0800 Subject: [PATCH] Move domain types to relayer --- enclaves/quartz/src/server.rs | 3 +- enclaves/quartz/src/types.rs | 58 ------------------------ utils/quartz-relayer/Cargo.toml | 5 +++ utils/quartz-relayer/src/lib.rs | 1 + utils/quartz-relayer/src/types.rs | 74 +++++++++++++++++++++++++++++++ 5 files changed, 81 insertions(+), 60 deletions(-) create mode 100644 utils/quartz-relayer/src/lib.rs create mode 100644 utils/quartz-relayer/src/types.rs diff --git a/enclaves/quartz/src/server.rs b/enclaves/quartz/src/server.rs index 600f546..e8d924c 100644 --- a/enclaves/quartz/src/server.rs +++ b/enclaves/quartz/src/server.rs @@ -11,10 +11,9 @@ use quartz_proto::quartz::{ core_server::Core, InstantiateRequest as RawInstantiateRequest, InstantiateResponse as RawInstantiateResponse, SessionCreateRequest, SessionCreateResponse, }; +use quartz_relayer::types::InstantiateResponse; use tonic::{Request, Response, Status}; -use crate::types::InstantiateResponse; - type TonicResult = Result; #[derive(Clone, Debug)] diff --git a/enclaves/quartz/src/types.rs b/enclaves/quartz/src/types.rs index e341e59..e69de29 100644 --- a/enclaves/quartz/src/types.rs +++ b/enclaves/quartz/src/types.rs @@ -1,58 +0,0 @@ -use cosmwasm_std::{HexBinary, StdError}; -use quartz_cw::state::{Config, RawConfig}; -use quartz_proto::quartz::InstantiateResponse as RawInstantiateResponse; -use serde::{Deserialize, Serialize}; - -#[derive(Clone, Debug, PartialEq)] -pub struct InstantiateResponse { - message: InstantiateResponseMsg, -} - -impl InstantiateResponse { - pub fn new(config: Config, quote: Vec) -> Self { - Self { - message: InstantiateResponseMsg { config, quote }, - } - } -} - -#[derive(Clone, Debug, PartialEq)] -pub struct InstantiateResponseMsg { - config: Config, - quote: Vec, -} - -#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] -pub struct RawInstantiateResponseMsg { - config: RawConfig, - quote: HexBinary, -} - -impl TryFrom for InstantiateResponseMsg { - type Error = StdError; - - fn try_from(value: RawInstantiateResponseMsg) -> Result { - Ok(Self { - config: value.config.try_into()?, - quote: value.quote.into(), - }) - } -} - -impl From for RawInstantiateResponseMsg { - fn from(value: InstantiateResponseMsg) -> Self { - Self { - config: value.config.into(), - quote: value.quote.into(), - } - } -} - -impl From for RawInstantiateResponse { - fn from(value: InstantiateResponse) -> Self { - let raw_message: RawInstantiateResponseMsg = value.message.into(); - Self { - message: serde_json::to_string(&raw_message).expect("infallible serializer"), - } - } -} diff --git a/utils/quartz-relayer/Cargo.toml b/utils/quartz-relayer/Cargo.toml index a5523e0..1bf6c0f 100644 --- a/utils/quartz-relayer/Cargo.toml +++ b/utils/quartz-relayer/Cargo.toml @@ -4,7 +4,12 @@ version = "0.1.0" edition = "2021" [dependencies] +clap = { version = "4.1.8", features = ["derive"] } +cosmwasm-std = "1.4.0" +serde = { version = "1.0.189", features = ["derive"] } +serde_json = "1.0.94" tonic = "0.11" tokio = { version = "1.0", features = ["macros", "rt-multi-thread"] } +quartz-cw = { path = "../../../bisenzone-cw-mvp/packages/quartz-cw" } quartz-proto = { path = "../../utils/quartz-proto" } diff --git a/utils/quartz-relayer/src/lib.rs b/utils/quartz-relayer/src/lib.rs new file mode 100644 index 0000000..cd40856 --- /dev/null +++ b/utils/quartz-relayer/src/lib.rs @@ -0,0 +1 @@ +pub mod types; diff --git a/utils/quartz-relayer/src/types.rs b/utils/quartz-relayer/src/types.rs new file mode 100644 index 0000000..354d56e --- /dev/null +++ b/utils/quartz-relayer/src/types.rs @@ -0,0 +1,74 @@ +use cosmwasm_std::{HexBinary, StdError}; +use quartz_cw::state::{Config, RawConfig}; +use quartz_proto::quartz::InstantiateResponse as RawInstantiateResponse; +use serde::{Deserialize, Serialize}; + +#[derive(Clone, Debug, PartialEq)] +pub struct InstantiateResponse { + message: InstantiateResponseMsg, +} + +impl InstantiateResponse { + pub fn new(config: Config, quote: Vec) -> Self { + Self { + message: InstantiateResponseMsg { config, quote }, + } + } + + pub fn quote(&self) -> &[u8] { + &self.message.quote + } +} + +impl TryFrom for InstantiateResponse { + type Error = StdError; + + fn try_from(value: RawInstantiateResponse) -> Result { + let raw_message: RawInstantiateResponseMsg = serde_json::from_str(&value.message) + .map_err(|e| StdError::parse_err("RawInstantiateResponseMsg", e))?; + Ok(Self { + message: raw_message.try_into()?, + }) + } +} + +impl From for RawInstantiateResponse { + fn from(value: InstantiateResponse) -> Self { + let raw_message: RawInstantiateResponseMsg = value.message.into(); + Self { + message: serde_json::to_string(&raw_message).expect("infallible serializer"), + } + } +} + +#[derive(Clone, Debug, PartialEq)] +pub struct InstantiateResponseMsg { + config: Config, + quote: Vec, +} + +#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] +pub struct RawInstantiateResponseMsg { + config: RawConfig, + quote: HexBinary, +} + +impl TryFrom for InstantiateResponseMsg { + type Error = StdError; + + fn try_from(value: RawInstantiateResponseMsg) -> Result { + Ok(Self { + config: value.config.try_into()?, + quote: value.quote.into(), + }) + } +} + +impl From for RawInstantiateResponseMsg { + fn from(value: InstantiateResponseMsg) -> Self { + Self { + config: value.config.into(), + quote: value.quote.into(), + } + } +}