sol_log_parser/
lib.rs

1//! A small utility crate for parsing solana logs
2pub use error::LogParseError;
3pub use parsed_log::ParsedLog;
4pub use raw_log::RawLog;
5pub use structured_log::{parsed::ParsedStructuredLog, raw::RawStructuredLog};
6
7pub mod error;
8pub mod parsed_log;
9pub mod raw_log;
10pub mod structured_log;
11
12pub type Result<T> = std::result::Result<T, LogParseError>;
13
14/// A small utility function to check if a string is a valid Solana public key.
15pub fn quick_pubkey_check(pubkey: &str) -> bool {
16    const MIN_CHARS: usize = 32;
17    const MAX_CHARS: usize = 44;
18
19    // pubkey should be composed of ascii characters
20    let bytes = pubkey.as_bytes();
21    let len = bytes.len();
22
23    // Check if the length is within the valid range
24    #[allow(clippy::manual_range_contains)]
25    if len < MIN_CHARS || len > MAX_CHARS {
26        return false;
27    }
28
29    // Check characters are valid base58 characters
30    bytes.iter().all(|b| {
31        matches!(
32            b,
33            b'1'..=b'9' | b'A'..=b'H' | b'J'..=b'N' | b'P'..=b'Z' | b'a'..=b'k' | b'm'..=b'z'
34        )
35    })
36}