Skip to content

Commit 1a3b17c

Browse files
authored
feat: add to recovered ref fns (#2316)
1 parent 1a10f2a commit 1a3b17c

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

Diff for: crates/consensus/src/signed.rs

+9
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,15 @@ impl<T: SignableTransaction<Signature>> Signed<T, Signature> {
227227
let signer = self.recover_signer()?;
228228
Ok(crate::transaction::Recovered::new_unchecked(self.tx, signer))
229229
}
230+
231+
/// Attempts to recover signer and constructs a [`crate::transaction::Recovered`] with a
232+
/// reference to the transaction `Recovered<&T>`
233+
pub fn try_to_recovered_ref(
234+
&self,
235+
) -> Result<crate::transaction::Recovered<&T>, alloy_primitives::SignatureError> {
236+
let signer = self.recover_signer()?;
237+
Ok(crate::transaction::Recovered::new_unchecked(&self.tx, signer))
238+
}
230239
}
231240

232241
#[cfg(all(any(test, feature = "arbitrary"), feature = "k256"))]

Diff for: crates/consensus/src/transaction/envelope.rs

+12
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,18 @@ impl<Eip4844: RlpEcdsaEncodableTx> EthereumTxEnvelope<Eip4844> {
511511
Ok(crate::transaction::Recovered::new_unchecked(self, signer))
512512
}
513513

514+
/// Recover the signer of the transaction and returns a `Recovered<&Self>`
515+
#[cfg(feature = "k256")]
516+
pub fn try_to_recovered_ref(
517+
&self,
518+
) -> Result<crate::transaction::Recovered<&Self>, alloy_primitives::SignatureError>
519+
where
520+
Eip4844: SignableTransaction<Signature>,
521+
{
522+
let signer = self.recover_signer()?;
523+
Ok(crate::transaction::Recovered::new_unchecked(self, signer))
524+
}
525+
514526
/// Calculate the signing hash for the transaction.
515527
pub fn signature_hash(&self) -> B256
516528
where

0 commit comments

Comments
 (0)