use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct EthContract {
#[serde(rename = "type", default = "default_contract_type")]
pub item_type: String,
pub address: String,
pub bytecode: String,
pub function_sighashes: Vec<String>,
pub is_erc20: bool,
pub is_erc721: bool,
pub block_number: u64,
#[serde(skip_serializing_if = "Option::is_none")]
pub block_hash: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub block_timestamp: Option<u64>,
}
fn default_contract_type() -> String {
"contract".to_string()
}
impl EthContract {
pub fn csv_headers() -> &'static [&'static str] {
&[
"address",
"bytecode",
"function_sighashes",
"is_erc20",
"is_erc721",
"block_number",
]
}
pub fn to_csv_row(&self) -> Vec<String> {
vec![
self.address.clone(),
self.bytecode.clone(),
self.function_sighashes.join(","),
self.is_erc20.to_string(),
self.is_erc721.to_string(),
self.block_number.to_string(),
]
}
}
pub const ERC20_SELECTORS: &[&str] = &[
"0x06fdde03", "0x95d89b41", "0x313ce567", "0x18160ddd", "0x70a08231", "0xa9059cbb", "0x23b872dd", "0x095ea7b3", "0xdd62ed3e", ];
pub const ERC721_SELECTORS: &[&str] = &[
"0x06fdde03", "0x95d89b41", "0x70a08231", "0x6352211e", "0x42842e0e", "0xb88d4fde", "0x23b872dd", "0x095ea7b3", "0xa22cb465", "0x081812fc", "0xe985e9c5", ];