mirror of
https://github.com/aljazceru/cdk.git
synced 2025-12-23 07:35:03 +01:00
feat: mint-proofs command
fix typo make output more readable. Co-authored-by: Pavol Rusnak <pavol@rusnak.io>
This commit is contained in:
@@ -70,6 +70,8 @@ enum Commands {
|
||||
Restore(sub_commands::restore::RestoreSubCommand),
|
||||
/// Update Mint Url
|
||||
UpdateMintUrl(sub_commands::update_mint_url::UpdateMintUrlSubCommand),
|
||||
/// Get proofs from mint.
|
||||
ListMintProofs,
|
||||
}
|
||||
|
||||
#[tokio::main]
|
||||
@@ -123,10 +125,10 @@ async fn main() -> Result<()> {
|
||||
let mut rng = rand::thread_rng();
|
||||
let random_bytes: [u8; 32] = rng.gen();
|
||||
|
||||
let mnemnic = Mnemonic::from_entropy(&random_bytes)?;
|
||||
let mnemonic = Mnemonic::from_entropy(&random_bytes)?;
|
||||
tracing::info!("Using randomly generated seed you will not be able to restore");
|
||||
|
||||
mnemnic
|
||||
mnemonic
|
||||
}
|
||||
};
|
||||
|
||||
@@ -199,5 +201,8 @@ async fn main() -> Result<()> {
|
||||
sub_commands::update_mint_url::update_mint_url(&multi_mint_wallet, sub_command_args)
|
||||
.await
|
||||
}
|
||||
Commands::ListMintProofs => {
|
||||
sub_commands::list_mint_proofs::proofs(&multi_mint_wallet).await
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
41
crates/cdk-cli/src/sub_commands/list_mint_proofs.rs
Normal file
41
crates/cdk-cli/src/sub_commands/list_mint_proofs.rs
Normal file
@@ -0,0 +1,41 @@
|
||||
use std::collections::BTreeMap;
|
||||
|
||||
use anyhow::Result;
|
||||
use cdk::{
|
||||
mint_url::MintUrl,
|
||||
nuts::{CurrencyUnit, Proof},
|
||||
wallet::multi_mint_wallet::MultiMintWallet,
|
||||
};
|
||||
|
||||
pub async fn proofs(multi_mint_wallet: &MultiMintWallet) -> Result<()> {
|
||||
list_proofs(multi_mint_wallet).await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn list_proofs(
|
||||
multi_mint_wallet: &MultiMintWallet,
|
||||
) -> Result<Vec<(MintUrl, (Vec<Proof>, CurrencyUnit))>> {
|
||||
let wallets_proofs: BTreeMap<MintUrl, (Vec<Proof>, CurrencyUnit)> =
|
||||
multi_mint_wallet.list_proofs().await?;
|
||||
|
||||
let mut proofs_vec = Vec::with_capacity(wallets_proofs.len());
|
||||
|
||||
for (i, (mint_url, proofs)) in wallets_proofs.iter().enumerate() {
|
||||
let mint_url = mint_url.clone();
|
||||
println!("{i}: {mint_url}");
|
||||
println!("| Amount | Unit | Secret | DLEQ proof included");
|
||||
println!("|----------|------|------------------------------------------------------------------|--------------------");
|
||||
for proof in &proofs.0 {
|
||||
println!(
|
||||
"| {:8} | {:4} | {:64} | {}",
|
||||
proof.amount,
|
||||
proofs.1,
|
||||
proof.secret,
|
||||
proof.dleq.is_some()
|
||||
);
|
||||
}
|
||||
println!();
|
||||
proofs_vec.push((mint_url, proofs.clone()))
|
||||
}
|
||||
Ok(proofs_vec)
|
||||
}
|
||||
@@ -2,6 +2,7 @@ pub mod balance;
|
||||
pub mod burn;
|
||||
pub mod check_spent;
|
||||
pub mod decode_token;
|
||||
pub mod list_mint_proofs;
|
||||
pub mod melt;
|
||||
pub mod mint;
|
||||
pub mod mint_info;
|
||||
|
||||
Reference in New Issue
Block a user