ic-query-cli 0.87.0

Command-line wrapper for read-only Internet Computer metadata queries
Documentation
//! Module: sns::commands::run::reward
//!
//! Responsibility: dispatch SNS reward evidence commands into library builders.
//! Does not own: Clap shape, live Governance calls, or report validation.
//! Boundary: maps parsed checkpoint options into one live report request.

use crate::{
    cli::common::{current_unix_secs, write_text_or_json},
    sns::commands::{SnsCommandError, options::reward_checkpoint_request},
};
use clap::ArgMatches;
use ic_query::sns::build_sns_reward_checkpoint_report;
use ic_query::sns::build_sns_reward_diff_report_from_paths;
use ic_query_text::sns::sns_reward_checkpoint_report_text;
use ic_query_text::sns::sns_reward_diff_report_text;

pub(super) async fn run_sns_reward(
    matches: &ArgMatches,
    network: &str,
    network_was_explicit: bool,
) -> Result<(), SnsCommandError> {
    match matches.subcommand() {
        Some(("checkpoint", matches)) => run_sns_reward_checkpoint(matches, network).await,
        Some(("diff", matches)) => {
            if network_was_explicit {
                return Err(SnsCommandError::Usage(
                    "--network is not supported by local-only `icq sns reward diff`".to_string(),
                ));
            }
            run_sns_reward_diff(matches)
        }
        _ => unreachable!("clap requires a known SNS reward subcommand"),
    }
}

fn run_sns_reward_diff(matches: &ArgMatches) -> Result<(), SnsCommandError> {
    let before: std::path::PathBuf = crate::cli::clap::required_typed(matches, "before-checkpoint");
    let after: std::path::PathBuf = crate::cli::clap::required_typed(matches, "after-checkpoint");
    let report = build_sns_reward_diff_report_from_paths(&before, &after)?;
    write_text_or_json(
        crate::cli::common::output_format(matches),
        &report,
        sns_reward_diff_report_text,
    )
}

async fn run_sns_reward_checkpoint(
    matches: &ArgMatches,
    network: &str,
) -> Result<(), SnsCommandError> {
    let (format, request) = reward_checkpoint_request(matches, network, current_unix_secs()?)?;
    let report = build_sns_reward_checkpoint_report(&request).await?;
    write_text_or_json(format, &report, sns_reward_checkpoint_report_text)
}