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),
|
Restore(sub_commands::restore::RestoreSubCommand),
|
||||||
/// Update Mint Url
|
/// Update Mint Url
|
||||||
UpdateMintUrl(sub_commands::update_mint_url::UpdateMintUrlSubCommand),
|
UpdateMintUrl(sub_commands::update_mint_url::UpdateMintUrlSubCommand),
|
||||||
|
/// Get proofs from mint.
|
||||||
|
ListMintProofs,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
@@ -123,10 +125,10 @@ async fn main() -> Result<()> {
|
|||||||
let mut rng = rand::thread_rng();
|
let mut rng = rand::thread_rng();
|
||||||
let random_bytes: [u8; 32] = rng.gen();
|
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");
|
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)
|
sub_commands::update_mint_url::update_mint_url(&multi_mint_wallet, sub_command_args)
|
||||||
.await
|
.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 burn;
|
||||||
pub mod check_spent;
|
pub mod check_spent;
|
||||||
pub mod decode_token;
|
pub mod decode_token;
|
||||||
|
pub mod list_mint_proofs;
|
||||||
pub mod melt;
|
pub mod melt;
|
||||||
pub mod mint;
|
pub mod mint;
|
||||||
pub mod mint_info;
|
pub mod mint_info;
|
||||||
|
|||||||
@@ -138,8 +138,12 @@ impl Default for &Amount {
|
|||||||
|
|
||||||
impl fmt::Display for Amount {
|
impl fmt::Display for Amount {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
|
if let Some(width) = f.width() {
|
||||||
|
write!(f, "{:width$}", self.0, width = width)
|
||||||
|
} else {
|
||||||
write!(f, "{}", self.0)
|
write!(f, "{}", self.0)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<u64> for Amount {
|
impl From<u64> for Amount {
|
||||||
|
|||||||
@@ -378,11 +378,16 @@ impl FromStr for CurrencyUnit {
|
|||||||
|
|
||||||
impl fmt::Display for CurrencyUnit {
|
impl fmt::Display for CurrencyUnit {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
match self {
|
let s = match self {
|
||||||
CurrencyUnit::Sat => write!(f, "sat"),
|
CurrencyUnit::Sat => "sat",
|
||||||
CurrencyUnit::Msat => write!(f, "msat"),
|
CurrencyUnit::Msat => "msat",
|
||||||
CurrencyUnit::Usd => write!(f, "usd"),
|
CurrencyUnit::Usd => "usd",
|
||||||
CurrencyUnit::Eur => write!(f, "eur"),
|
CurrencyUnit::Eur => "eur",
|
||||||
|
};
|
||||||
|
if let Some(width) = f.width() {
|
||||||
|
write!(f, "{:width$}", s, width = width)
|
||||||
|
} else {
|
||||||
|
write!(f, "{}", s)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ use super::types::SendKind;
|
|||||||
use super::Error;
|
use super::Error;
|
||||||
use crate::amount::SplitTarget;
|
use crate::amount::SplitTarget;
|
||||||
use crate::mint_url::MintUrl;
|
use crate::mint_url::MintUrl;
|
||||||
use crate::nuts::{CurrencyUnit, SecretKey, SpendingConditions, Token};
|
use crate::nuts::{CurrencyUnit, Proof, SecretKey, SpendingConditions, Token};
|
||||||
use crate::types::Melted;
|
use crate::types::Melted;
|
||||||
use crate::wallet::types::MintQuote;
|
use crate::wallet::types::MintQuote;
|
||||||
use crate::{Amount, Wallet};
|
use crate::{Amount, Wallet};
|
||||||
@@ -117,6 +117,20 @@ impl MultiMintWallet {
|
|||||||
Ok(balances)
|
Ok(balances)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// List proofs.
|
||||||
|
#[instrument(skip(self))]
|
||||||
|
pub async fn list_proofs(
|
||||||
|
&self,
|
||||||
|
) -> Result<BTreeMap<MintUrl, (Vec<Proof>, CurrencyUnit)>, Error> {
|
||||||
|
let mut mint_proofs = BTreeMap::new();
|
||||||
|
|
||||||
|
for (WalletKey { mint_url, unit: u }, wallet) in self.wallets.lock().await.iter() {
|
||||||
|
let wallet_proofs = wallet.get_proofs().await?;
|
||||||
|
mint_proofs.insert(mint_url.clone(), (wallet_proofs, *u));
|
||||||
|
}
|
||||||
|
Ok(mint_proofs)
|
||||||
|
}
|
||||||
|
|
||||||
/// Create cashu token
|
/// Create cashu token
|
||||||
#[instrument(skip(self))]
|
#[instrument(skip(self))]
|
||||||
pub async fn send(
|
pub async fn send(
|
||||||
|
|||||||
Reference in New Issue
Block a user