Skip to content

Commit

Permalink
Add stage related queries
Browse files Browse the repository at this point in the history
  • Loading branch information
MightOfOaks committed Sep 3, 2024
1 parent bce3553 commit 5edd2c6
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 6 deletions.
29 changes: 23 additions & 6 deletions contracts/whitelists/whitelist-tiered/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,11 @@ use crate::admin::{
use crate::error::ContractError;
use crate::helpers::validators::map_validate;
use crate::helpers::{fetch_active_stage, fetch_active_stage_index, validate_stages};
use crate::msg::{
AddMembersMsg, ConfigResponse, ExecuteMsg, HasEndedResponse, HasMemberResponse,
HasStartedResponse, InstantiateMsg, IsActiveResponse, MembersResponse, QueryMsg,
RemoveMembersMsg, UpdateStageConfigMsg,
};
use crate::msg::{AddMembersMsg, ConfigResponse, ExecuteMsg, HasEndedResponse, HasMemberResponse, HasStartedResponse, InstantiateMsg, IsActiveResponse, MembersResponse, QueryMsg, RemoveMembersMsg, StageResponse, StagesResponse, UpdateStageConfigMsg};
use crate::state::{AdminList, Config, Stage, ADMIN_LIST, CONFIG, WHITELIST_STAGES};
#[cfg(not(feature = "library"))]
use cosmwasm_std::entry_point;
use cosmwasm_std::Order;
use cosmwasm_std::{Order, StdError};
use cosmwasm_std::{
ensure, to_json_binary, Binary, Coin, Deps, DepsMut, Env, MessageInfo, StdResult, Timestamp,
Uint128,
Expand Down Expand Up @@ -392,6 +388,8 @@ pub fn query(deps: Deps, env: Env, msg: QueryMsg) -> StdResult<Binary> {
QueryMsg::ActiveStage {} => to_json_binary(&fetch_active_stage(deps.storage, &env)),
QueryMsg::HasMember { member } => to_json_binary(&query_has_member(deps, env, member)?),
QueryMsg::Config {} => to_json_binary(&query_config(deps, env)?),
QueryMsg::Stage { stage_id } => to_json_binary(&query_stage(deps, stage_id)?),
QueryMsg::Stages {} => to_json_binary(&query_stage_list(deps)?),
QueryMsg::AdminList {} => to_json_binary(&query_admin_list(deps)?),
QueryMsg::CanExecute { sender, .. } => to_json_binary(&query_can_execute(deps, &sender)?),
}
Expand Down Expand Up @@ -492,3 +490,22 @@ pub fn query_config(deps: Deps, env: Env) -> StdResult<ConfigResponse> {
})
}
}

pub fn query_stage(deps: Deps, stage_id: u32) -> StdResult<StageResponse> {
let config = CONFIG.load(deps.storage)?;
ensure!(
stage_id < config.stages.len() as u32,
StdError::generic_err("Stage not found")
);
Ok(StageResponse {
stage: config.stages[stage_id as usize].clone(),
})
}

pub fn query_stage_list(deps: Deps) -> StdResult<StagesResponse> {
let config = CONFIG.load(deps.storage)?;
ensure! (!config.stages.is_empty(), StdError::generic_err("No stages found"));
Ok(StagesResponse {
stages: config.stages.clone(),
})
}
16 changes: 16 additions & 0 deletions contracts/whitelists/whitelist-tiered/src/msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,12 @@ pub enum QueryMsg {
},
Config {},

Stage {
stage_id: u32,
},

Stages {},

AdminList {},

CanExecute {
Expand Down Expand Up @@ -137,3 +143,13 @@ pub enum SudoMsg {
pub struct CanExecuteResponse {
pub can_execute: bool,
}

#[cw_serde]
pub struct StageResponse {
pub stage: Stage,
}

#[cw_serde]
pub struct StagesResponse {
pub stages: Vec<Stage>,
}

0 comments on commit 5edd2c6

Please sign in to comment.