diff --git a/examples/interfaces/cw4/src/lib.rs b/examples/interfaces/cw4/src/lib.rs index 10e10bcd..b4c4ecbb 100644 --- a/examples/interfaces/cw4/src/lib.rs +++ b/examples/interfaces/cw4/src/lib.rs @@ -1,4 +1,9 @@ +pub mod responses; + use cosmwasm_std::{Response, StdError}; +use responses::{ + AdminResponse, HooksResponse, MemberListResponse, MemberResponse, TotalWeightResponse, +}; use sylvia::types::{CustomMsg, CustomQuery, ExecCtx, QueryCtx}; use sylvia::{interface, schemars}; @@ -7,11 +12,6 @@ pub trait Cw4 { type Error: From; type ExecC: CustomMsg; type QueryC: CustomQuery; - type MemberCustomMsg: CustomMsg; - type ListMembersCustomMsg: CustomMsg; - type TotalWeightCustomMsg: CustomMsg; - type AdminCustomMsg: CustomMsg; - type HooksCustomMsg: CustomMsg; #[sv::msg(exec)] fn update_admin( @@ -46,36 +46,30 @@ pub trait Cw4 { &self, ctx: QueryCtx, member: String, - ) -> Result, Self::Error>; + ) -> Result, Self::Error>; #[sv::msg(query)] fn list_members( &self, ctx: QueryCtx, - ) -> Result, Self::Error>; + ) -> Result, Self::Error>; #[sv::msg(query)] fn total_weight( &self, ctx: QueryCtx, - ) -> Result, Self::Error>; + ) -> Result, Self::Error>; #[sv::msg(query)] - fn admin( - &self, - ctx: QueryCtx, - ) -> Result, Self::Error>; + fn admin(&self, ctx: QueryCtx) -> Result, Self::Error>; #[sv::msg(query)] - fn hooks( - &self, - ctx: QueryCtx, - ) -> Result, Self::Error>; + fn hooks(&self, ctx: QueryCtx) -> Result, Self::Error>; } #[cfg(test)] mod tests { - use cosmwasm_std::{from_json, to_json_binary, Empty}; + use cosmwasm_std::{from_json, to_json_binary}; use super::sv::*; @@ -96,8 +90,7 @@ mod tests { let original_msg = Cw4QueryMsg::Admin {}; let serialized_msg = to_json_binary(&original_msg).unwrap(); - let serialized_msg: Cw4QueryMsg = - from_json(serialized_msg).unwrap(); + let serialized_msg: Cw4QueryMsg = from_json(serialized_msg).unwrap(); assert_eq!(serialized_msg, original_msg); } @@ -116,8 +109,7 @@ mod tests { #[test] fn query_from_json() { - let deserialized: Cw4QueryMsg = - from_json(br#"{"admin": {}}"#).unwrap(); + let deserialized: Cw4QueryMsg = from_json(br#"{"admin": {}}"#).unwrap(); assert_eq!(deserialized, Cw4QueryMsg::Admin {}); } diff --git a/examples/interfaces/cw4/src/responses.rs b/examples/interfaces/cw4/src/responses.rs new file mode 100644 index 00000000..f5797e8b --- /dev/null +++ b/examples/interfaces/cw4/src/responses.rs @@ -0,0 +1,35 @@ +use cosmwasm_schema::cw_serde; + +#[cw_serde] +pub struct AdminResponse { + pub admin: Option, +} + +/// A group member has a weight associated with them. +/// This may all be equal, or may have meaning in the app that +/// makes use of the group (eg. voting power) +#[cw_serde] +pub struct Member { + pub addr: String, + pub weight: u64, +} + +#[cw_serde] +pub struct MemberListResponse { + pub members: Vec, +} + +#[cw_serde] +pub struct MemberResponse { + pub weight: Option, +} + +#[cw_serde] +pub struct TotalWeightResponse { + pub weight: u64, +} + +#[cw_serde] +pub struct HooksResponse { + pub hooks: Vec, +}