#![warn(clippy::all, clippy::pedantic, clippy::style)]
#[cfg(feature = "download")]
extern crate reqwest;
#[cfg(feature = "download")]
mod download;
mod parsing;
mod selector;
pub use selector::Selector;
use anyhow::Result;
use ethers::abi::Function;
use parsing::parse_line;
use std::{collections::HashMap, fs, path::Path};
#[derive(Debug, Clone)]
pub struct EvmSelectors {
items: HashMap<Selector, Vec<Function>>,
}
impl EvmSelectors {
pub fn new_from_file(path: &Path) -> Result<Self> {
let raw = fs::read_to_string(path)?;
Self::new_from_raw(&raw)
}
pub fn new_from_raw(raw: &str) -> Result<Self> {
Ok(Self {
items: raw
.lines()
.map(parse_line) .collect::<Result<Vec<_>>>()? .into_iter()
.flatten() .fold(HashMap::new(), |mut map, (selector, function)| {
map.entry(selector).or_default().push(function);
map
}),
})
}
#[must_use]
pub fn items(&self) -> &HashMap<Selector, Vec<Function>> {
&self.items
}
#[must_use]
pub fn get(&self, selector: &Selector) -> Option<&Vec<Function>> {
self.items.get(selector)
}
pub fn push(&mut self, selector: Selector, function: Function) {
self.items.entry(selector).or_default().push(function);
}
}