Skip to content

Commit

Permalink
Add claim_deallocation to the staking pallet
Browse files Browse the repository at this point in the history
  • Loading branch information
kayabaNerve committed Oct 12, 2023
1 parent 3da5577 commit 108e2b5
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
19 changes: 16 additions & 3 deletions substrate/staking/pallet/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions substrate/validator-sets/pallet/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
Expand Down

0 comments on commit 108e2b5

Please sign in to comment.