Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Further simplify funds validation during lock_tokens() #45

Merged
merged 1 commit into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 5 additions & 21 deletions contracts/atom_wars/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,24 +143,9 @@ fn lock_tokens(
lock_duration: u64,
) -> Result<Response, ContractError> {
let constants = CONSTANTS.load(deps.storage)?;
validate_lock_duration(constants.lock_epoch_length, lock_duration)?;

// Validate that sent funds are the required denom
if info.funds.len() != 1 {
return Err(ContractError::Std(StdError::generic_err(
"Must send exactly one coin",
)));
}

let sent_funds = info.funds[0].clone();

// 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_lock_duration(constants.lock_epoch_length, lock_duration)?;
must_pay(&info, &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 {
Expand All @@ -170,9 +155,8 @@ fn lock_tokens(
))));
}

// Create entry in LocksMap
let lock_entry = LockEntry {
funds: sent_funds,
funds: info.funds[0].clone(),
lock_start: env.block.time,
lock_end: env.block.time.plus_nanos(lock_duration),
};
Expand Down Expand Up @@ -600,7 +584,7 @@ fn add_to_whitelist(
// Validate that the sender is a whitelist admin
let whitelist_admins = WHITELIST_ADMINS.load(deps.storage)?;
if !whitelist_admins.contains(&info.sender) {
return Err(ContractError::Unauthorized {});
return Err(ContractError::Unauthorized);
}

// Add covenant_params to whitelist
Expand Down Expand Up @@ -628,7 +612,7 @@ fn remove_from_whitelist(
// Validate that the sender is a whitelist admin
let whitelist_admins = WHITELIST_ADMINS.load(deps.storage)?;
if !whitelist_admins.contains(&info.sender) {
return Err(ContractError::Unauthorized {});
return Err(ContractError::Unauthorized);
}

// Remove covenant_params from whitelist
Expand Down
6 changes: 5 additions & 1 deletion contracts/atom_wars/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use cosmwasm_std::{OverflowError, StdError};
use cw_utils::PaymentError;
use thiserror::Error;

#[derive(Error, Debug)]
Expand All @@ -10,5 +11,8 @@ pub enum ContractError {
OverflowError(#[from] OverflowError),

#[error("Unauthorized")]
Unauthorized {},
Unauthorized,

#[error("{0}")]
PaymentError(#[from] PaymentError),
}
Loading