-
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: implement AccessTuple conversion methods in firehose-protos
- Loading branch information
1 parent
34fe435
commit 59e6704
Showing
7 changed files
with
45 additions
and
26 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
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,33 @@ | ||
use crate::error::ProtosError; | ||
|
||
use super::AccessTuple; | ||
|
||
use alloy_eip2930::AccessListItem; | ||
use alloy_primitives::{hex, Address, B256}; | ||
|
||
impl TryFrom<&AccessTuple> for AccessListItem { | ||
type Error = ProtosError; | ||
|
||
fn try_from(tuple: &AccessTuple) -> Result<Self, Self::Error> { | ||
let address = Address::from_slice(tuple.address.as_slice()); | ||
|
||
let storage_keys = tuple | ||
.storage_keys | ||
.iter() | ||
.map(convert_to_b256) | ||
.collect::<Result<Vec<B256>, ProtosError>>()?; | ||
|
||
Ok(AccessListItem { | ||
address, | ||
storage_keys, | ||
}) | ||
} | ||
} | ||
|
||
fn convert_to_b256(key: &Vec<u8>) -> Result<B256, ProtosError> { | ||
let key_bytes: [u8; 32] = key | ||
.as_slice() | ||
.try_into() | ||
.map_err(|_| ProtosError::InvalidAccessTupleStorageKey(hex::encode(key.clone())))?; | ||
Ok(B256::from(key_bytes)) | ||
} |
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 |
---|---|---|
@@ -1,37 +1,14 @@ | ||
use crate::transactions::error::TransactionError; | ||
use alloy_eip2930::{AccessList, AccessListItem}; | ||
use alloy_primitives::{Address, B256}; | ||
use firehose_protos::ethereum_v2::AccessTuple; | ||
use revm_primitives::hex; | ||
|
||
pub(crate) fn compute_access_list( | ||
access_list: &[AccessTuple], | ||
) -> Result<AccessList, TransactionError> { | ||
let access_list_items: Vec<AccessListItem> = access_list | ||
let access_list_items = access_list | ||
.iter() | ||
.map(atuple_to_alist_item) | ||
.collect::<Result<Vec<AccessListItem>, TransactionError>>( | ||
)?; | ||
.map(AccessListItem::try_from) | ||
.collect::<Result<Vec<AccessListItem>, _>>()?; | ||
|
||
Ok(AccessList(access_list_items)) | ||
} | ||
|
||
fn atuple_to_alist_item(tuple: &AccessTuple) -> Result<AccessListItem, TransactionError> { | ||
let address: Address = Address::from_slice(tuple.address.as_slice()); | ||
let storage_keys = tuple | ||
.storage_keys | ||
.iter() | ||
.map(|key| { | ||
let key_bytes: [u8; 32] = key | ||
.as_slice() | ||
.try_into() | ||
.map_err(|_| TransactionError::InvalidStorageKey(hex::encode(key.clone())))?; | ||
Ok(B256::from(key_bytes)) | ||
}) | ||
.collect::<Result<Vec<B256>, TransactionError>>()?; | ||
|
||
Ok(AccessListItem { | ||
address, | ||
storage_keys, | ||
}) | ||
} |
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