Skip to content
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
9 changes: 7 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,13 @@ collection_is_never_read = "warn"
dbg_macro = "warn"
empty_line_after_doc_comments = "warn"
empty_line_after_outer_attr = "warn"
enum_glob_use = "warn"
explicit_into_iter_loop = "warn"
explicit_iter_loop = "warn"
from_iter_instead_of_collect = "warn"
if_then_some_else_none = "warn"
implicit_clone = "warn"
if_not_else = "warn"
imprecise_flops = "warn"
iter_on_empty_collections = "warn"
iter_with_drain = "warn"
Expand All @@ -66,13 +71,15 @@ nonstandard_macro_braces = "warn"
path_buf_push_overwrite = "warn"
read_zero_byte_vec = "warn"
redundant_clone = "warn"
single_char_pattern = "warn"
redundant_else = "warn"
string_lit_chars_any = "warn"
suboptimal_flops = "warn"
suspicious_operation_groupings = "warn"
transmute_undefined_repr = "warn"
uninhabited_references = "warn"
uninlined_format_args = "warn"
unnested_or_patterns = "warn"
unused_rounding = "warn"
use_self = "warn"
while_float = "warn"
Expand All @@ -92,8 +99,6 @@ significant_drop_tightening = "allow"
too_long_first_doc_paragraph = "allow"

# Specific allows.
# until <https://github.com/rust-lang/rust-clippy/issues/13885> is fixed
literal_string_with_formatting_args = "allow"
result_large_err = "allow"

[workspace.lints.rust]
Expand Down
6 changes: 3 additions & 3 deletions benches/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,13 +175,13 @@ impl BenchmarkProject {
.status()
.wrap_err("Failed to run npm install")?;

if !status.success() {
if status.success() {
sh_println!(" ✅ npm install completed successfully");
} else {
sh_println!(
" ⚠️ Warning: npm install failed with exit code: {:?}",
status.code()
);
} else {
sh_println!(" ✅ npm install completed successfully");
}
}
Ok(())
Expand Down
2 changes: 1 addition & 1 deletion crates/anvil/src/eth/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ impl<N: Network> EthApi<N> {
}
})
.unwrap_or_default(),
network: if self.backend.is_tempo() { Some("tempo".to_string()) } else { None },
network: self.backend.is_tempo().then(|| "tempo".to_string()),
})
}

Expand Down
4 changes: 2 additions & 2 deletions crates/anvil/src/eth/backend/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ pub trait Db:

/// Deserialize and add all chain data to the backend storage
fn load_state(&mut self, state: SerializableState) -> DatabaseResult<bool> {
for (addr, account) in state.accounts.into_iter() {
for (addr, account) in state.accounts {
let old_account_nonce = DatabaseRef::basic_ref(self, addr)
.ok()
.and_then(|acc| acc.map(|acc| acc.nonce))
Expand All @@ -250,7 +250,7 @@ pub trait Db:
},
);

for (k, v) in account.storage.into_iter() {
for (k, v) in account.storage {
self.set_storage_at(addr, k, v)?;
}
}
Expand Down
8 changes: 3 additions & 5 deletions crates/anvil/src/eth/backend/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -436,13 +436,11 @@ where
trace!(target: "backend", ?exit_reason, ?gas_used, "[{:?}] executed with out={:?}", pool_tx.hash(), out);
trace!(target: "backend::executor", "transacted [{:?}], result: {:?} gas {}", pool_tx.hash(), exit_reason, gas_used);

let contract_address = if pending.transaction.to().is_none() {
let contract_address = pending.transaction.to().is_none().then(|| {
let addr = sender.create(nonce);
trace!(target: "backend", "Contract creation tx: computed address {:?}", addr);
Some(addr)
} else {
None
};
addr
});

// TODO: replace `TransactionInfo` with alloy receipt/transaction types
let transaction_index = tx_info.len() as u64;
Expand Down
29 changes: 9 additions & 20 deletions crates/anvil/src/eth/backend/mem/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1384,11 +1384,7 @@ impl<N: Network> Backend<N> {
gas_priority_fee: max_priority_fee_per_gas,
max_fee_per_blob_gas: max_fee_per_blob_gas
.or_else(|| {
if !blob_hashes.is_empty() {
evm_env.block_env.blob_gasprice()
} else {
Some(0)
}
if blob_hashes.is_empty() { Some(0) } else { evm_env.block_env.blob_gasprice() }
})
.unwrap_or_default(),
kind: match to {
Expand Down Expand Up @@ -1434,7 +1430,7 @@ impl<N: Network> Backend<N> {
let mut inspector = self.build_inspector();

// Extract Tempo-specific fields before `build_call_env` consumes `other`.
let tempo_overrides = if self.is_tempo() {
let tempo_overrides = self.is_tempo().then(|| {
let fee_token =
request.other.get_deserialized::<Address>("feeToken").and_then(|r| r.ok());
let nonce_key = request
Expand All @@ -1444,10 +1440,8 @@ impl<N: Network> Backend<N> {
.unwrap_or_default();
let valid_before =
request.other.get_deserialized::<u64>("validBefore").and_then(|r| r.ok());
Some((fee_token, nonce_key, valid_before))
} else {
None
};
(fee_token, nonce_key, valid_before)
});

let (evm_env, tx_env) = self.build_call_env(request, fee_details, block_env);

Expand Down Expand Up @@ -2173,7 +2167,7 @@ impl<N: Network> Backend<N> {
}

// Clear all storage and reinitialize with genesis
let base_fee = if self.fees.is_eip1559() { Some(self.fees.base_fee()) } else { None };
let base_fee = self.fees.is_eip1559().then(|| self.fees.base_fee());
*self.blockchain.storage.write() = BlockchainStorage::new(
&self.evm_env.read(),
base_fee,
Expand Down Expand Up @@ -2503,8 +2497,7 @@ where
let mix_hash = evm_env.block_env.prevrandao;
let beneficiary = evm_env.block_env.beneficiary;
let timestamp = evm_env.block_env.timestamp;
let base_fee =
if spec_id >= SpecId::LONDON { Some(evm_env.block_env.basefee) } else { None };
let base_fee = (spec_id >= SpecId::LONDON).then_some(evm_env.block_env.basefee);
let excess_blob_gas =
if is_cancun { evm_env.block_env.blob_excess_gas() } else { None };

Expand Down Expand Up @@ -2746,8 +2739,7 @@ where
let mix_hash = evm_env.block_env.prevrandao;
let beneficiary = evm_env.block_env.beneficiary;
let timestamp = evm_env.block_env.timestamp;
let base_fee =
if spec_id >= SpecId::LONDON { Some(evm_env.block_env.basefee) } else { None };
let base_fee = (spec_id >= SpecId::LONDON).then_some(evm_env.block_env.basefee);
let excess_blob_gas = if is_cancun { evm_env.block_env.blob_excess_gas() } else { None };

let inspector_tx_config = self.inspector_tx_config();
Expand Down Expand Up @@ -3718,11 +3710,8 @@ impl<N: Network<ReceiptEnvelope = FoundryReceiptEnvelope>> Backend<N> {
let best_number = self.blockchain.storage.read().best_number;
let blocks = self.blockchain.storage.read().serialized_blocks();
let transactions = self.blockchain.storage.read().serialized_transactions();
let historical_states = if preserve_historical_states {
Some(self.states.write().serialized_states())
} else {
None
};
let historical_states =
preserve_historical_states.then(|| self.states.write().serialized_states());

let state = self.db.read().await.dump_state(
at,
Expand Down
2 changes: 1 addition & 1 deletion crates/anvil/src/eth/fees.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ impl FeeManager {
}

pub fn excess_blob_gas_and_price(&self) -> Option<BlobExcessGasAndPrice> {
if self.is_eip4844() { Some(*self.blob_excess_gas_and_price.read()) } else { None }
self.is_eip4844().then(|| *self.blob_excess_gas_and_price.read())
}

pub fn base_fee_per_blob_gas(&self) -> u128 {
Expand Down
6 changes: 1 addition & 5 deletions crates/anvil/src/eth/pool/transactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -515,11 +515,7 @@ impl<T> ReadyTransactions<T> {
if let Some(idx) = tx2.unlocks.iter().position(|i| i == &hash) {
tx2.unlocks.swap_remove(idx);
}
if tx2.unlocks.is_empty() {
Some(tx2.transaction.transaction.provides.clone())
} else {
None
}
tx2.unlocks.is_empty().then(|| tx2.transaction.transaction.provides.clone())
};

// find previous transactions
Expand Down
8 changes: 4 additions & 4 deletions crates/anvil/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -465,15 +465,15 @@ pub fn init_tracing() -> LoggingManager {
let manager = LoggingManager::default();

let _ = if let Ok(rust_log_val) = std::env::var("RUST_LOG")
&& !rust_log_val.contains("=")
&& !rust_log_val.contains('=')
{
// Mutate the given filter to include `node` logs if it is not already present.
// This prevents the unexpected behaviour of not seeing any node logs if a RUST_LOG
// is already present that doesn't set it.
let rust_log_val = if !rust_log_val.contains("node") {
format!("{rust_log_val},node=info")
} else {
let rust_log_val = if rust_log_val.contains("node") {
rust_log_val
} else {
format!("{rust_log_val},node=info")
};

let env_filter: EnvFilter =
Expand Down
6 changes: 3 additions & 3 deletions crates/cast/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,10 +195,10 @@ pub async fn run_command(args: CastArgs) -> Result<()> {
print_tokens(&tokens);
}
CastSubcommand::AbiEncode { sig, packed, args } => {
if !packed {
sh_println!("{}", SimpleCast::abi_encode(&sig, &args)?)?
} else {
if packed {
sh_println!("{}", SimpleCast::abi_encode_packed(&sig, &args)?)?
} else {
sh_println!("{}", SimpleCast::abi_encode(&sig, &args)?)?
}
}
CastSubcommand::AbiEncodeEvent { sig, args } => {
Expand Down
6 changes: 2 additions & 4 deletions crates/cast/src/cmd/batch_mktx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::{
use alloy_consensus::SignableTransaction;
use alloy_eips::eip2718::Encodable2718;
use alloy_network::{EthereumWallet, TransactionBuilder};
use alloy_primitives::{Address, Bytes, U256};
use alloy_primitives::{Address, Bytes};
use alloy_provider::Provider;
use alloy_signer::Signer;
use clap::Parser;
Expand Down Expand Up @@ -115,9 +115,7 @@ impl BatchMakeTxArgs {
// Set dummy "to" from first call
let first_call_to = call_specs.first().map(|s| s.to);
let builder = builder.with_to(first_call_to.map(Into::into)).await?;
let mut tx_builder = builder.with_code_sig_and_args(None, None, vec![]).await?;
tx_builder.tx.clear_kind();
tx_builder.tx.set_value(U256::ZERO);
let tx_builder = builder.with_code_sig_and_args(None, None, vec![]).await?;

if raw_unsigned {
if eth.wallet.from.is_none() && !has_nonce {
Expand Down
8 changes: 3 additions & 5 deletions crates/cast/src/cmd/batch_send.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ use crate::{
cmd::send::cast_send,
tx::{self, CastTxBuilder, CastTxSender, SendTxOpts},
};
use alloy_network::{EthereumWallet, TransactionBuilder};
use alloy_primitives::{Bytes, U256};
use alloy_network::EthereumWallet;
use alloy_primitives::Bytes;
use alloy_provider::{Provider, ProviderBuilder as AlloyProviderBuilder};
use alloy_signer::Signer;
use clap::Parser;
Expand Down Expand Up @@ -119,9 +119,7 @@ impl BatchSendArgs {
let builder = builder.with_to(first_call_to.map(Into::into)).await?;

// Use empty sig/args since we're using calls directly
let mut builder = builder.with_code_sig_and_args(None, None, vec![]).await?;
builder.tx.clear_kind();
builder.tx.set_value(U256::ZERO);
let builder = builder.with_code_sig_and_args(None, None, vec![]).await?;

let timeout = send_tx.timeout.unwrap_or(config.transaction_timeout);

Expand Down
2 changes: 1 addition & 1 deletion crates/cast/src/cmd/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ impl InterfaceArgs {
};

// Build config for to_sol conversion.
let config = if flatten { Some(ToSolConfig::new().one_contract(true)) } else { None };
let config = flatten.then(|| ToSolConfig::new().one_contract(true));

// Retrieve interfaces from the array of ABIs.
let interfaces = get_interfaces(abis, config)?;
Expand Down
34 changes: 17 additions & 17 deletions crates/cast/src/cmd/keychain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,9 @@ async fn run_check(wallet_address: Address, key_address: Address, rpc: RpcOpts)

// Expiry: show human-readable date and whether it's expired.
let expiry_str = format_expiry(info.expiry);
if info.expiry != u64::MAX {
if info.expiry == u64::MAX {
sh_println!("Expiry: {}", expiry_str)?;
} else {
let now = std::time::SystemTime::now()
.duration_since(std::time::UNIX_EPOCH)
.unwrap_or_default()
Expand All @@ -556,8 +558,6 @@ async fn run_check(wallet_address: Address, key_address: Address, rpc: RpcOpts)
} else {
sh_println!("Expiry: {}", expiry_str)?;
}
} else {
sh_println!("Expiry: {}", expiry_str)?;
}

sh_println!("Spending Limits: {}", if info.enforceLimits { "enforced" } else { "none" })?;
Expand All @@ -579,7 +579,17 @@ async fn run_authorize(
) -> Result<()> {
let enforce = enforce_limits || !limits.is_empty();

let calldata = if !allowed_calls.is_empty() {
let calldata = if allowed_calls.is_empty() {
// Use the legacy authorizeKey when no scopes are needed.
IAccountKeychain::authorizeKeyCall {
keyId: key_address,
signatureType: key_type,
expiry,
enforceLimits: enforce,
limits,
}
.abi_encode()
} else {
// Use the T3+ authorizeKey overload with KeyRestrictions when scopes are provided.
let sig_type_u8 = match key_type {
SignatureType::Secp256k1 => 0u8,
Expand All @@ -603,16 +613,6 @@ async fn run_authorize(
config: restrictions,
}
.abi_encode()
} else {
// Use the legacy authorizeKey when no scopes are needed.
IAccountKeychain::authorizeKeyCall {
keyId: key_address,
signatureType: key_type,
expiry,
enforceLimits: enforce,
limits,
}
.abi_encode()
};

send_keychain_tx(calldata, tx_opts, &send_tx).await
Expand Down Expand Up @@ -783,10 +783,10 @@ fn print_key_entry(entry: &tempo::KeyEntry) -> Result<()> {
if let Some(key_address) = entry.key_address {
sh_println!("Key Address: {key_address}")?;

if key_address != entry.wallet_address {
sh_println!("Mode: keychain (access key)")?;
} else {
if key_address == entry.wallet_address {
sh_println!("Mode: direct (EOA)")?;
} else {
sh_println!("Mode: keychain (access key)")?;
}
} else {
sh_println!("Key Address: (not set)")?;
Expand Down
2 changes: 1 addition & 1 deletion crates/cast/src/cmd/wallet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ impl WalletSubcommands {
Self::New { path, account_name, unsafe_password, number, password, force } => {
let mut rng = thread_rng();

let mut json_values = if shell::is_json() { Some(vec![]) } else { None };
let mut json_values = shell::is_json().then(std::vec::Vec::new);

let path = if let Some(path) = path {
match dunce::canonicalize(&path) {
Expand Down
5 changes: 5 additions & 0 deletions crates/cast/src/tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,11 @@ where
let sender = sender.into();
self.prepare(&sender);

// For batch transactions with calls, clear `to` and `value` so the node correctly
// identifies this as an AA batch transaction. The `calls` field determines the actual
// targets. If `to` is set, `build_aa()` would add a spurious extra call.
self.tx.clear_batch_to();

// resolve
let tx_nonce = self.resolve_nonce(sender.address(), fill).await?;
self.resolve_auth(&sender, tx_nonce).await?;
Expand Down
2 changes: 1 addition & 1 deletion crates/cast/tests/cli/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3977,7 +3977,7 @@ Error: Failed to estimate gas: server returned an error response: error code 3:

// <https://basescan.org/block/30558838>
casttest!(estimate_base_da, |_prj, cmd| {
cmd.args(["da-estimate", "30558838", "--rpc-url", "https://mainnet.base.org/"])
cmd.args(["da-estimate", "30558838", "-r", "https://mainnet.base.org/"])
.assert_success()
.stdout_eq(str![[r#"
Estimated data availability size for block 30558838 with 225 transactions: 52916546100
Expand Down
2 changes: 1 addition & 1 deletion crates/cheatcodes/src/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,7 @@ fn get_artifact_code<FEN: FoundryEvmNetwork>(
// Try filtering by profile as well
filtered.retain(|(id, _)| id.profile == running.profile);

if filtered.len() == 1 { Some(filtered[0]) } else { None }
(filtered.len() == 1).then(|| filtered[0])
})
.ok_or_else(|| fmt_err!("multiple matching artifacts found")),
)
Expand Down
Loading
Loading