CW Item Set

Set of non-duplicate items for CosmWasm smart contract store.

How to use

In this example, we create a whitelist of users. This may be useful in, for example, NFT minting whitelists.

```rust use cosmwasmstd::{DepsMut, Order, StdResult}; use cwitem_set::Set;

// "whitelist": namespace under which the items are to be stored // "whitelistcounter": key for storing the total number of items in the set const WHITELIST: Set<&str> = Set::new("whitelist", "whitelistcounter");

fn example(deps: DepsMut) -> StdResult<()> { // Add a new user to the whitelist WHITELIST.insert(deps.storage, "larry")?;

// Remove a user from the whitelist
// Note that we don't check whether the user already exists in the whitelist.
// Attempting to remove a non-existent user won't result in error.
WHITELIST.remove(deps.storage, "jake")?;

// Check whether a user is in the whitelist
let is_whitelisted = WHITELIST.contains(deps.as_ref().storage, "pumpkin");

// Check the total number of users in the whitelist
let num_users = WHITELIST.count(deps.as_ref().storage)?;

// Enumerate all users in the whitelist
for res in WHITELIST.items(deps.as_ref().storage, None, None, Order::Ascending) {
    let user = res?;
    println!("{} is whitelisted!", user);
}

// Delete all users in the whitelist
WHITELIST.clear(deps.storage);

Ok(())

} ```

Features

There are two optional features, both enabled by default:

License

Contents of this crate at or prior to version 0.7.0 are published under GNU Affero General Public License v3 or later; contents after the said version are published under Apache-2.0 license.