Skip to content

Commit

Permalink
refactor: use alloy_primitives::TxKind
Browse files Browse the repository at this point in the history
  • Loading branch information
Wodann committed Apr 29, 2024
1 parent d0d7e49 commit b1fbce4
Show file tree
Hide file tree
Showing 17 changed files with 75 additions and 148 deletions.
4 changes: 2 additions & 2 deletions crates/edr_eth/src/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
//! transaction related data

mod fake_signature;
mod kind;
mod request;
mod signed;

pub use revm_primitives::alloy_primitives::TxKind;
use revm_primitives::B256;

pub use self::{kind::TransactionKind, request::*, signed::*};
pub use self::{request::*, signed::*};
use crate::{access_list::AccessListItem, Address, Bytes, U256};

/// Represents _all_ transaction requests received from RPC
Expand Down
58 changes: 0 additions & 58 deletions crates/edr_eth/src/transaction/kind.rs

This file was deleted.

10 changes: 4 additions & 6 deletions crates/edr_eth/src/transaction/request/eip155.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ use revm_primitives::keccak256;

use crate::{
signature::{Signature, SignatureError},
transaction::{
fake_signature::make_fake_signature, kind::TransactionKind, signed::Eip155SignedTransaction,
},
transaction::{fake_signature::make_fake_signature, signed::Eip155SignedTransaction, TxKind},
Address, Bytes, B256, U256,
};

Expand All @@ -18,7 +16,7 @@ pub struct Eip155TransactionRequest {
pub nonce: u64,
pub gas_price: U256,
pub gas_limit: u64,
pub kind: TransactionKind,
pub kind: TxKind,
pub value: U256,
pub input: Bytes,
pub chain_id: u64,
Expand Down Expand Up @@ -142,7 +140,7 @@ mod tests {
nonce: 1,
gas_price: U256::from(2),
gas_limit: 3,
kind: TransactionKind::Call(to),
kind: TxKind::Call(to),
value: U256::from(4),
input: Bytes::from(input),
chain_id: 1,
Expand Down Expand Up @@ -182,7 +180,7 @@ mod tests {
nonce: 0,
gas_price: U256::from(678_912),
gas_limit: 30_000,
kind: TransactionKind::Call("0xb5bc06d4548a3ac17d72b372ae1e416bf65b8ead".parse()?),
kind: TxKind::Call("0xb5bc06d4548a3ac17d72b372ae1e416bf65b8ead".parse()?),
value: U256::from(1),
input: Bytes::default(),
chain_id: 123,
Expand Down
13 changes: 5 additions & 8 deletions crates/edr_eth/src/transaction/request/eip1559.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@ use revm_primitives::keccak256;
use crate::{
access_list::AccessListItem,
signature::{Signature, SignatureError},
transaction::{
fake_signature::make_fake_signature, kind::TransactionKind,
signed::Eip1559SignedTransaction,
},
transaction::{fake_signature::make_fake_signature, signed::Eip1559SignedTransaction, TxKind},
utils::envelop_bytes,
Address, Bytes, B256, U256,
};
Expand All @@ -23,7 +20,7 @@ pub struct Eip1559TransactionRequest {
pub max_priority_fee_per_gas: U256,
pub max_fee_per_gas: U256,
pub gas_limit: u64,
pub kind: TransactionKind,
pub kind: TxKind,
pub value: U256,
pub input: Bytes,
pub access_list: Vec<AccessListItem>,
Expand Down Expand Up @@ -114,7 +111,7 @@ pub(crate) mod tests {
max_priority_fee_per_gas: U256::from(2),
max_fee_per_gas: U256::from(5),
gas_limit: 3,
kind: TransactionKind::Call(to),
kind: TxKind::Call(to),
value: U256::from(4),
input: Bytes::from(input),
access_list: vec![AccessListItem {
Expand Down Expand Up @@ -150,7 +147,7 @@ pub(crate) mod tests {
max_priority_fee_per_gas: U256::ZERO,
max_fee_per_gas: U256::ZERO,
gas_limit: 0,
kind: TransactionKind::Create,
kind: TxKind::Create,
value: U256::ZERO,
input: Bytes::new(),
access_list: vec![],
Expand Down Expand Up @@ -182,7 +179,7 @@ pub(crate) mod tests {
max_priority_fee_per_gas: U256::from(2),
max_fee_per_gas: U256::from(12),
gas_limit: 30_000,
kind: TransactionKind::Call("0xb5bc06d4548a3ac17d72b372ae1e416bf65b8ead".parse()?),
kind: TxKind::Call("0xb5bc06d4548a3ac17d72b372ae1e416bf65b8ead".parse()?),
value: U256::from(1),
input: Bytes::default(),
access_list: vec![],
Expand Down
11 changes: 4 additions & 7 deletions crates/edr_eth/src/transaction/request/eip2930.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@ use revm_primitives::keccak256;
use crate::{
access_list::AccessListItem,
signature::{Signature, SignatureError},
transaction::{
fake_signature::make_fake_signature, kind::TransactionKind,
signed::Eip2930SignedTransaction,
},
transaction::{fake_signature::make_fake_signature, signed::Eip2930SignedTransaction, TxKind},
utils::envelop_bytes,
Address, Bytes, B256, U256,
};
Expand All @@ -22,7 +19,7 @@ pub struct Eip2930TransactionRequest {
pub nonce: u64,
pub gas_price: U256,
pub gas_limit: u64,
pub kind: TransactionKind,
pub kind: TxKind,
pub value: U256,
pub input: Bytes,
pub access_list: Vec<AccessListItem>,
Expand Down Expand Up @@ -111,7 +108,7 @@ mod tests {
nonce: 1,
gas_price: U256::from(2),
gas_limit: 3,
kind: TransactionKind::Call(to),
kind: TxKind::Call(to),
value: U256::from(4),
input: Bytes::from(input),
access_list: vec![AccessListItem {
Expand Down Expand Up @@ -157,7 +154,7 @@ mod tests {
nonce: 0,
gas_price: U256::from(1),
gas_limit: 30_000,
kind: TransactionKind::Call("0xb5bc06d4548a3ac17d72b372ae1e416bf65b8ead".parse()?),
kind: TxKind::Call("0xb5bc06d4548a3ac17d72b372ae1e416bf65b8ead".parse()?),
value: U256::from(1),
input: Bytes::default(),
access_list: vec![AccessListItem {
Expand Down
10 changes: 4 additions & 6 deletions crates/edr_eth/src/transaction/request/legacy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ use revm_primitives::keccak256;

use crate::{
signature::{Signature, SignatureError},
transaction::{
fake_signature::make_fake_signature, kind::TransactionKind, signed::LegacySignedTransaction,
},
transaction::{fake_signature::make_fake_signature, signed::LegacySignedTransaction, TxKind},
Address, Bytes, B256, U256,
};

Expand All @@ -18,7 +16,7 @@ pub struct LegacyTransactionRequest {
pub nonce: u64,
pub gas_price: U256,
pub gas_limit: u64,
pub kind: TransactionKind,
pub kind: TxKind,
pub value: U256,
pub input: Bytes,
}
Expand Down Expand Up @@ -93,7 +91,7 @@ mod tests {
nonce: 1,
gas_price: U256::from(2),
gas_limit: 3,
kind: TransactionKind::Call(to),
kind: TxKind::Call(to),
value: U256::from(4),
input: Bytes::from(input),
}
Expand Down Expand Up @@ -131,7 +129,7 @@ mod tests {
nonce: 0,
gas_price: U256::from(678_912),
gas_limit: 30_000,
kind: TransactionKind::Call("0xb5bc06d4548a3ac17d72b372ae1e416bf65b8ead".parse()?),
kind: TxKind::Call("0xb5bc06d4548a3ac17d72b372ae1e416bf65b8ead".parse()?),
value: U256::from(1),
input: Bytes::default(),
};
Expand Down
28 changes: 14 additions & 14 deletions crates/edr_eth/src/transaction/signed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pub use self::{
eip2930::Eip2930SignedTransaction, eip4844::Eip4844SignedTransaction,
legacy::LegacySignedTransaction,
};
use super::kind::TransactionKind;
use super::TxKind;
use crate::{
access_list::AccessList,
signature::{Signature, SignatureError},
Expand Down Expand Up @@ -227,19 +227,19 @@ impl SignedTransaction {
}

/// Returns what kind of transaction this is
pub fn kind(&self) -> TransactionKind {
pub fn kind(&self) -> TxKind {
match self {
SignedTransaction::PreEip155Legacy(tx) => tx.kind,
SignedTransaction::PostEip155Legacy(tx) => tx.kind,
SignedTransaction::Eip2930(tx) => tx.kind,
SignedTransaction::Eip1559(tx) => tx.kind,
SignedTransaction::Eip4844(tx) => TransactionKind::Call(tx.to),
SignedTransaction::Eip4844(tx) => TxKind::Call(tx.to),
}
}

/// Returns the callee if this transaction is a call
pub fn to(&self) -> Option<Address> {
self.kind().as_call().copied()
self.kind().to().copied()
}

/// Returns the [`Signature`] of the transaction
Expand Down Expand Up @@ -408,7 +408,7 @@ mod tests {
assert_eq!(tx.gas_price, U256::from(0x01u64));
assert_eq!(tx.gas_limit, 0x5208u64);
assert_eq!(tx.nonce, 0x00u64);
if let TransactionKind::Call(ref to) = tx.kind {
if let TxKind::Call(ref to) = tx.kind {
assert_eq!(
*to,
"0x095e7baea6a6c7c4c2dfeb977efac326af552d87"
Expand Down Expand Up @@ -452,7 +452,7 @@ mod tests {
nonce: 0,
gas_price: U256::from(1),
gas_limit: 2,
kind: TransactionKind::Call(Address::default()),
kind: TxKind::Call(Address::default()),
value: U256::from(3),
input: Bytes::from(vec![1, 2]),
signature: Signature {
Expand All @@ -467,7 +467,7 @@ mod tests {
nonce: 0,
gas_price: U256::from(1),
gas_limit: 2,
kind: TransactionKind::Create,
kind: TxKind::Create,
value: U256::from(3),
input: Bytes::from(vec![1, 2]),
signature: Signature {
Expand All @@ -483,7 +483,7 @@ mod tests {
nonce: 0,
gas_price: U256::from(1),
gas_limit: 2,
kind: TransactionKind::Call(Address::random()),
kind: TxKind::Call(Address::random()),
value: U256::from(3),
input: Bytes::from(vec![1, 2]),
odd_y_parity: true,
Expand All @@ -499,7 +499,7 @@ mod tests {
max_priority_fee_per_gas: U256::from(1),
max_fee_per_gas: U256::from(2),
gas_limit: 3,
kind: TransactionKind::Create,
kind: TxKind::Create,
value: U256::from(4),
input: Bytes::from(vec![1, 2]),
access_list: vec![].into(),
Expand Down Expand Up @@ -538,7 +538,7 @@ mod tests {
nonce: 2u64,
gas_price: U256::from(1000000000u64),
gas_limit: 100000,
kind: TransactionKind::Call(Address::from_slice(
kind: TxKind::Call(Address::from_slice(
&hex::decode("d3e8763675e4c425df46cc3b5c0f6cbdac396046").unwrap(),
)),
value: U256::from(1000000000000000u64),
Expand Down Expand Up @@ -567,7 +567,7 @@ mod tests {
nonce: 1,
gas_price: U256::from(1000000000u64),
gas_limit: 100000,
kind: TransactionKind::Call(Address::from_slice(
kind: TxKind::Call(Address::from_slice(
&hex::decode("d3e8763675e4c425df46cc3b5c0f6cbdac396046").unwrap(),
)),
value: U256::from(693361000000000u64),
Expand Down Expand Up @@ -596,7 +596,7 @@ mod tests {
nonce: 3,
gas_price: U256::from(2000000000u64),
gas_limit: 10000000,
kind: TransactionKind::Call(Address::from_slice(
kind: TxKind::Call(Address::from_slice(
&hex::decode("d3e8763675e4c425df46cc3b5c0f6cbdac396046").unwrap(),
)),
value: U256::from(1000000000000000u64),
Expand Down Expand Up @@ -627,7 +627,7 @@ mod tests {
max_priority_fee_per_gas: U256::from(1500000000u64),
max_fee_per_gas: U256::from(1500000013u64),
gas_limit: 21000,
kind: TransactionKind::Call(Address::from_slice(
kind: TxKind::Call(Address::from_slice(
&hex::decode("61815774383099e24810ab832a5b2a5425c154d5").unwrap(),
)),
value: U256::from(3000000000000000000u64),
Expand All @@ -651,7 +651,7 @@ mod tests {
nonce: 15u64,
gas_price: U256::from(2200000000u64),
gas_limit: 34811,
kind: TransactionKind::Call(Address::from_slice(
kind: TxKind::Call(Address::from_slice(
&hex::decode("cf7f9e66af820a19257a2108375b180b0ec49167").unwrap(),
)),
value: U256::from(1234u64),
Expand Down
7 changes: 3 additions & 4 deletions crates/edr_eth/src/transaction/signed/eip155.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ use super::LegacySignedTransaction;
use crate::{
signature::{Signature, SignatureError},
transaction::{
fake_signature::recover_fake_signature, kind::TransactionKind,
request::Eip155TransactionRequest,
fake_signature::recover_fake_signature, request::Eip155TransactionRequest, TxKind,
},
Address, Bytes, B256, U256,
};
Expand All @@ -22,7 +21,7 @@ pub struct Eip155SignedTransaction {
pub gas_price: U256,
#[cfg_attr(feature = "serde", serde(with = "crate::serde::u64"))]
pub gas_limit: u64,
pub kind: TransactionKind,
pub kind: TxKind,
pub value: U256,
pub input: Bytes,
pub signature: Signature,
Expand Down Expand Up @@ -102,7 +101,7 @@ mod tests {
nonce: 1,
gas_price: U256::from(2),
gas_limit: 3,
kind: TransactionKind::Call(to),
kind: TxKind::Call(to),
value: U256::from(4),
input: Bytes::from(input),
chain_id: 1,
Expand Down
Loading

0 comments on commit b1fbce4

Please sign in to comment.