diff --git a/ethers-core/src/types/transaction/eip1559.rs b/ethers-core/src/types/transaction/eip1559.rs index 0f7893300..396e88da1 100644 --- a/ethers-core/src/types/transaction/eip1559.rs +++ b/ethers-core/src/types/transaction/eip1559.rs @@ -1,9 +1,6 @@ -use super::{decode_to, eip2930::AccessList, normalize_v, rlp_opt}; -use crate::{ - types::{ - Address, Bytes, NameOrAddress, Signature, SignatureError, Transaction, H256, U256, U64, - }, - utils::keccak256, +use super::{decode_to, eip2718::TypedTransaction, eip2930::AccessList, normalize_v, rlp_opt}; +use crate::types::{ + Address, Bytes, NameOrAddress, Signature, SignatureError, Transaction, U256, U64, }; use rlp::{Decodable, DecoderError, RlpStream}; use thiserror::Error; @@ -80,9 +77,6 @@ pub struct Eip1559TransactionRequest { } impl Eip1559TransactionRequest { - /// EIP-2718 transaction type - const TX_TYPE: u8 = 0x02; - /// Creates an empty transaction request with all fields left empty pub fn new() -> Self { Self::default() @@ -160,14 +154,6 @@ impl Eip1559TransactionRequest { self } - /// Hashes the transaction's data for signing - pub fn sighash(&self) -> H256 { - let mut encoded = vec![]; - encoded.extend_from_slice(&[Self::TX_TYPE]); - encoded.extend_from_slice(self.rlp().as_ref()); - keccak256(encoded).into() - } - /// Gets the unsigned transaction's RLP encoding pub fn rlp(&self) -> Bytes { let mut rlp = RlpStream::new(); @@ -247,7 +233,7 @@ impl Eip1559TransactionRequest { let s = rlp.val_at(offset)?; let sig = Signature { r, s, v }; - txn.from = Some(sig.recover(txn.sighash())?); + txn.from = Some(sig.recover(TypedTransaction::Eip1559(txn.clone()).sighash())?); Ok((txn, sig)) } diff --git a/ethers-core/src/types/transaction/eip2930.rs b/ethers-core/src/types/transaction/eip2930.rs index f7b2e1a87..3defdad65 100644 --- a/ethers-core/src/types/transaction/eip2930.rs +++ b/ethers-core/src/types/transaction/eip2930.rs @@ -1,9 +1,6 @@ -use super::normalize_v; -use crate::{ - types::{ - Address, Bytes, Signature, SignatureError, Transaction, TransactionRequest, H256, U256, U64, - }, - utils::keccak256, +use super::{eip2718::TypedTransaction, normalize_v}; +use crate::types::{ + Address, Bytes, Signature, SignatureError, Transaction, TransactionRequest, H256, U256, U64, }; use rlp::{Decodable, RlpStream}; use rlp_derive::{RlpDecodable, RlpDecodableWrapper, RlpEncodable, RlpEncodableWrapper}; @@ -84,9 +81,6 @@ pub struct Eip2930TransactionRequest { } impl Eip2930TransactionRequest { - /// EIP-2718 transaction type - const TX_TYPE: u8 = 0x01; - pub fn new(tx: TransactionRequest, access_list: AccessList) -> Self { Self { tx, access_list } } @@ -153,17 +147,9 @@ impl Eip2930TransactionRequest { let s = rlp.val_at(offset)?; let sig = Signature { r, s, v }; - txn.tx.from = Some(sig.recover(txn.sighash())?); + txn.tx.from = Some(sig.recover(TypedTransaction::Eip2930(txn.clone()).sighash())?); Ok((txn, sig)) } - - /// Hashes the transaction's data for signing - pub fn sighash(&self) -> H256 { - let mut encoded = vec![]; - encoded.extend_from_slice(&[Self::TX_TYPE]); - encoded.extend_from_slice(self.rlp().as_ref()); - keccak256(encoded).into() - } } /// Get a Eip2930TransactionRequest from a rlp encoded byte stream