Skip to content

feat: add to recovered ref fns #2316

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions crates/consensus/src/signed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,15 @@ impl<T: SignableTransaction<Signature>> Signed<T, Signature> {
let signer = self.recover_signer()?;
Ok(crate::transaction::Recovered::new_unchecked(self.tx, signer))
}

/// Attempts to recover signer and constructs a [`crate::transaction::Recovered`] with a
/// reference to the transaction `Recovered<&T>`
pub fn try_to_recovered_ref(
&self,
) -> Result<crate::transaction::Recovered<&T>, alloy_primitives::SignatureError> {
let signer = self.recover_signer()?;
Ok(crate::transaction::Recovered::new_unchecked(&self.tx, signer))
}
}

#[cfg(all(any(test, feature = "arbitrary"), feature = "k256"))]
Expand Down
12 changes: 12 additions & 0 deletions crates/consensus/src/transaction/envelope.rs
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,18 @@ impl<Eip4844: RlpEcdsaEncodableTx> EthereumTxEnvelope<Eip4844> {
Ok(crate::transaction::Recovered::new_unchecked(self, signer))
}

/// Recover the signer of the transaction and returns a `Recovered<&Self>`
#[cfg(feature = "k256")]
pub fn try_to_recovered_ref(
&self,
) -> Result<crate::transaction::Recovered<&Self>, alloy_primitives::SignatureError>
where
Eip4844: SignableTransaction<Signature>,
{
let signer = self.recover_signer()?;
Ok(crate::transaction::Recovered::new_unchecked(self, signer))
}

/// Calculate the signing hash for the transaction.
pub fn signature_hash(&self) -> B256
where
Expand Down
Loading