use crate::{transaction::signed::RecoveryError, Recovered, SignedTransaction};
use alloc::vec::Vec;
use alloy_consensus::transaction::SignerRecoverable;
use alloy_primitives::Address;
#[cfg(feature = "rayon")]
use rayon::prelude::{IntoParallelIterator, ParallelIterator};
#[cfg(feature = "rayon")]
pub fn recover_signers<'a, I, T>(txes: I) -> Result<Vec<Address>, RecoveryError>
where
T: SignedTransaction,
I: IntoParallelIterator<Item = &'a T>,
{
txes.into_par_iter().map(|tx| tx.recover_signer()).collect()
}
#[cfg(not(feature = "rayon"))]
pub fn recover_signers<'a, I, T>(txes: I) -> Result<Vec<Address>, RecoveryError>
where
T: SignedTransaction,
I: IntoIterator<Item = &'a T>,
{
txes.into_iter().map(|tx| tx.recover_signer()).collect()
}
#[cfg(feature = "rayon")]
pub fn recover_signers_unchecked<'a, I, T>(txes: I) -> Result<Vec<Address>, RecoveryError>
where
T: SignedTransaction,
I: IntoParallelIterator<Item = &'a T>,
{
txes.into_par_iter().map(|tx| tx.recover_signer_unchecked()).collect()
}
#[cfg(not(feature = "rayon"))]
pub fn recover_signers_unchecked<'a, I, T>(txes: I) -> Result<Vec<Address>, RecoveryError>
where
T: SignedTransaction,
I: IntoIterator<Item = &'a T>,
{
txes.into_iter().map(|tx| tx.recover_signer_unchecked()).collect()
}
#[cfg(feature = "rayon")]
pub trait TryRecoverItems: IntoParallelIterator {}
#[cfg(not(feature = "rayon"))]
pub trait TryRecoverItems: IntoIterator {}
#[cfg(feature = "rayon")]
impl<I: IntoParallelIterator> TryRecoverItems for I {}
#[cfg(not(feature = "rayon"))]
impl<I: IntoIterator> TryRecoverItems for I {}
#[cfg(feature = "rayon")]
pub trait TryRecoverFn<Item, T>: Fn(Item) -> Result<T, RecoveryError> + Sync {}
#[cfg(not(feature = "rayon"))]
pub trait TryRecoverFn<Item, T>: Fn(Item) -> Result<T, RecoveryError> {}
#[cfg(feature = "rayon")]
impl<Item, T, F: Fn(Item) -> Result<T, RecoveryError> + Sync> TryRecoverFn<Item, T> for F {}
#[cfg(not(feature = "rayon"))]
impl<Item, T, F: Fn(Item) -> Result<T, RecoveryError>> TryRecoverFn<Item, T> for F {}
#[cfg(feature = "rayon")]
pub fn try_recover_signers<I, F, T>(items: I, decode: F) -> Result<Vec<Recovered<T>>, RecoveryError>
where
I: IntoParallelIterator,
F: Fn(I::Item) -> Result<T, RecoveryError> + Sync,
T: SignedTransaction,
{
items
.into_par_iter()
.map(|item| {
let tx = decode(item)?;
SignerRecoverable::try_into_recovered(tx)
})
.collect()
}
#[cfg(not(feature = "rayon"))]
pub fn try_recover_signers<I, F, T>(items: I, decode: F) -> Result<Vec<Recovered<T>>, RecoveryError>
where
I: IntoIterator,
F: Fn(I::Item) -> Result<T, RecoveryError>,
T: SignedTransaction,
{
items
.into_iter()
.map(|item| {
let tx = decode(item)?;
SignerRecoverable::try_into_recovered(tx)
})
.collect()
}