1//! Helpers for recovering signers from a set of transactions
23#[cfg(feature = "rayon")]
4pub use rayon::*;
56#[cfg(not(feature = "rayon"))]
7pub use iter::*;
89#[cfg(feature = "rayon")]
10mod rayon {
11use crate::{transaction::signed::RecoveryError, SignedTransaction};
12use alloc::vec::Vec;
13use alloy_primitives::Address;
14use rayon::prelude::{IntoParallelIterator, ParallelIterator};
1516/// Recovers a list of signers from a transaction list iterator.
17 ///
18 /// Returns `None`, if some transaction's signature is invalid
19pub fn recover_signers<'a, I, T>(txes: I) -> Result<Vec<Address>, RecoveryError>
20where
21T: SignedTransaction,
22 I: IntoParallelIterator<Item = &'a T> + IntoIterator<Item = &'a T> + Send,
23 {
24txes.into_par_iter().map(|tx| tx.recover_signer()).collect()
25 }
2627/// Recovers a list of signers from a transaction list iterator _without ensuring that the
28 /// signature has a low `s` value_.
29 ///
30 /// Returns `None`, if some transaction's signature is invalid.
31pub fn recover_signers_unchecked<'a, I, T>(txes: I) -> Result<Vec<Address>, RecoveryError>
32where
33T: SignedTransaction,
34 I: IntoParallelIterator<Item = &'a T> + IntoIterator<Item = &'a T> + Send,
35 {
36txes.into_par_iter().map(|tx| tx.recover_signer_unchecked()).collect()
37 }
38}
3940#[cfg(not(feature = "rayon"))]
41mod iter {
42use crate::{transaction::signed::RecoveryError, SignedTransaction};
43use alloc::vec::Vec;
44use alloy_primitives::Address;
4546/// Recovers a list of signers from a transaction list iterator.
47 ///
48 /// Returns `Err(RecoveryError)`, if some transaction's signature is invalid
49pub fn recover_signers<'a, I, T>(txes: I) -> Result<Vec<Address>, RecoveryError>
50where
51T: SignedTransaction,
52 I: IntoIterator<Item = &'a T>,
53 {
54 txes.into_iter().map(|tx| tx.recover_signer()).collect()
55 }
5657/// Recovers a list of signers from a transaction list iterator _without ensuring that the
58 /// signature has a low `s` value_.
59 ///
60 /// Returns `Err(RecoveryError)`, if some transaction's signature is invalid.
61pub fn recover_signers_unchecked<'a, I, T>(txes: I) -> Result<Vec<Address>, RecoveryError>
62where
63T: SignedTransaction,
64 I: IntoIterator<Item = &'a T>,
65 {
66 txes.into_iter().map(|tx| tx.recover_signer_unchecked()).collect()
67 }
68}