reth_primitives_traits/transaction/
recover.rs

1//! Helpers for recovering signers from a set of transactions
2
3#[cfg(feature = "rayon")]
4pub use rayon::*;
5
6#[cfg(not(feature = "rayon"))]
7pub use iter::*;
8
9#[cfg(feature = "rayon")]
10mod rayon {
11    use crate::{transaction::signed::RecoveryError, SignedTransaction};
12    use alloc::vec::Vec;
13    use alloy_primitives::Address;
14    use rayon::prelude::{IntoParallelIterator, ParallelIterator};
15
16    /// Recovers a list of signers from a transaction list iterator.
17    ///
18    /// Returns `None`, if some transaction's signature is invalid
19    pub fn recover_signers<'a, I, T>(txes: I) -> Result<Vec<Address>, RecoveryError>
20    where
21        T: SignedTransaction,
22        I: IntoParallelIterator<Item = &'a T> + IntoIterator<Item = &'a T> + Send,
23    {
24        txes.into_par_iter().map(|tx| tx.recover_signer()).collect()
25    }
26
27    /// 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.
31    pub fn recover_signers_unchecked<'a, I, T>(txes: I) -> Result<Vec<Address>, RecoveryError>
32    where
33        T: SignedTransaction,
34        I: IntoParallelIterator<Item = &'a T> + IntoIterator<Item = &'a T> + Send,
35    {
36        txes.into_par_iter().map(|tx| tx.recover_signer_unchecked()).collect()
37    }
38}
39
40#[cfg(not(feature = "rayon"))]
41mod iter {
42    use crate::{transaction::signed::RecoveryError, SignedTransaction};
43    use alloc::vec::Vec;
44    use alloy_primitives::Address;
45
46    /// Recovers a list of signers from a transaction list iterator.
47    ///
48    /// Returns `Err(RecoveryError)`, if some transaction's signature is invalid
49    pub fn recover_signers<'a, I, T>(txes: I) -> Result<Vec<Address>, RecoveryError>
50    where
51        T: SignedTransaction,
52        I: IntoIterator<Item = &'a T>,
53    {
54        txes.into_iter().map(|tx| tx.recover_signer()).collect()
55    }
56
57    /// 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.
61    pub fn recover_signers_unchecked<'a, I, T>(txes: I) -> Result<Vec<Address>, RecoveryError>
62    where
63        T: SignedTransaction,
64        I: IntoIterator<Item = &'a T>,
65    {
66        txes.into_iter().map(|tx| tx.recover_signer_unchecked()).collect()
67    }
68}