Skip to content

Commit

Permalink
Remover MEMBERS SnapshotMap
Browse files Browse the repository at this point in the history
  • Loading branch information
maurolacy committed Apr 16, 2021
1 parent de09ee1 commit 5ba6368
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 11 deletions.
6 changes: 3 additions & 3 deletions contracts/cw4-group/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use cw_storage_plus::Bound;

use crate::error::ContractError;
use crate::msg::{ExecuteMsg, InstantiateMsg, QueryMsg};
use crate::state::{members, ADMIN, HOOKS, MEMBERS, TOTAL};
use crate::state::{members, ADMIN, HOOKS, TOTAL};

// version info for migration info
const CONTRACT_NAME: &str = "crates.io:cw4-group";
Expand Down Expand Up @@ -176,7 +176,7 @@ fn query_total_weight(deps: Deps) -> StdResult<TotalWeightResponse> {
fn query_member(deps: Deps, addr: String, height: Option<u64>) -> StdResult<MemberResponse> {
let addr = deps.api.addr_validate(&addr)?;
let weight = match height {
Some(h) => MEMBERS.may_load_at_height(deps.storage, &addr, h),
Some(h) => members().primary.may_load_at_height(deps.storage, &addr, h),
None => members().may_load(deps.storage, &addr),
}?;
Ok(MemberResponse { weight })
Expand All @@ -195,7 +195,7 @@ fn list_members(
let addr = maybe_addr(deps.api, start_after)?;
let start = addr.map(|addr| Bound::exclusive(addr.to_string()));

let members: StdResult<Vec<_>> = MEMBERS
let members: StdResult<Vec<_>> = members()
.range(deps.storage, start, None, Order::Ascending)
.take(limit)
.map(|item| {
Expand Down
9 changes: 1 addition & 8 deletions contracts/cw4-group/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,14 @@ use cosmwasm_std::Addr;
use cw4::TOTAL_KEY;
use cw_controllers::{Admin, Hooks};
use cw_storage_plus::{
Index, IndexList, IndexedSnapshotMap, Item, MultiIndex, PkOwned, SnapshotMap, Strategy, U64Key,
Index, IndexList, IndexedSnapshotMap, Item, MultiIndex, PkOwned, Strategy, U64Key,
};

pub const ADMIN: Admin = Admin::new("admin");
pub const HOOKS: Hooks = Hooks::new("cw4-hooks");

pub const TOTAL: Item<u64> = Item::new(TOTAL_KEY);

pub const MEMBERS: SnapshotMap<&Addr, u64> = SnapshotMap::new(
cw4::MEMBERS_KEY,
cw4::MEMBERS_CHECKPOINTS,
cw4::MEMBERS_CHANGELOG,
Strategy::EveryBlock,
);

pub struct MemberIndexes<'a> {
// pk goes to second tuple element
pub weight: MultiIndex<'a, (U64Key, PkOwned), u64>,
Expand Down

0 comments on commit 5ba6368

Please sign in to comment.