Skip to content

Commit

Permalink
feat(storage): add the query to get bucket information
Browse files Browse the repository at this point in the history
  • Loading branch information
bdeneux committed Feb 24, 2023
1 parent 7e29305 commit 35b6184
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions contracts/cw-storage/src/contract.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -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<Binary> {
Err(StdError::generic_err("Not implemented"))
pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> StdResult<Binary> {
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<BucketResponse> {
let bucket = BUCKET.load(deps.storage)?;

Ok(BucketResponse { name: bucket.name, limits: bucket.limits })
}
}

0 comments on commit 35b6184

Please sign in to comment.