alloy_consensus/
signed.rsuse crate::transaction::SignableTransaction;
use alloy_primitives::{Signature, B256};
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Signed<T, Sig = Signature> {
#[cfg_attr(feature = "serde", serde(flatten))]
#[doc(alias = "transaction")]
tx: T,
#[cfg_attr(feature = "serde", serde(flatten))]
signature: Sig,
#[doc(alias = "tx_hash", alias = "transaction_hash")]
hash: B256,
}
impl<T, Sig> Signed<T, Sig> {
#[doc(alias = "transaction")]
pub const fn tx(&self) -> &T {
&self.tx
}
pub const fn signature(&self) -> &Sig {
&self.signature
}
#[doc(alias = "tx_hash", alias = "transaction_hash")]
pub const fn hash(&self) -> &B256 {
&self.hash
}
pub fn into_parts(self) -> (T, Sig, B256) {
(self.tx, self.signature, self.hash)
}
pub fn strip_signature(self) -> T {
self.tx
}
}
impl<T: SignableTransaction<Sig>, Sig> Signed<T, Sig> {
pub const fn new_unchecked(tx: T, signature: Sig, hash: B256) -> Self {
Self { tx, signature, hash }
}
pub fn signature_hash(&self) -> B256 {
self.tx.signature_hash()
}
}
#[cfg(feature = "k256")]
impl<T: SignableTransaction<Signature>> Signed<T, Signature> {
pub fn recover_signer(
&self,
) -> Result<alloy_primitives::Address, alloy_primitives::SignatureError> {
let sighash = self.tx.signature_hash();
self.signature.recover_address_from_prehash(&sighash)
}
}