Skip to main content

quicknode_cascade/plugins/
stdout.rs

1//! Stdout plugin — prints block data as JSON lines to stdout.
2//!
3//! Useful for piping to `jq`, `grep`, or other CLI tools.
4
5use crate::solana::{BlockData, Plugin, PluginFuture};
6
7/// Built-in plugin that prints block data to stdout as one JSON line per block.
8///
9/// In structured mode, prints `BlockData` JSON. Logs go to stderr.
10pub struct StdoutPlugin;
11
12impl Plugin for StdoutPlugin {
13    fn name(&self) -> &'static str {
14        "stdout"
15    }
16
17    fn on_block<'a>(&'a self, block: &'a BlockData) -> PluginFuture<'a> {
18        Box::pin(async move {
19            let json = serde_json::to_string(block)
20                .map_err(|e| Box::new(e) as Box<dyn std::error::Error + Send + Sync>)?;
21            println!("{}", json);
22            Ok(())
23        })
24    }
25}