common_primitives/
capacity.rs1use crate::msa::MessageSourceId;
2use frame_support::traits::tokens::Balance;
3use scale_info::TypeInfo;
4use sp_core::{Decode, Encode, MaxEncodedLen, RuntimeDebug};
5use sp_runtime::DispatchError;
6
7pub type RewardEra = u32;
9
10pub trait TargetValidator {
12 fn validate(target: MessageSourceId) -> bool;
14}
15
16impl TargetValidator for () {
18 fn validate(_target: MessageSourceId) -> bool {
19 false
20 }
21}
22
23pub trait Nontransferable {
25 type Balance: Balance;
27
28 fn balance(msa_id: MessageSourceId) -> Self::Balance;
30
31 fn replenishable_balance(msa_id: MessageSourceId) -> Self::Balance;
33
34 fn deduct(msa_id: MessageSourceId, capacity_amount: Self::Balance)
36 -> Result<(), DispatchError>;
37
38 fn deposit(
40 msa_id: MessageSourceId,
41 token_amount: Self::Balance,
42 capacity_amount: Self::Balance,
43 ) -> Result<(), DispatchError>;
44}
45
46pub trait Replenishable {
48 type Balance: Balance;
50
51 fn replenish_by_amount(
53 msa_id: MessageSourceId,
54 amount: Self::Balance,
55 ) -> Result<(), DispatchError>;
56
57 fn replenish_all_for(msa_id: MessageSourceId) -> Result<(), DispatchError>;
59
60 fn can_replenish(msa_id: MessageSourceId) -> bool;
62}
63
64#[derive(
66 Copy, Clone, Default, Encode, Eq, Decode, RuntimeDebug, MaxEncodedLen, PartialEq, TypeInfo,
67)]
68
69pub struct UnclaimedRewardInfo<Balance, BlockNumber> {
70 pub reward_era: RewardEra,
72 pub expires_at_block: BlockNumber,
74 pub staked_amount: Balance,
76 pub eligible_amount: Balance,
79 pub earned_amount: Balance,
81}