cw_boolean_contract/entry_points/execute/toggle.rs
1//! Execute logic that inverts the current stored boolean value.
2
3use crate::errors::ContractError;
4use crate::state::{Config, CONFIG};
5use cosmwasm_std::{DepsMut, Env, MessageInfo, Response};
6
7/// Logic for the [Toggle](crate::msgs::execute_msg::ExecuteMsg::Toggle) (`toggle`) method
8pub fn execute(deps: DepsMut, _env: Env, _info: MessageInfo) -> Result<Response, ContractError> {
9 // Get the current value
10 let current_val = CONFIG.load(deps.storage)?;
11 let toggle_boolean = Config {
12 // The exclamation point says, "the opposite of the true/false, please"
13 is_true: !current_val.is_true,
14 };
15 CONFIG.save(deps.storage, &toggle_boolean)?;
16 Ok(Response::default())
17}