Skip to content

Commit

Permalink
add missing error types and remove unwrap from exstrinsics
Browse files Browse the repository at this point in the history
  • Loading branch information
Raid5594 committed Aug 23, 2023
1 parent 7677a58 commit b87f620
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
8 changes: 5 additions & 3 deletions pallets/ddc-accounts/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,8 @@ pub mod pallet {
NoMoreChunks,
/// Internal state has become somehow corrupted and the operation cannot continue.
BadState,
/// Current era not set
DDCEraNotSet,
}

#[pallet::genesis_config]
Expand Down Expand Up @@ -425,8 +427,8 @@ pub mod pallet {
ledger.active = Zero::zero();
}

let current_era =
ddc_staking::pallet::Pallet::<T>::current_era().ok_or("DDC era not set")?;
let current_era = ddc_staking::pallet::Pallet::<T>::current_era()
.ok_or(Error::<T>::DDCEraNotSet)?;
// Note: bonding for extra era to allow for accounting
let era = current_era + <T as pallet::Config>::BondingDuration::get();
log::debug!("Era for the unbond: {:?}", era);
Expand Down Expand Up @@ -468,7 +470,7 @@ pub mod pallet {
let mut ledger = Self::ledger(&controller).ok_or(Error::<T>::NotController)?;
let (stash, old_total) = (ledger.stash.clone(), ledger.total);
let current_era =
ddc_staking::pallet::Pallet::<T>::current_era().ok_or("DDC era not set")?;
ddc_staking::pallet::Pallet::<T>::current_era().ok_or(Error::<T>::DDCEraNotSet)?;
ledger = ledger.consolidate_unlocked(current_era);
log::debug!("Current era: {:?}", current_era);

Expand Down
5 changes: 4 additions & 1 deletion pallets/ddc-staking/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,7 @@ pub mod pallet {
DoubleSpendRewards,
PricingNotSet,
BudgetOverflow,
DDCEraNotSet,
}

#[pallet::hooks]
Expand Down Expand Up @@ -839,10 +840,12 @@ pub mod pallet {
#[pallet::weight(100_000)]
pub fn payout_stakers(origin: OriginFor<T>, era: EraIndex) -> DispatchResult {
ensure_signed(origin)?;
let current_era = Self::current_era().ok_or("DDC era not set")?;
let current_era = Self::current_era().ok_or(Error::<T>::DDCEraNotSet)?;

// Makes sure this era hasn't been paid out yet
ensure!(!Self::paideras(era), Error::<T>::DoubleSpendRewards);

// This should be adjusted based on the finality of validation
ensure!(current_era >= era + 2, Error::<T>::EraNotValidated);

PaidEras::<T>::insert(era, true);
Expand Down
13 changes: 7 additions & 6 deletions pallets/ddc-validator/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,11 +265,13 @@ pub mod pallet {

#[pallet::error]
pub enum Error<T> {
DDCEraNotSet,
NotController,
OCWKeyNotRegistered,
ContentOwnersDoubleSpend,
ValidationDecisionAlreadySet,
NodeNotActive,
PricingNotSet,
}

#[pallet::event]
Expand Down Expand Up @@ -494,7 +496,7 @@ pub mod pallet {
log::debug!("Controller is {:?}", controller);

let current_era =
ddc_staking::pallet::Pallet::<T>::current_era().ok_or("DDC era not set")?;
ddc_staking::pallet::Pallet::<T>::current_era().ok_or(Error::<T>::DDCEraNotSet)?;

ensure!(
OffchainWorkerKeys::<T>::contains_key(&controller),
Expand All @@ -506,12 +508,11 @@ pub mod pallet {
Error::<T>::ContentOwnersDoubleSpend
);

let pricing: u128 = <ddc_staking::pallet::Pallet<T>>::pricing().unwrap();
<ddc_accounts::pallet::Pallet<T>>::charge_payments_new(paying_accounts, pricing);

let pricing: u128 =
<ddc_staking::pallet::Pallet<T>>::pricing().ok_or(Error::<T>::PricingNotSet)?;
EraContentOwnersCharged::<T>::insert(current_era, controller, true);

Ok(())
<ddc_accounts::pallet::Pallet<T>>::charge_payments_new(paying_accounts, pricing)
}

#[pallet::weight(100_000)]
Expand All @@ -525,7 +526,7 @@ pub mod pallet {
pub fn set_ocw_key(origin: OriginFor<T>, ocw_pub: T::AccountId) -> DispatchResult {
let controller = ensure_signed(origin)?;
let ledger = staking::Ledger::<T>::get(&controller).ok_or(Error::<T>::NotController)?;
let era = staking::Pallet::<T>::current_era().unwrap();
let era = staking::Pallet::<T>::current_era().ok_or(Error::<T>::DDCEraNotSet)?;

ensure!(
staking::ErasStakers::<T>::contains_key(era, &ledger.stash),
Expand Down

0 comments on commit b87f620

Please sign in to comment.