alloy_consensus/transaction/
hashable.rs1use alloy_eips::Typed2718;
2use alloy_primitives::{Signature, TxHash};
3
4use crate::transaction::RlpEcdsaEncodableTx;
5
6pub trait TxHashable<S>: Typed2718 {
8 fn tx_hash_with_type(&self, signature: &S, ty: u8) -> TxHash;
10
11 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 fn tx_hash_with_type(&self, signature: &Signature, ty: u8) -> TxHash {
23 RlpEcdsaEncodableTx::tx_hash_with_type(self, signature, ty)
24 }
25}
26
27#[cfg(test)]
28mod tests {
29 use super::*;
30 use crate::{Signed, TxLegacy};
31 use alloy_primitives::U256;
32
33 #[test]
34 fn hashable_signed() {
35 let tx = TxLegacy::default();
36 let signature = Signature::new(U256::from(1u64), U256::from(1u64), false);
37 let signed = Signed::new_unhashed(tx, signature);
38 let _hash = signed.hash();
39 }
40}