reth_optimism_txpool/supervisor/access_list.rs
1// Source: https://github.com/op-rs/kona
2// Copyright © 2023 kona contributors Copyright © 2024 Optimism
3//
4// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
5// associated documentation files (the “Software”), to deal in the Software without restriction,
6// including without limitation the rights to use, copy, modify, merge, publish, distribute,
7// sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
8// furnished to do so, subject to the following conditions:
9//
10// The above copyright notice and this permission notice shall be included in all copies or
11// substantial portions of the Software.
12//
13// THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
14// NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
15// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
16// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
17// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
18use crate::supervisor::CROSS_L2_INBOX_ADDRESS;
19use alloy_eips::eip2930::AccessListItem;
20use alloy_primitives::B256;
21
22/// Parses [`AccessListItem`]s to inbox entries.
23///
24/// Return flattened iterator with all inbox entries.
25pub fn parse_access_list_items_to_inbox_entries<'a>(
26 access_list_items: impl Iterator<Item = &'a AccessListItem>,
27) -> impl Iterator<Item = &'a B256> {
28 access_list_items.filter_map(parse_access_list_item_to_inbox_entries).flatten()
29}
30
31/// Parse [`AccessListItem`] to inbox entries, if any.
32/// Max 3 inbox entries can exist per [`AccessListItem`] that points to [`CROSS_L2_INBOX_ADDRESS`].
33///
34/// Returns `Vec::new()` if [`AccessListItem`] address doesn't point to [`CROSS_L2_INBOX_ADDRESS`].
35// TODO: add url to spec once [pr](https://github.com/ethereum-optimism/specs/pull/612) is merged
36fn parse_access_list_item_to_inbox_entries(
37 access_list_item: &AccessListItem,
38) -> Option<impl Iterator<Item = &B256>> {
39 (access_list_item.address == CROSS_L2_INBOX_ADDRESS)
40 .then(|| access_list_item.storage_keys.iter())
41}