1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
use super::*;
use frame_support::sp_runtime::traits::Zero;
use frame_support::traits::LockIdentifier;
use hydradx_traits::LockedBalance;
pub struct MultiCurrencyLockedBalance<T>(sp_std::marker::PhantomData<T>);
impl<T: orml_tokens::Config + pallet_balances::Config + frame_system::Config>
LockedBalance<AssetId, T::AccountId, Balance> for MultiCurrencyLockedBalance<T>
where
AssetId: Into<<T as orml_tokens::Config>::CurrencyId>,
Balance: From<<T as orml_tokens::Config>::Balance>,
Balance: From<<T as pallet_balances::Config>::Balance>,
{
fn get_by_lock(lock_id: LockIdentifier, currency_id: AssetId, who: T::AccountId) -> Balance {
if currency_id == NativeAssetId::get() {
match pallet_balances::Pallet::<T>::locks(who)
.into_iter()
.find(|lock| lock.id == lock_id)
{
Some(lock) => lock.amount.into(),
None => Zero::zero(),
}
} else {
match orml_tokens::Pallet::<T>::locks(who, currency_id.into())
.into_iter()
.find(|lock| lock.id == lock_id)
{
Some(lock) => lock.amount.into(),
None => Zero::zero(),
}
}
}
}