From 6aecf30731d34f8823039d57969f2f20447c1cc3 Mon Sep 17 00:00:00 2001 From: logicalmechanism Date: Tue, 7 Jan 2025 20:23:07 -0800 Subject: [PATCH 1/2] good base function for future statistics --- seedelf-cli/src/commands/util/mod.rs | 9 +++++++++ seedelf-cli/src/commands/util/statistics.rs | 10 ++++++++++ seedelf-cli/src/utxos.rs | 21 +++++++++++++++++++++ 3 files changed, 40 insertions(+) create mode 100644 seedelf-cli/src/commands/util/statistics.rs diff --git a/seedelf-cli/src/commands/util/mod.rs b/seedelf-cli/src/commands/util/mod.rs index b5e50ee..73832da 100644 --- a/seedelf-cli/src/commands/util/mod.rs +++ b/seedelf-cli/src/commands/util/mod.rs @@ -2,6 +2,7 @@ use clap::{Args, Subcommand}; pub mod expose_key; pub mod find_seedelf; +pub mod statistics; #[derive(Subcommand)] pub enum UtilCommands { @@ -9,6 +10,8 @@ pub enum UtilCommands { ExposeKey, /// Find all Seedelfs by a label / personal tag FindSeedelf(find_seedelf::FindArgs), + /// Display statistics about seedelf + Statistics, } #[derive(Args)] @@ -27,5 +30,11 @@ pub async fn run(args: UtilArgs, preprod_flag: bool) { eprintln!("Error: {}", err); } } + UtilCommands::Statistics => { + if let Err(err) = statistics::run(preprod_flag).await { + eprintln!("Error: {}", err); + } + + } } } \ No newline at end of file diff --git a/seedelf-cli/src/commands/util/statistics.rs b/seedelf-cli/src/commands/util/statistics.rs new file mode 100644 index 0000000..c55320f --- /dev/null +++ b/seedelf-cli/src/commands/util/statistics.rs @@ -0,0 +1,10 @@ +use colored::Colorize; +use seedelf_cli::display::preprod_text; +use seedelf_cli::utxos::count_lovelace_and_utxos; + +pub async fn run(network_flag: bool) -> Result<(), String> { + preprod_text(network_flag); + println!("\n{}", "Seedelf Statistics".bright_blue()); + count_lovelace_and_utxos(network_flag).await; + Ok(()) +} \ No newline at end of file diff --git a/seedelf-cli/src/utxos.rs b/seedelf-cli/src/utxos.rs index dd3ef18..d9f3514 100644 --- a/seedelf-cli/src/utxos.rs +++ b/seedelf-cli/src/utxos.rs @@ -344,4 +344,25 @@ pub async fn find_and_print_all_seedelfs(label: String, network_flag: bool) { ); } } +} + +/// Find a seedelf that contains the label and print the match. +pub async fn count_lovelace_and_utxos(network_flag: bool) { + match credential_utxos(WALLET_CONTRACT_HASH, network_flag).await { + Ok(utxos) => { + let mut total_lovelace: u64 = 0; + for utxo in utxos.clone() { + let value: u64 = string_to_u64(utxo.value.clone()).unwrap(); + total_lovelace += value; + } + println!("\nBalance: {} ₳", format!("{:.6}", total_lovelace as f64 / 1_000_000.0).bright_yellow()); + println!("Contract Has {} UTxOs", utxos.len().to_string().bright_yellow()); + } + Err(err) => { + eprintln!( + "Failed to fetch UTxOs: {}\nWait a few moments and try again.", + err + ); + } + } } \ No newline at end of file From f92ea5fcb3684647d359bec973eef23670e9faa2 Mon Sep 17 00:00:00 2001 From: logicalmechanism Date: Tue, 7 Jan 2025 20:31:31 -0800 Subject: [PATCH 2/2] added a quick comment --- seedelf-cli/src/commands/util/statistics.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/seedelf-cli/src/commands/util/statistics.rs b/seedelf-cli/src/commands/util/statistics.rs index c55320f..77dfb7b 100644 --- a/seedelf-cli/src/commands/util/statistics.rs +++ b/seedelf-cli/src/commands/util/statistics.rs @@ -6,5 +6,6 @@ pub async fn run(network_flag: bool) -> Result<(), String> { preprod_text(network_flag); println!("\n{}", "Seedelf Statistics".bright_blue()); count_lovelace_and_utxos(network_flag).await; + // other things can go here Ok(()) } \ No newline at end of file