solana-program-dumper 0.1.0

Dump a Solana program's executable (.so) and every account it owns, in one command.
mod cli;
mod dump;

use std::process::ExitCode;

use clap::Parser;

use crate::{
    cli::Args,
    dump::{dump_accounts, dump_program},
};

fn main() -> ExitCode {
    let args = Args::parse();

    if let Err(e) = std::fs::create_dir_all(&args.dir) {
        eprintln!("error: could not create {}: {e}", args.dir.display());
        return ExitCode::FAILURE;
    }

    // The two halves are independent: a program whose .so cannot be dumped
    // (closed, non-upgradeable, unavailable) may still have accounts worth
    // having, and vice versa. Run both, then fail if either did.
    let mut ok = true;

    if let Err(e) = dump_program(&args) {
        eprintln!("error: could not dump program executable: {e}");
        ok = false;
    }

    if let Err(e) = dump_accounts(&args) {
        eprintln!("error: could not dump program accounts: {e}");
        ok = false;
    }

    if ok {
        ExitCode::SUCCESS
    } else {
        ExitCode::FAILURE
    }
}