From 4977c21f4e6a1b13ddc58bd4b4b91bcd3f10f454 Mon Sep 17 00:00:00 2001 From: lcfr Date: Fri, 10 Jan 2025 15:36:05 -0500 Subject: [PATCH] fix warnings/redudant imports/conversions --- .../providers/examples/mempool_tracecall.rs | 12 ++-- examples/providers/examples/trace_block.rs | 39 +++++-------- .../examples/tx_hash_miner_data.rs | 57 ++++++++----------- .../examples/tx_hash_miner_fee.rs | 27 +++------ .../examples/tx_hash_miner_gas.rs | 35 +++++------- .../examples/tx_hash_miner_priority.rs | 26 +++------ 6 files changed, 71 insertions(+), 125 deletions(-) diff --git a/examples/providers/examples/mempool_tracecall.rs b/examples/providers/examples/mempool_tracecall.rs index 2fb13fd..5914ce6 100644 --- a/examples/providers/examples/mempool_tracecall.rs +++ b/examples/providers/examples/mempool_tracecall.rs @@ -1,8 +1,7 @@ -//! Example of using trace_call on pending transactions. - +//! Example of using `trace_call` on pending transactions. use alloy::{ - providers::{ext::TraceApi, ProviderBuilder, Provider, WsConnect}, - rpc::types::{trace::parity::TraceType}, + providers::{ext::TraceApi, Provider, ProviderBuilder, WsConnect}, + rpc::types::trace::parity::TraceType, }; use eyre::Result; @@ -23,13 +22,12 @@ async fn main() -> Result<()> { let handle = tokio::spawn(async move { while let Some(tx) = stream.next().await { - let trace_type = [TraceType::Trace]; + let trace_type = [TraceType::Trace]; let result = provider.trace_call(&tx.into(), &trace_type).await; println!("{:?}", result.unwrap().trace); - } + } }); handle.await?; Ok(()) } - diff --git a/examples/providers/examples/trace_block.rs b/examples/providers/examples/trace_block.rs index b76d7e3..7f007cd 100644 --- a/examples/providers/examples/trace_block.rs +++ b/examples/providers/examples/trace_block.rs @@ -1,9 +1,7 @@ -//! Example of using trace_block to examine transactions of the latest block. - +//! Example of using `trace_block` to examine transactions of the latest block. use alloy::{ providers::{ext::TraceApi, Provider, ProviderBuilder, WsConnect}, - rpc::types::trace::parity::{Action, TraceOutput}, - rpc::types::{BlockId, BlockNumberOrTag}, + rpc::types::{trace::parity::Action, BlockId, BlockNumberOrTag}, }; use eyre::Result; @@ -11,38 +9,27 @@ use futures_util::StreamExt; #[tokio::main] async fn main() -> Result<()> { - let ws_url = "wss://eth-mainnet.g.alchemy.com/v2/your-api-key"; - + //let ws_url = "wss://eth-mainnet.g.alchemy.com/v2/your-api-key"; + let ws_url = "ws://10.0.0.145:8546"; let ws = WsConnect::new(ws_url); let provider = ProviderBuilder::new().on_ws(ws).await?; - let subscription = provider.subscribe_blocks().await?; let mut stream = subscription.into_stream(); while let Some(block) = stream.next().await { - println!( - "Received block number: {}", - block.inner.number - ); + println!("Received block number: {}", block.inner.number); - let traces = provider.trace_block( - BlockId::Number( - BlockNumberOrTag::Number( - block.inner.number - ) - ) - ).await?; + let traces = provider + .trace_block(BlockId::Number(BlockNumberOrTag::Number(block.inner.number))) + .await?; for trace in traces { - match trace.trace.action { - Action::Call(tx) => { - if tx.input.0.len() < 4 { - continue; - } - println!("{:?}", tx); - }, - _ => {} + if let Action::Call(tx) = trace.trace.action { + if tx.input.0.len() < 4 { + continue; + } + println!("{:?}", tx); } } } diff --git a/examples/tx-hash-mining/examples/tx_hash_miner_data.rs b/examples/tx-hash-mining/examples/tx_hash_miner_data.rs index 149eafa..c4258a2 100644 --- a/examples/tx-hash-mining/examples/tx_hash_miner_data.rs +++ b/examples/tx-hash-mining/examples/tx_hash_miner_data.rs @@ -1,23 +1,26 @@ -//! Example of mining a vanity Transaction hash using the data field of a DynamicTyped input/function. +//! Example of mining a vanity Transaction hash using the data field of a `DynamicTyped` +//! input/function. /// Dynamic types encode the length of the data at the start of the data: -/// appended bytes beyond the end of the datas length will be ignored by evm when decoding the data. -/// We can use this to mine a transaction hash with a specific prefix. - -/// ➜ x = "HelloWorld" +/// appended bytes beyond the end of the datas length will be ignored by evm when decoding the +/// data. We can use this to mine a transaction hash with a specific prefix. +/// ➜ x = "`HelloWorld`" /// Type: string -/// ├ UTF-8: HelloWorld +/// ├ UTF-8: `HelloWorld` /// ├ Hex (Memory): -/// ├─ Length ([0x00:0x20]): 0x000000000000000000000000000000000000000000000000000000000000000a -/// ├─ Contents ([0x20:..]): 0x48656c6c6f576f726c6400000000000000000000000000000000000000000000 +/// ├─ Length ([0x00:0x20]): +/// 0x000000000000000000000000000000000000000000000000000000000000000a ├─ Contents +/// ([0x20:..]): 0x48656c6c6f576f726c6400000000000000000000000000000000000000000000 /// -/// ➜ abi.encodeWithSignature("setName(string)", "HelloWorld") +/// ➜ abi.encodeWithSignature("setName(string)", "`HelloWorld`") /// Type: dynamic bytes /// ├ Hex (Memory): -/// ├─ Length ([0x00:0x20]): 0x0000000000000000000000000000000000000000000000000000000000000064 -/// ├─ Contents ([0x20:..]): 0xc47f00270000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000a48656c6c6f576f726c640000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +/// ├─ Length ([0x00:0x20]): +/// 0x0000000000000000000000000000000000000000000000000000000000000064 ├─ Contents +/// ([0x20:..]): +/// 0xc47f00270000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000a48656c6c6f576f726c640000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 /// -/// cd dynamic-example && forge script scripts/Counter.s.sol --rpc-url http://127.0.0.1:8545 --private-key $PK --broadcast +/// cd dynamic-example && forge script scripts/Counter.s.sol --rpc-url `` --private-key $PK --broadcast /// ... /// cargo example -- /// Transaction: 0xdead2a52c2d7517e2b7d6a4092bb9061496906c018fd4c1d5cce5a2dec96da2c @@ -26,26 +29,20 @@ /// Block Number: 2 /// Block Hash: 0xa29bcce5697f3febdcd150ceb73f558b35d53dcadc485f0ba928f94f245c5de0 /// Block Time: "Mon, 16 Sep 2024 01:51:30 +0000" - use alloy::{ + consensus::TxEnvelope, + hex, network::{EthereumWallet, TransactionBuilder}, - primitives::{U256, Bytes}, + primitives::{Bytes, U256}, providers::{Provider, ProviderBuilder}, rpc::types::TransactionRequest, signers::local::PrivateKeySigner, - consensus::TxEnvelope, - signers::local::{ - coins_bip39::English, - MnemonicBuilder, LocalSignerError, - }, - hex, + signers::local::{coins_bip39::English, LocalSignerError, MnemonicBuilder}, sol, sol_types::SolCall, }; - use eyre::Result; use rand::Rng; -use tokio; sol!( #[allow(missing_docs)] @@ -65,25 +62,21 @@ async fn main() -> Result<()> { // set to local anvil provider let rpc_url = "http://127.0.0.1:8545".parse()?; - let new_wallet = create_wallet() - .await - .unwrap(); + let new_wallet = create_wallet().await.unwrap(); let wallet = EthereumWallet::from(new_wallet.clone()); - let provider = ProviderBuilder::new() - .with_recommended_fillers() - .wallet(wallet.clone()) - .on_http(rpc_url); + let provider = + ProviderBuilder::new().with_recommended_fillers().wallet(wallet.clone()).on_http(rpc_url); let nonce = provider.get_transaction_count(new_wallet.address()).await?; let eip1559_est = provider.estimate_eip1559_fees(None).await?; let call = setNameCall { s: "hello".to_string() }.abi_encode(); - let input = Bytes::from(call); + let input = Bytes::from(call); let mut tx_envelope; - let mut rng = rand::thread_rng(); + let mut rng = rand::thread_rng(); loop { let mut input_vec = input.to_vec(); @@ -94,7 +87,7 @@ async fn main() -> Result<()> { let modified_input = Bytes::from(input_vec); let tx = TransactionRequest::default() - // this should be the local address dynamicExample is deployed to via anvil + // this should be the local address dynamicExample is deployed to via anvil .with_to("0xdEAD000000000000000042069420694206942069".parse()?) .with_nonce(nonce) .with_chain_id(31337) diff --git a/examples/tx-hash-mining/examples/tx_hash_miner_fee.rs b/examples/tx-hash-mining/examples/tx_hash_miner_fee.rs index 85a58e2..df4a2bf 100644 --- a/examples/tx-hash-mining/examples/tx_hash_miner_fee.rs +++ b/examples/tx-hash-mining/examples/tx_hash_miner_fee.rs @@ -1,21 +1,14 @@ -//! Example of mining a vanity Transaction hash using the max_fee_per_gas field. - +//! Example of mining a vanity Transaction hash using the `max_fee_per_gas` field. use alloy::{ + consensus::TxEnvelope, + hex, network::{EthereumWallet, TransactionBuilder}, primitives::U256, providers::{Provider, ProviderBuilder}, rpc::types::TransactionRequest, - signers::local::PrivateKeySigner, - consensus::TxEnvelope, - hex, - signers::local::{ - coins_bip39::English, - MnemonicBuilder, LocalSignerError, - }, - + signers::local::{coins_bip39::English, LocalSignerError, MnemonicBuilder, PrivateKeySigner}, }; use eyre::Result; -use tokio; async fn create_wallet() -> Result { let wallet = MnemonicBuilder::::default() @@ -29,16 +22,12 @@ async fn create_wallet() -> Result { async fn main() -> Result<()> { let rpc_url = "https://eth.merkle.io".parse()?; - let new_wallet = create_wallet() - .await - .unwrap(); + let new_wallet = create_wallet().await.unwrap(); let wallet = EthereumWallet::from(new_wallet.clone()); - let provider = ProviderBuilder::new() - .with_recommended_fillers() - .wallet(wallet.clone()) - .on_http(rpc_url); + let provider = + ProviderBuilder::new().with_recommended_fillers().wallet(wallet.clone()).on_http(rpc_url); let nonce = provider.get_transaction_count(new_wallet.address()).await?; let eip1559_est = provider.estimate_eip1559_fees(None).await?; @@ -55,7 +44,7 @@ async fn main() -> Result<()> { .with_value(U256::from(0)) .with_gas_limit(21_000) .with_max_priority_fee_per_gas(eip1559_est.max_priority_fee_per_gas) - .with_max_fee_per_gas(max_fee_per_gas.into()); + .with_max_fee_per_gas(max_fee_per_gas); tx_envelope = tx.build(&wallet).await?; diff --git a/examples/tx-hash-mining/examples/tx_hash_miner_gas.rs b/examples/tx-hash-mining/examples/tx_hash_miner_gas.rs index 2a13d8f..614d471 100644 --- a/examples/tx-hash-mining/examples/tx_hash_miner_gas.rs +++ b/examples/tx-hash-mining/examples/tx_hash_miner_gas.rs @@ -1,26 +1,21 @@ -//! Example of mining a vanity Transaction hash using the GAS field. - -/// Extra gas is refunded to the sender. This can be used to mine a tx hash that starts with a specific prefix -/// by increasing the gas limit from X until the tx hash starts with the desired prefix. +//! Example of mining a vanity Transaction hash using the `gas` field. +/// Extra gas is refunded to the sender. This can be used to mine a tx hash that starts with a +/// specific prefix by increasing the gas limit from X until the tx hash starts with the +/// desired prefix. use alloy::{ + consensus::TxEnvelope, + hex, network::{EthereumWallet, TransactionBuilder}, primitives::U256, providers::{Provider, ProviderBuilder}, rpc::types::TransactionRequest, signers::local::PrivateKeySigner, - consensus::TxEnvelope, - hex, - signers::local::{ - coins_bip39::English, - MnemonicBuilder, LocalSignerError, - }, - + signers::local::{coins_bip39::English, LocalSignerError, MnemonicBuilder}, }; use eyre::Result; -use tokio; -async fn create_wallet() -> Result { +async fn create_wallet() -> Result { let wallet = MnemonicBuilder::::default() .word_count(12) .derivation_path("m/44'/60'/0'/2/1")? @@ -31,17 +26,13 @@ async fn create_wallet() -> Result { #[tokio::main] async fn main() -> Result<()> { let rpc_url = "https://eth.merkle.io".parse()?; - - let new_wallet = create_wallet() - .await - .unwrap(); + + let new_wallet = create_wallet().await.unwrap(); let wallet = EthereumWallet::from(new_wallet.clone()); - let provider = ProviderBuilder::new() - .with_recommended_fillers() - .wallet(wallet.clone()) - .on_http(rpc_url); + let provider = + ProviderBuilder::new().with_recommended_fillers().wallet(wallet.clone()).on_http(rpc_url); let nonce = provider.get_transaction_count(new_wallet.address()).await?; let eip1559_est = provider.estimate_eip1559_fees(None).await?; @@ -55,7 +46,7 @@ async fn main() -> Result<()> { .with_nonce(nonce) .with_chain_id(1) .with_value(U256::from(0)) - .with_gas_limit(gas.into()) + .with_gas_limit(gas) .with_max_priority_fee_per_gas(eip1559_est.max_priority_fee_per_gas) .with_max_fee_per_gas(eip1559_est.max_fee_per_gas); diff --git a/examples/tx-hash-mining/examples/tx_hash_miner_priority.rs b/examples/tx-hash-mining/examples/tx_hash_miner_priority.rs index 0ecbc3a..f76e4cc 100644 --- a/examples/tx-hash-mining/examples/tx_hash_miner_priority.rs +++ b/examples/tx-hash-mining/examples/tx_hash_miner_priority.rs @@ -1,21 +1,14 @@ -//! Example of mining a vanity Transaction hash using the max_priority_fee_per_gas field. - +//! Example of mining a vanity Transaction hash using the `max_priority_fee_per_gas` field. use alloy::{ + consensus::TxEnvelope, + hex, network::{EthereumWallet, TransactionBuilder}, primitives::U256, providers::{Provider, ProviderBuilder}, rpc::types::TransactionRequest, - signers::local::PrivateKeySigner, - consensus::TxEnvelope, - hex, - signers::local::{ - coins_bip39::English, - MnemonicBuilder, LocalSignerError, - }, - + signers::local::{coins_bip39::English, LocalSignerError, MnemonicBuilder, PrivateKeySigner}, }; use eyre::Result; -use tokio; async fn create_wallet() -> Result { let wallet = MnemonicBuilder::::default() @@ -29,16 +22,12 @@ async fn create_wallet() -> Result { async fn main() -> Result<()> { let rpc_url = "https://eth.merkle.io".parse()?; - let new_wallet = create_wallet() - .await - .unwrap(); + let new_wallet = create_wallet().await.unwrap(); let wallet = EthereumWallet::from(new_wallet.clone()); - let provider = ProviderBuilder::new() - .with_recommended_fillers() - .wallet(wallet.clone()) - .on_http(rpc_url); + let provider = + ProviderBuilder::new().with_recommended_fillers().wallet(wallet.clone()).on_http(rpc_url); let nonce = provider.get_transaction_count(new_wallet.address()).await?; let eip1559_est = provider.estimate_eip1559_fees(None).await?; @@ -72,4 +61,3 @@ async fn main() -> Result<()> { } Ok(()) } -