Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reorg the transaction module #54

Merged
merged 2 commits into from
Feb 18, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is unnecessary. alloc is also available in no_std.

So I would prefer we just always do use alloc::vec::Vec regardless of std or no_std.

Same for all below.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated


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
Loading