diff --git a/modules/incentives/src/lib.rs b/modules/incentives/src/lib.rs index 6a13855b7..b7a90da49 100644 --- a/modules/incentives/src/lib.rs +++ b/modules/incentives/src/lib.rs @@ -42,7 +42,7 @@ use frame_support::{pallet_prelude::*, transactional, PalletId}; use frame_system::pallet_prelude::*; use module_support::{DEXIncentives, EmergencyShutdown, FractionalRate, IncentivesManager, PoolId, Rate}; -use orml_traits::{Handler, Happened, MultiCurrency, RewardHandler}; +use orml_traits::{Handler, MultiCurrency, RewardHandler}; use primitives::{Amount, Balance, CurrencyId}; use sp_runtime::{ traits::{AccountIdConversion, UniqueSaturatedInto, Zero}, @@ -619,15 +619,15 @@ impl Handler<(T::AccountId, Balance)> for OnEarningUnbonded { } pub struct OnNomineesElectionBonded(sp_std::marker::PhantomData); -impl Happened<(T::AccountId, Balance)> for OnNomineesElectionBonded { - fn happened((who, amount): &(T::AccountId, Balance)) { - let _ = >::add_share(who, &PoolId::NomineesElection, *amount); +impl Handler<(T::AccountId, Balance)> for OnNomineesElectionBonded { + fn handle((who, amount): &(T::AccountId, Balance)) -> DispatchResult { + >::add_share(who, &PoolId::NomineesElection, *amount) } } pub struct OnNomineesElectionUnbonded(sp_std::marker::PhantomData); -impl Happened<(T::AccountId, Balance)> for OnNomineesElectionUnbonded { - fn happened((who, amount): &(T::AccountId, Balance)) { - let _ = >::remove_share(who, &PoolId::NomineesElection, *amount); +impl Handler<(T::AccountId, Balance)> for OnNomineesElectionUnbonded { + fn handle((who, amount): &(T::AccountId, Balance)) -> DispatchResult { + >::remove_share(who, &PoolId::NomineesElection, *amount) } } diff --git a/modules/incentives/src/tests.rs b/modules/incentives/src/tests.rs index 9ef12a22b..85e3651ed 100644 --- a/modules/incentives/src/tests.rs +++ b/modules/incentives/src/tests.rs @@ -1342,7 +1342,7 @@ fn claim_reward_deduction_currency_works() { #[test] fn nominees_election_should_work() { ExtBuilder::default().build().execute_with(|| { - OnNomineesElectionBonded::::happened(&(ALICE::get(), 80)); + OnNomineesElectionBonded::::handle(&(ALICE::get(), 80)); assert_eq!( RewardsModule::pool_infos(PoolId::NomineesElection), PoolInfo { @@ -1355,7 +1355,7 @@ fn nominees_election_should_work() { (80, Default::default()) ); - OnNomineesElectionUnbonded::::happened(&(ALICE::get(), 20)); + OnNomineesElectionUnbonded::::handle(&(ALICE::get(), 20)); assert_eq!( RewardsModule::pool_infos(PoolId::NomineesElection), PoolInfo { @@ -1368,7 +1368,7 @@ fn nominees_election_should_work() { (60, Default::default()) ); - OnNomineesElectionUnbonded::::happened(&(ALICE::get(), 60)); + OnNomineesElectionUnbonded::::handle(&(ALICE::get(), 60)); assert_eq!( RewardsModule::pool_infos(PoolId::NomineesElection), PoolInfo { ..Default::default() } diff --git a/modules/nominees-election/src/lib.rs b/modules/nominees-election/src/lib.rs index 16d5c2dab..af6d087ab 100644 --- a/modules/nominees-election/src/lib.rs +++ b/modules/nominees-election/src/lib.rs @@ -27,7 +27,7 @@ use frame_support::{ }; use frame_system::pallet_prelude::*; use module_support::NomineesProvider; -use orml_traits::{BasicCurrency, BasicLockableCurrency, Happened}; +use orml_traits::{BasicCurrency, BasicLockableCurrency, Handler}; use primitives::{ bonding::{self, BondingController}, Balance, EraIndex, @@ -84,10 +84,10 @@ pub mod module { type GovernanceOrigin: EnsureOrigin; /// Callback when an account bonded. - type OnBonded: Happened<(Self::AccountId, Balance)>; + type OnBonded: Handler<(Self::AccountId, Balance)>; /// Callback when an account unbonded. - type OnUnbonded: Happened<(Self::AccountId, Balance)>; + type OnUnbonded: Handler<(Self::AccountId, Balance)>; /// Current era. type CurrentEra: Get; @@ -199,7 +199,7 @@ pub mod module { Self::update_votes(change.old, &old_nominations, change.new, &old_nominations); - T::OnBonded::happened(&(who.clone(), change.change)); + T::OnBonded::handle(&(who.clone(), change.change))?; Self::deposit_event(Event::Bond { who, @@ -222,7 +222,7 @@ pub mod module { Self::update_votes(change.old, &old_nominations, change.new, &old_nominations); - T::OnUnbonded::happened(&(who.clone(), change.change)); + T::OnUnbonded::handle(&(who.clone(), change.change))?; Self::deposit_event(Event::Unbond { who, @@ -245,7 +245,7 @@ pub mod module { Self::update_votes(change.old, &old_nominations, change.new, &old_nominations); - T::OnBonded::happened(&(who.clone(), change.change)); + T::OnBonded::handle(&(who.clone(), change.change))?; Self::deposit_event(Event::Rebond { who, diff --git a/modules/nominees-election/src/mock.rs b/modules/nominees-election/src/mock.rs index defa1d390..1e4f7ee6a 100644 --- a/modules/nominees-election/src/mock.rs +++ b/modules/nominees-election/src/mock.rs @@ -130,8 +130,8 @@ parameter_types! { } pub struct MockOnBonded; -impl Happened<(AccountId, Balance)> for MockOnBonded { - fn happened(info: &(AccountId, Balance)) { +impl Handler<(AccountId, Balance)> for MockOnBonded { + fn handle(info: &(AccountId, Balance)) -> DispatchResult { let (account_id, amount) = info; Shares::mutate(|v| { let mut old_map = v.clone(); @@ -143,12 +143,13 @@ impl Happened<(AccountId, Balance)> for MockOnBonded { *v = old_map; }); + Ok(()) } } pub struct MockOnUnbonded; -impl Happened<(AccountId, Balance)> for MockOnUnbonded { - fn happened(info: &(AccountId, Balance)) { +impl Handler<(AccountId, Balance)> for MockOnUnbonded { + fn handle(info: &(AccountId, Balance)) -> DispatchResult { let (account_id, amount) = info; Shares::mutate(|v| { let mut old_map = v.clone(); @@ -160,6 +161,7 @@ impl Happened<(AccountId, Balance)> for MockOnUnbonded { *v = old_map; }); + Ok(()) } }