Skip to content

Commit

Permalink
fix: only owner can add or remove tokens in fee contract (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
aleksuss authored Apr 13, 2024
1 parent 5893411 commit f173068
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion fees/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,11 @@ impl FeesCalculator {
/// Panics if the invoker of the transaction is not owner.
#[allow(clippy::needless_pass_by_value)]
pub fn set_fee_percent(&mut self, percent: Option<String>) {
assert_eq!(env::predecessor_account_id(), self.owner);
assert_eq!(
env::predecessor_account_id(),
self.owner,
"Only owner can set fee percent"
);

match parse_percent(percent.as_deref()) {
Ok(value) => self.percent = value,
Expand Down Expand Up @@ -110,6 +114,11 @@ impl FeesCalculator {
///
/// Panic if the added token is already exist.
pub fn add_supported_token(&mut self, token_id: AccountId) {
assert_eq!(
env::predecessor_account_id(),
self.owner,
"Only owner can add token"
);
assert!(
self.supported_tokens.insert(token_id),
"Token is already present"
Expand All @@ -122,6 +131,11 @@ impl FeesCalculator {
///
/// Panics if the removed token is not exists.
pub fn remove_supported_token(&mut self, token_id: &AccountId) {
assert_eq!(
env::predecessor_account_id(),
self.owner,
"Only owner can remove token"
);
assert!(
self.supported_tokens.remove(token_id),
"Nothing to remove, token: {token_id} hasn't been added"
Expand Down

0 comments on commit f173068

Please sign in to comment.