Skip to content

Commit cb41ec5

Browse files
committed
update
1 parent 0d1ca5c commit cb41ec5

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

xtokens/src/lib.rs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ use frame_support::{
3636
pallet_prelude::*,
3737
require_transactional,
3838
traits::{Contains, Get},
39-
Parameter,
39+
transactional, Parameter,
4040
};
4141
use frame_system::{ensure_signed, pallet_prelude::*};
4242
use sp_runtime::{
@@ -516,6 +516,28 @@ pub mod module {
516516
}
517517

518518
impl<T: Config> Pallet<T> {
519+
#[transactional]
520+
fn transfer_assets_delay_check(who: &T::AccountId, assets: Assets) -> DispatchResult {
521+
let rate_limiter_id = T::RateLimiterId::get();
522+
let asset_len = assets.len();
523+
for i in 0..asset_len {
524+
let asset = assets.get(i).ok_or(Error::<T>::AssetIndexNonExistent)?;
525+
526+
// per asset check
527+
let amount = match asset.fun {
528+
Fungibility::Fungible(amount) => amount,
529+
Fungibility::NonFungible(_) => 1,
530+
};
531+
532+
// try consume quota of the rate limiter.
533+
// NOTE: use AssetId as the key, use AccountId as whitelist filter key.
534+
T::RateLimiter::try_consume(rate_limiter_id, asset.id.clone(), amount, Some(who))
535+
.map_err(|_| Error::<T>::RateLimited)?;
536+
}
537+
538+
Ok(())
539+
}
540+
519541
fn do_transfer(
520542
who: T::AccountId,
521543
currency_id: T::CurrencyId,

0 commit comments

Comments
 (0)