mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
docs(exex): include code for ExEx book from real files (#11545)
This commit is contained in:
13
book/sources/exex/hello-world/Cargo.toml
Normal file
13
book/sources/exex/hello-world/Cargo.toml
Normal file
@ -0,0 +1,13 @@
|
||||
[package]
|
||||
name = "my-exex"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
reth = { git = "https://github.com/paradigmxyz/reth.git" } # Reth
|
||||
reth-exex = { git = "https://github.com/paradigmxyz/reth.git" } # Execution Extensions
|
||||
reth-node-ethereum = { git = "https://github.com/paradigmxyz/reth.git" } # Ethereum Node implementation
|
||||
reth-tracing = { git = "https://github.com/paradigmxyz/reth.git" } # Logging
|
||||
|
||||
eyre = "0.6" # Easy error handling
|
||||
futures-util = "0.3" # Stream utilities for consuming notifications
|
||||
9
book/sources/exex/hello-world/src/bin/1.rs
Normal file
9
book/sources/exex/hello-world/src/bin/1.rs
Normal file
@ -0,0 +1,9 @@
|
||||
use reth_node_ethereum::EthereumNode;
|
||||
|
||||
fn main() -> eyre::Result<()> {
|
||||
reth::cli::Cli::parse_args().run(|builder, _| async move {
|
||||
let handle = builder.node(EthereumNode::default()).launch().await?;
|
||||
|
||||
handle.wait_for_node_exit().await
|
||||
})
|
||||
}
|
||||
20
book/sources/exex/hello-world/src/bin/2.rs
Normal file
20
book/sources/exex/hello-world/src/bin/2.rs
Normal file
@ -0,0 +1,20 @@
|
||||
use reth::api::FullNodeComponents;
|
||||
use reth_exex::ExExContext;
|
||||
use reth_node_ethereum::EthereumNode;
|
||||
|
||||
async fn my_exex<Node: FullNodeComponents>(mut _ctx: ExExContext<Node>) -> eyre::Result<()> {
|
||||
#[allow(clippy::empty_loop)]
|
||||
loop {}
|
||||
}
|
||||
|
||||
fn main() -> eyre::Result<()> {
|
||||
reth::cli::Cli::parse_args().run(|builder, _| async move {
|
||||
let handle = builder
|
||||
.node(EthereumNode::default())
|
||||
.install_exex("my-exex", |ctx| async move { Ok(my_exex(ctx)) })
|
||||
.launch()
|
||||
.await?;
|
||||
|
||||
handle.wait_for_node_exit().await
|
||||
})
|
||||
}
|
||||
39
book/sources/exex/hello-world/src/bin/3.rs
Normal file
39
book/sources/exex/hello-world/src/bin/3.rs
Normal file
@ -0,0 +1,39 @@
|
||||
use futures_util::TryStreamExt;
|
||||
use reth::api::FullNodeComponents;
|
||||
use reth_exex::{ExExContext, ExExEvent, ExExNotification};
|
||||
use reth_node_ethereum::EthereumNode;
|
||||
use reth_tracing::tracing::info;
|
||||
|
||||
async fn my_exex<Node: FullNodeComponents>(mut ctx: ExExContext<Node>) -> eyre::Result<()> {
|
||||
while let Some(notification) = ctx.notifications.try_next().await? {
|
||||
match ¬ification {
|
||||
ExExNotification::ChainCommitted { new } => {
|
||||
info!(committed_chain = ?new.range(), "Received commit");
|
||||
}
|
||||
ExExNotification::ChainReorged { old, new } => {
|
||||
info!(from_chain = ?old.range(), to_chain = ?new.range(), "Received reorg");
|
||||
}
|
||||
ExExNotification::ChainReverted { old } => {
|
||||
info!(reverted_chain = ?old.range(), "Received revert");
|
||||
}
|
||||
};
|
||||
|
||||
if let Some(committed_chain) = notification.committed_chain() {
|
||||
ctx.events.send(ExExEvent::FinishedHeight(committed_chain.tip().num_hash()))?;
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn main() -> eyre::Result<()> {
|
||||
reth::cli::Cli::parse_args().run(|builder, _| async move {
|
||||
let handle = builder
|
||||
.node(EthereumNode::default())
|
||||
.install_exex("my-exex", |ctx| async move { Ok(my_exex(ctx)) })
|
||||
.launch()
|
||||
.await?;
|
||||
|
||||
handle.wait_for_node_exit().await
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user