Skip to content

Commit

Permalink
chore: improve beacon api example (paradigmxyz#9660)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattsse authored Jul 19, 2024
1 parent 9b05703 commit 06eb97c
Showing 1 changed file with 22 additions and 19 deletions.
41 changes: 22 additions & 19 deletions examples/beacon-api-sidecar-fetcher/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pub mod mined_sidecar;

fn main() {
Cli::<BeaconSidecarConfig>::parse()
.run(|builder, args| async move {
.run(|builder, beacon_config| async move {
// launch the node
let NodeHandle { node, node_exit_future } =
builder.node(EthereumNode::default()).launch().await?;
Expand All @@ -38,27 +38,30 @@ fn main() {

let pool = node.pool.clone();

let mut sidecar_stream = MinedSidecarStream {
events: notifications,
pool,
beacon_config: args,
client: reqwest::Client::new(),
pending_requests: FuturesUnordered::new(),
queued_actions: VecDeque::new(),
};
node.task_executor.spawn(async move {
let mut sidecar_stream = MinedSidecarStream {
events: notifications,
pool,
beacon_config,
client: reqwest::Client::new(),
pending_requests: FuturesUnordered::new(),
queued_actions: VecDeque::new(),
};

while let Some(result) = sidecar_stream.next().await {
match result {
Ok(blob_transaction) => {
// Handle successful transaction
println!("Processed BlobTransaction: {:?}", blob_transaction);
}
Err(e) => {
// Handle errors specifically
eprintln!("Failed to process transaction: {:?}", e);
while let Some(result) = sidecar_stream.next().await {
match result {
Ok(blob_transaction) => {
// Handle successful transaction
println!("Processed BlobTransaction: {:?}", blob_transaction);
}
Err(e) => {
// Handle errors specifically
eprintln!("Failed to process transaction: {:?}", e);
}
}
}
}
});

node_exit_future.await
})
.unwrap();
Expand Down

0 comments on commit 06eb97c

Please sign in to comment.