mirror of
https://github.com/paradigmxyz/reth.git
synced 2026-01-09 23:38:10 -05:00
feat: Block::iter_recovered (#18476)
This commit is contained in:
@@ -5,7 +5,7 @@ use crate::{
|
||||
MaybeSerdeBincodeCompat, SignedTransaction,
|
||||
};
|
||||
use alloc::{fmt, vec::Vec};
|
||||
use alloy_consensus::{Transaction, Typed2718};
|
||||
use alloy_consensus::{transaction::Recovered, Transaction, Typed2718};
|
||||
use alloy_eips::{eip2718::Encodable2718, eip4895::Withdrawals};
|
||||
use alloy_primitives::{Address, Bytes, B256};
|
||||
|
||||
@@ -157,20 +157,14 @@ pub trait BlockBody:
|
||||
}
|
||||
|
||||
/// Recover signer addresses for all transactions in the block body.
|
||||
fn recover_signers(&self) -> Result<Vec<Address>, RecoveryError>
|
||||
where
|
||||
Self::Transaction: SignedTransaction,
|
||||
{
|
||||
fn recover_signers(&self) -> Result<Vec<Address>, RecoveryError> {
|
||||
crate::transaction::recover::recover_signers(self.transactions())
|
||||
}
|
||||
|
||||
/// Recover signer addresses for all transactions in the block body.
|
||||
///
|
||||
/// Returns an error if some transaction's signature is invalid.
|
||||
fn try_recover_signers(&self) -> Result<Vec<Address>, RecoveryError>
|
||||
where
|
||||
Self::Transaction: SignedTransaction,
|
||||
{
|
||||
fn try_recover_signers(&self) -> Result<Vec<Address>, RecoveryError> {
|
||||
self.recover_signers()
|
||||
}
|
||||
|
||||
@@ -178,10 +172,7 @@ pub trait BlockBody:
|
||||
/// signature has a low `s` value_.
|
||||
///
|
||||
/// Returns `RecoveryError`, if some transaction's signature is invalid.
|
||||
fn recover_signers_unchecked(&self) -> Result<Vec<Address>, RecoveryError>
|
||||
where
|
||||
Self::Transaction: SignedTransaction,
|
||||
{
|
||||
fn recover_signers_unchecked(&self) -> Result<Vec<Address>, RecoveryError> {
|
||||
crate::transaction::recover::recover_signers_unchecked(self.transactions())
|
||||
}
|
||||
|
||||
@@ -189,12 +180,21 @@ pub trait BlockBody:
|
||||
/// signature has a low `s` value_.
|
||||
///
|
||||
/// Returns an error if some transaction's signature is invalid.
|
||||
fn try_recover_signers_unchecked(&self) -> Result<Vec<Address>, RecoveryError>
|
||||
where
|
||||
Self::Transaction: SignedTransaction,
|
||||
{
|
||||
fn try_recover_signers_unchecked(&self) -> Result<Vec<Address>, RecoveryError> {
|
||||
self.recover_signers_unchecked()
|
||||
}
|
||||
|
||||
/// Recovers signers for all transactions in the block body and returns a vector of
|
||||
/// [`Recovered`].
|
||||
fn recover_transactions(&self) -> Result<Vec<Recovered<Self::Transaction>>, RecoveryError> {
|
||||
self.recover_signers().map(|signers| {
|
||||
self.transactions()
|
||||
.iter()
|
||||
.zip(signers)
|
||||
.map(|(tx, signer)| tx.clone().with_signer(signer))
|
||||
.collect()
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl<T, H> BlockBody for alloy_consensus::BlockBody<T, H>
|
||||
|
||||
@@ -190,10 +190,7 @@ pub trait Block:
|
||||
/// transactions.
|
||||
///
|
||||
/// Returns the block as error if a signature is invalid.
|
||||
fn try_into_recovered(self) -> Result<RecoveredBlock<Self>, BlockRecoveryError<Self>>
|
||||
where
|
||||
<Self::Body as BlockBody>::Transaction: SignedTransaction,
|
||||
{
|
||||
fn try_into_recovered(self) -> Result<RecoveredBlock<Self>, BlockRecoveryError<Self>> {
|
||||
let Ok(signers) = self.body().recover_signers() else {
|
||||
return Err(BlockRecoveryError::new(self))
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user