Skip to content

Commit

Permalink
feat: no_std network primitives (#1248)
Browse files Browse the repository at this point in the history
  • Loading branch information
refcell authored Sep 6, 2024
1 parent ad0538b commit 122c4b1
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/no_std.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
strategy:
fail-fast: false
matrix:
crate: ["alloy-eips", "alloy-consensus", "alloy-genesis"]
crate: ["alloy-eips", "alloy-consensus", "alloy-genesis", "alloy-network-primitives"]
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ auto_impl = "1.2"
base64 = "0.22"
bimap = "0.6"
home = "0.5"
itertools = "0.13"
itertools = { version = "0.13", default-features = false }
once_cell = { version = "1.19", default-features = false }
pin-project = "1.1"
rand = "0.8"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ When updating this, also update:
- .github/workflows/ci.yml
-->

The current MSRV (minimum supported rust version) is 1.78.
The current MSRV (minimum supported rust version) is 1.79.

Alloy will keep a rolling MSRV policy of **at least** two versions behind the
latest stable release (so if the latest stable release is 1.58, we would
Expand Down
4 changes: 4 additions & 0 deletions crates/network-primitives/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,7 @@ serde.workspace = true

[dev-dependencies]
rand.workspace = true

[features]
default = ["std"]
std = ["alloy-primitives/std"]
12 changes: 8 additions & 4 deletions crates/network-primitives/src/block.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
use alloy_primitives::B256;
use serde::{Deserialize, Serialize};

use alloc::{vec, vec::Vec};
use core::slice;

use crate::TransactionResponse;

/// Block Transactions depending on the boolean attribute of `eth_getBlockBy*`,
Expand Down Expand Up @@ -69,10 +72,10 @@ impl<T> BlockTransactions<T> {

/// Returns an iterator over the transactions (if any). This will be empty if the block is not
/// full.
pub fn into_transactions(self) -> std::vec::IntoIter<T> {
pub fn into_transactions(self) -> vec::IntoIter<T> {
match self {
Self::Full(txs) => txs.into_iter(),
_ => std::vec::IntoIter::default(),
_ => vec::IntoIter::default(),
}
}

Expand Down Expand Up @@ -149,8 +152,8 @@ pub struct BlockTransactionHashes<'a, T>(BlockTransactionHashesInner<'a, T>);

#[derive(Clone, Debug)]
enum BlockTransactionHashesInner<'a, T> {
Hashes(std::slice::Iter<'a, B256>),
Full(std::slice::Iter<'a, T>),
Hashes(slice::Iter<'a, B256>),
Full(slice::Iter<'a, T>),
Uncle,
}

Expand Down Expand Up @@ -209,6 +212,7 @@ impl<T: TransactionResponse> DoubleEndedIterator for BlockTransactionHashes<'_,
}
}

#[cfg(feature = "std")]
impl<'a, T: TransactionResponse> std::iter::FusedIterator for BlockTransactionHashes<'a, T> {}

/// Determines how the `transactions` field of block should be filled.
Expand Down
3 changes: 3 additions & 0 deletions crates/network-primitives/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
)]
#![cfg_attr(not(test), warn(unused_crate_dependencies))]
#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]
#![cfg_attr(not(feature = "std"), no_std)]

extern crate alloc;

mod traits;
pub use traits::{BlockResponse, HeaderResponse, ReceiptResponse, TransactionResponse};
Expand Down
4 changes: 2 additions & 2 deletions crates/rpc-types-eth/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ alloy-rlp = { workspace = true, features = ["arrayvec", "derive"] }
alloy-primitives = { workspace = true, features = ["rlp", "serde", "std"] }
alloy-serde.workspace = true

alloy-consensus = { workspace = true, features = ["std", "serde"] }
alloy-eips = { workspace = true, features = ["std", "serde"] }
alloy-consensus = { workspace = true, features = ["serde", "std"] }
alloy-eips = { workspace = true, features = ["serde", "std"] }

alloy-network-primitives.workspace = true

Expand Down

0 comments on commit 122c4b1

Please sign in to comment.