Sitelet https://github.com/njelich/examples/commit/090ba457b1876d9273b67894cf8e14f7adc0120e
Skip to content

Commit 090ba45

Browse files
authored
chore: minor consistency fixes, remove redundant imports (alloy-rs#167)
* minor fixes * reorder in terms of visibility
1 parent f94e00d commit 090ba45

16 files changed

Lines changed: 33 additions & 21 deletions

File tree

‎README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,14 @@ This repository contains the following examples:
6363
- [x] [Subscribe and listen to pending transactions in the public mempool](./examples/subscriptions/examples/subscribe_pending_transactions.rs)
6464
- [x] [Event multiplexer](./examples/subscriptions/examples/event_multiplexer.rs)
6565
- [x] Providers
66-
- [x] [JSON-RPC Batch Request](./examples/providers/examples/batch_rpc.rs)
6766
- [x] [Builder](./examples/providers/examples/builder.rs)
6867
- [x] [Builtin](./examples/providers/examples/builtin.rs)
6968
- [x] [HTTP with authentication](./examples/providers/examples/http_with_auth.rs)
7069
- [x] [HTTP](./examples/providers/examples/http.rs)
7170
- [x] [IPC](./examples/providers/examples/ipc.rs)
7271
- [x] [WS](./examples/providers/examples/ws.rs)
7372
- [x] [WS with authentication](./examples/providers/examples/ws_with_auth.rs)
73+
- [x] [JSON-RPC Batch Request](./examples/providers/examples/batch_rpc.rs)
7474
- [x] Queries
7575
- [x] [Query contract storage](./examples/queries/examples/query_contract_storage.rs)
7676
- [x] [Query contract deployed bytecode](./examples/queries/examples/query_deployed_bytecode.rs)

‎examples/advanced/examples/reth_db_layer.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
//! `RethDbLayer` implementation to be used with `RethDbProvider` to wrap the Provider trait over
22
//! reth-db.
3+
34
#![allow(dead_code)]
45
use std::path::PathBuf;
56

‎examples/advanced/examples/reth_db_provider.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
//! their own implementation of the `Provider` trait and fetch results from any source.
1111
//!
1212
//! Learn more about `ProviderCall` [here](https://github.com/alloy-rs/alloy/pull/788).
13+
1314
use std::{marker::PhantomData, path::PathBuf, sync::Arc};
1415

1516
use alloy::{

‎examples/big-numbers/examples/comparison_equivalence.rs‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
//! Example of comparison and equivalence of `U256` instances.
22
33
use alloy::primitives::U256;
4+
use eyre::Result;
45

56
/// `U256` implements traits in `std::cmp`, that means `U256` instances
67
/// can be easily compared using standard Rust operators.
7-
fn main() {
8+
fn main() -> Result<()> {
89
// a == b
910
let a = U256::from(100_u32);
1011
let b = U256::from(100_u32);
@@ -33,4 +34,6 @@ fn main() {
3334
// a == 0
3435
let a = U256::ZERO;
3536
assert!(a.is_zero());
37+
38+
Ok(())
3639
}

‎examples/big-numbers/examples/create_instances.rs‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
//! Example of creating instances of `U256` from strings and numbers.
22
3+
use std::str::FromStr;
4+
35
use alloy::primitives::{
46
utils::{parse_units, ParseUnits},
57
U256,
68
};
79
use eyre::Result;
8-
use std::str::FromStr;
910

1011
fn main() -> Result<()> {
1112
// From strings

‎examples/big-numbers/examples/math_operations.rs‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
//! Example of performing arithmetic operations with `U256`.
22
3+
use std::ops::{Div, Mul};
4+
35
use alloy::primitives::{utils::format_units, U256};
46
use eyre::Result;
5-
use std::ops::{Div, Mul};
67

78
/// `U256` implements traits in `std::ops`, that means it supports arithmetic operations
89
/// using standard Rust operators `+`, `-`. `*`, `/`, `%`, along with additional utilities to

‎examples/comparison/examples/compare_new_heads.rs‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
//! Example of comparing new block headers from multiple providers.
22
3+
use std::{collections::HashMap, sync::Arc};
4+
35
use alloy::{
46
network::AnyNetwork,
57
providers::{Provider, ProviderBuilder},
@@ -8,7 +10,6 @@ use chrono::Utc;
810
use clap::Parser;
911
use eyre::Result;
1012
use futures_util::StreamExt;
11-
use std::{collections::HashMap, sync::Arc};
1213
use tokio::sync::mpsc;
1314

1415
#[derive(Debug, Parser)]

‎examples/layers/examples/logging_layer.rs‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
//! This examples demonstrates how to implement your own custom transport layer.
22
//! As a demonstration we implement a simple request / response logging layer.
33
4+
use std::{
5+
fmt::Debug,
6+
future::{Future, IntoFuture},
7+
pin::Pin,
8+
task::{Context, Poll},
9+
};
10+
411
use alloy::{
512
node_bindings::Anvil,
613
providers::{Provider, ProviderBuilder},
@@ -11,12 +18,6 @@ use alloy::{
1118
transports::TransportError,
1219
};
1320
use eyre::Result;
14-
use std::{
15-
fmt::Debug,
16-
future::{Future, IntoFuture},
17-
pin::Pin,
18-
task::{Context, Poll},
19-
};
2021
use tower::{Layer, Service};
2122

2223
struct LoggingLayer;

‎examples/primitives/examples/hashing_functions.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! Example of basic usage of hashing functions.
22
33
use alloy::primitives::{eip191_hash_message, keccak256};
4-
use eyre::{Ok, Result};
4+
use eyre::Result;
55

66
fn main() -> Result<()> {
77
// [`Keccak-256`]: https://en.wikipedia.org/wiki/SHA-3

‎examples/providers/examples/batch_rpc.rs‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ use eyre::Result;
99

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

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

3032
let vitalik = address!("d8da6bf26964af9d7eed9e03e53415d37aa96045");
31-
3233
let vitalik_nonce_fut = batch
3334
.add_call("eth_getTransactionCount", &(vitalik, "latest"))? // Vitalik's nonce at BlockId::Latest
3435
.map_resp(|resp: U128| resp.to::<u128>());

0 commit comments

Comments
 (0)