cw_boolean_contract/entry_points/execute/set_value.rs
1//! Execute logic that explicitly sets the state boolean to `true` or `false`
2
3use crate::errors::ContractError;
4use crate::state::{Config, CONFIG};
5use cosmwasm_std::{DepsMut, Env, MessageInfo, Response};
6
7/// Logic for the [SetValue](crate::msgs::execute_msg::ExecuteMsg::SetValue) (`set_value`) method
8pub fn execute(
9 deps: DepsMut,
10 _env: Env,
11 _info: MessageInfo,
12 is_true: bool,
13) -> Result<Response, ContractError> {
14 // Set our state variable according to the input
15 let update_config = Config { is_true };
16 // The question mark at the end of this line means it'll return an error
17 // if something went wrong
18 CONFIG.save(deps.storage, &update_config)?;
19
20 // We basically say, "yup that worked" but returning Ok(…)
21 // It's also best practice to use Response::default()
22 // instead of Response::new() even though that would ✌️work ✌️
23 Ok(Response::default())
24}