Skip to content

Commit

Permalink
minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
zerosnacks committed Dec 10, 2024
1 parent f94e00d commit 2984de4
Show file tree
Hide file tree
Showing 15 changed files with 32 additions and 20 deletions.
1 change: 1 addition & 0 deletions examples/advanced/examples/reth_db_layer.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//! `RethDbLayer` implementation to be used with `RethDbProvider` to wrap the Provider trait over
//! reth-db.
#![allow(dead_code)]
use std::path::PathBuf;

Expand Down
1 change: 1 addition & 0 deletions examples/advanced/examples/reth_db_provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
//! their own implementation of the `Provider` trait and fetch results from any source.
//!
//! Learn more about `ProviderCall` [here](https://github.com/alloy-rs/alloy/pull/788).
use std::{marker::PhantomData, path::PathBuf, sync::Arc};

use alloy::{
Expand Down
5 changes: 4 additions & 1 deletion examples/big-numbers/examples/comparison_equivalence.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
//! Example of comparison and equivalence of `U256` instances.
use alloy::primitives::U256;
use eyre::Result;

/// `U256` implements traits in `std::cmp`, that means `U256` instances
/// can be easily compared using standard Rust operators.
fn main() {
fn main() -> Result<()> {
// a == b
let a = U256::from(100_u32);
let b = U256::from(100_u32);
Expand Down Expand Up @@ -33,4 +34,6 @@ fn main() {
// a == 0
let a = U256::ZERO;
assert!(a.is_zero());

Ok(())
}
3 changes: 2 additions & 1 deletion examples/big-numbers/examples/create_instances.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
//! Example of creating instances of `U256` from strings and numbers.
use std::str::FromStr;

use alloy::primitives::{
utils::{parse_units, ParseUnits},
U256,
};
use eyre::Result;
use std::str::FromStr;

fn main() -> Result<()> {
// From strings
Expand Down
3 changes: 2 additions & 1 deletion examples/big-numbers/examples/math_operations.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
//! Example of performing arithmetic operations with `U256`.
use std::ops::{Div, Mul};

use alloy::primitives::{utils::format_units, U256};
use eyre::Result;
use std::ops::{Div, Mul};

/// `U256` implements traits in `std::ops`, that means it supports arithmetic operations
/// using standard Rust operators `+`, `-`. `*`, `/`, `%`, along with additional utilities to
Expand Down
3 changes: 2 additions & 1 deletion examples/comparison/examples/compare_new_heads.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
//! Example of comparing new block headers from multiple providers.
use std::{collections::HashMap, sync::Arc};

use alloy::{
network::AnyNetwork,
providers::{Provider, ProviderBuilder},
Expand All @@ -8,7 +10,6 @@ use chrono::Utc;
use clap::Parser;
use eyre::Result;
use futures_util::StreamExt;
use std::{collections::HashMap, sync::Arc};
use tokio::sync::mpsc;

#[derive(Debug, Parser)]
Expand Down
13 changes: 7 additions & 6 deletions examples/layers/examples/logging_layer.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
//! This examples demonstrates how to implement your own custom transport layer.
//! As a demonstration we implement a simple request / response logging layer.
use std::{
fmt::Debug,
future::{Future, IntoFuture},
pin::Pin,
task::{Context, Poll},
};

use alloy::{
node_bindings::Anvil,
providers::{Provider, ProviderBuilder},
Expand All @@ -11,12 +18,6 @@ use alloy::{
transports::TransportError,
};
use eyre::Result;
use std::{
fmt::Debug,
future::{Future, IntoFuture},
pin::Pin,
task::{Context, Poll},
};
use tower::{Layer, Service};

struct LoggingLayer;
Expand Down
2 changes: 1 addition & 1 deletion examples/primitives/examples/hashing_functions.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Example of basic usage of hashing functions.
use alloy::primitives::{eip191_hash_message, keccak256};
use eyre::{Ok, Result};
use eyre::Result;

fn main() -> Result<()> {
// [`Keccak-256`]: https://en.wikipedia.org/wiki/SHA-3
Expand Down
3 changes: 2 additions & 1 deletion examples/providers/examples/batch_rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ use eyre::Result;

#[tokio::main]
async fn main() -> Result<()> {
// Spin up a local Anvil node.
// Ensure `anvil` is available in $PATH.
let anvil = Anvil::new().spawn();

// Swap this out with a RPC_URL provider that supports JSON-RPC batch requests. e.g. https://eth.merkle.io
Expand All @@ -28,7 +30,6 @@ async fn main() -> Result<()> {
batch.add_call("eth_gasPrice", &())?.map_resp(|resp: U128| resp.to::<u128>());

let vitalik = address!("d8da6bf26964af9d7eed9e03e53415d37aa96045");

let vitalik_nonce_fut = batch
.add_call("eth_getTransactionCount", &(vitalik, "latest"))? // Vitalik's nonce at BlockId::Latest
.map_resp(|resp: U128| resp.to::<u128>());
Expand Down
3 changes: 2 additions & 1 deletion examples/subscriptions/examples/event_multiplexer.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
//! Example of multiplexing the watching of event logs.
use std::str::FromStr;

use alloy::{
node_bindings::Anvil,
primitives::I256,
Expand All @@ -9,7 +11,6 @@ use alloy::{
};
use eyre::Result;
use futures_util::StreamExt;
use std::str::FromStr;

// Codegen from embedded Solidity code and precompiled bytecode.
// solc v0.8.26; solc EventMultiplexer.sol --via-ir --optimize --bin
Expand Down
3 changes: 1 addition & 2 deletions examples/transactions/examples/trace_call_many.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ use alloy::{
providers::{ext::TraceApi, ProviderBuilder},
rpc::types::{trace::parity::TraceType, TransactionRequest},
};

use eyre::{Ok, Result};
use eyre::Result;

#[tokio::main]
async fn main() -> Result<()> {
Expand Down
3 changes: 2 additions & 1 deletion examples/wallets/examples/create_keystore.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
//! Example of creating a keystore file from a private key and password, and then reading it back.
use std::fs::read_to_string;

use alloy::{primitives::hex, signers::local::LocalSigner};
use eyre::Result;
use rand::thread_rng;
use std::fs::read_to_string;
use tempfile::tempdir;

#[tokio::main]
Expand Down
2 changes: 1 addition & 1 deletion examples/wallets/examples/gcp_signer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use alloy::signers::{
gcp::{GcpKeyRingRef, GcpSigner, KeySpecifier},
Signer,
};
use eyre::{Ok, Result};
use eyre::Result;
use gcloud_sdk::{
google::cloud::kms::v1::key_management_service_client::KeyManagementServiceClient, GoogleApi,
};
Expand Down
5 changes: 3 additions & 2 deletions examples/wallets/examples/keystore_signer.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
//! Example of using a keystore wallet to sign and send a transaction.
use std::path::PathBuf;

use alloy::{
network::{EthereumWallet, TransactionBuilder},
primitives::{address, U256},
Expand All @@ -8,7 +10,6 @@ use alloy::{
signers::local::LocalSigner,
};
use eyre::Result;
use std::{env, path::PathBuf};

#[tokio::main]
async fn main() -> Result<()> {
Expand All @@ -18,7 +19,7 @@ async fn main() -> Result<()> {
// Set up signer using Alice's keystore file.
// The private key belongs to Alice, the first default Anvil account.
let keystore_file_path =
PathBuf::from(env::var("CARGO_MANIFEST_DIR")?).join("examples/keystore/alice.json");
PathBuf::from(std::env::var("CARGO_MANIFEST_DIR")?).join("examples/keystore/alice.json");
let signer = LocalSigner::decrypt_keystore(keystore_file_path, password)?;
let wallet = EthereumWallet::from(signer);

Expand Down
2 changes: 1 addition & 1 deletion examples/wallets/examples/verify_message.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Example of verifying that a message was signed by the provided address.
use alloy::signers::{local::PrivateKeySigner, SignerSync};
use eyre::{Ok, Result};
use eyre::Result;

#[tokio::main]
async fn main() -> Result<()> {
Expand Down

0 comments on commit 2984de4

Please sign in to comment.