2023-07-10 05:23:32 +03:00
|
|
|
use crate::balance::Balance;
|
|
|
|
use crate::frontend::authorization::{AuthorizationChecks, RpcSecretKey};
|
2023-07-08 01:15:41 +03:00
|
|
|
use moka::future::Cache;
|
|
|
|
use std::fmt;
|
|
|
|
use std::net::IpAddr;
|
|
|
|
use std::sync::Arc;
|
2023-07-10 05:23:32 +03:00
|
|
|
use tokio::sync::RwLock as AsyncRwLock;
|
2023-07-08 01:15:41 +03:00
|
|
|
|
|
|
|
/// Cache data from the database about rpc keys
|
|
|
|
pub type RpcSecretKeyCache = Cache<RpcSecretKey, AuthorizationChecks>;
|
|
|
|
/// Cache data from the database about user balances
|
2023-07-10 05:23:32 +03:00
|
|
|
pub type UserBalanceCache = Cache<u64, Arc<AsyncRwLock<Balance>>>;
|
2023-07-08 01:15:41 +03:00
|
|
|
|
|
|
|
#[derive(Clone, Copy, Hash, Eq, PartialEq)]
|
|
|
|
pub struct RegisteredUserRateLimitKey(pub u64, pub IpAddr);
|
|
|
|
|
|
|
|
impl std::fmt::Display for RegisteredUserRateLimitKey {
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
|
|
write!(f, "{}-{}", self.0, self.1)
|
|
|
|
}
|
|
|
|
}
|