use codec::{Decode, DecodeWithMemTracking, Encode, MaxEncodedLen};
use frame_system::pallet_prelude::BlockNumberFor;
use scale_info::TypeInfo;
use sp_runtime::RuntimeDebug;
#[derive(
Encode,
Decode,
DecodeWithMemTracking,
Clone,
PartialEq,
Eq,
Default,
RuntimeDebug,
MaxEncodedLen,
TypeInfo,
)]
pub enum Status {
#[default]
Limited,
Unlimited,
}
#[derive(
Encode,
Decode,
DecodeWithMemTracking,
Clone,
PartialEq,
Eq,
Default,
RuntimeDebug,
MaxEncodedLen,
TypeInfo,
)]
pub struct Rate<BlockNumber> {
pub last_block: BlockNumber,
pub tx_since_last: u32,
pub size_since_last: u32,
pub status: Status,
}
#[derive(
Encode,
Decode,
DecodeWithMemTracking,
Clone,
PartialEq,
Eq,
Default,
RuntimeDebug,
MaxEncodedLen,
TypeInfo,
)]
pub struct AccountData<Balance, BlockNumber> {
pub balance: pallet_balances::AccountData<Balance>,
pub rate: Rate<BlockNumber>,
}
pub trait RateLimiter<T: frame_system::Config> {
fn is_allowed(&self, b: BlockNumberFor<T>, size: u32) -> bool;
fn update_rate(&mut self, b: BlockNumberFor<T>, size: u32);
}