alloy_consensus/transaction/
hashable.rs

1use alloy_eips::Typed2718;
2use alloy_primitives::{Signature, TxHash};
3
4use crate::transaction::RlpEcdsaEncodableTx;
5
6/// Generic trait to get a transaction hash from any signature type
7pub trait TxHashable<S>: Typed2718 {
8    /// Calculate the transaction hash for the given signature and type.
9    fn tx_hash_with_type(&self, signature: &S, ty: u8) -> TxHash;
10
11    /// Calculate the transaction hash for the given signature.
12    fn tx_hash(&self, signature: &S) -> TxHash {
13        self.tx_hash_with_type(signature, self.ty())
14    }
15}
16
17impl<T> TxHashable<Signature> for T
18where
19    T: RlpEcdsaEncodableTx,
20{
21    /// Calculate the transaction hash for the given signature and type.
22    fn tx_hash_with_type(&self, signature: &Signature, ty: u8) -> alloy_primitives::TxHash {
23        self.tx_hash_with_type(signature, ty)
24    }
25}