-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(decoder): move receipt log conversions to firehose-protos
- Loading branch information
1 parent
5cf5124
commit 6bdcb09
Showing
8 changed files
with
138 additions
and
118 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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,46 @@ | ||
use alloy_primitives::{hex, Address, Bytes, B256}; | ||
use reth_primitives::LogData; | ||
|
||
use crate::error::ProtosError; | ||
|
||
use super::Log; | ||
|
||
impl TryFrom<&Log> for alloy_primitives::Log { | ||
type Error = ProtosError; | ||
|
||
fn try_from(log: &Log) -> Result<Self, Self::Error> { | ||
let address = Address::try_from(log)?; | ||
let topics = log.to_topics()?; | ||
let log_data = Bytes::copy_from_slice(log.data.as_slice()); | ||
let data = LogData::new_unchecked(topics, log_data); | ||
|
||
Ok(alloy_primitives::Log { address, data }) | ||
} | ||
} | ||
|
||
impl TryFrom<&Log> for Address { | ||
type Error = ProtosError; | ||
|
||
fn try_from(log: &Log) -> Result<Self, Self::Error> { | ||
let slice: [u8; 20] = log | ||
.address | ||
.as_slice() | ||
.try_into() | ||
.map_err(|_| Self::Error::InvalidLogAddress(hex::encode(log.address.clone())))?; | ||
Ok(Address::from(slice)) | ||
} | ||
} | ||
|
||
impl Log { | ||
fn to_topics(&self) -> Result<Vec<B256>, ProtosError> { | ||
fn to_b256(slice: &[u8]) -> Result<B256, ProtosError> { | ||
B256::try_from(slice).map_err(|_| ProtosError::InvalidLogTopic(hex::encode(slice))) | ||
} | ||
|
||
self.topics | ||
.iter() | ||
.map(Vec::as_slice) | ||
.map(to_b256) | ||
.collect::<Result<Vec<_>, _>>() | ||
} | ||
} |
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 |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
//! | ||
|
||
pub mod eth_block; | ||
pub mod log; | ||
pub mod transaction; | ||
|
||
tonic::include_proto!("sf.ethereum.r#type.v2"); |
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 was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,5 +1,4 @@ | ||
pub mod error; | ||
pub mod logs; | ||
pub mod receipt; | ||
|
||
use crate::receipts::error::ReceiptError; | ||
|
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