Skip to content

Commit

Permalink
Merge branch 'main' into connect_builtin
Browse files Browse the repository at this point in the history
  • Loading branch information
yash-atreya authored Mar 28, 2024
2 parents 61252e0 + 0b6148f commit 25ec522
Show file tree
Hide file tree
Showing 48 changed files with 568 additions and 359 deletions.
33 changes: 33 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<!--
Thank you for your Pull Request. Please provide a description above and review
the requirements below.
Bug fixes and new features should include tests.
Contributors guide: https://github.com/alloy-rs/examples/blob/main/CONTRIBUTING.md
The contributors guide includes instructions for running rustfmt and building the
documentation.
-->

<!-- ** Please select "Allow edits from maintainers" in the PR Options ** -->

## Motivation

<!--
Explain the context and why you're making that change. What is the problem
you're trying to solve? In some cases there is not a problem and this can be
thought of as being the motivation for your change.
-->

## Solution

<!--
Summarize the solution and provide any necessary context needed to understand
the code change.
-->

## PR Checklist

- [ ] Added Documentation
- [ ] Breaking changes
4 changes: 2 additions & 2 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
- uses: Swatinem/rust-cache@v2
with:
cache-on-failure: true
- run: cargo clippy --workspace --all-targets --all-features
- run: cargo +nightly clippy --examples --all-features
env:
RUSTFLAGS: -Dwarnings

Expand All @@ -36,4 +36,4 @@ jobs:
- uses: dtolnay/rust-toolchain@nightly
with:
components: rustfmt
- run: cargo fmt --all --check
- run: cargo +nightly fmt --all --check
10 changes: 6 additions & 4 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,13 @@ less work from you.
This section lists some commonly needed commands.

```sh
cargo check --all-features
cargo check --examples --all-features
cargo build --examples --all-features
cargo +nightly fmt --all
cargo build --all-features
cargo test --all-features
cargo +nightly clippy --all-features
cargo +nightly clippy \
--examples \
--all-features \
-- -D warnings
```

### Tests
Expand Down
83 changes: 75 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,75 @@ repository = "https://github.com/alloy-rs/examples"
publish = false
exclude = ["examples/"]

[workspace.lints]
rust.missing_debug_implementations = "warn"
rust.missing_docs = "warn"
rust.unreachable_pub = "warn"
rustdoc.all = "warn"
rust.unused_must_use = "deny"
rust.rust_2018_idioms = "deny"

[workspace.lints.clippy]
# These are some of clippy's nursery (i.e., experimental) lints that we like.
# By default, nursery lints are allowed. Some of the lints below have made good
# suggestions which we fixed. The others didn't have any findings, so we can
# assume they don't have that many false positives. Let's enable them to
# prevent future problems.
branches_sharing_code = "warn"
clear_with_drain = "warn"
derive_partial_eq_without_eq = "warn"
empty_line_after_outer_attr = "warn"
equatable_if_let = "warn"
imprecise_flops = "warn"
iter_on_empty_collections = "warn"
iter_with_drain = "warn"
large_stack_frames = "warn"
manual_clamp = "warn"
mutex_integer = "warn"
needless_pass_by_ref_mut = "warn"
nonstandard_macro_braces = "warn"
or_fun_call = "warn"
path_buf_push_overwrite = "warn"
read_zero_byte_vec = "warn"
redundant_clone = "warn"
suboptimal_flops = "warn"
suspicious_operation_groupings = "warn"
trailing_empty_array = "warn"
trait_duplication_in_bounds = "warn"
transmute_undefined_repr = "warn"
trivial_regex = "warn"
tuple_array_conversions = "warn"
uninhabited_references = "warn"
unused_peekable = "warn"
unused_rounding = "warn"
useless_let_if_seq = "warn"
uninlined_format_args = "warn"

# These are nursery lints which have findings. Allow them for now. Some are not
# quite mature enough for use in our codebase and some we don't really want.
# Explicitly listing should make it easier to fix in the future.
as_ptr_cast_mut = "allow"
cognitive_complexity = "allow"
collection_is_never_read = "allow"
debug_assert_with_mut_call = "allow"
empty_line_after_doc_comments = "allow"
fallible_impl_from = "allow"
future_not_send = "allow"
iter_on_single_items = "allow"
missing_const_for_fn = "allow"
needless_collect = "allow"
non_send_fields_in_send_ty = "allow"
option_if_let_else = "allow"
redundant_pub_crate = "allow"
significant_drop_in_scrutinee = "allow"
significant_drop_tightening = "allow"
string_lit_as_bytes = "allow"
type_repetition_in_bounds = "allow"
unnecessary_struct_initialization = "allow"
use_self = "allow"

[workspace.dependencies]
alloy = { git = "https://github.com/alloy-rs/alloy", rev = "f7333c4", features = [
alloy = { git = "https://github.com/alloy-rs/alloy", rev = "66fa192", features = [
# "dyn-abi",
# "json-abi",
# "json",
Expand Down Expand Up @@ -58,10 +125,10 @@ tokio = "1"
eyre = "0.6.12"

[patch.crates-io]
alloy-core = { git = "https://github.com/alloy-rs/core", rev = "907d61a45a9135e979310990744080eef5f03fe5" }
alloy-dyn-abi = { git = "https://github.com/alloy-rs/core", rev = "907d61a45a9135e979310990744080eef5f03fe5" }
alloy-json-abi = { git = "https://github.com/alloy-rs/core", rev = "907d61a45a9135e979310990744080eef5f03fe5" }
alloy-primitives = { git = "https://github.com/alloy-rs/core", rev = "907d61a45a9135e979310990744080eef5f03fe5" }
alloy-sol-macro = { git = "https://github.com/alloy-rs/core", rev = "907d61a45a9135e979310990744080eef5f03fe5" }
alloy-sol-types = { git = "https://github.com/alloy-rs/core", rev = "907d61a45a9135e979310990744080eef5f03fe5" }
syn-solidity = { git = "https://github.com/alloy-rs/core", rev = "907d61a45a9135e979310990744080eef5f03fe5" }
alloy-core = { git = "https://github.com/alloy-rs/core", rev = "525a233" }
alloy-dyn-abi = { git = "https://github.com/alloy-rs/core", rev = "525a233" }
alloy-json-abi = { git = "https://github.com/alloy-rs/core", rev = "525a233" }
alloy-primitives = { git = "https://github.com/alloy-rs/core", rev = "525a233" }
alloy-sol-macro = { git = "https://github.com/alloy-rs/core", rev = "525a233" }
alloy-sol-types = { git = "https://github.com/alloy-rs/core", rev = "525a233" }
syn-solidity = { git = "https://github.com/alloy-rs/core", rev = "525a233" }
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
Example code using [alloy](https://github.com/alloy-rs/alloy) and [alloy-core](https://github.com/alloy-rs/core).

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

To run an example, use the command `cargo run --example <Example>`:

```sh
cargo run --example mnemonic_signer
Expand Down
4 changes: 3 additions & 1 deletion examples/anvil/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
[package]
name = "examples-anvil"

publish.workspace = true
version.workspace = true
edition.workspace = true
Expand All @@ -10,6 +9,9 @@ license.workspace = true
homepage.workspace = true
repository.workspace = true

[lints]
workspace = true

[dev-dependencies]
alloy.workspace = true

Expand Down
15 changes: 8 additions & 7 deletions examples/anvil/examples/deploy_contract_anvil.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use eyre::Result;

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

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

// Create a provider with a signer and the network.
let http = anvil.endpoint().parse()?;
let rpc_url = anvil.endpoint().parse()?;
let provider = ProviderBuilder::new()
.signer(EthereumSigner::from(wallet))
.on_client(RpcClient::new_http(http));
.signer(EthereumSigner::from(signer))
.on_client(RpcClient::new_http(rpc_url));

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

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

println!("Deployed contract at address: {:?}", contract_address);
println!("Deployed contract at address: {contract_address:?}");

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

Expand Down
2 changes: 1 addition & 1 deletion examples/anvil/examples/fork_anvil.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use eyre::Result;
#[tokio::main]
async fn main() -> Result<()> {
// Spin up a forked Anvil node.
// Ensure `anvil` is available in $PATH
// Ensure `anvil` is available in $PATH.
let anvil = Anvil::new().fork("https://eth.merkle.io").try_spawn()?;

println!("Anvil running at `{}`", anvil.endpoint());
Expand Down
2 changes: 1 addition & 1 deletion examples/anvil/examples/local_anvil.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use eyre::Result;
#[tokio::main]
async fn main() -> Result<()> {
// Spin up a local Anvil node.
// Ensure `anvil` is available in $PATH
// Ensure `anvil` is available in $PATH.
let anvil = Anvil::new().block_time(1).chain_id(1337).try_spawn()?;

println!("Anvil running at `{}`", anvil.endpoint());
Expand Down
4 changes: 3 additions & 1 deletion examples/big-numbers/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
[package]
name = "examples-big-numbers"

publish.workspace = true
version.workspace = true
edition.workspace = true
Expand All @@ -10,6 +9,9 @@ license.workspace = true
homepage.workspace = true
repository.workspace = true

[lints]
workspace = true

[dev-dependencies]
alloy.workspace = true

Expand Down
4 changes: 3 additions & 1 deletion examples/contracts/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
[package]
name = "examples-contracts"

publish.workspace = true
version.workspace = true
edition.workspace = true
Expand All @@ -10,6 +9,9 @@ license.workspace = true
homepage.workspace = true
repository.workspace = true

[lints]
workspace = true

[dev-dependencies]
alloy.workspace = true

Expand Down
15 changes: 8 additions & 7 deletions examples/contracts/examples/deploy_from_artifact.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use eyre::Result;

// Codegen from artifact.
sol!(
#[allow(missing_docs)]
#[sol(rpc)]
Counter,
"examples/artifacts/Counter.json"
Expand All @@ -21,17 +22,17 @@ sol!(
#[tokio::main]
async fn main() -> Result<()> {
// Spin up a local Anvil node.
// Ensure `anvil` is available in $PATH
// Ensure `anvil` is available in $PATH.
let anvil = Anvil::new().try_spawn()?;

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

// Create a provider with a signer.
let http = anvil.endpoint().parse()?;
let rpc_url = anvil.endpoint().parse()?;
let provider = ProviderBuilder::new()
.signer(EthereumSigner::from(wallet))
.on_client(RpcClient::new_http(http));
.signer(EthereumSigner::from(signer))
.on_client(RpcClient::new_http(rpc_url));

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

Expand All @@ -44,7 +45,7 @@ async fn main() -> Result<()> {
let contract_address =
contract_builder.gas(estimate).gas_price(base_fee).nonce(0).deploy().await?;

println!("Deployed contract at address: {:?}", contract_address);
println!("Deployed contract at address: {contract_address:?}");

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

Expand Down
15 changes: 8 additions & 7 deletions examples/contracts/examples/deploy_from_contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use eyre::Result;

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

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

// Create a provider with a signer.
let http = anvil.endpoint().parse()?;
let rpc_url = anvil.endpoint().parse()?;
let provider = ProviderBuilder::new()
.signer(EthereumSigner::from(wallet))
.on_client(RpcClient::new_http(http));
.signer(EthereumSigner::from(signer))
.on_client(RpcClient::new_http(rpc_url));

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

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

println!("Deployed contract at address: {:?}", contract_address);
println!("Deployed contract at address: {contract_address:?}");

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

Expand Down
3 changes: 2 additions & 1 deletion examples/contracts/examples/generate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use eyre::Result;

// Codegen from ABI file to interact with the contract.
sol!(
#[allow(missing_docs)]
#[sol(rpc)]
IERC20,
"examples/abi/IERC20.json"
Expand All @@ -13,7 +14,7 @@ sol!(
#[tokio::main]
async fn main() -> Result<()> {
// Spin up a forked Anvil node.
// Ensure `anvil` is available in $PATH
// Ensure `anvil` is available in $PATH.
let anvil = Anvil::new().fork("https://eth.merkle.io").try_spawn()?;

// Create a provider.
Expand Down
4 changes: 3 additions & 1 deletion examples/layers/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
[package]
name = "examples-layers"

publish.workspace = true
version.workspace = true
edition.workspace = true
Expand All @@ -10,6 +9,9 @@ license.workspace = true
homepage.workspace = true
repository.workspace = true

[lints]
workspace = true

[dev-dependencies]
alloy.workspace = true

Expand Down
Loading

0 comments on commit 25ec522

Please sign in to comment.