Skip to content

Commit

Permalink
Update stage removal logic
Browse files Browse the repository at this point in the history
  • Loading branch information
MightOfOaks committed Nov 11, 2024
1 parent 14c4612 commit 7cdd10e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 18 deletions.
19 changes: 10 additions & 9 deletions contracts/whitelists/tiered-whitelist-flex/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ use crate::state::{AdminList, Config, Stage, ADMIN_LIST, CONFIG, MEMBER_COUNT, W
#[cfg(not(feature = "library"))]
use cosmwasm_std::entry_point;
use cosmwasm_std::{
ensure, to_json_binary, Binary, Coin, Deps, DepsMut, Env, MessageInfo, StdResult, Timestamp,
Uint128,
ensure, to_json_binary, Addr, Binary, Coin, Deps, DepsMut, Env, MessageInfo, StdResult,
Timestamp, Uint128,
};
use cosmwasm_std::{Order, StdError};
use cw2::set_contract_version;
Expand Down Expand Up @@ -305,7 +305,7 @@ pub fn execute_add_stage(
CONFIG.save(deps.storage, &config)?;
Ok(Response::new()
.add_attribute("action", "add_stage")
.add_attribute("stage_id", config.stages.len().to_string())
.add_attribute("stage_count", config.stages.len().to_string())
.add_attribute("sender", info.sender))
}

Expand All @@ -331,22 +331,23 @@ pub fn execute_remove_stage(
for stage in stage_id..config.stages.len() as u32 {
let members = WHITELIST_STAGES
.prefix(stage)
.keys(deps.storage, None, None, Order::Ascending)
.map(|key| key.unwrap())
.collect::<Vec<_>>();
for member in members.into_iter() {
.range(deps.storage, None, None, Order::Ascending)
.map(|addr| addr.unwrap().0)
.collect::<Vec<Addr>>();
for member in members {
WHITELIST_STAGES.remove(deps.storage, (stage, member));
config.num_members -= 1;
}
MEMBER_COUNT.remove(deps.storage, stage);
}

// remove the stage and following stages permanently
config.stages = config.stages.into_iter().take(stage_id as usize).collect();

CONFIG.save(deps.storage, &config)?;
Ok(Response::new()
.add_attribute("action", "add_stage")
.add_attribute("stage_id", config.stages.len().to_string())
.add_attribute("action", "remove_stage")
.add_attribute("stage_count", config.stages.len().to_string())
.add_attribute("sender", info.sender))
}

Expand Down
18 changes: 9 additions & 9 deletions contracts/whitelists/tiered-whitelist/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ use crate::state::{AdminList, Config, Stage, ADMIN_LIST, CONFIG, MEMBER_COUNT, W
#[cfg(not(feature = "library"))]
use cosmwasm_std::entry_point;
use cosmwasm_std::{
ensure, to_json_binary, Binary, Coin, Deps, DepsMut, Env, MessageInfo, StdResult, Timestamp,
Uint128,
ensure, to_json_binary, Addr, Binary, Coin, Deps, DepsMut, Env, MessageInfo, StdResult,
Timestamp, Uint128,
};
use cosmwasm_std::{Order, StdError};
use cw2::set_contract_version;
Expand Down Expand Up @@ -305,7 +305,7 @@ pub fn execute_add_stage(
CONFIG.save(deps.storage, &config)?;
Ok(Response::new()
.add_attribute("action", "add_stage")
.add_attribute("stage_id", config.stages.len().to_string())
.add_attribute("stage_count", config.stages.len().to_string())
.add_attribute("sender", info.sender))
}

Expand All @@ -331,10 +331,10 @@ pub fn execute_remove_stage(
for stage in stage_id..config.stages.len() as u32 {
let members = WHITELIST_STAGES
.prefix(stage)
.keys(deps.storage, None, None, Order::Ascending)
.map(|key| key.unwrap())
.collect::<Vec<_>>();
for member in members.into_iter() {
.range(deps.storage, None, None, Order::Ascending)
.map(|addr| addr.unwrap().0)
.collect::<Vec<Addr>>();
for member in members {
WHITELIST_STAGES.remove(deps.storage, (stage, member));
config.num_members -= 1;
}
Expand All @@ -346,8 +346,8 @@ pub fn execute_remove_stage(

CONFIG.save(deps.storage, &config)?;
Ok(Response::new()
.add_attribute("action", "add_stage")
.add_attribute("stage_id", config.stages.len().to_string())
.add_attribute("action", "remove_stage")
.add_attribute("stage_count", config.stages.len().to_string())
.add_attribute("sender", info.sender))
}

Expand Down

0 comments on commit 7cdd10e

Please sign in to comment.