Skip to content

Commit

Permalink
feat(indexer): add InvalidAddress error handling to load_event_handler
Browse files Browse the repository at this point in the history
  • Loading branch information
luis-herasme committed Jul 26, 2024
1 parent 1f6b9bd commit 0185944
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
5 changes: 5 additions & 0 deletions ghost-crab/src/indexer/error.rs
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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)
}
}
}
}
Expand Down
7 changes: 6 additions & 1 deletion ghost-crab/src/indexer/indexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down Expand Up @@ -45,9 +46,13 @@ impl Indexer {

let provider = self.get_provider(&event_config.network).await?;

let address = str::parse::<Address>(&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(),
Expand Down

0 comments on commit 0185944

Please sign in to comment.