-
Notifications
You must be signed in to change notification settings - Fork 4
Add example for eip7702 #73
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
WalkthroughAdds a new Rust example crate at examples/eip7702. Cargo.toml defines dependencies and project metadata. main.rs implements an async example using hypersync-client to query EIP-7702-related transactions from https://eth.hypersync.xyz, prints authorization_list fields, and uses Tokio, serde_json, ruint, and env_logger. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
actor User
participant App as eip7702 example (main.rs)
participant Client as hypersync-client
participant API as Hypersync API
User->>App: Run binary
App->>Client: new Client("https://eth.hypersync.xyz")
App->>App: Build JSON query (blocks, txs.authorization_list, field selection)
App->>Client: get(query) (async)
Client->>API: HTTP request with query
API-->>Client: Response (transactions batches)
Client-->>App: Result { data.transactions }
loop For each batch
App->>App: Iterate txs and print authorization_list
end
App-->>User: Console output
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
Tip 🔌 Remote MCP (Model Context Protocol) integration is now available!Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats. ✨ Finishing Touches
🧪 Generate unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🧹 Nitpick comments (9)
examples/eip7702/Cargo.toml (3)
1-5
: Mark the example crate as non-publishable to avoid accidental release to crates.ioAdd
publish = false
under[package]
. Optional: includelicense
andrepository
metadata for consistency with the workspace.[package] name = "eip7702" version = "0.1.0" edition = "2021" +publish = false
9-9
: Avoid Tokio “full” feature set in examples to reduce compile times and binary sizeThis example needs only the runtime and macros. Consider trimming the features.
-tokio = { version = "1", features = ["full"] } +tokio = { version = "1", features = ["rt-multi-thread", "macros"] }
11-11
:ruint
isn’t used — remove it or put it to use (e.g., parsing U256 chain IDs)If you don’t use it in the example, drop the dependency to keep the example lean.
-ruint = "1"
If you intend to decode chain IDs or other 256-bit ints here, I can add a small snippet that demonstrates that and keeps
ruint
.examples/eip7702/src/main.rs (6)
1-2
: Header comment doesn’t match the actual query (limited block range vs. “all”)Either change the header to reflect a range-based example, or adjust the query to truly fetch “all”.
-// Example of getting all EIP-7702 transactions +// Example: fetch EIP-7702 transactions in a specific block range
3-3
: Remove unused Arc import
Arc
isn’t needed — the client isn’t shared across threads/tasks.-use std::sync::Arc;
33-34
: Drop the unnecessaryArc
wrapping of the clientYou construct an
Arc<Client>
but never clone or share it. Keep it as a plainClient
.- let client = Arc::new(client); + // No Arc needed; keep the client as-is.
17-31
: Make the query more robust and clean up comments/typos
- Inline block comment inside
json!
is odd; move notes above the JSON.- Typo: “filterring” → “filtering”.
- The “start from block 0…” comment contradicts the actual range; update it here or remove it.
If the typed
Query
has a builder API, prefer that overfrom_value
to catch shape errors at compile time. Otherwise, at least keep comments outside the JSON.- let query: Query = serde_json::from_value(serde_json::json!( { - // start from block 0 and go to the end of the chain (we don't specify a toBlock). + // NOTE: chain_id filtering is currently not working. + let query: Query = serde_json::from_value(serde_json::json!({ + // Fetch a small block range for the example "from_block": 22490287, "to_block": 22490297, "transactions": [ - {"authorization_list": [{/*"chain_id": [1], // chain_id filterring isn't working currently*/ "address": ["0x80296ff8d1ed46f8e3c7992664d13b833504c2bb"]}]} + { + "authorization_list": [{ + "address": ["0x80296ff8d1ed46f8e3c7992664d13b833504c2bb"] + }] + } ], - // Select the fields we are interested in, notice topics are selected as topic0,1,2,3 + // Select the fields we are interested in "field_selection": { "transaction": [ - "hash","authorization_list" + "hash", "authorization_list" ] }, - })) + }))
37-43
: Avoid panicking on network/parse errors; log and exit gracefully. Also include tx hash in output for contextThis improves the example’s ergonomics and makes failures clearer.
- let res = client.get(&query).await.unwrap(); + let res = match client.get(&query).await { + Ok(r) => r, + Err(err) => { + eprintln!("Request failed: {err}"); + return; + } + }; for batch in res.data.transactions { for tx in batch { - println!("Transaction: {:?}", tx.authorization_list); + println!("Transaction {:?}: {:?}", tx.hash, tx.authorization_list); } }
11-15
: Optional: allow overriding the service URL via env for easier testingKeeping the default as eth mainnet is fine; this just makes the example more flexible without adding complexity.
- let client = Client::new(ClientConfig { - url: Some("https://eth.hypersync.xyz".parse().unwrap()), + let default_url = "https://eth.hypersync.xyz".to_string(); + let url = std::env::var("HYPERSYNC_URL").unwrap_or(default_url); + let client = Client::new(ClientConfig { + url: Some(url.parse().unwrap()), ..Default::default() })
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
💡 Knowledge Base configuration:
- MCP integration is disabled by default for public repositories
- Jira integration is disabled by default for public repositories
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (2)
examples/eip7702/Cargo.toml
(1 hunks)examples/eip7702/src/main.rs
(1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
- GitHub Check: test_release
- GitHub Check: test_dev
🔇 Additional comments (2)
examples/eip7702/Cargo.toml (1)
12-12
: No change needed: env_logger 0.4’sinit()
already returns aResult
Our inspection of env_logger v0.4.3 shows that both the builder’s
init(&mut self) -> Result<(), SetLoggerError>
and the freeinit() -> Result<(), SetLoggerError>
return aResult
, so calling.unwrap()
oninit()
compiles fine. You can keepenv_logger = "0.4"
in Cargo.toml and retainenv_logger::init().unwrap()
in main.rs without errors.Likely an incorrect or invalid review comment.
examples/eip7702/src/main.rs (1)
39-43
: Minor: handle empty batches defensively (no action required)If
res.data.transactions
can be empty, the loop is already safe. Just noting it; no change needed.
|
||
#[tokio::main] | ||
async fn main() { | ||
env_logger::init().unwrap(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix env_logger initialization
env_logger::init()
shouldn’t be unwrapped; with env_logger 0.4 it returns ()
. If you upgraded env_logger (per Cargo.toml comment), init()
still returns ()
. Use try_init()
only if you want to handle the error.
- env_logger::init().unwrap();
+ env_logger::init();
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
env_logger::init().unwrap(); | |
env_logger::init(); |
🤖 Prompt for AI Agents
In examples/eip7702/src/main.rs around line 9, the call
env_logger::init().unwrap() is incorrect because init() returns () (or if
upgraded you should use try_init() to handle errors); remove the .unwrap() and
call env_logger::init() directly, or if you need to handle initialization
failures use env_logger::try_init() and handle the Result (e.g., log or
propagate the error) instead of unwrapping.
This is an older example I wrote, just noticed I didn't push.
Summary by CodeRabbit