Skip to content

Commit

Permalink
Add subscribe_all_logs example (#84)
Browse files Browse the repository at this point in the history
* add subscribe_all_logs example

* use getter, prebuild examples for speedup

* fix clippy

* remote optimization, causes issues with rapid anvil spawning

* safely handle getting topic0

* fix clippy

* remove api key

* use topic0, update to latest version of Alloy

* clean up lint rules
  • Loading branch information
zerosnacks authored May 30, 2024
1 parent 71351eb commit 2573367
Show file tree
Hide file tree
Showing 12 changed files with 373 additions and 27 deletions.
1 change: 1 addition & 0 deletions .github/workflows/integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ jobs:
-e 'ws' \
-e 'ws_auth' \
-e 'subscribe_logs' \
-e 'subscribe_all_logs' \
-e 'trace_call' \
-e 'trace_transaction' \
| xargs -n1 echo
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ jobs:
-e 'ws' \
-e 'ws_auth' \
-e 'subscribe_logs' \
-e 'subscribe_all_logs' \
-e 'trace_call' \
-e 'trace_transaction' \
| xargs -n1 echo
Expand Down
1 change: 1 addition & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ cargo run --example 2>&1 \
-e 'ws' \
-e 'ws_auth' \
-e 'subscribe_logs' \
-e 'subscribe_all_logs' \
-e 'trace_call' \
-e 'trace_transaction' \
| xargs -I {} sh -c 'if cargo run --example {} --quiet 1>/dev/null; then \
Expand Down
19 changes: 9 additions & 10 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ exclude = ["examples/"]
[workspace.lints]
rust.missing_debug_implementations = "warn"
rust.missing_docs = "warn"
rust.rust_2018_idioms = { level = "deny", priority = -1 }
rust.unreachable_pub = "warn"
rust.unused_must_use = "deny"
rust.rust_2018_idioms = { level = "deny", priority = -1 }
rustdoc.all = "warn"

[workspace.lints.clippy]
Expand All @@ -37,6 +37,7 @@ iter_on_empty_collections = "warn"
iter_with_drain = "warn"
large_stack_frames = "warn"
manual_clamp = "warn"
missing_const_for_fn = "warn"
mutex_integer = "warn"
needless_pass_by_ref_mut = "warn"
nonstandard_macro_braces = "warn"
Expand All @@ -54,8 +55,8 @@ tuple_array_conversions = "warn"
uninhabited_references = "warn"
unused_peekable = "warn"
unused_rounding = "warn"
use_self = "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.
Expand All @@ -68,7 +69,6 @@ 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"
Expand All @@ -78,33 +78,32 @@ 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 = "bd39117", features = [
alloy = { git = "https://github.com/alloy-rs/alloy", rev = "3edca45", features = [
"consensus",
"kzg",
"eips",
"contract",
"eips",
"kzg",
"network",
"node-bindings",
"providers",
"provider-http",
"provider-ipc",
"provider-ws",
"rpc-client",
"providers",
"rpc-client-ipc",
"rpc-client-ws",
"rpc-client",
"rpc-types-eth",
"rpc-types-trace",
"signers",
"signer-aws",
"signer-keystore",
"signer-ledger",
"signer-mnemonic",
"signer-trezor",
"signer-wallet",
"signer-yubihsm",
"signers",
] }

# async
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ This repository contains the following examples:
- [x] Subscriptions
- [x] [Subscribe and watch blocks](./examples/subscriptions/examples/subscribe_blocks.rs)
- [x] [Watch and poll for contract event logs](./examples/subscriptions/examples/poll_logs.rs)
- [x] [Subscribe and listen for contract event logs](./examples/subscriptions/examples/subscribe_logs.rs)
- [x] [Subscribe and listen for specific contract event logs](./examples/subscriptions/examples/subscribe_logs.rs)
- [x] [Subscribe and listen for all contract event logs](./examples/subscriptions/examples/subscribe_all_logs.rs)
- [x] [Event multiplexer](./examples/subscriptions/examples/event_multiplexer.rs)
- [x] Providers
- [x] [Builder](./examples/providers/examples/builder.rs)
Expand Down
File renamed without changes.
8 changes: 4 additions & 4 deletions examples/contracts/examples/interact_with_abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ use eyre::Result;
sol!(
#[allow(missing_docs)]
#[sol(rpc)]
IERC20,
"examples/abi/IERC20.json"
IWETH9,
"examples/abi/IWETH9.json"
);

#[tokio::main]
Expand All @@ -22,10 +22,10 @@ async fn main() -> Result<()> {
let provider = ProviderBuilder::new().on_http(rpc_url);

// Create a contract instance.
let contract = IERC20::new("0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2".parse()?, provider);
let contract = IWETH9::new("0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2".parse()?, provider);

// Call the contract, retrieve the total supply.
let IERC20::totalSupplyReturn { _0 } = contract.totalSupply().call().await?;
let IWETH9::totalSupplyReturn { _0 } = contract.totalSupply().call().await?;

println!("WETH total supply is {_0}");

Expand Down
6 changes: 3 additions & 3 deletions examples/queries/examples/query_logs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ async fn main() -> Result<()> {
}

// Get all logs from the latest block that match the transfer event signature/topic.
let tranfer_event_signature =
let transfer_event_signature =
b256!("ddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef");
let filter = Filter::new().event_signature(tranfer_event_signature).from_block(latest_block);
let filter = Filter::new().event_signature(transfer_event_signature).from_block(latest_block);
// You could also use the event name instead of the event signature like so:
// .event("Transfer(address,address,uint256)")

Expand All @@ -40,7 +40,7 @@ async fn main() -> Result<()> {
println!("Transfer event: {log:?}");
}

// Get all from the latest block emitted by the UNI token address.
// Get all logs from the latest block emitted by the UNI token address.
let uniswap_token_address = address!("1f9840a85d5aF5bf1D1762F925BDADdC4201F984");
let filter = Filter::new().address(uniswap_token_address).from_block(latest_block);

Expand Down
Loading

0 comments on commit 2573367

Please sign in to comment.