revm_primitives/eip7702/
authorization_list.rs
1pub use alloy_eip7702::{
2 Authorization, RecoveredAuthority, RecoveredAuthorization, SignedAuthorization,
3};
4pub use alloy_primitives::Signature;
5
6use std::{boxed::Box, vec::Vec};
7
8#[derive(Clone, Debug, Eq, PartialEq)]
10#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
11pub enum AuthorizationList {
12 Signed(Vec<SignedAuthorization>),
13 Recovered(Vec<RecoveredAuthorization>),
14}
15
16impl From<Vec<SignedAuthorization>> for AuthorizationList {
17 fn from(signed: Vec<SignedAuthorization>) -> Self {
18 Self::Signed(signed)
19 }
20}
21
22impl From<Vec<RecoveredAuthorization>> for AuthorizationList {
23 fn from(recovered: Vec<RecoveredAuthorization>) -> Self {
24 Self::Recovered(recovered)
25 }
26}
27
28impl AuthorizationList {
29 pub fn len(&self) -> usize {
31 match self {
32 Self::Signed(signed) => signed.len(),
33 Self::Recovered(recovered) => recovered.len(),
34 }
35 }
36
37 pub fn empty() -> Self {
39 Self::Recovered(Vec::new())
40 }
41
42 pub fn is_empty(&self) -> bool {
44 self.len() == 0
45 }
46
47 pub fn recovered_iter<'a>(&'a self) -> Box<dyn Iterator<Item = RecoveredAuthorization> + 'a> {
49 match self {
50 Self::Signed(signed) => Box::new(signed.iter().map(|signed| signed.clone().into())),
51 Self::Recovered(recovered) => Box::new(recovered.clone().into_iter()),
52 }
53 }
54
55 pub fn into_recovered(self) -> Self {
57 let Self::Signed(signed) = self else {
58 return self;
59 };
60 Self::Recovered(signed.into_iter().map(|signed| signed.into()).collect())
61 }
62}