use crate::api::{http::HttpClient, types::ApiResult};
use rrelayer_core::gas::GasEstimatorResult;
use rrelayer_core::network::{ChainId, Network};
use std::sync::Arc;
#[derive(Clone)]
pub struct NetworkApi {
client: Arc<HttpClient>,
}
impl NetworkApi {
pub fn new(client: Arc<HttpClient>) -> Self {
Self { client }
}
pub async fn get(&self, chain_id: &ChainId) -> ApiResult<Option<Network>> {
let endpoint = format!("networks/{}", chain_id);
self.client.get(&endpoint).await
}
pub async fn get_all(&self) -> ApiResult<Vec<Network>> {
self.client.get("networks").await
}
pub async fn get_gas_prices(&self, chain_id: u64) -> ApiResult<Option<GasEstimatorResult>> {
let endpoint = format!("networks/gas/price/{}", chain_id);
self.client.get(&endpoint).await
}
}