revm_context_interface/transaction/access_list.rs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
use auto_impl::auto_impl;
use primitives::{Address, B256};
/// Access list type is introduced in EIP-2930, and every
/// transaction after it contains access list.
///
/// Note
///
/// Iterator over access list returns account address and storage slot keys that
/// are warm loaded before transaction execution.
///
/// Number of account and storage slots is used to calculate initial tx gas cost.
#[auto_impl(&, Box, Arc, Rc)]
pub trait AccessListTrait: Clone {
/// Iterate over access list.
fn iter(&self) -> impl Iterator<Item = (Address, impl Iterator<Item = B256>)>;
/// Returns number of account and storage slots.
fn num_account_storages(&self) -> (usize, usize) {
let storage_num = self.iter().map(|i| i.1.count()).sum();
let account_num = self.iter().count();
(account_num, storage_num)
}
}
// TODO move to default context
use specification::eip2930::AccessList;
impl AccessListTrait for AccessList {
fn iter(&self) -> impl Iterator<Item = (Address, impl Iterator<Item = B256>)> {
self.0.iter().map(|item| {
let slots = item.storage_keys.iter().copied();
(item.address, slots)
})
}
}