diff --git a/src/contract.rs b/src/contract.rs index 68d0191..db328a1 100644 --- a/src/contract.rs +++ b/src/contract.rs @@ -18,11 +18,12 @@ const CONTRACT_VERSION: &str = env!("CARGO_PKG_VERSION"); pub fn instantiate( deps: DepsMut, _env: Env, - _info: MessageInfo, + info: MessageInfo, msg: InstantiateMsg, ) -> Result { let state = State { route: msg.route.clone(), + admin: info.sender, tokens: BTreeMap::default(), handled_tickets: BTreeSet::default(), handled_directives: BTreeSet::default(), @@ -67,6 +68,7 @@ pub fn execute( ExecuteMsg::BurnToken { token_id, amount } => { execute::burn_token(deps, env, info, token_id, amount) } + ExecuteMsg::UpdateRoute { route } => execute::update_route(deps, info, route), }?; Ok(response.add_event(Event::new("execute_msg").add_attribute("contract", contract))) } @@ -298,6 +300,25 @@ pub mod execute { )) } + pub fn update_route( + deps: DepsMut, + info: MessageInfo, + route: Addr, + ) -> Result { + if read_state(deps.storage, |s| info.sender != s.admin) { + return Err(ContractError::Unauthorized); + } + + STATE.update(deps.storage, |mut state| -> Result<_, ContractError> { + state.route = route.clone(); + Ok(state) + })?; + + Ok(Response::new().add_event( + Event::new("RouteUpdated").add_attributes(vec![Attribute::new("new_route", route)]), + )) + } + fn build_burn_msg( contract_addr: Addr, sender: Addr, diff --git a/src/msg.rs b/src/msg.rs index 3ba6856..bcb77b5 100644 --- a/src/msg.rs +++ b/src/msg.rs @@ -35,6 +35,9 @@ pub enum ExecuteMsg { token_id: String, amount: String, }, + UpdateRoute { + route: Addr, + } } #[cw_serde] diff --git a/src/state.rs b/src/state.rs index 1832b5b..baf0184 100644 --- a/src/state.rs +++ b/src/state.rs @@ -9,6 +9,7 @@ use cw_storage_plus::Item; #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)] pub struct State { pub route: Addr, + pub admin: Addr, pub tokens: BTreeMap, pub handled_tickets: BTreeSet, pub handled_directives: BTreeSet,