openzeppelin_monitor/utils/client_storage.rs
1use std::{collections::HashMap, sync::Arc};
2use tokio::sync::RwLock;
3
4/// Generic client storage that can hold any type of client (blockchain, transport, etc.)
5///
6/// Clients are stored in a thread-safe way using a HashMap and an RwLock.
7/// The HashMap is indexed by the network slug and the value is an Arc of the client.
8#[derive(Default)]
9pub struct ClientStorage<T> {
10 pub clients: Arc<RwLock<HashMap<String, Arc<T>>>>,
11}
12
13impl<T> ClientStorage<T> {
14 pub fn new() -> Self {
15 Self {
16 clients: Arc::new(RwLock::new(HashMap::new())),
17 }
18 }
19}