Skip to content

Commit

Permalink
parent d0794e5
Browse files Browse the repository at this point in the history
author yjhmelody <[email protected]> 1705643916 +0800
committer James <[email protected]> 1710369825 -0700
gpgsig -----BEGIN PGP SIGNATURE-----

 iHUEABYKAB0WIQR9scgTYj1qiZ/GDEs40AdhaDP6LwUCZfIsIQAKCRA40AdhaDP6
 Lw/9AP9BPQf6MkehqIH4fcmeWyfjMvKGka2De0h2tIxZmHKPrwEA4IRPXrdAuZ7a
 nXK7OqUb83QkLYi3eNqc+nW0+/OC1gQ=
 =y90O
 -----END PGP SIGNATURE-----

wip

use core/alloc; remove unused error

improve clippy

remove thiserror; impl by hand

fix `alloy-rpc-types` dep
  • Loading branch information
yjhmelody authored and prestwich committed Mar 13, 2024
1 parent d0794e5 commit 69d26fe
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 16 deletions.
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,11 @@ rand = "0.8"
reqwest = { version = "0.11", default-features = false }
semver = "1.0"
thiserror = "1.0"
thiserror-no-std = "2.0.2"
url = "2.5"

## serde
serde = { version = "1.0", features = ["derive"] }
serde = { version = "1.0", features = ["derive"], default-features = false }
serde_json = "1.0"

## misc-testing
Expand Down
13 changes: 9 additions & 4 deletions crates/eips/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,11 @@ repository.workspace = true
exclude.workspace = true

[dependencies]
alloy-primitives = { workspace = true, features = ["rlp"] }
alloy-primitives = { workspace = true, features = ["rlp"], default-features = false }
alloy-rlp = { workspace = true, features = ["derive"] }

thiserror.workspace = true

# serde
serde = { workspace = true, optional = true }
serde = { workspace = true, default-features = false, optional = true }

# arbitrary
arbitrary = { workspace = true, features = ["derive"], optional = true }
Expand All @@ -31,5 +29,12 @@ proptest = { workspace = true }
proptest-derive = { workspace = true }

[features]
default = ["std"]
std = [
"alloy-primitives/std",
"alloy-rlp/std",

"serde/std",
]
serde = ["dep:serde", "alloy-primitives/serde"]
arbitrary = ["dep:arbitrary", "dep:proptest-derive", "dep:proptest", "alloy-primitives/arbitrary"]
32 changes: 25 additions & 7 deletions crates/eips/src/eip2718.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,46 @@
//!
//! [EIP-2718]: https://eips.ethereum.org/EIPS/eip-2718
use alloc::{vec, vec::Vec};
use alloy_primitives::{keccak256, Sealed, B256};
use alloy_rlp::{BufMut, Header, EMPTY_STRING_CODE};
use core::{
fmt,
fmt::{Display, Formatter},
};

// https://eips.ethereum.org/EIPS/eip-2718#transactiontype-only-goes-up-to-0x7f
const TX_TYPE_BYTE_MAX: u8 = 0x7f;

/// [EIP-2718] decoding errors.
///
/// [EIP-2718]: https://eips.ethereum.org/EIPS/eip-2718
#[derive(thiserror::Error, Debug)]
#[derive(Debug, Copy, Clone)]
pub enum Eip2718Error {
/// Rlp error from [`alloy_rlp`].
#[error(transparent)]
RlpError(#[from] alloy_rlp::Error),
RlpError(alloy_rlp::Error),
/// Got an unexpected type flag while decoding.
#[error("Unexpected type flag. Got {0}.")]
UnexpectedType(u8),
/// Some other error occurred.
#[error(transparent)]
Custom(#[from] Box<dyn std::error::Error>),
}

impl Display for Eip2718Error {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
match self {
Self::RlpError(err) => write!(f, "{err}"),
Self::UnexpectedType(t) => write!(f, "Unexpected type flag. Got {t}."),
}
}
}

impl From<alloy_rlp::Error> for Eip2718Error {
fn from(err: alloy_rlp::Error) -> Self {
Self::RlpError(err)
}
}

#[cfg(feature = "std")]
impl std::error::Error for Eip2718Error {}

/// Decoding trait for [EIP-2718] envelopes. These envelopes wrap a transaction
/// or a receipt with a type flag.
///
Expand Down
3 changes: 2 additions & 1 deletion crates/eips/src/eip2930.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
#![allow(unknown_lints, non_local_definitions)]

use alloc::vec::Vec;
use alloy_primitives::{Address, B256, U256};
use alloy_rlp::{RlpDecodable, RlpDecodableWrapper, RlpEncodable, RlpEncodableWrapper};
use std::mem;
use core::mem;

/// A list of addresses and storage keys that the transaction plans to access.
/// Accesses outside the list are possible, but become more expensive.
Expand Down
5 changes: 4 additions & 1 deletion crates/eips/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,12 @@
clippy::missing_const_for_fn,
rustdoc::all
)]
#![cfg_attr(not(test), warn(unused_crate_dependencies))]
#![deny(unused_must_use, rust_2018_idioms)]
#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]
#![cfg_attr(feature = "arbitrary", cfg(feature = "std"))]
#![cfg_attr(not(feature = "std"), no_std)]

extern crate alloc;

pub mod eip1559;
pub use eip1559::calc_next_block_base_fee;
Expand Down
2 changes: 1 addition & 1 deletion crates/eips/src/merge.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Constants related to the beacon chain consensus.
use std::time::Duration;
use core::time::Duration;

/// An EPOCH is a series of 32 slots.
pub const EPOCH_SLOTS: u64 = 32;
Expand Down
2 changes: 1 addition & 1 deletion crates/rpc-types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ exclude.workspace = true
[dependencies]
# ethereum
alloy-rlp = { workspace = true, features = ["arrayvec", "derive"] }
alloy-primitives = { workspace = true, features = ["rlp", "serde"] }
alloy-primitives = { workspace = true, features = ["rlp", "serde", "std"] }
alloy-serde.workspace = true

ethereum_ssz_derive = { workspace = true, optional = true }
Expand Down

0 comments on commit 69d26fe

Please sign in to comment.