Repository: unionlabs/union
File: hubble/src/eth/indexer.rs (Rust)

Code before:
        use ethers::{
            core::{abi::ethabi::ethereum_types::BloomInput, types::Filter},
            types::Log,
        };

        let block = provider
            .get_block(id)
            .await?
            .ok_or(FromProviderError::BlockNotFound)?;

        // We check for a potential log match, which potentially avoids querying
        // eth_getLogs.
        if let (Some(bloom), Some(filter)) = (block.logs_bloom, &filter) {
            if !filter
                .iter()
                .any(|address| bloom.contains_input(BloomInput::Raw(address.as_bytes())))
            {
                return Ok(None);
            }
        }

        // We know now there is a potential match, we still apply a Filter to only
        // get the logs we want.
        let log_filer = Filter::new().select(block.hash.unwrap());

        let log_filer = if let Some(filter) = filter {
            let addresses: Vec<_> = filter.iter().cloned().collect();
            log_filer.address(addresses)
        } else {
            log_filer
        };

        let logs = provider
            .get_logs(&log_filer)
            .await
            .map_err(FromProviderError::DataNotFound)?;

        // The bloom filter returned a false positive, and we don't actually have matching logs.
        if logs.is_empty() {
            return Ok(None);
        }

        let partitioned = {
            let mut map: HashMap<(_, _), Vec<Log>> = HashMap::with_capacity(logs.len());
            for log in logs {
                if log.removed.unwrap_or_default() {
                    continue;
                }

                map.entry((
                    log.transaction_hash.unwrap(),

Review comment (suggestion):
```suggestion
        let log_filter = if let Some(filter) = filter {
```

Code after:
        use ethers::{
            core::{abi::ethabi::ethereum_types::BloomInput, types::Filter},
            types::Log,
        };

        let block = provider
            .get_block(id)
            .await?
            .ok_or(FromProviderError::BlockNotFound)?;

        // We check for a potential log match, which potentially avoids querying
        // eth_getLogs.
        if let (Some(bloom), Some(filter)) = (block.logs_bloom, &filter) {
            if !filter
                .iter()
                .any(|address| bloom.contains_input(BloomInput::Raw(address.as_bytes())))
            {
                return Ok(None);
            }
        }

        // We know now there is a potential match, we still apply a Filter to only
        // get the logs we want.
        let log_filter = Filter::new().select(block.hash.unwrap());

        let log_filter = if let Some(filter) = filter {
            let addresses: Vec<_> = filter.iter().cloned().collect();
            log_filter.address(addresses)
        } else {
            log_filter
        };

        let logs = provider
            .get_logs(&log_filter)
            .await
            .map_err(FromProviderError::DataNotFound)?;

        // The bloom filter returned a false positive, and we don't actually have matching logs.
        if logs.is_empty() {
            return Ok(None);
        }

        let partitioned = {
            let mut map: HashMap<(_, _), Vec<Log>> = HashMap::with_capacity(logs.len());
            for log in logs {
                if log.removed.unwrap_or_default() {
                    continue;
                }

                map.entry((
                    log.transaction_hash.unwrap(),