diff --git a/Cargo.lock b/Cargo.lock index 5a54aa8..069da33 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -981,6 +981,27 @@ dependencies = [ "subtle", ] +[[package]] +name = "csv" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac574ff4d437a7b5ad237ef331c17ccca63c46479e5b5453eb8e10bb99a759fe" +dependencies = [ + "csv-core", + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "csv-core" +version = "0.1.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5efa2b3d7902f4b634a20cae3c9c4e6209dc4779feb6863329607560143efa70" +dependencies = [ + "memchr", +] + [[package]] name = "ctr" version = "0.8.0" @@ -5220,6 +5241,7 @@ dependencies = [ "cargo-lock", "clap", "crossbeam-channel", + "csv", "futures", "git-version", "hostname", diff --git a/yellowstone-grpc-geyser/Cargo.toml b/yellowstone-grpc-geyser/Cargo.toml index 8cac576..12d57dd 100644 --- a/yellowstone-grpc-geyser/Cargo.toml +++ b/yellowstone-grpc-geyser/Cargo.toml @@ -42,6 +42,8 @@ tonic = { workspace = true, features = ["gzip", "tls", "tls-roots"] } tonic-health = { workspace = true } yellowstone-grpc-proto = { workspace = true } +csv = "1.3.0" + [build-dependencies] anyhow = { workspace = true } cargo-lock = { workspace = true } diff --git a/yellowstone-grpc-geyser/src/plugin.rs b/yellowstone-grpc-geyser/src/plugin.rs index 8275145..6b3c7f6 100644 --- a/yellowstone-grpc-geyser/src/plugin.rs +++ b/yellowstone-grpc-geyser/src/plugin.rs @@ -1,5 +1,8 @@ -use log::warn; -use tokio::sync::mpsc::error::SendError; +use std::cell::RefCell; +use std::fs::File; +use std::sync::Mutex; +use csv::Writer; +use log::{info, warn}; use { crate::{ config::Config, @@ -32,6 +35,7 @@ pub struct PluginInner { grpc_channel: mpsc::UnboundedSender, grpc_shutdown: Arc, prometheus: PrometheusService, + csv_writer: Arc>>, } impl PluginInner { @@ -100,12 +104,15 @@ impl GeyserPlugin for Plugin { )) })?; + let mut csv_writer = Writer::from_path("account-sizes.csv").expect("must be able to use CSV"); + self.inner = Some(PluginInner { runtime, snapshot_channel, grpc_channel, grpc_shutdown, prometheus, + csv_writer: Arc::new(Mutex::new(csv_writer)), }); Ok(())