Skip to content

Commit

Permalink
Fix wrong allowed_currencies_len variable (#298)
Browse files Browse the repository at this point in the history
  • Loading branch information
ebma authored Aug 15, 2023
1 parent 54c0039 commit 05607a1
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion pallets/orml-currencies-allowance-extension/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ pub mod pallet {

// Check if the resulting vector of allowed currencies is less than the maximum allowed.
// We check after the insertion to avoid counting duplicates.
let allowed_currencies_len: usize = currencies.len();
let allowed_currencies_len: usize = AllowedCurrencies::<T>::iter().count();
ensure!(
allowed_currencies_len <= max_allowed_currencies,
Error::<T>::ExceedsNumberOfAllowedCurrencies
Expand All @@ -181,6 +181,16 @@ pub mod pallet {
currencies: Vec<CurrencyOf<T>>,
) -> DispatchResult {
ensure_root(origin)?;

// Check if the supplied amount of currencies is less than the maximum allowed
// Although this is not strictly necessary, it is a good sanity check and prevents callers
// from using too large currency vectors.
let max_allowed_currencies: usize = T::MaxAllowedCurrencies::get() as usize;
ensure!(
currencies.len() <= max_allowed_currencies,
Error::<T>::ExceedsNumberOfAllowedCurrencies
);

for i in currencies.clone() {
AllowedCurrencies::<T>::remove(i);
}
Expand Down

0 comments on commit 05607a1

Please sign in to comment.