diff --git a/ghost-crab/src/indexer/error.rs b/ghost-crab/src/indexer/error.rs index 040686d..4e22217 100644 --- a/ghost-crab/src/indexer/error.rs +++ b/ghost-crab/src/indexer/error.rs @@ -1,9 +1,11 @@ +use alloy::hex::FromHexError; use core::fmt; #[derive(Debug)] pub enum AddHandlerError { NotFound(String), NetworkNotFound(String), + InvalidAddress { address: String, error: FromHexError }, } impl fmt::Display for AddHandlerError { @@ -15,6 +17,9 @@ impl fmt::Display for AddHandlerError { AddHandlerError::NetworkNotFound(network) => { write!(f, "Network not found: {}", network) } + AddHandlerError::InvalidAddress { address, error } => { + write!(f, "Invalid address: {}.\nError: {}", address, error) + } } } } diff --git a/ghost-crab/src/indexer/indexer.rs b/ghost-crab/src/indexer/indexer.rs index 01f7d4e..137501f 100644 --- a/ghost-crab/src/indexer/indexer.rs +++ b/ghost-crab/src/indexer/indexer.rs @@ -2,6 +2,7 @@ use crate::block_handler::{process_blocks, BlockHandlerInstance, ProcessBlocksIn use crate::cache::manager::{CacheProvider, RPCManager}; use crate::event_handler::{process_events, EventHandlerInstance, ProcessEventsInput}; +use alloy::primitives::Address; use ghost_crab_common::config::{self, Config, ConfigError}; use tokio::sync::mpsc::{self, Receiver}; @@ -45,9 +46,13 @@ impl Indexer { let provider = self.get_provider(&event_config.network).await?; + let address = str::parse::
(&event_config.address).map_err(|error| { + AddHandlerError::InvalidAddress { address: event_config.address, error } + })?; + self.handlers.push(ProcessEventsInput { start_block: event_config.start_block, - address: event_config.address.parse().unwrap(), + address, step: 10_000, handler, templates: self.templates.clone(),