Skip to content

Commit

Permalink
Merge pull request #71 from logical-mechanism/70-count-total-lovelace…
Browse files Browse the repository at this point in the history
…-and-utxos-in-contract

70 count total lovelace and utxos in contract
  • Loading branch information
quinn-logicalmechanism authored Jan 8, 2025
2 parents 2fc5e31 + f92ea5f commit 1148be9
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
9 changes: 9 additions & 0 deletions seedelf-cli/src/commands/util/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@ use clap::{Args, Subcommand};

pub mod expose_key;
pub mod find_seedelf;
pub mod statistics;

#[derive(Subcommand)]
pub enum UtilCommands {
/// Exposes the wallets secret key, use with caution!
ExposeKey,
/// Find all Seedelfs by a label / personal tag
FindSeedelf(find_seedelf::FindArgs),
/// Display statistics about seedelf
Statistics,
}

#[derive(Args)]
Expand All @@ -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);
}

}
}
}
11 changes: 11 additions & 0 deletions seedelf-cli/src/commands/util/statistics.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
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;
// other things can go here
Ok(())
}
21 changes: 21 additions & 0 deletions seedelf-cli/src/utxos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
}
}
}

0 comments on commit 1148be9

Please sign in to comment.