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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
use cosmwasm_std::{Addr, Api, CanonicalAddr, StdResult};
pub fn maybe_canonical(api: &dyn Api, human: Option<Addr>) -> StdResult<Option<CanonicalAddr>> {
human.map(|x| api.addr_canonicalize(x.as_ref())).transpose()
}
pub fn maybe_addr(api: &dyn Api, human: Option<String>) -> StdResult<Option<Addr>> {
human.map(|x| api.addr_validate(&x)).transpose()
}
pub fn calc_range_start_human(
api: &dyn Api,
start_after: Option<Addr>,
) -> StdResult<Option<Vec<u8>>> {
match start_after {
Some(human) => {
let mut v: Vec<u8> = api.addr_canonicalize(human.as_ref())?.0.into();
v.push(0);
Ok(Some(v))
}
None => Ok(None),
}
}
pub fn calc_range_end_human(api: &dyn Api, end_before: Option<Addr>) -> StdResult<Option<Vec<u8>>> {
match end_before {
Some(human) => {
let v: Vec<u8> = api.addr_canonicalize(human.as_ref())?.into();
Ok(Some(v))
}
None => Ok(None),
}
}
pub fn calc_range_start_string(start_after: Option<String>) -> Option<Vec<u8>> {
start_after.map(|token_id| {
let mut v: Vec<u8> = token_id.into_bytes();
v.push(0);
v
})
}
#[cfg(test)]
mod test {
#[ignore]
#[test]
fn add_some_tests() {}
}