Skip to content

Commit

Permalink
Reorg the transaction module
Browse files Browse the repository at this point in the history
 - split the transaction module to legacy/eip2930/eip1559 modules
 - add to_message method for LegacyTransaction/EIP2930Transaction/EIP1559Transaction
 - adjust some imports
  • Loading branch information
koushiro committed Feb 17, 2024
1 parent 8cacae5 commit 063d03b
Show file tree
Hide file tree
Showing 10 changed files with 967 additions and 899 deletions.
19 changes: 12 additions & 7 deletions src/block.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
use crate::{
util::ordered_trie_root, EnvelopedDecodable, EnvelopedEncodable, Header, PartialHeader,
TransactionAny, TransactionV0, TransactionV1, TransactionV2,
};
#[cfg(not(feature = "std"))]
use alloc::vec::Vec;

use ethereum_types::H256;
use rlp::{Decodable, DecoderError, Encodable, Rlp, RlpStream};
use rlp::{DecoderError, Rlp, RlpStream};
use sha3::{Digest, Keccak256};

use crate::{
enveloped::{EnvelopedDecodable, EnvelopedEncodable},
header::{Header, PartialHeader},
transaction::{TransactionAny, TransactionV0, TransactionV1, TransactionV2},
util::ordered_trie_root,
};

#[derive(Clone, Debug, PartialEq, Eq)]
#[cfg_attr(
feature = "with-codec",
Expand All @@ -19,7 +24,7 @@ pub struct Block<T> {
pub ommers: Vec<Header>,
}

impl<T: EnvelopedEncodable> Encodable for Block<T> {
impl<T: EnvelopedEncodable> rlp::Encodable for Block<T> {
fn rlp_append(&self, s: &mut RlpStream) {
s.begin_list(3);
s.append(&self.header);
Expand All @@ -34,7 +39,7 @@ impl<T: EnvelopedEncodable> Encodable for Block<T> {
}
}

impl<T: EnvelopedDecodable> Decodable for Block<T> {
impl<T: EnvelopedDecodable> rlp::Decodable for Block<T> {
fn decode(rlp: &Rlp) -> Result<Self, DecoderError> {
Ok(Self {
header: rlp.val_at(0)?,
Expand Down
18 changes: 11 additions & 7 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#![cfg_attr(not(feature = "std"), no_std)]

#[cfg(not(feature = "std"))]
extern crate alloc;

mod account;
Expand All @@ -12,12 +13,15 @@ mod transaction;
pub mod util;

// Alias for `Vec<u8>`. This type alias is necessary for rlp-derive to work correctly.
#[cfg(not(feature = "std"))]
type Bytes = alloc::vec::Vec<u8>;
#[cfg(feature = "std")]
type Bytes = Vec<u8>;

pub use account::Account;
pub use block::*;
pub use enveloped::*;
pub use header::{Header, PartialHeader};
pub use log::Log;
pub use receipt::*;
pub use transaction::*;
pub use crate::account::Account;
pub use crate::block::*;
pub use crate::enveloped::*;
pub use crate::header::{Header, PartialHeader};
pub use crate::log::Log;
pub use crate::receipt::*;
pub use crate::transaction::*;
5 changes: 4 additions & 1 deletion src/log.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
use crate::Bytes;
#[cfg(not(feature = "std"))]
use alloc::vec::Vec;

use ethereum_types::{H160, H256};

use crate::Bytes;

#[derive(Clone, Debug, PartialEq, Eq)]
#[derive(rlp::RlpEncodable, rlp::RlpDecodable)]
#[cfg_attr(
Expand Down
8 changes: 7 additions & 1 deletion src/receipt.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
use crate::{EnvelopedDecodable, EnvelopedDecoderError, EnvelopedEncodable, Log};
#[cfg(not(feature = "std"))]
use alloc::vec::Vec;

use bytes::BytesMut;
use ethereum_types::{Bloom, H256, U256};
use rlp::{Decodable, DecoderError, Rlp};

use crate::{
enveloped::{EnvelopedDecodable, EnvelopedDecoderError, EnvelopedEncodable},
log::Log,
};

#[derive(Clone, Debug, PartialEq, Eq)]
#[derive(rlp::RlpEncodable, rlp::RlpDecodable)]
#[cfg_attr(
Expand Down
Loading

0 comments on commit 063d03b

Please sign in to comment.