-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: Refactor indexer and add errors
- Loading branch information
1 parent
6128230
commit ab5f9c5
Showing
9 changed files
with
94 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
use core::fmt; | ||
|
||
#[derive(Debug)] | ||
pub enum AddHandlerError { | ||
NotFound(String), | ||
NetworkNotFound(String), | ||
} | ||
|
||
impl fmt::Display for AddHandlerError { | ||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
match self { | ||
AddHandlerError::NotFound(handler) => { | ||
write!(f, "Handler not found: {}", handler) | ||
} | ||
AddHandlerError::NetworkNotFound(network) => { | ||
write!(f, "Network not found: {}", network) | ||
} | ||
} | ||
} | ||
} | ||
|
||
impl std::error::Error for AddHandlerError {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
pub mod error; | ||
pub mod indexer; | ||
pub mod templates; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
use alloy::primitives::Address; | ||
use tokio::sync::mpsc::error::SendError; | ||
use tokio::sync::mpsc::Sender; | ||
|
||
use crate::event_handler::EventHandlerInstance; | ||
|
||
pub struct Template { | ||
pub start_block: u64, | ||
pub address: Address, | ||
pub handler: EventHandlerInstance, | ||
} | ||
|
||
#[derive(Clone)] | ||
pub struct TemplateManager { | ||
tx: Sender<Template>, | ||
} | ||
|
||
impl TemplateManager { | ||
pub fn new(tx: Sender<Template>) -> TemplateManager { | ||
TemplateManager { tx } | ||
} | ||
|
||
pub async fn start(&self, template: Template) -> Result<(), SendError<Template>> { | ||
self.tx.send(template).await | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters