Skip to content

Commit

Permalink
Utilize must_pay for denom validation
Browse files Browse the repository at this point in the history
  • Loading branch information
p-offtermatt committed Jul 1, 2024
1 parent 654ab7f commit ede8b37
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ thiserror = { version = "1.0.49" }
cw-storage-plus = { version = "1.1.0" }
cw2 = "1.1.1"
cosmwasm-schema = { version = "1.4.0" }
proptest = "1.0.0"
proptest = "1.0.0"
cw-utils = "1.0.3"
1 change: 1 addition & 0 deletions contracts/atom_wars/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ thiserror = { workspace = true }
cw-storage-plus = { workspace = true }
cw2 = { workspace = true }
cosmwasm-schema = { workspace = true }
cw-utils = { workspace = true }

[dev-dependencies]
cosmwasm-schema = { workspace = true }
Expand Down
16 changes: 10 additions & 6 deletions contracts/atom_wars/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use crate::state::{
PROPOSAL_MAP, PROPS_BY_SCORE, PROP_ID, TOTAL_ROUND_POWER, TOTAL_VOTED_POWER, TRANCHE_MAP,
VOTE_MAP, WHITELIST, WHITELIST_ADMINS,
};
use cw_utils::must_pay;

/// Contract name that is used for migration.
const CONTRACT_NAME: &str = env!("CARGO_PKG_NAME");
Expand Down Expand Up @@ -148,11 +149,14 @@ fn lock_tokens(
}

let sent_funds = info.funds[0].clone();
if sent_funds.denom != constants.denom {
return Err(ContractError::Std(StdError::generic_err(
"Must send the correct denom",
)));
}

// validate that the sent funds are the required denom using must_pay
must_pay(&info, &constants.denom).map_err(|_| {
ContractError::Std(StdError::generic_err(format!(
"Must send {} tokens",
constants.denom
)))
})?;

// validate that the user does not have too many locks
if get_lock_count(deps.as_ref(), info.sender.clone()) >= MAX_LOCK_ENTRIES.try_into().unwrap() {
Expand Down Expand Up @@ -745,8 +749,8 @@ pub fn query_proposal(
}

pub fn query_user_voting_power(deps: Deps, env: Env, address: String) -> StdResult<u128> {
let constants = CONSTANTS.load(deps.storage)?;
let user_address = deps.api.addr_validate(&address)?;
let constants = CONSTANTS.load(deps.storage)?;
let current_round_id = compute_current_round_id(&env, &constants)?;
let round_end = compute_round_end(&constants, current_round_id)?;
let lock_epoch_length = constants.lock_epoch_length;
Expand Down

0 comments on commit ede8b37

Please sign in to comment.