transaction-decoder 0.1.13

A CLI tool for decoding EVM transactions
Documentation
use clap::Parser;

/// Command-line arguments for the transaction decoder CLI.
#[derive(Parser, Debug)]
#[command(name = "transaction-decoder", version = "0.1.10", about = "EVM Transaction Decoder CLI", long_about = None )]
pub struct Args {
    #[arg(value_parser = validate_tx_hash, help = "Transaction hash to fetch. Must be a valid EVM transaction hash.")]
    pub transaction_hash: String,

    #[arg(short, long, default_value_t = String::from("https://eth.llamarpc.com"))]
    pub rpc_url: String,

    #[arg(short, long, help = "Decode and print logs if present")]
    pub logs: bool,

    #[arg(short, long, help = "Print transaction traces")]
    pub traces: bool,

    #[arg(
        short,
        long,
        help = "Print output in plain text format (non-interactive)"
    )]
    pub plain: bool,
}

/// Validates that the input string is a valid transaction hash.
fn validate_tx_hash(hash: &str) -> Result<String, String> {
    if hash.len() != 66
        || !hash.starts_with("0x")
        || !hash[2..].chars().all(|c| c.is_ascii_hexdigit())
    {
        Err("Invalid transaction hash".to_string())
    } else {
        Ok(hash.to_string())
    }
}