use types::{BlockNumber, Bytes, U256, H160, H256};
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct Log {
pub address: H160,
pub topics: Vec<H256>,
pub data: Bytes,
#[serde(rename="blockHash")]
pub block_hash: Option<H256>,
#[serde(rename="blockNumber")]
pub block_number: Option<U256>,
#[serde(rename="transactionHash")]
pub transaction_hash: Option<H256>,
#[serde(rename="transactionIndex")]
pub transaction_index: Option<U256>,
#[serde(rename="logIndex")]
pub log_index: Option<U256>,
#[serde(rename="transactionLogIndex")]
pub transaction_log_index: Option<U256>,
#[serde(rename="type")]
pub log_type: String,
}
#[derive(Default, Debug, PartialEq, Clone, Serialize)]
pub struct Filter {
#[serde(rename="fromBlock")]
from_block: Option<BlockNumber>,
#[serde(rename="toBlock")]
to_block: Option<BlockNumber>,
address: Option<Vec<H160>>,
topics: Option<Vec<Option<Vec<H256>>>>,
limit: Option<usize>,
}
#[derive(Default, Clone)]
pub struct FilterBuilder {
filter: Filter,
}
impl FilterBuilder {
pub fn from_block(mut self, block: BlockNumber) -> Self {
self.filter.from_block = Some(block);
self
}
pub fn to_block(mut self, block: BlockNumber) -> Self {
self.filter.to_block = Some(block);
self
}
pub fn address(mut self, address: Vec<H160>) -> Self {
self.filter.address = Some(address);
self
}
pub fn topics(
mut self,
topic1: Option<Vec<H256>>,
topic2: Option<Vec<H256>>,
topic3: Option<Vec<H256>>,
topic4: Option<Vec<H256>>,
) -> Self {
self.filter.topics = Some(vec![topic1, topic2, topic3, topic4]);
self
}
pub fn limit(mut self, limit: usize) -> Self {
self.filter.limit = Some(limit);
self
}
pub fn build(&self) -> Filter {
self.filter.clone()
}
}