mod account;
mod analytics;
mod dispatch;
mod ledger;
pub(in crate::icrc) mod options;
#[cfg(test)]
mod tests;
use account::AccountCommand;
use analytics::AnalyticsCommand;
pub use dispatch::run_matches;
use ledger::LedgerCommand;
use crate::cli::clap::principal_text_value_parser;
use clap::{Command as ClapCommand, Subcommand, builder::ValueParser};
use ic_query::icrc::normalize_subaccount_hex;
const DEFAULT_ICRC_TRANSACTIONS_LIMIT: &str = "25";
const MAX_ICRC_TRANSACTIONS_LIMIT: u64 = 100;
const DEFAULT_ICRC_ACCOUNT_TRANSACTION_PAGE_SIZE: &str = "100";
#[derive(Subcommand)]
#[command(about = "Inspect generic ICRC ledgers and official analytics", long_about = None)]
enum IcrcCommand {
#[command(subcommand)]
Ledger(LedgerCommand),
#[command(subcommand)]
Account(AccountCommand),
#[command(subcommand)]
Analytics(AnalyticsCommand),
}
pub fn command() -> ClapCommand {
IcrcCommand::augment_subcommands(ClapCommand::new("icrc"))
.mut_subcommand("ledger", |command| {
command.mut_subcommands(|command| {
command
.mut_arg("source-endpoint", |arg| {
arg.help("IC API endpoint used for ICRC ledger queries")
.display_order(20)
})
.mut_arg("json", |arg| arg.display_order(22))
})
})
.mut_subcommand("account", with_account_endpoint)
.mut_subcommand("analytics", analytics::configure)
}
fn with_account_endpoint(command: ClapCommand) -> ClapCommand {
if command.has_subcommands() {
command.mut_subcommands(with_account_endpoint)
} else {
command
.mut_arg("source-endpoint", |arg| {
arg.help("IC API endpoint used for ICRC ledger queries")
.display_order(1000)
})
.mut_arg("json", |arg| arg.display_order(1001))
}
}
fn subaccount_hex_value_parser() -> ValueParser {
ValueParser::new(|value: &str| normalize_subaccount_hex(value).map_err(|err| err.to_string()))
}