-
Notifications
You must be signed in to change notification settings - Fork 141
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
52 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
use cosmwasm_std::{Addr, Deps, StdResult}; | ||
|
||
/// validate addresses and add to and/or remove from an existing list of | ||
/// addresses, removing any duplicates. mutates the original list. | ||
pub fn add_and_remove_addresses( | ||
deps: Deps, | ||
list: &mut Vec<Addr>, | ||
add: Option<Vec<String>>, | ||
remove: Option<Vec<String>>, | ||
) -> StdResult<()> { | ||
if let Some(add) = add { | ||
let mut addrs = add | ||
.iter() | ||
.map(|addr| deps.api.addr_validate(addr)) | ||
.collect::<StdResult<Vec<Addr>>>()?; | ||
|
||
list.append(&mut addrs); | ||
list.sort(); | ||
list.dedup(); | ||
} | ||
|
||
if let Some(remove) = remove { | ||
let addrs = remove | ||
.iter() | ||
.map(|addr| deps.api.addr_validate(addr)) | ||
.collect::<StdResult<Vec<Addr>>>()?; | ||
|
||
list.retain(|a| !addrs.contains(a)); | ||
} | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
|
||
pub mod error; | ||
pub mod execute; | ||
pub mod helpers; | ||
pub mod msg; | ||
pub mod state; | ||
|
||
|