From 2514fbc98c5ae50e4e1ef261e11578fa92a7a14c Mon Sep 17 00:00:00 2001 From: Sergey Ratiashvili Date: Thu, 14 Dec 2023 09:56:44 +0100 Subject: [PATCH] feat: move queries to the messages --- contracts/core/src/bin/lido-core-schema.rs | 5 +---- contracts/core/src/contract.rs | 4 ++-- contracts/token/src/bin/lido-token-schema.rs | 5 +---- contracts/token/src/lib.rs | 4 ++-- packages/base/src/msg/core.rs | 13 +++++++++++-- packages/base/src/msg/token.rs | 15 ++++++++++++++- packages/base/src/state/core.rs | 12 +----------- packages/base/src/state/token.rs | 13 ------------- 8 files changed, 32 insertions(+), 39 deletions(-) diff --git a/contracts/core/src/bin/lido-core-schema.rs b/contracts/core/src/bin/lido-core-schema.rs index eb460abc..cac8e638 100644 --- a/contracts/core/src/bin/lido-core-schema.rs +++ b/contracts/core/src/bin/lido-core-schema.rs @@ -1,8 +1,5 @@ use cosmwasm_schema::write_api; -use lido_staking_base::{ - msg::core::{ExecuteMsg, InstantiateMsg, MigrateMsg}, - state::core::QueryMsg, -}; +use lido_staking_base::msg::core::{ExecuteMsg, InstantiateMsg, MigrateMsg, QueryMsg}; fn main() { write_api! { diff --git a/contracts/core/src/contract.rs b/contracts/core/src/contract.rs index bbef1fd2..862fc23a 100644 --- a/contracts/core/src/contract.rs +++ b/contracts/core/src/contract.rs @@ -4,9 +4,9 @@ use cosmwasm_std::{ DepsMut, Env, MessageInfo, Response, StdResult, Uint128, WasmMsg, }; use cw2::set_contract_version; -use lido_staking_base::msg::core::{ExecuteMsg, InstantiateMsg}; +use lido_staking_base::msg::core::{ExecuteMsg, InstantiateMsg, QueryMsg}; use lido_staking_base::msg::token::ExecuteMsg as TokenExecuteMsg; -use lido_staking_base::state::core::{QueryMsg, CONFIG}; +use lido_staking_base::state::core::CONFIG; use neutron_sdk::{ bindings::{msg::NeutronMsg, query::NeutronQuery}, NeutronResult, diff --git a/contracts/token/src/bin/lido-token-schema.rs b/contracts/token/src/bin/lido-token-schema.rs index 555f2cf1..ecb0a4aa 100644 --- a/contracts/token/src/bin/lido-token-schema.rs +++ b/contracts/token/src/bin/lido-token-schema.rs @@ -1,9 +1,6 @@ use cosmwasm_schema::write_api; -use lido_staking_base::{ - msg::token::{ExecuteMsg, InstantiateMsg, MigrateMsg}, - state::token::QueryMsg, -}; +use lido_staking_base::msg::token::{ExecuteMsg, InstantiateMsg, MigrateMsg, QueryMsg}; fn main() { write_api! { diff --git a/contracts/token/src/lib.rs b/contracts/token/src/lib.rs index 6a543a1d..b8397773 100644 --- a/contracts/token/src/lib.rs +++ b/contracts/token/src/lib.rs @@ -4,8 +4,8 @@ use cosmwasm_std::{ }; use lido_staking_base::{ - msg::token::{ExecuteMsg, InstantiateMsg, MigrateMsg}, - state::token::{ConfigResponse, QueryMsg, CORE_ADDRESS, DENOM}, + msg::token::{ConfigResponse, ExecuteMsg, InstantiateMsg, MigrateMsg, QueryMsg}, + state::token::{CORE_ADDRESS, DENOM}, }; use neutron_sdk::{ bindings::{msg::NeutronMsg, query::NeutronQuery}, diff --git a/packages/base/src/msg/core.rs b/packages/base/src/msg/core.rs index c03f9392..d742411b 100644 --- a/packages/base/src/msg/core.rs +++ b/packages/base/src/msg/core.rs @@ -1,5 +1,5 @@ -use cosmwasm_schema::cw_serde; -use cosmwasm_std::Uint128; +use cosmwasm_schema::{cw_serde, QueryResponses}; +use cosmwasm_std::{Decimal256, Uint128}; use crate::state::core::Config; @@ -11,6 +11,15 @@ pub struct InstantiateMsg { pub owner: String, } +#[cw_serde] +#[derive(QueryResponses)] +pub enum QueryMsg { + #[returns(Config)] + Config {}, + #[returns(Decimal256)] + ExchangeRate {}, +} + #[cw_serde] pub enum ExecuteMsg { Bond {}, diff --git a/packages/base/src/msg/token.rs b/packages/base/src/msg/token.rs index d6f98a42..3aea5c9e 100644 --- a/packages/base/src/msg/token.rs +++ b/packages/base/src/msg/token.rs @@ -1,6 +1,19 @@ -use cosmwasm_schema::cw_serde; +use cosmwasm_schema::{cw_serde, QueryResponses}; use cosmwasm_std::Uint128; +#[cosmwasm_schema::cw_serde] +#[derive(QueryResponses)] +pub enum QueryMsg { + #[returns(ConfigResponse)] + Config {}, +} + +#[cosmwasm_schema::cw_serde] +pub struct ConfigResponse { + pub core_address: String, + pub denom: String, +} + #[cw_serde] pub enum ExecuteMsg { Mint { amount: Uint128, receiver: String }, diff --git a/packages/base/src/state/core.rs b/packages/base/src/state/core.rs index 44653773..4b978bc5 100644 --- a/packages/base/src/state/core.rs +++ b/packages/base/src/state/core.rs @@ -1,5 +1,4 @@ -use cosmwasm_schema::{cw_serde, QueryResponses}; -use cosmwasm_std::Decimal256; +use cosmwasm_schema::cw_serde; use cw_storage_plus::Item; #[cw_serde] @@ -10,13 +9,4 @@ pub struct Config { pub owner: String, } -#[cw_serde] -#[derive(QueryResponses)] -pub enum QueryMsg { - #[returns(Config)] - Config {}, - #[returns(Decimal256)] - ExchangeRate {}, -} - pub const CONFIG: Item = Item::new("config"); diff --git a/packages/base/src/state/token.rs b/packages/base/src/state/token.rs index 6af60a57..838e2a48 100644 --- a/packages/base/src/state/token.rs +++ b/packages/base/src/state/token.rs @@ -1,18 +1,5 @@ use cosmwasm_std::Addr; use cw_storage_plus::Item; -#[cosmwasm_schema::cw_serde] -#[derive(cosmwasm_schema::QueryResponses)] -pub enum QueryMsg { - #[returns(ConfigResponse)] - Config {}, -} - -#[cosmwasm_schema::cw_serde] -pub struct ConfigResponse { - pub core_address: String, - pub denom: String, -} - pub const CORE_ADDRESS: Item = Item::new("core"); pub const DENOM: Item = Item::new("denom");