Move domain types to relayer
This commit is contained in:
parent
aa32b7798a
commit
83ef846afa
5 changed files with 81 additions and 60 deletions
|
@ -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<T> = Result<T, Status>;
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
|
|
|
@ -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<u8>) -> Self {
|
||||
Self {
|
||||
message: InstantiateResponseMsg { config, quote },
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct InstantiateResponseMsg {
|
||||
config: Config,
|
||||
quote: Vec<u8>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
||||
pub struct RawInstantiateResponseMsg {
|
||||
config: RawConfig,
|
||||
quote: HexBinary,
|
||||
}
|
||||
|
||||
impl TryFrom<RawInstantiateResponseMsg> for InstantiateResponseMsg {
|
||||
type Error = StdError;
|
||||
|
||||
fn try_from(value: RawInstantiateResponseMsg) -> Result<Self, Self::Error> {
|
||||
Ok(Self {
|
||||
config: value.config.try_into()?,
|
||||
quote: value.quote.into(),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl From<InstantiateResponseMsg> for RawInstantiateResponseMsg {
|
||||
fn from(value: InstantiateResponseMsg) -> Self {
|
||||
Self {
|
||||
config: value.config.into(),
|
||||
quote: value.quote.into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<InstantiateResponse> 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"),
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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" }
|
||||
|
|
1
utils/quartz-relayer/src/lib.rs
Normal file
1
utils/quartz-relayer/src/lib.rs
Normal file
|
@ -0,0 +1 @@
|
|||
pub mod types;
|
74
utils/quartz-relayer/src/types.rs
Normal file
74
utils/quartz-relayer/src/types.rs
Normal file
|
@ -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<u8>) -> Self {
|
||||
Self {
|
||||
message: InstantiateResponseMsg { config, quote },
|
||||
}
|
||||
}
|
||||
|
||||
pub fn quote(&self) -> &[u8] {
|
||||
&self.message.quote
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFrom<RawInstantiateResponse> for InstantiateResponse {
|
||||
type Error = StdError;
|
||||
|
||||
fn try_from(value: RawInstantiateResponse) -> Result<Self, Self::Error> {
|
||||
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<InstantiateResponse> 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<u8>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
||||
pub struct RawInstantiateResponseMsg {
|
||||
config: RawConfig,
|
||||
quote: HexBinary,
|
||||
}
|
||||
|
||||
impl TryFrom<RawInstantiateResponseMsg> for InstantiateResponseMsg {
|
||||
type Error = StdError;
|
||||
|
||||
fn try_from(value: RawInstantiateResponseMsg) -> Result<Self, Self::Error> {
|
||||
Ok(Self {
|
||||
config: value.config.try_into()?,
|
||||
quote: value.quote.into(),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl From<InstantiateResponseMsg> for RawInstantiateResponseMsg {
|
||||
fn from(value: InstantiateResponseMsg) -> Self {
|
||||
Self {
|
||||
config: value.config.into(),
|
||||
quote: value.quote.into(),
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue