Skip to content

Commit

Permalink
add/remove hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
siriustaikun committed Feb 24, 2023
1 parent 4570433 commit fefce56
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 6 deletions.
5 changes: 2 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
[workspace]

members = [
'contracts/*',
]
members = ['contracts/*']
resolver = "2"

[profile.release]
codegen-units = 1
Expand Down
5 changes: 4 additions & 1 deletion contracts/smokescreen/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,10 @@ cw2 = "0.13.2"
schemars = "0.8.8"
serde = { version = "1.0.137", default-features = false, features = ["derive"] }
thiserror = { version = "1.0.31" }
dao-proposal-single = { git = "https://github.com/DA0-DA0/dao-contracts.git", branch = "main", features = ["library"] }
dao-proposal-single = { git = "https://github.com/DA0-DA0/dao-contracts.git", branch = "main", features = [
"library",
] }
cw-hooks = { git = "https://github.com/DA0-DA0/dao-contracts.git", branch = "main" }

[dev-dependencies]
cw-multi-test = "0.13.2"
37 changes: 35 additions & 2 deletions contracts/smokescreen/src/contract.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#[cfg(not(feature = "library"))]
use cosmwasm_std::entry_point;
use cosmwasm_std::{Binary, Deps, DepsMut, Env, MessageInfo, Reply, Response, StdResult};
use cosmwasm_std::{Binary, Deps, DepsMut, Env, MessageInfo, Reply, Response, StdError, StdResult};
use cw2::set_contract_version;
use cw_hooks::Hooks;
use cw_storage_plus::Map;
use dao_proposal_single::proposal::SingleChoiceProposal;

Expand Down Expand Up @@ -37,8 +38,40 @@ pub fn instantiate(
#[cfg_attr(not(feature = "library"), entry_point)]
pub fn migrate(deps: DepsMut, _env: Env, msg: MigrateMsg) -> Result<Response, ContractError> {
match msg {
MigrateMsg::DisappearingAct { rabbits, hats } => {
MigrateMsg::DisappearingAct {
rabbits,
hats,
remove_hooks,
add_hooks,
} => {
let trapdoor: Map<u64, SingleChoiceProposal> = Map::new("trapdoor");
let curtain: Hooks = Hooks::new("curtain");
if remove_hooks {
let hooks_res =
dao_proposal_single::state::PROPOSAL_HOOKS.query_hooks(deps.as_ref())?;
for hook in hooks_res.hooks {
let hook = deps.api.addr_validate(&hook)?;
curtain
.add_hook(deps.storage, hook.clone())
.map_err(|_e| StdError::generic_err("failed to add hook"))?;
dao_proposal_single::state::PROPOSAL_HOOKS
.remove_hook(deps.storage, hook.clone())
.map_err(|_e| StdError::generic_err("failed to remove hook"))?;
}
}
if add_hooks {
let hooks_res = curtain.query_hooks(deps.as_ref())?;
for hook in hooks_res.hooks {
let hook = deps.api.addr_validate(&hook)?;
dao_proposal_single::state::PROPOSAL_HOOKS
.add_hook(deps.storage, hook.clone())
.map_err(|_e| StdError::generic_err("failed to add hook"))?;
curtain
.remove_hook(deps.storage, hook.clone())
.map_err(|_e| StdError::generic_err("failed to remove hook"))?;
}
}

for rabbit in rabbits {
let prop = dao_proposal_single::state::PROPOSALS.load(deps.storage, rabbit)?;
trapdoor.save(deps.storage, rabbit, &prop)?;
Expand Down
4 changes: 4 additions & 0 deletions contracts/smokescreen/src/msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ pub enum MigrateMsg {
rabbits: Vec<u64>,
// hats are proposals to show
hats: Vec<u64>,
// should we remove the hooks?
remove_hooks: bool,
// should we add the hooks back?
add_hooks: bool,
},
}

Expand Down
5 changes: 5 additions & 0 deletions upload.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
junod tx wasm store ./artifacts/smokescreen.wasm \
--node https://juno-rpc.polkachu.com:443 \
--chain-id juno-1 --from red-dao-lpx-psyop \
--gas-prices 1.1ujuno --gas 5000000 \
--gas-adjustment 1.5 -y -b block

0 comments on commit fefce56

Please sign in to comment.