mirror of
https://github.com/serai-dex/serai.git
synced 2024-11-17 01:17:36 +00:00
Add claim_deallocation to the staking pallet
This commit is contained in:
parent
3da5577950
commit
108e2b57d9
2 changed files with 17 additions and 3 deletions
|
@ -13,12 +13,13 @@ pub mod pallet {
|
|||
|
||||
use serai_primitives::{NetworkId, Amount, PublicKey};
|
||||
|
||||
use validator_sets_pallet::{Config as VsConfig, Pallet as VsPallet};
|
||||
use validator_sets_pallet::{primitives::Session, Config as VsConfig, Pallet as VsPallet};
|
||||
use pallet_session::{Config as SessionConfig, SessionManager};
|
||||
|
||||
#[pallet::error]
|
||||
pub enum Error<T> {
|
||||
StakeUnavilable,
|
||||
NoDeallocation,
|
||||
}
|
||||
|
||||
// TODO: Event
|
||||
|
@ -76,7 +77,6 @@ pub mod pallet {
|
|||
})
|
||||
}
|
||||
|
||||
#[allow(unused)] // TODO
|
||||
fn deallocate_internal(account: &T::AccountId, amount: u64) -> Result<(), Error<T>> {
|
||||
Allocated::<T>::try_mutate(account, |allocated| {
|
||||
if *allocated < amount {
|
||||
|
@ -150,7 +150,20 @@ pub mod pallet {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
// TODO: Add a function to reclaim deallocated funds
|
||||
#[pallet::call_index(4)]
|
||||
#[pallet::weight((0, DispatchClass::Operational))] // TODO
|
||||
pub fn claim_deallocation(
|
||||
origin: OriginFor<T>,
|
||||
network: NetworkId,
|
||||
session: Session,
|
||||
) -> DispatchResult {
|
||||
let account = ensure_signed(origin)?;
|
||||
let Some(amount) = VsPallet::<T>::take_deallocatable_amount(network, session, account) else {
|
||||
Err(Error::<T>::NoDeallocation)?
|
||||
};
|
||||
Self::deallocate_internal(&account, amount.0)?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
// Call order is end_session(i - 1) -> start_session(i) -> new_session(i + 1)
|
||||
|
|
|
@ -163,6 +163,7 @@ pub mod pallet {
|
|||
#[pallet::getter(fn keys)]
|
||||
pub type Keys<T: Config> = StorageMap<_, Twox64Concat, ValidatorSet, KeyPair, OptionQuery>;
|
||||
|
||||
// TODO: Expand
|
||||
#[pallet::event]
|
||||
#[pallet::generate_deposit(pub(super) fn deposit_event)]
|
||||
pub enum Event<T: Config> {
|
||||
|
|
Loading…
Reference in a new issue