Skip to content

Commit

Permalink
fix(rpc-types): access list keys (#42)
Browse files Browse the repository at this point in the history
* workaround

* fix: actual fix

* fix: actual fix part 2

* fix access list keys

---------

Co-authored-by: Enrique Ortiz <hi@enriqueortiz.dev>
  • Loading branch information
onbjerg and Evalir committed Nov 25, 2023
1 parent fa0aac7 commit f7d77a8
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 10 deletions.
2 changes: 1 addition & 1 deletion crates/providers/src/provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -854,7 +854,7 @@ mod providers_test {
let fee_history = provider
.get_fee_history(
U256::from(utils::EIP1559_FEE_ESTIMATION_PAST_BLOCKS),
BlockNumberOrTag::Number(block_number.to()),
BlockNumberOrTag::Number(block_number),
&[utils::EIP1559_FEE_ESTIMATION_REWARD_PERCENTILE],
)
.await
Expand Down
34 changes: 25 additions & 9 deletions crates/rpc-types/src/eth/transaction/access_list.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use alloy_primitives::{Address, U256};
use alloy_primitives::{Address, U256, B256};
use serde::{Deserialize, Serialize};

/// A list of addresses and storage keys that the transaction plans to access.
Expand All @@ -9,7 +9,7 @@ pub struct AccessListItem {
/// Account addresses that would be loaded at the start of execution
pub address: Address,
/// Keys of storage that would be loaded at the start of execution
pub storage_keys: Vec<U256>,
pub storage_keys: Vec<B256>,
}

/// AccessList as defined in EIP-2930
Expand All @@ -29,12 +29,28 @@ impl AccessList {

/// Consumes the type and returns an iterator over the list's addresses and storage keys.
pub fn into_flatten(self) -> impl Iterator<Item = (Address, Vec<U256>)> {
self.0.into_iter().map(|item| (item.address, item.storage_keys))
self.0.into_iter().map(|item| {
(
item.address,
item.storage_keys
.into_iter()
.map(|slot| U256::from_be_bytes(slot.0))
.collect(),
)
})
}

/// Returns an iterator over the list's addresses and storage keys.
pub fn flatten(&self) -> impl Iterator<Item = (Address, &[U256])> + '_ {
self.0.iter().map(|item| (item.address, item.storage_keys.as_slice()))
pub fn flatten(&self) -> impl Iterator<Item = (Address, Vec<U256>)> + '_ {
self.0.iter().map(|item| {
(
item.address,
item.storage_keys
.iter()
.map(|slot| U256::from_be_bytes(slot.0))
.collect(),
)
})
}
}

Expand All @@ -55,8 +71,8 @@ mod tests {
#[test]
fn access_list_serde() {
let list = AccessList(vec![
AccessListItem { address: Address::ZERO, storage_keys: vec![U256::ZERO] },
AccessListItem { address: Address::ZERO, storage_keys: vec![U256::ZERO] },
AccessListItem { address: Address::ZERO, storage_keys: vec![B256::ZERO] },
AccessListItem { address: Address::ZERO, storage_keys: vec![B256::ZERO] },
]);
let json = serde_json::to_string(&list).unwrap();
let list2 = serde_json::from_str::<AccessList>(&json).unwrap();
Expand All @@ -67,8 +83,8 @@ mod tests {
fn access_list_with_gas_used() {
let list = AccessListWithGasUsed {
access_list: AccessList(vec![
AccessListItem { address: Address::ZERO, storage_keys: vec![U256::ZERO] },
AccessListItem { address: Address::ZERO, storage_keys: vec![U256::ZERO] },
AccessListItem { address: Address::ZERO, storage_keys: vec![B256::ZERO] },
AccessListItem { address: Address::ZERO, storage_keys: vec![B256::ZERO] },
]),
gas_used: U256::from(100),
};
Expand Down

0 comments on commit f7d77a8

Please sign in to comment.