Skip to content

Commit 710a158

Browse files
chore: bump to rust edition 2024 (#10802)
* 1 shot * apply minimal fixes * unpin rustfmt nightly * fix clippy * fix clippy * fixes * name * fmts * clippy --fix * cargo fmt * update rustfmt config to be inline with other projects since we're formatting anyway * cargo fmt again --------- Co-authored-by: DaniPopes <[email protected]>
1 parent 9ec0299 commit 710a158

File tree

369 files changed

+2456
-2421
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

369 files changed

+2456
-2421
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ resolver = "2"
2929

3030
[workspace.package]
3131
version = "1.2.3"
32-
edition = "2021"
32+
edition = "2024"
3333
# Remember to update clippy.toml as well
3434
rust-version = "1.87"
3535
authors = ["Foundry Contributors"]

crates/anvil/core/src/eth/block.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use super::transaction::{TransactionInfo, TypedReceipt};
2-
use alloy_consensus::{proofs::calculate_transaction_root, Header, EMPTY_OMMER_ROOT_HASH};
3-
use alloy_primitives::{Address, Bloom, Bytes, B256, B64, U256};
2+
use alloy_consensus::{EMPTY_OMMER_ROOT_HASH, Header, proofs::calculate_transaction_root};
3+
use alloy_primitives::{Address, B64, B256, Bloom, Bytes, U256};
44
use alloy_rlp::{RlpDecodable, RlpEncodable};
55

66
// Type alias to optionally support impersonated transactions

crates/anvil/core/src/eth/mod.rs

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use crate::{eth::subscription::SubscriptionId, types::ReorgOptions};
2-
use alloy_primitives::{Address, Bytes, TxHash, B256, B64, U256};
2+
use alloy_primitives::{Address, B64, B256, Bytes, TxHash, U256};
33
use alloy_rpc_types::{
4+
BlockId, BlockNumberOrTag as BlockNumber, BlockOverrides, Filter, Index,
45
anvil::{Forking, MineOptions},
56
pubsub::{Params as SubscriptionParams, SubscriptionKind},
67
request::TransactionRequest,
@@ -10,7 +11,6 @@ use alloy_rpc_types::{
1011
filter::TraceFilter,
1112
geth::{GethDebugTracingCallOptions, GethDebugTracingOptions},
1213
},
13-
BlockId, BlockNumberOrTag as BlockNumber, BlockOverrides, Filter, Index,
1414
};
1515
use alloy_serde::WithOtherFields;
1616
use foundry_common::serde_helpers::{
@@ -331,23 +331,15 @@ pub enum EthRequest {
331331
SetAutomine(bool),
332332

333333
/// Sets the mining behavior to interval with the given interval (seconds)
334-
#[serde(
335-
rename = "anvil_setIntervalMining",
336-
alias = "evm_setIntervalMining",
337-
with = "sequence"
338-
)]
334+
#[serde(rename = "anvil_setIntervalMining", alias = "evm_setIntervalMining", with = "sequence")]
339335
SetIntervalMining(u64),
340336

341337
/// Gets the current mining behavior
342338
#[serde(rename = "anvil_getIntervalMining", with = "empty_params")]
343339
GetIntervalMining(()),
344340

345341
/// Removes transactions from the pool
346-
#[serde(
347-
rename = "anvil_dropTransaction",
348-
alias = "hardhat_dropTransaction",
349-
with = "sequence"
350-
)]
342+
#[serde(rename = "anvil_dropTransaction", alias = "hardhat_dropTransaction", with = "sequence")]
351343
DropTransaction(B256),
352344

353345
/// Removes transactions from the pool

crates/anvil/core/src/eth/serde_helpers.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
pub mod sequence {
44
use serde::{
5-
de::DeserializeOwned, ser::SerializeSeq, Deserialize, Deserializer, Serialize, Serializer,
5+
Deserialize, Deserializer, Serialize, Serializer, de::DeserializeOwned, ser::SerializeSeq,
66
};
77

88
pub fn serialize<S, T>(val: &T, s: S) -> Result<S::Ok, S::Error>
@@ -25,7 +25,7 @@ pub mod sequence {
2525
return Err(serde::de::Error::custom(format!(
2626
"expected params sequence with length 1 but got {}",
2727
seq.len()
28-
)))
28+
)));
2929
}
3030
Ok(seq.remove(0))
3131
}
@@ -44,7 +44,7 @@ pub mod empty_params {
4444
return Err(serde::de::Error::custom(format!(
4545
"expected params sequence with length 0 but got {}",
4646
seq.len()
47-
)))
47+
)));
4848
}
4949
Ok(())
5050
}

crates/anvil/core/src/eth/subscription.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! Subscription types
22
use alloy_primitives::hex;
3-
use rand::{distr::Alphanumeric, rng, Rng};
3+
use rand::{Rng, distr::Alphanumeric, rng};
44
use std::fmt;
55

66
/// Unique subscription id
@@ -46,7 +46,7 @@ pub struct HexIdProvider {
4646

4747
impl HexIdProvider {
4848
/// Generates a random hex encoded Id
49-
pub fn gen(&self) -> String {
49+
pub fn generate(&self) -> String {
5050
let id: String =
5151
(&mut rng()).sample_iter(Alphanumeric).map(char::from).take(self.len).collect();
5252
let out = hex::encode(id);
@@ -62,5 +62,5 @@ impl Default for HexIdProvider {
6262

6363
/// Returns a new random hex identifier
6464
pub fn hex_id() -> String {
65-
HexIdProvider::default().gen()
65+
HexIdProvider::default().generate()
6666
}

crates/anvil/core/src/eth/transaction/mod.rs

Lines changed: 44 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
11
//! Transaction related types
22
use alloy_consensus::{
3+
Receipt, ReceiptEnvelope, ReceiptWithBloom, Signed, Transaction, TxEip1559, TxEip2930,
4+
TxEnvelope, TxLegacy, TxReceipt, Typed2718,
35
transaction::{
4-
eip4844::{TxEip4844, TxEip4844Variant, TxEip4844WithSidecar},
56
Recovered, TxEip7702,
7+
eip4844::{TxEip4844, TxEip4844Variant, TxEip4844WithSidecar},
68
},
7-
Receipt, ReceiptEnvelope, ReceiptWithBloom, Signed, Transaction, TxEip1559, TxEip2930,
8-
TxEnvelope, TxLegacy, TxReceipt, Typed2718,
99
};
1010
use alloy_eips::eip2718::{Decodable2718, Eip2718Error, Encodable2718};
1111
use alloy_network::{AnyReceiptEnvelope, AnyRpcTransaction, AnyTransactionReceipt, AnyTxEnvelope};
12-
use alloy_primitives::{Address, Bloom, Bytes, Log, Signature, TxHash, TxKind, B256, U256, U64};
13-
use alloy_rlp::{length_of_length, Decodable, Encodable, Header};
12+
use alloy_primitives::{Address, B256, Bloom, Bytes, Log, Signature, TxHash, TxKind, U64, U256};
13+
use alloy_rlp::{Decodable, Encodable, Header, length_of_length};
1414
use alloy_rpc_types::{
15-
request::TransactionRequest, trace::otterscan::OtsReceipt, AccessList, ConversionError,
16-
Transaction as RpcTransaction, TransactionReceipt,
15+
AccessList, ConversionError, Transaction as RpcTransaction, TransactionReceipt,
16+
request::TransactionRequest, trace::otterscan::OtsReceipt,
1717
};
1818
use alloy_serde::{OtherFields, WithOtherFields};
1919
use bytes::BufMut;
2020
use foundry_evm::traces::CallTraceNode;
21-
use op_alloy_consensus::{TxDeposit, DEPOSIT_TX_TYPE_ID};
22-
use op_revm::{transaction::deposit::DepositTransactionParts, OpTransaction};
21+
use op_alloy_consensus::{DEPOSIT_TX_TYPE_ID, TxDeposit};
22+
use op_revm::{OpTransaction, transaction::deposit::DepositTransactionParts};
2323
use revm::{context::TxEnv, interpreter::InstructionResult};
2424
use serde::{Deserialize, Serialize};
2525
use std::ops::{Deref, Mul};
@@ -97,8 +97,8 @@ pub fn transaction_request_to_typed(
9797
to,
9898
) {
9999
// legacy transaction
100-
(Some(0), _, None, None, None, None, None, None, _) |
101-
(None, Some(_), None, None, None, None, None, None, _) => {
100+
(Some(0), _, None, None, None, None, None, None, _)
101+
| (None, Some(_), None, None, None, None, None, None, _) => {
102102
Some(TypedTransactionRequest::Legacy(TxLegacy {
103103
nonce: nonce.unwrap_or_default(),
104104
gas_price: gas_price.unwrap_or_default(),
@@ -110,8 +110,8 @@ pub fn transaction_request_to_typed(
110110
}))
111111
}
112112
// EIP2930
113-
(Some(1), _, None, None, _, None, None, None, _) |
114-
(None, _, None, None, Some(_), None, None, None, _) => {
113+
(Some(1), _, None, None, _, None, None, None, _)
114+
| (None, _, None, None, Some(_), None, None, None, _) => {
115115
Some(TypedTransactionRequest::EIP2930(TxEip2930 {
116116
nonce: nonce.unwrap_or_default(),
117117
gas_price: gas_price.unwrap_or_default(),
@@ -124,10 +124,10 @@ pub fn transaction_request_to_typed(
124124
}))
125125
}
126126
// EIP1559
127-
(Some(2), None, _, _, _, _, None, None, _) |
128-
(None, None, Some(_), _, _, _, None, None, _) |
129-
(None, None, _, Some(_), _, _, None, None, _) |
130-
(None, None, None, None, None, _, None, None, _) => {
127+
(Some(2), None, _, _, _, _, None, None, _)
128+
| (None, None, Some(_), _, _, _, None, None, _)
129+
| (None, None, _, Some(_), _, _, None, None, _)
130+
| (None, None, None, None, None, _, None, None, _) => {
131131
// Empty fields fall back to the canonical transaction schema.
132132
Some(TypedTransactionRequest::EIP1559(TxEip1559 {
133133
nonce: nonce.unwrap_or_default(),
@@ -173,9 +173,9 @@ pub fn transaction_request_to_typed(
173173
}
174174

175175
pub fn has_optimism_fields(other: &OtherFields) -> bool {
176-
other.contains_key("sourceHash") &&
177-
other.contains_key("mint") &&
178-
other.contains_key("isSystemTx")
176+
other.contains_key("sourceHash")
177+
&& other.contains_key("mint")
178+
&& other.contains_key("isSystemTx")
179179
}
180180

181181
#[derive(Clone, Debug, PartialEq, Eq)]
@@ -225,7 +225,7 @@ impl MaybeImpersonatedTransaction {
225225
/// Returns the hash of the transaction
226226
pub fn hash(&self) -> B256 {
227227
if let Some(sender) = self.impersonated_sender {
228-
return self.transaction.impersonated_hash(sender)
228+
return self.transaction.impersonated_hash(sender);
229229
}
230230
self.transaction.hash()
231231
}
@@ -1006,7 +1006,7 @@ impl Encodable2718 for TypedTransaction {
10061006
impl Decodable2718 for TypedTransaction {
10071007
fn typed_decode(ty: u8, buf: &mut &[u8]) -> Result<Self, Eip2718Error> {
10081008
if ty == 0x7E {
1009-
return Ok(Self::Deposit(TxDeposit::decode(buf)?))
1009+
return Ok(Self::Deposit(TxDeposit::decode(buf)?));
10101010
}
10111011
match TxEnvelope::typed_decode(ty, buf)? {
10121012
TxEnvelope::Eip2930(tx) => Ok(Self::EIP2930(tx)),
@@ -1081,12 +1081,12 @@ pub struct DepositReceipt<T = Receipt<alloy_primitives::Log>> {
10811081

10821082
impl DepositReceipt {
10831083
fn payload_len(&self) -> usize {
1084-
self.inner.receipt.status.length() +
1085-
self.inner.receipt.cumulative_gas_used.length() +
1086-
self.inner.logs_bloom.length() +
1087-
self.inner.receipt.logs.length() +
1088-
self.deposit_nonce.map_or(0, |n| n.length()) +
1089-
self.deposit_receipt_version.map_or(0, |n| n.length())
1084+
self.inner.receipt.status.length()
1085+
+ self.inner.receipt.cumulative_gas_used.length()
1086+
+ self.inner.logs_bloom.length()
1087+
+ self.inner.receipt.logs.length()
1088+
+ self.deposit_nonce.map_or(0, |n| n.length())
1089+
+ self.deposit_receipt_version.map_or(0, |n| n.length())
10901090
}
10911091

10921092
/// Returns the rlp header for the receipt payload.
@@ -1186,11 +1186,11 @@ pub enum TypedReceipt<T = Receipt<alloy_primitives::Log>> {
11861186
impl<T> TypedReceipt<T> {
11871187
pub fn as_receipt_with_bloom(&self) -> &ReceiptWithBloom<T> {
11881188
match self {
1189-
Self::Legacy(r) |
1190-
Self::EIP1559(r) |
1191-
Self::EIP2930(r) |
1192-
Self::EIP4844(r) |
1193-
Self::EIP7702(r) => r,
1189+
Self::Legacy(r)
1190+
| Self::EIP1559(r)
1191+
| Self::EIP2930(r)
1192+
| Self::EIP4844(r)
1193+
| Self::EIP7702(r) => r,
11941194
Self::Deposit(r) => &r.inner,
11951195
}
11961196
}
@@ -1199,11 +1199,11 @@ impl<T> TypedReceipt<T> {
11991199
impl<T> From<TypedReceipt<T>> for ReceiptWithBloom<T> {
12001200
fn from(value: TypedReceipt<T>) -> Self {
12011201
match value {
1202-
TypedReceipt::Legacy(r) |
1203-
TypedReceipt::EIP1559(r) |
1204-
TypedReceipt::EIP2930(r) |
1205-
TypedReceipt::EIP4844(r) |
1206-
TypedReceipt::EIP7702(r) => r,
1202+
TypedReceipt::Legacy(r)
1203+
| TypedReceipt::EIP1559(r)
1204+
| TypedReceipt::EIP2930(r)
1205+
| TypedReceipt::EIP4844(r)
1206+
| TypedReceipt::EIP7702(r) => r,
12071207
TypedReceipt::Deposit(r) => r.inner,
12081208
}
12091209
}
@@ -1371,11 +1371,11 @@ impl Encodable2718 for TypedReceipt {
13711371
out.put_u8(ty);
13721372
}
13731373
match self {
1374-
Self::Legacy(r) |
1375-
Self::EIP2930(r) |
1376-
Self::EIP1559(r) |
1377-
Self::EIP4844(r) |
1378-
Self::EIP7702(r) => r.encode(out),
1374+
Self::Legacy(r)
1375+
| Self::EIP2930(r)
1376+
| Self::EIP1559(r)
1377+
| Self::EIP4844(r)
1378+
| Self::EIP7702(r) => r.encode(out),
13791379
Self::Deposit(r) => r.encode(out),
13801380
}
13811381
}
@@ -1463,7 +1463,7 @@ pub fn convert_to_anvil_receipt(receipt: AnyTransactionReceipt) -> Option<Receip
14631463
#[cfg(test)]
14641464
mod tests {
14651465
use super::*;
1466-
use alloy_primitives::{b256, hex, LogData};
1466+
use alloy_primitives::{LogData, b256, hex};
14671467
use std::str::FromStr;
14681468

14691469
// <https://github.com/foundry-rs/foundry/issues/10852>

crates/anvil/core/src/eth/wallet.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use alloy_primitives::{map::HashMap, Address, ChainId, U64};
1+
use alloy_primitives::{Address, ChainId, U64, map::HashMap};
22
use serde::{Deserialize, Serialize};
33

44
/// The capability to perform [EIP-7702][eip-7702] delegations, sponsored by the sequencer.

crates/anvil/server/src/handler.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ use anvil_rpc::{
55
response::{Response, RpcResponse},
66
};
77
use axum::{
8-
extract::{rejection::JsonRejection, State},
98
Json,
9+
extract::{State, rejection::JsonRejection},
1010
};
11-
use futures::{future, FutureExt};
11+
use futures::{FutureExt, future};
1212

1313
/// Handles incoming JSON-RPC Request.
1414
// NOTE: `handler` must come first because the `request` extractor consumes the request body.

crates/anvil/server/src/ipc.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
//! IPC handling
22
3-
use crate::{error::RequestError, pubsub::PubSubConnection, PubSubRpcHandler};
3+
use crate::{PubSubRpcHandler, error::RequestError, pubsub::PubSubConnection};
44
use anvil_rpc::request::Request;
55
use bytes::{BufMut, BytesMut};
6-
use futures::{ready, Sink, Stream, StreamExt};
6+
use futures::{Sink, Stream, StreamExt, ready};
77
use interprocess::local_socket::{self as ls, tokio::prelude::*};
88
use std::{
9-
future::Future,
109
io,
1110
pin::Pin,
1211
task::{Context, Poll},
@@ -159,7 +158,7 @@ impl tokio_util::codec::Decoder for JsonRpcCodec {
159158
return match String::from_utf8(bts.as_ref().to_vec()) {
160159
Ok(val) => Ok(Some(val)),
161160
Err(_) => Ok(None),
162-
}
161+
};
163162
}
164163
}
165164
Ok(None)

crates/anvil/server/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ use anvil_rpc::{
1212
response::{ResponseResult, RpcResponse},
1313
};
1414
use axum::{
15-
extract::DefaultBodyLimit,
16-
http::{header, HeaderValue, Method},
17-
routing::{post, MethodRouter},
1815
Router,
16+
extract::DefaultBodyLimit,
17+
http::{HeaderValue, Method, header},
18+
routing::{MethodRouter, post},
1919
};
2020
use serde::de::DeserializeOwned;
2121
use std::fmt;

0 commit comments

Comments
 (0)