Skip to content

Commit

Permalink
Imp From rpc-types to primitives Log
Browse files Browse the repository at this point in the history
  • Loading branch information
leruaa committed Nov 29, 2023
1 parent 73cf4b8 commit e1d2064
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
16 changes: 16 additions & 0 deletions crates/rpc-types/src/eth/log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,22 @@ pub struct Log {
pub removed: bool,
}

impl TryFrom<Log> for alloy_primitives::Log {
type Error = LogError;

fn try_from(value: Log) -> Result<Self, Self::Error> {
alloy_primitives::Log::new(value.topics, value.data).ok_or(LogError::InvalidTopics)
}
}

/// Error that can occur when converting other types to logs
#[derive(Debug, thiserror::Error)]
pub enum LogError {
/// The topics are invalid
#[error("invalid topics")]
InvalidTopics,
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down
2 changes: 1 addition & 1 deletion crates/rpc-types/src/eth/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub use block::*;
pub use call::{Bundle, CallInput, CallInputError, CallRequest, EthCallResponse, StateContext};
pub use fee::{FeeHistory, TxGasAndReward};
pub use filter::*;
pub use log::Log;
pub use log::*;
pub use raw_log::{logs_bloom, Log as RawLog};
pub use syncing::*;
pub use transaction::*;
Expand Down

0 comments on commit e1d2064

Please sign in to comment.