From 35b6184c9478c53b44f08bd645ba319072c73184 Mon Sep 17 00:00:00 2001 From: Benjamin DENEUX Date: Fri, 24 Feb 2023 16:43:55 +0100 Subject: [PATCH] feat(storage): add the query to get bucket information --- contracts/cw-storage/src/contract.rs | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/contracts/cw-storage/src/contract.rs b/contracts/cw-storage/src/contract.rs index 1e25f210..05ecda79 100644 --- a/contracts/cw-storage/src/contract.rs +++ b/contracts/cw-storage/src/contract.rs @@ -1,6 +1,6 @@ #[cfg(not(feature = "library"))] use cosmwasm_std::entry_point; -use cosmwasm_std::{Binary, Deps, DepsMut, Env, MessageInfo, Response, StdError, StdResult}; +use cosmwasm_std::{Binary, Deps, DepsMut, Env, MessageInfo, Response, StdError, StdResult, to_binary}; use cw2::set_contract_version; use ContractError::NotImplemented; @@ -41,8 +41,21 @@ pub fn execute( pub mod execute {} #[cfg_attr(not(feature = "library"), entry_point)] -pub fn query(_deps: Deps, _env: Env, _msg: QueryMsg) -> StdResult { - Err(StdError::generic_err("Not implemented")) +pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> StdResult { + match msg { + QueryMsg::Bucket {} => to_binary(&query::bucket(deps)?), + _ => Err(StdError::generic_err("Not implemented")) + } + } -pub mod query {} +pub mod query { + use crate::msg::BucketResponse; + use super::*; + + pub fn bucket(deps: Deps) -> StdResult { + let bucket = BUCKET.load(deps.storage)?; + + Ok(BucketResponse { name: bucket.name, limits: bucket.limits }) + } +}