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

chore: fix warnings on no_std #1355

Merged
merged 1 commit into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 2 additions & 1 deletion crates/rpc-types-eth/src/account.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use alloy_primitives::{Address, Bytes, B256, B512, U256};
#![allow(unused_imports)]

use alloc::{string::String, vec::Vec};
use alloy_primitives::{Address, Bytes, B256, B512, U256};

// re-export account type for `eth_getAccount`
pub use alloy_consensus::Account;
Expand Down
4 changes: 1 addition & 3 deletions crates/rpc-types-eth/src/call.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
use crate::{request::TransactionRequest, BlockId, BlockOverrides};
use alloy_primitives::Bytes;

use alloc::{
format,
string::{String, ToString},
vec::Vec,
};
use alloy_primitives::Bytes;

/// Bundle of transactions
#[derive(Clone, Debug, Default, PartialEq, Eq)]
Expand Down
8 changes: 4 additions & 4 deletions crates/rpc-types-eth/src/filter.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::{BlockNumberOrTag, Log as RpcLog, Transaction};
use alloc::{format, string::String, vec::Vec};
use alloc::{string::String, vec::Vec};
use alloy_primitives::{keccak256, Address, BlockHash, Bloom, BloomInput, B256, U256, U64};
use itertools::{EitherOrBoth::*, Itertools};

Expand Down Expand Up @@ -584,15 +584,15 @@ impl serde::Serialize for Filter {
}
}

type RawAddressFilter = ValueOrArray<Option<Address>>;
type RawTopicsFilter = Vec<Option<ValueOrArray<Option<B256>>>>;

#[cfg(feature = "serde")]
impl<'de> serde::Deserialize<'de> for Filter {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: serde::Deserializer<'de>,
{
type RawAddressFilter = ValueOrArray<Option<Address>>;
type RawTopicsFilter = Vec<Option<ValueOrArray<Option<B256>>>>;

struct FilterVisitor;

impl<'de> serde::de::Visitor<'de> for FilterVisitor {
Expand Down
11 changes: 1 addition & 10 deletions crates/rpc-types-eth/src/index.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
use alloc::{format, string::String};
use alloy_primitives::U256;
use core::fmt;

/// A hex encoded or decimal index that's intended to be used as a rust index, hence it's
/// deserialized into a `usize`.
Expand Down Expand Up @@ -46,7 +44,7 @@ impl<'a> serde::Deserialize<'a> for Index {
impl<'a> serde::de::Visitor<'a> for IndexVisitor {
type Value = Index;

fn expecting(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
fn expecting(&self, formatter: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(formatter, "hex-encoded or decimal index")
}

Expand Down Expand Up @@ -76,13 +74,6 @@ impl<'a> serde::Deserialize<'a> for Index {
},
)
}

fn visit_string<E>(self, value: String) -> Result<Self::Value, E>
where
E: serde::de::Error,
{
self.visit_str(value.as_ref())
}
}

deserializer.deserialize_any(IndexVisitor)
Expand Down
2 changes: 2 additions & 0 deletions crates/rpc-types-eth/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]
#![cfg_attr(not(any(test, feature = "std")), no_std)]

#[macro_use]
#[allow(unused_imports)]
extern crate alloc;

/// Standardized collections across `std` and `no_std` environments.
Expand Down
7 changes: 3 additions & 4 deletions crates/rpc-types-eth/src/transaction/receipt.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
use crate::Log;
use alloy_consensus::{AnyReceiptEnvelope, ReceiptEnvelope, TxReceipt, TxType};
use alloc::vec::Vec;
use alloy_consensus::{ReceiptEnvelope, TxReceipt, TxType};
use alloy_eips::eip7702::SignedAuthorization;
use alloy_network_primitives::ReceiptResponse;
use alloy_primitives::{Address, BlockHash, TxHash, B256};

use alloc::vec::Vec;

/// Transaction receipt
///
/// This type is generic over an inner [`ReceiptEnvelope`] which contains
Expand Down Expand Up @@ -145,7 +144,7 @@ impl<T> TransactionReceipt<T> {
#[doc(alias = "AnyTxReceipt")]
#[cfg(feature = "serde")]
pub type AnyTransactionReceipt =
alloy_serde::WithOtherFields<TransactionReceipt<AnyReceiptEnvelope<Log>>>;
alloy_serde::WithOtherFields<TransactionReceipt<alloy_consensus::AnyReceiptEnvelope<Log>>>;

impl<T: TxReceipt<Log>> ReceiptResponse for TransactionReceipt<T> {
fn contract_address(&self) -> Option<Address> {
Expand Down
7 changes: 3 additions & 4 deletions crates/rpc-types-eth/src/transaction/signature.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
//! Signature related RPC values
use alloy_primitives::U256;
//! Signature related RPC values.

use alloc::{format, string::String};
use alloy_primitives::U256;

/// Container type for all signature fields in RPC
#[cfg_attr(any(test, feature = "arbitrary"), derive(arbitrary::Arbitrary))]
Expand Down Expand Up @@ -64,7 +63,7 @@ where
D: serde::Deserializer<'de>,
{
use serde::Deserialize;
let s = String::deserialize(deserializer)?;
let s = alloc::string::String::deserialize(deserializer)?;
match s.as_str() {
"0x0" => Ok(false),
"0x1" => Ok(true),
Expand Down
11 changes: 4 additions & 7 deletions crates/rpc-types-eth/src/work.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use alloy_primitives::{B256, U256};
use core::fmt;
use alloy_primitives::B256;

/// The result of an `eth_getWork` request
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
Expand All @@ -20,10 +19,8 @@ impl serde::Serialize for Work {
where
S: serde::Serializer,
{
match self.number.as_ref() {
Some(num) => {
(&self.pow_hash, &self.seed_hash, &self.target, U256::from(*num)).serialize(s)
}
match self.number.map(alloy_primitives::U64::from) {
Some(num) => (&self.pow_hash, &self.seed_hash, &self.target, num).serialize(s),
None => (&self.pow_hash, &self.seed_hash, &self.target).serialize(s),
}
}
Expand All @@ -40,7 +37,7 @@ impl<'a> serde::Deserialize<'a> for Work {
impl<'a> serde::de::Visitor<'a> for WorkVisitor {
type Value = Work;

fn expecting(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
fn expecting(&self, formatter: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(formatter, "Work object")
}

Expand Down