Skip to content

Commit

Permalink
deposit events should be placed in the end of an exstrinsic as they a…
Browse files Browse the repository at this point in the history
…re not reversible
  • Loading branch information
Raid5594 committed Aug 24, 2023
1 parent 6c45c94 commit db88c54
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 20 deletions.
11 changes: 4 additions & 7 deletions pallets/ddc-accounts/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,6 @@ pub struct BucketsDetails<Balance: HasCompact> {
pub amount: Balance,
}

#[derive(PartialEq, Eq, Clone, Encode, Decode, RuntimeDebug, TypeInfo)]
pub struct ReceiverDetails<AccountId, Balance: HasCompact> {
cdn_owner: AccountId,
amount: Balance,
}

#[derive(PartialEq, Eq, Clone, Encode, Decode, RuntimeDebug, TypeInfo)]
pub struct AccountsLedger<AccountId, Balance: HasCompact> {
/// The stash account whose balance is actually locked and can be used for CDN usage.
Expand Down Expand Up @@ -251,6 +245,9 @@ pub mod pallet {

#[pallet::call]
impl<T: Config> Pallet<T> {
/// Create new bucket with provided public availability & reserved resources
///
/// Anyone can create a bucket
#[pallet::weight(10_000)]
pub fn create_bucket(
origin: OriginFor<T>,
Expand Down Expand Up @@ -309,14 +306,14 @@ pub mod pallet {

let stash_balance = <T as pallet::Config>::Currency::free_balance(&stash);
let value = value.min(stash_balance);
Self::deposit_event(Event::<T>::Deposited(stash.clone(), value));
let item = AccountsLedger {
stash: stash.clone(),
total: value,
active: value,
unlocking: Default::default(),
};
Self::update_ledger_and_deposit(&stash, &controller, &item)?;
Self::deposit_event(Event::<T>::Deposited(stash.clone(), value));
Ok(())
}

Expand Down
4 changes: 2 additions & 2 deletions pallets/ddc-staking/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -528,15 +528,15 @@ pub mod pallet {

let stash_balance = T::Currency::free_balance(&stash);
let value = value.min(stash_balance);
Self::deposit_event(Event::<T>::Bonded(stash.clone(), value));
let item = StakingLedger {
stash,
stash: stash.clone(),
total: value,
active: value,
chilling: Default::default(),
unlocking: Default::default(),
};
Self::update_ledger(&controller, &item);
Self::deposit_event(Event::<T>::Bonded(stash, value));
Ok(())
}

Expand Down
22 changes: 11 additions & 11 deletions pallets/ddc-validator/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -422,8 +422,8 @@ pub mod pallet {
);

ensure!(
staking::Validators::<T>::contains_key(Self::get_stash_for_ddc_validator(
&ddc_valitor_key).unwrap()
staking::Validators::<T>::contains_key(
Self::get_stash_for_ddc_validator(&ddc_valitor_key).unwrap()
),
Error::<T>::NotValidatorStash
);
Expand All @@ -440,14 +440,14 @@ pub mod pallet {

ValidationDecisions::<T>::insert(era, cdn_node.clone(), validation_decision.clone());

ValidationDecisionSetForNode::<T>::insert(era, cdn_node.clone(), true);

Self::deposit_event(Event::<T>::ValidationDecision(
era,
cdn_node.clone(),
cdn_node,
validation_decision,
));

ValidationDecisionSetForNode::<T>::insert(era, cdn_node, true);

Ok(())
}

Expand Down Expand Up @@ -475,8 +475,8 @@ pub mod pallet {
);

ensure!(
staking::Validators::<T>::contains_key(Self::get_stash_for_ddc_validator(
&ddc_valitor_key).unwrap()
staking::Validators::<T>::contains_key(
Self::get_stash_for_ddc_validator(&ddc_valitor_key).unwrap()
),
Error::<T>::NotValidatorStash
);
Expand Down Expand Up @@ -527,8 +527,8 @@ pub mod pallet {
);

ensure!(
staking::Validators::<T>::contains_key(Self::get_stash_for_ddc_validator(
&ddc_valitor_key).unwrap()
staking::Validators::<T>::contains_key(
Self::get_stash_for_ddc_validator(&ddc_valitor_key).unwrap()
),
Error::<T>::NotValidatorStash
);
Expand All @@ -546,8 +546,8 @@ pub mod pallet {
}

/// Exstrinsic registers a ddc validator key for future use
///
/// Only controller of validator can call this exstrinsic
///
/// Only controller of validator can call this exstrinsic
/// Validator has to be in the active set
#[pallet::weight(100_000)]
pub fn set_validator_key(
Expand Down

0 comments on commit db88c54

Please sign in to comment.