Skip to content

Commit

Permalink
remove FirehoseNetworks
Browse files Browse the repository at this point in the history
  • Loading branch information
mangas committed May 13, 2024
1 parent b353601 commit f15c7dd
Showing 1 changed file with 2 additions and 47 deletions.
49 changes: 2 additions & 47 deletions graph/src/firehose/endpoints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,8 @@ use itertools::Itertools;
use prost::Message;
use slog::Logger;
use std::{
collections::{BTreeMap, HashMap},
fmt::Display,
marker::PhantomData,
ops::ControlFlow,
str::FromStr,
sync::Arc,
time::Duration,
collections::HashMap, fmt::Display, marker::PhantomData, ops::ControlFlow, str::FromStr,
sync::Arc, time::Duration,
};
use tonic::codegen::InterceptedService;
use tonic::{
Expand Down Expand Up @@ -692,46 +687,6 @@ impl FirehoseEndpoints {
}
}

#[derive(Clone, Debug)]
pub struct FirehoseNetworks {
/// networks contains a map from chain id (`near-mainnet`, `near-testnet`, `solana-mainnet`, etc.)
/// to a list of FirehoseEndpoint (type wrapper around `Arc<Vec<FirehoseEndpoint>>`).
pub networks: BTreeMap<String, Vec<Arc<FirehoseEndpoint>>>,
}

impl FirehoseNetworks {
pub fn new() -> FirehoseNetworks {
FirehoseNetworks {
networks: BTreeMap::new(),
}
}

pub fn insert(&mut self, chain_id: String, endpoint: Arc<FirehoseEndpoint>) {
let endpoints = self.networks.entry(chain_id).or_insert_with(|| Vec::new());

endpoints.push(endpoint);
}

/// Returns a `HashMap` where the key is the chain's id and the key is an endpoint for this chain.
/// There can be multiple keys with the same chain id but with different
/// endpoint where multiple providers exist for a single chain id. Providers with the same
/// label do not need to be tested individually, if one is working, every other endpoint in the
/// pool should also work.
pub fn flatten(&self) -> HashMap<(String, Word), Arc<FirehoseEndpoint>> {
self.networks
.iter()
.flat_map(|(chain_id, firehose_endpoints)| {
firehose_endpoints.iter().map(move |endpoint| {
(
(chain_id.clone(), endpoint.provider.clone()),
endpoint.clone(),
)
})
})
.collect()
}
}

#[cfg(test)]
mod test {
use std::{mem, sync::Arc};
Expand Down

0 comments on commit f15c7dd

Please sign in to comment.