Skip to content

Commit

Permalink
Emit an event instead of a log
Browse files Browse the repository at this point in the history
  • Loading branch information
aurexav committed Nov 6, 2023
1 parent 8fd5718 commit 49b007a
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 25 deletions.
18 changes: 15 additions & 3 deletions pallet/staking/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,12 @@ pub mod pallet {
/// A payout has been made for the staker.
Payout {
staker: T::AccountId,
ring_amount: Balance,
amount: Balance,
},
/// Unable to pay the staker's reward.
Unpaied {
staker: T::AccountId,
amount: Balance,
},
/// A new collator set has been elected.
Elected {
Expand Down Expand Up @@ -814,15 +819,22 @@ pub mod pallet {

Self::deposit_event(Event::Payout {
staker: n_exposure.who,
ring_amount: n_payout,
amount: n_payout,
});
} else {
Self::deposit_event(Event::Unpaied {
staker: n_exposure.who,
amount: n_payout,
});
}
}

if T::OnSessionEnd::reward(&c, c_payout).is_ok() {
actual_payout += c_payout;

Self::deposit_event(Event::Payout { staker: c, ring_amount: c_payout });
Self::deposit_event(Event::Payout { staker: c, amount: c_payout });
} else {
Self::deposit_event(Event::Unpaied { staker: c, amount: c_payout });
}
}

Expand Down
9 changes: 2 additions & 7 deletions runtime/crab/src/pallets/staking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,17 +79,12 @@ impl darwinia_staking::OnSessionEnd<Runtime> for OnCrabSessionEnd {
}

fn reward(who: &AccountId, amount: Balance) -> sp_runtime::DispatchResult {
if let Err(e) = <Balances as Currency<AccountId>>::transfer(
<Balances as Currency<AccountId>>::transfer(
&Treasury::account_id(),
who,
amount,
frame_support::traits::ExistenceRequirement::KeepAlive,
) {
// TODO: log
// log::error!("[runtime::staking] reward error: {:?}", e);
}

Ok(())
)
}
}

Expand Down
5 changes: 1 addition & 4 deletions runtime/darwinia/src/pallets/staking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,7 @@ impl darwinia_staking::OnSessionEnd<Runtime> for OnDarwiniaSessionEnd {
}

fn reward(who: &AccountId, amount: Balance) -> sp_runtime::DispatchResult {
if let Err(e) = Balances::deposit_into_existing(who, amount) {
// TODO: log
// log::error!("[runtime::staking] reward error: {:?}", e);
}
let _ = Balances::deposit_into_existing(who, amount)?;

Ok(())
}
Expand Down
9 changes: 2 additions & 7 deletions runtime/pangolin/src/pallets/staking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,17 +73,12 @@ impl darwinia_staking::OnSessionEnd<Runtime> for OnPangolinSessionEnd {
}

fn reward(who: &AccountId, amount: Balance) -> sp_runtime::DispatchResult {
if let Err(e) = <Balances as frame_support::traits::Currency<AccountId>>::transfer(
<Balances as frame_support::traits::Currency<AccountId>>::transfer(
&Treasury::account_id(),
who,
amount,
frame_support::traits::ExistenceRequirement::KeepAlive,
) {
// TODO: log
// log::error!("[runtime::staking] reward error: {:?}", e);
}

Ok(())
)
}
}

Expand Down
5 changes: 1 addition & 4 deletions runtime/pangoro/src/pallets/staking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,7 @@ impl darwinia_staking::OnSessionEnd<Runtime> for OnPangoroSessionEnd {
}

fn reward(who: &AccountId, amount: Balance) -> sp_runtime::DispatchResult {
if let Err(e) = Balances::deposit_into_existing(who, amount) {
// TODO: log
// log::error!("[runtime::staking] reward error: {:?}", e);
}
let _ = Balances::deposit_into_existing(who, amount)?;

Ok(())
}
Expand Down

0 comments on commit 49b007a

Please sign in to comment.