Sitelet https://github.com/lcfr-eth/examples/commit/e716e949501383afc4457248b460a3ab60dd985b
Skip to content

Commit e716e94

Browse files
authored
[Debt] Improve consistency of best practice application (alloy-rs#32)
* use ? * clean up * undo * clean up examples, avoid importing Anvil when only used for addresses * url -> rpc_url, more consistency for code blocks * additional comments, wallet -> signer * add extra comments * rerun bytecode and document settings * remove redundant macro * additional comments, best practices * improve consistency; * improve readability * add links * move out users into own block * broadcast -> send * use trailing . for comments * clean up comments * add clippy lints * fixed_bytes! -> b256! * inline format string lint setting * apply fix * update instructions * add pull request template
1 parent 60d14df commit e716e94

47 files changed

Lines changed: 521 additions & 335 deletions

Some content is hidden

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

‎.github/PULL_REQUEST_TEMPLATE.md‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<!--
2+
Thank you for your Pull Request. Please provide a description above and review
3+
the requirements below.
4+
5+
Bug fixes and new features should include tests.
6+
7+
Contributors guide: https://github.com/alloy-rs/examples/blob/main/CONTRIBUTING.md
8+
9+
The contributors guide includes instructions for running rustfmt and building the
10+
documentation.
11+
-->
12+
13+
<!-- ** Please select "Allow edits from maintainers" in the PR Options ** -->
14+
15+
## Motivation
16+
17+
<!--
18+
Explain the context and why you're making that change. What is the problem
19+
you're trying to solve? In some cases there is not a problem and this can be
20+
thought of as being the motivation for your change.
21+
-->
22+
23+
## Solution
24+
25+
<!--
26+
Summarize the solution and provide any necessary context needed to understand
27+
the code change.
28+
-->
29+
30+
## PR Checklist
31+
32+
- [ ] Added Documentation
33+
- [ ] Breaking changes

‎CONTRIBUTING.md‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,11 +125,13 @@ less work from you.
125125
This section lists some commonly needed commands.
126126

127127
```sh
128-
cargo check --all-features
128+
cargo check --examples --all-features
129+
cargo build --examples --all-features
129130
cargo +nightly fmt --all
130-
cargo build --all-features
131-
cargo test --all-features
132-
cargo +nightly clippy --all-features
131+
cargo +nightly clippy \
132+
--examples \
133+
--all-features \
134+
-- -D warnings
133135
```
134136

135137
### Tests

‎Cargo.toml‎

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,50 @@ repository = "https://github.com/alloy-rs/examples"
1313
publish = false
1414
exclude = ["examples/"]
1515

16+
[workspace.lints]
17+
rust.missing_debug_implementations = "warn"
18+
rust.missing_docs = "warn"
19+
rust.unreachable_pub = "warn"
20+
rustdoc.all = "warn"
21+
rust.unused_must_use = "deny"
22+
rust.rust_2018_idioms = "deny"
23+
24+
[workspace.lints.clippy]
25+
# These are some of clippy's nursery (i.e., experimental) lints that we like.
26+
# By default, nursery lints are allowed. Some of the lints below have made good
27+
# suggestions which we fixed. The others didn't have any findings, so we can
28+
# assume they don't have that many false positives. Let's enable them to
29+
# prevent future problems.
30+
branches_sharing_code = "warn"
31+
clear_with_drain = "warn"
32+
derive_partial_eq_without_eq = "warn"
33+
empty_line_after_outer_attr = "warn"
34+
equatable_if_let = "warn"
35+
imprecise_flops = "warn"
36+
iter_on_empty_collections = "warn"
37+
iter_with_drain = "warn"
38+
large_stack_frames = "warn"
39+
manual_clamp = "warn"
40+
mutex_integer = "warn"
41+
needless_pass_by_ref_mut = "warn"
42+
nonstandard_macro_braces = "warn"
43+
or_fun_call = "warn"
44+
path_buf_push_overwrite = "warn"
45+
read_zero_byte_vec = "warn"
46+
redundant_clone = "warn"
47+
suboptimal_flops = "warn"
48+
suspicious_operation_groupings = "warn"
49+
trailing_empty_array = "warn"
50+
trait_duplication_in_bounds = "warn"
51+
transmute_undefined_repr = "warn"
52+
trivial_regex = "warn"
53+
tuple_array_conversions = "warn"
54+
uninhabited_references = "warn"
55+
unused_peekable = "warn"
56+
unused_rounding = "warn"
57+
useless_let_if_seq = "warn"
58+
uninlined_format_args = "warn"
59+
1660
[workspace.dependencies]
1761
alloy = { git = "https://github.com/alloy-rs/alloy", rev = "f7333c4", features = [
1862
# "dyn-abi",

‎README.md‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
Example code using [alloy](https://github.com/alloy-rs/alloy) and [alloy-core](https://github.com/alloy-rs/core).
44

55
These examples demonstrate the main features of [Alloy](https://github.com/alloy-rs/alloy) and how to use them.
6-
To run an example, use the command `cargo run --example <Example>`.
6+
7+
To run an example, use the command `cargo run --example <Example>`:
78

89
```sh
910
cargo run --example mnemonic_signer

‎examples/anvil/Cargo.toml‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
[package]
22
name = "examples-anvil"
3-
43
publish.workspace = true
54
version.workspace = true
65
edition.workspace = true
@@ -10,6 +9,9 @@ license.workspace = true
109
homepage.workspace = true
1110
repository.workspace = true
1211

12+
[lints]
13+
workspace = true
14+
1315
[dev-dependencies]
1416
alloy.workspace = true
1517

‎examples/anvil/examples/deploy_contract_anvil.rs‎

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use eyre::Result;
1313

1414
// Codegen from embedded Solidity code and precompiled bytecode.
1515
sol! {
16+
#[allow(missing_docs)]
1617
// solc v0.8.24; solc a.sol --via-ir --optimize --bin
1718
#[sol(rpc, bytecode="608080604052346100155760d2908161001a8239f35b5f80fdfe60808060405260043610156011575f80fd5b5f3560e01c9081633fb5c1cb1460865781638381f58a14606f575063d09de08a146039575f80fd5b34606b575f366003190112606b575f545f1981146057576001015f55005b634e487b7160e01b5f52601160045260245ffd5b5f80fd5b34606b575f366003190112606b576020905f548152f35b34606b576020366003190112606b576004355f5500fea2646970667358221220bdecd3c1dd631eb40587cafcd6e8297479db76db6a328e18ad1ea5b340852e3864736f6c63430008180033")]
1819
contract Counter {
@@ -31,17 +32,17 @@ sol! {
3132
#[tokio::main]
3233
async fn main() -> Result<()> {
3334
// Spin up a local Anvil node.
34-
// Ensure `anvil` is available in $PATH
35+
// Ensure `anvil` is available in $PATH.
3536
let anvil = Anvil::new().try_spawn()?;
3637

37-
// Set up wallet
38-
let wallet: LocalWallet = anvil.keys()[0].clone().into();
38+
// Set up signer from the first default Anvil account (Alice).
39+
let signer: LocalWallet = anvil.keys()[0].clone().into();
3940

4041
// Create a provider with a signer and the network.
41-
let http = anvil.endpoint().parse()?;
42+
let rpc_url = anvil.endpoint().parse()?;
4243
let provider = ProviderBuilder::new()
43-
.signer(EthereumSigner::from(wallet))
44-
.on_client(RpcClient::new_http(http));
44+
.signer(EthereumSigner::from(signer))
45+
.on_client(RpcClient::new_http(rpc_url));
4546

4647
println!("Anvil running at `{}`", anvil.endpoint());
4748

@@ -54,7 +55,7 @@ async fn main() -> Result<()> {
5455
let contract_address =
5556
contract_builder.gas(estimate).gas_price(base_fee).nonce(0).deploy().await?;
5657

57-
println!("Deployed contract at address: {:?}", contract_address);
58+
println!("Deployed contract at address: {contract_address:?}");
5859

5960
let contract = Counter::new(contract_address, &provider);
6061

‎examples/anvil/examples/fork_anvil.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use eyre::Result;
66
#[tokio::main]
77
async fn main() -> Result<()> {
88
// Spin up a forked Anvil node.
9-
// Ensure `anvil` is available in $PATH
9+
// Ensure `anvil` is available in $PATH.
1010
let anvil = Anvil::new().fork("https://eth.merkle.io").try_spawn()?;
1111

1212
println!("Anvil running at `{}`", anvil.endpoint());

‎examples/anvil/examples/local_anvil.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use eyre::Result;
66
#[tokio::main]
77
async fn main() -> Result<()> {
88
// Spin up a local Anvil node.
9-
// Ensure `anvil` is available in $PATH
9+
// Ensure `anvil` is available in $PATH.
1010
let anvil = Anvil::new().block_time(1).chain_id(1337).try_spawn()?;
1111

1212
println!("Anvil running at `{}`", anvil.endpoint());

‎examples/big-numbers/Cargo.toml‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
[package]
22
name = "examples-big-numbers"
3-
43
publish.workspace = true
54
version.workspace = true
65
edition.workspace = true
@@ -10,6 +9,9 @@ license.workspace = true
109
homepage.workspace = true
1110
repository.workspace = true
1211

12+
[lints]
13+
workspace = true
14+
1315
[dev-dependencies]
1416
alloy.workspace = true
1517

‎examples/contracts/Cargo.toml‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
[package]
22
name = "examples-contracts"
3-
43
publish.workspace = true
54
version.workspace = true
65
edition.workspace = true
@@ -10,6 +9,9 @@ license.workspace = true
109
homepage.workspace = true
1110
repository.workspace = true
1211

12+
[lints]
13+
workspace = true
14+
1315
[dev-dependencies]
1416
alloy.workspace = true
1517

0 commit comments

Comments
 (0)