pallet_parachain_staking/
traits.rs

1// Copyright 2019-2025 PureStake Inc.
2// This file is part of Moonbeam.
3
4// Moonbeam is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8
9// Moonbeam is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12// GNU General Public License for more details.
13
14// You should have received a copy of the GNU General Public License
15// along with Moonbeam.  If not, see <http://www.gnu.org/licenses/>.
16
17//! traits for parachain-staking
18
19use crate::weights::WeightInfo;
20use frame_support::{dispatch::PostDispatchInfo, pallet_prelude::Weight};
21use sp_runtime::DispatchErrorWithPostInfo;
22
23pub trait OnCollatorPayout<AccountId, Balance> {
24	fn on_collator_payout(
25		for_round: crate::RoundIndex,
26		collator_id: AccountId,
27		amount: Balance,
28	) -> Weight;
29}
30impl<AccountId, Balance> OnCollatorPayout<AccountId, Balance> for () {
31	fn on_collator_payout(
32		_for_round: crate::RoundIndex,
33		_collator_id: AccountId,
34		_amount: Balance,
35	) -> Weight {
36		Weight::zero()
37	}
38}
39
40pub trait OnNewRound {
41	fn on_new_round(round_index: crate::RoundIndex) -> Weight;
42}
43impl OnNewRound for () {
44	fn on_new_round(_round_index: crate::RoundIndex) -> Weight {
45		Weight::zero()
46	}
47}
48
49/// Defines the behavior to payout the collator's reward.
50pub trait PayoutCollatorReward<Runtime: crate::Config> {
51	fn payout_collator_reward(
52		round_index: crate::RoundIndex,
53		collator_id: Runtime::AccountId,
54		amount: crate::BalanceOf<Runtime>,
55	) -> Weight;
56}
57
58/// Defines the default behavior for paying out the collator's reward. The amount is directly
59/// deposited into the collator's account.
60impl<Runtime: crate::Config> PayoutCollatorReward<Runtime> for () {
61	fn payout_collator_reward(
62		for_round: crate::RoundIndex,
63		collator_id: Runtime::AccountId,
64		amount: crate::BalanceOf<Runtime>,
65	) -> Weight {
66		crate::Pallet::<Runtime>::mint_collator_reward(for_round, collator_id, amount)
67	}
68}
69
70pub trait OnInactiveCollator<Runtime: crate::Config> {
71	fn on_inactive_collator(
72		collator_id: Runtime::AccountId,
73		round: crate::RoundIndex,
74	) -> Result<Weight, DispatchErrorWithPostInfo<PostDispatchInfo>>;
75}
76
77impl<Runtime: crate::Config> OnInactiveCollator<Runtime> for () {
78	fn on_inactive_collator(
79		collator_id: <Runtime>::AccountId,
80		_round: crate::RoundIndex,
81	) -> Result<Weight, DispatchErrorWithPostInfo<PostDispatchInfo>> {
82		crate::Pallet::<Runtime>::go_offline_inner(collator_id)?;
83		Ok(<Runtime as crate::Config>::WeightInfo::go_offline(
84			crate::MAX_CANDIDATES,
85		))
86	}
87}