revm_primitives/eip7702/
authorization_list.rspub use alloy_eip7702::{
Authorization, RecoveredAuthority, RecoveredAuthorization, SignedAuthorization,
};
pub use alloy_primitives::Signature;
use std::{boxed::Box, vec::Vec};
#[derive(Clone, Debug, Eq, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum AuthorizationList {
Signed(Vec<SignedAuthorization>),
Recovered(Vec<RecoveredAuthorization>),
}
impl From<Vec<SignedAuthorization>> for AuthorizationList {
fn from(signed: Vec<SignedAuthorization>) -> Self {
Self::Signed(signed)
}
}
impl From<Vec<RecoveredAuthorization>> for AuthorizationList {
fn from(recovered: Vec<RecoveredAuthorization>) -> Self {
Self::Recovered(recovered)
}
}
impl AuthorizationList {
pub fn len(&self) -> usize {
match self {
Self::Signed(signed) => signed.len(),
Self::Recovered(recovered) => recovered.len(),
}
}
pub fn empty() -> Self {
Self::Recovered(Vec::new())
}
pub fn is_empty(&self) -> bool {
self.len() == 0
}
pub fn recovered_iter<'a>(&'a self) -> Box<dyn Iterator<Item = RecoveredAuthorization> + 'a> {
match self {
Self::Signed(signed) => Box::new(signed.iter().map(|signed| signed.clone().into())),
Self::Recovered(recovered) => Box::new(recovered.clone().into_iter()),
}
}
pub fn into_recovered(self) -> Self {
let Self::Signed(signed) = self else {
return self;
};
Self::Recovered(signed.into_iter().map(|signed| signed.into()).collect())
}
}