use crate::types::*;
use regex::Regex;
use web3::{
Web3,
transports::http::Http,
};
pub(crate) static BSC_RPC_ENDPOINT: &str = "https://bsc-dataseed.binance.org/";
pub(crate) static ETHEREUM_RPC_ENDPOINT: &str = "https://rpc.ankr.com/eth";
pub(crate) static POLYGON_RPC_ENDPOINT: &str = "https://polygon-rpc.com/";
pub fn create_web3(chain: ChainType) -> Web3<Http> {
let rpc_endpoint = match chain {
ChainType::BSC => BSC_RPC_ENDPOINT,
ChainType::Ethereum => ETHEREUM_RPC_ENDPOINT,
ChainType::Polygon => POLYGON_RPC_ENDPOINT,
};
let http = Http::new(rpc_endpoint).unwrap();
Web3::new(http)
}
pub fn is_address_simplified(address: &str) -> bool {
let lowercase_address = address.to_lowercase();
let regex: Regex = Regex::new(r#"^(0x)?[0-9a-f]{40}$"#).unwrap();
regex.is_match(&lowercase_address)
}