variable_provider/
query.rs1use std::collections::BTreeMap;
2
3use cosmwasm_std::{Deps, StdError, StdResult};
4use variable_provider_pkg::definitions::Variable;
5
6use crate::state::VARIABLES;
7
8pub fn qy_get_variable(deps: Deps, key: String) -> StdResult<Variable> {
9 VARIABLES
10 .load(deps.storage, key.clone())
11 .map_err(|_| StdError::generic_err(format!("variable not found - key: {key}")))
12}
13
14pub fn qy_get_variables(deps: Deps, keys: Vec<String>) -> StdResult<BTreeMap<String, Variable>> {
15 keys.into_iter()
16 .map(|key| {
17 Ok((
18 key.clone(),
19 VARIABLES.load(deps.storage, key.clone()).map_err(|_| {
20 StdError::generic_err(format!("Variable not found - key: {key}"))
21 })?,
22 ))
23 })
24 .collect::<StdResult<BTreeMap<String, Variable>>>()
25}
26
27pub fn qy_get_all_variables(
28 deps: Deps,
29 start_after: Option<String>,
30 limit: Option<u32>,
31) -> StdResult<Vec<(String, Variable)>> {
32 rhaki_cw_plus::storage::map::get_items(
33 deps.storage,
34 &VARIABLES,
35 cosmwasm_std::Order::Ascending,
36 limit,
37 start_after,
38 )
39}