1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
use std::collections::BTreeMap;

use variable_provider_pkg::definitions::Variable;
use cosmwasm_std::{Deps, StdError, StdResult};

use crate::state::VARIABLES;

pub fn qy_get_variable(deps: Deps, key: String) -> StdResult<Variable> {
    VARIABLES
        .load(deps.storage, key.clone())
        .map_err(|_| StdError::generic_err(format!("variable not found - key: {key}")))
}

pub fn qy_get_variables(deps: Deps, keys: Vec<String>) -> StdResult<BTreeMap<String, Variable>> {
    keys.into_iter()
        .map(|key| {
            Ok((
                key.clone(),
                VARIABLES.load(deps.storage, key.clone()).map_err(|_| {
                    StdError::generic_err(format!("Variable not found - key: {key}"))
                })?,
            ))
        })
        .collect::<StdResult<BTreeMap<String, Variable>>>()
}

pub fn qy_get_all_variables(
    deps: Deps,
    start_after: Option<String>,
    limit: Option<u32>,
) -> StdResult<Vec<(String, Variable)>> {
    rhaki_cw_plus::storage::map::get_items(
        deps.storage,
        &VARIABLES,
        cosmwasm_std::Order::Ascending,
        limit,
        start_after,
    )
}