use crate::{
domain::{Asset, BlockSelector, NetworkId},
error::Error,
};
use super::{HttpConfig, RpcEndpoint, RpcLimits};
#[derive(Clone, Debug)]
pub struct EvmConfig {
network: NetworkId,
http: HttpConfig,
native_asset: Asset,
default_selector: BlockSelector,
}
impl EvmConfig {
pub fn new(
network: NetworkId,
endpoint: RpcEndpoint,
native_decimals: u8,
native_symbol: Option<String>,
default_selector: BlockSelector,
limits: RpcLimits,
provider_id: impl Into<String>,
) -> Result<Self, Error> {
let http = HttpConfig::new(endpoint, limits, provider_id)?;
let native_asset = Asset::native(network.clone(), native_decimals, native_symbol)?;
Ok(Self {
network,
http,
native_asset,
default_selector,
})
}
#[must_use]
pub const fn network(&self) -> &NetworkId {
&self.network
}
#[must_use]
pub const fn endpoint(&self) -> &RpcEndpoint {
self.http.endpoint()
}
#[must_use]
pub const fn native_asset(&self) -> &Asset {
&self.native_asset
}
#[must_use]
pub const fn default_selector(&self) -> BlockSelector {
self.default_selector
}
#[must_use]
pub const fn limits(&self) -> RpcLimits {
self.http.limits()
}
#[must_use]
pub fn provider_id(&self) -> &str {
self.http.provider_id()
}
pub(crate) const fn http_config(&self) -> &HttpConfig {
&self.http
}
}