mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
chore: add hash+signer fn (#5493)
This commit is contained in:
@ -1,8 +1,10 @@
|
||||
//! Helper enum functions for `Transaction`, `TransactionSigned` and
|
||||
//! `TransactionSignedEcRecovered`
|
||||
use crate::{
|
||||
Transaction, TransactionSigned, TransactionSignedEcRecovered, TransactionSignedNoHash,
|
||||
Address, Transaction, TransactionSigned, TransactionSignedEcRecovered, TransactionSignedNoHash,
|
||||
B256,
|
||||
};
|
||||
use std::ops::Deref;
|
||||
|
||||
/// Represents various different transaction formats used in reth.
|
||||
///
|
||||
@ -29,6 +31,26 @@ impl TransactionSignedVariant {
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns the hash of the transaction
|
||||
pub fn hash(&self) -> B256 {
|
||||
match self {
|
||||
TransactionSignedVariant::SignedNoHash(tx) => tx.hash(),
|
||||
TransactionSignedVariant::Signed(tx) => tx.hash,
|
||||
TransactionSignedVariant::SignedEcRecovered(tx) => tx.hash,
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns the signer of the transaction.
|
||||
///
|
||||
/// If the transaction is of not of [TransactionSignedEcRecovered] it will be recovered.
|
||||
pub fn signer(&self) -> Option<Address> {
|
||||
match self {
|
||||
TransactionSignedVariant::SignedNoHash(tx) => tx.recover_signer(),
|
||||
TransactionSignedVariant::Signed(tx) => tx.recover_signer(),
|
||||
TransactionSignedVariant::SignedEcRecovered(tx) => Some(tx.signer),
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns [TransactionSigned] type
|
||||
/// else None
|
||||
pub fn as_signed(&self) -> Option<&TransactionSigned> {
|
||||
@ -130,3 +152,11 @@ impl AsRef<Transaction> for TransactionSignedVariant {
|
||||
self.as_raw()
|
||||
}
|
||||
}
|
||||
|
||||
impl Deref for TransactionSignedVariant {
|
||||
type Target = Transaction;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
self.as_raw()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user