use super::{super::misc::WithdrawReasons, Currency};
use crate::{dispatch::DispatchResult, traits::misc::Get};
pub type LockIdentifier = [u8; 8];
pub trait LockableCurrency<AccountId>: Currency<AccountId> {
type Moment;
type MaxLocks: Get<u32>;
fn set_lock(
id: LockIdentifier,
who: &AccountId,
amount: Self::Balance,
reasons: WithdrawReasons,
);
fn extend_lock(
id: LockIdentifier,
who: &AccountId,
amount: Self::Balance,
reasons: WithdrawReasons,
);
fn remove_lock(id: LockIdentifier, who: &AccountId);
}
pub trait InspectLockableCurrency<AccountId>: LockableCurrency<AccountId> {
fn balance_locked(id: LockIdentifier, who: &AccountId) -> Self::Balance;
}
pub trait VestingSchedule<AccountId> {
type Moment;
type Currency: Currency<AccountId>;
fn vesting_balance(who: &AccountId)
-> Option<<Self::Currency as Currency<AccountId>>::Balance>;
fn add_vesting_schedule(
who: &AccountId,
locked: <Self::Currency as Currency<AccountId>>::Balance,
per_block: <Self::Currency as Currency<AccountId>>::Balance,
starting_block: Self::Moment,
) -> DispatchResult;
fn can_add_vesting_schedule(
who: &AccountId,
locked: <Self::Currency as Currency<AccountId>>::Balance,
per_block: <Self::Currency as Currency<AccountId>>::Balance,
starting_block: Self::Moment,
) -> DispatchResult;
fn remove_vesting_schedule(who: &AccountId, schedule_index: u32) -> DispatchResult;
}
pub trait VestedTransfer<AccountId> {
type Moment;
type Currency: Currency<AccountId>;
fn vested_transfer(
source: &AccountId,
target: &AccountId,
locked: <Self::Currency as Currency<AccountId>>::Balance,
per_block: <Self::Currency as Currency<AccountId>>::Balance,
starting_block: Self::Moment,
) -> DispatchResult;
}
pub struct NoVestedTransfers<C> {
phantom: core::marker::PhantomData<C>,
}
impl<AccountId, C: Currency<AccountId>> VestedTransfer<AccountId> for NoVestedTransfers<C> {
type Moment = ();
type Currency = C;
fn vested_transfer(
_source: &AccountId,
_target: &AccountId,
_locked: <Self::Currency as Currency<AccountId>>::Balance,
_per_block: <Self::Currency as Currency<AccountId>>::Balance,
_starting_block: Self::Moment,
) -> DispatchResult {
Err(sp_runtime::DispatchError::Unavailable.into())
}
}