tensor_eigen/formatting/
mod.rs1use std::{fmt::Display, fs::File, io::Write};
2
3use {
4 anyhow::Result,
5 chrono::DateTime,
6 solana_sdk::{account::Account, pubkey::Pubkey},
7};
8
9pub mod amm;
10pub mod marketplace;
11pub mod price_lock;
12pub mod raydium;
13pub mod wallet;
14pub mod whitelist;
15
16pub trait CustomFormat {
17 fn custom_format(&self) -> String;
18}
19
20pub fn option_formatter<T: Display>(value: &Option<T>) -> String {
21 match value {
22 Some(value) => value.to_string(),
23 None => "None".to_string(),
24 }
25}
26
27pub fn pad_label(label: &str, max_length: usize) -> String {
28 format!("{:<width$}", label, width = max_length)
29}
30
31pub fn format_timestamp(timestamp: i64) -> String {
32 DateTime::from_timestamp(timestamp, 0)
33 .unwrap_or_default()
34 .to_rfc3339()
35}
36
37pub struct AccountEntry {
38 pub address: Pubkey,
39 pub account: Account,
40}
41
42pub fn write_formatted<T: CustomFormat>(file_path: &str, items: &[T]) -> Result<()> {
43 let mut file = File::create(file_path)?;
44 for item in items {
45 writeln!(file, "{}\n", item.custom_format())?;
46 }
47 Ok(())
48}