Skip to content

Commit

Permalink
add module account check
Browse files Browse the repository at this point in the history
  • Loading branch information
joldie777 committed Sep 5, 2024
1 parent bbd196c commit 4e061fc
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 17 deletions.
6 changes: 3 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 9 additions & 12 deletions contracts/cron/src/contract.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
use crate::msg::{ExecuteMsg, InstantiateMsg, QueryMsg};
use crate::state::{BEGIN_BLOCKER_SHEDULES, END_BLOCKER_SHEDULES};
use cosmwasm_std::{
entry_point, to_json_binary, Binary, Deps, DepsMut, Env, MessageInfo, Response, StdResult,
entry_point, to_json_binary, Binary, Deps, DepsMut, Env, MessageInfo, Response, StdError,
StdResult,
};
use cw2::set_contract_version;

const CONTRACT_NAME: &str = concat!("crates.io:neutron-contracts__", env!("CARGO_PKG_NAME"));
const CONTRACT_VERSION: &str = env!("CARGO_PKG_VERSION");

const MODULE_ACCOUNT: &str = "neutron1cd6wafvehv79pm2yxth40thpyc7dc0yrqkyk95";

#[entry_point]
pub fn instantiate(
deps: DepsMut,
Expand All @@ -21,10 +24,14 @@ pub fn instantiate(
}

#[entry_point]
pub fn execute(deps: DepsMut, _: Env, _: MessageInfo, msg: ExecuteMsg) -> StdResult<Response> {
pub fn execute(deps: DepsMut, _: Env, info: MessageInfo, msg: ExecuteMsg) -> StdResult<Response> {
deps.api
.debug(format!("WASMDEBUG: execute: received msg: {:?}", msg).as_str());

if info.sender.as_str() != MODULE_ACCOUNT {
return Err(StdError::generic_err("Unauthorized"));
}

match msg {
ExecuteMsg::AddBeginBlockerSchedule { name } => {
let counter = BEGIN_BLOCKER_SHEDULES
Expand All @@ -46,16 +53,6 @@ pub fn execute(deps: DepsMut, _: Env, _: MessageInfo, msg: ExecuteMsg) -> StdRes

END_BLOCKER_SHEDULES.save(deps.storage, name, &counter)?;

Ok(Response::default())
}
ExecuteMsg::RemoveBeginBlockerSchedule { name } => {
BEGIN_BLOCKER_SHEDULES.remove(deps.storage, name);

Ok(Response::default())
}
ExecuteMsg::RemoveEndBlockerSchedule { name } => {
END_BLOCKER_SHEDULES.remove(deps.storage, name);

Ok(Response::default())
}
}
Expand Down
2 changes: 0 additions & 2 deletions contracts/cron/src/msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ pub struct InstantiateMsg {}
pub enum ExecuteMsg {
AddBeginBlockerSchedule { name: String },
AddEndBlockerSchedule { name: String },
RemoveBeginBlockerSchedule { name: String },
RemoveEndBlockerSchedule { name: String },
}

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
Expand Down

0 comments on commit 4e061fc

Please sign in to comment.