Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

List proofs #397

Merged
merged 1 commit into from
Oct 13, 2024
Merged

List proofs #397

merged 1 commit into from
Oct 13, 2024

Conversation

ubbabeck
Copy link
Contributor

About

New command which lists proofs in wallet. Sorted buy mint and time received.

Would it be preferred to sort the proofs buy amount instead?

@thesimplekid
Copy link
Collaborator

Thanks for this, I think we should list them under a header for each mint and then we shouldn't print the whole proofs as its too hard to read and i think has too much info. I'm thinking something like below and those proofs sorted by amount.

0: https://test.mint.com
| Amount | Unit | Secret | Includes bleq (bool)

@prusnak
Copy link
Contributor

prusnak commented Oct 11, 2024

We can simplify formatting if we modify formatters for Amounts and CurrencyUnits:

diff --git a/crates/cdk-cli/src/sub_commands/list_mint_proofs.rs b/crates/cdk-cli/src/sub_commands/list_mint_proofs.rs
index d9661db..f4e8a4d 100644
--- a/crates/cdk-cli/src/sub_commands/list_mint_proofs.rs
+++ b/crates/cdk-cli/src/sub_commands/list_mint_proofs.rs
@@ -23,11 +23,11 @@ async fn list_proofs(
     for (i, (mint_url, proofs)) in wallets_proofs.iter().enumerate() {
         let mint_url = mint_url.clone();
         println!("{i}: {mint_url}");
-        // TODO make this try to format this to a more readable format.
-        println!("|Amount |Unit\t| Secret\t\t\t\t\t\t\t\t| Dleq proof included(bool)");
+        println!("|   Amount | Unit | Secret                                                           | DLEQ proof included");
+        println!("|----------|------|------------------------------------------------------------------|--------------------");
         for proof in &proofs.0 {
             println!(
-                "|{}\t|{}\t| {}\t| {:#?}",
+                "| {:8} | {:4} | {:64} | {}",
                 proof.amount,
                 proofs.1,
                 proof.secret,
diff --git a/crates/cdk/src/amount.rs b/crates/cdk/src/amount.rs
index 7e2d4e2..2d9fa34 100644
--- a/crates/cdk/src/amount.rs
+++ b/crates/cdk/src/amount.rs
@@ -138,7 +138,11 @@ impl Default for &Amount {
 
 impl fmt::Display for Amount {
     fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
-        write!(f, "{}", self.0)
+        if let Some(width) = f.width() {
+            write!(f, "{:width$}", self.0, width = width)
+        } else {
+            write!(f, "{}", self.0)
+        }
     }
 }
 
diff --git a/crates/cdk/src/nuts/nut00/mod.rs b/crates/cdk/src/nuts/nut00/mod.rs
index 58fff63..9822379 100644
--- a/crates/cdk/src/nuts/nut00/mod.rs
+++ b/crates/cdk/src/nuts/nut00/mod.rs
@@ -378,11 +378,16 @@ impl FromStr for CurrencyUnit {
 
 impl fmt::Display for CurrencyUnit {
     fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
-        match self {
-            CurrencyUnit::Sat => write!(f, "sat"),
-            CurrencyUnit::Msat => write!(f, "msat"),
-            CurrencyUnit::Usd => write!(f, "usd"),
-            CurrencyUnit::Eur => write!(f, "eur"),
+        let s = match self {
+            CurrencyUnit::Sat => "sat",
+            CurrencyUnit::Msat => "msat",
+            CurrencyUnit::Usd => "usd",
+            CurrencyUnit::Eur => "eur",
+        };
+        if let Some(width) = f.width() {
+            write!(f, "{:width$}", s, width = width)
+        } else {
+            write!(f, "{}", s)
         }
     }
 }

@ubbabeck
Copy link
Contributor Author

Thanks for this, I think we should list them under a header for each mint and then we shouldn't print the whole proofs as its too hard to read and i think has too much info. I'm thinking something like below and those proofs sorted by amount.

0: https://test.mint.com | Amount | Unit | Secret | Includes bleq (bool)

Thank you for the feedback, I agree it was way to verbose to print the whole proof, changed it to be more readable.

@ubbabeck
Copy link
Contributor Author

ubbabeck commented Oct 11, 2024

We can simplify formatting if we modify formatters for Amounts and CurrencyUnits:

diff --git a/crates/cdk-cli/src/sub_commands/list_mint_proofs.rs b/crates/cdk-cli/src/sub_commands/list_mint_proofs.rs
index d9661db..f4e8a4d 100644
--- a/crates/cdk-cli/src/sub_commands/list_mint_proofs.rs
+++ b/crates/cdk-cli/src/sub_commands/list_mint_proofs.rs
@@ -23,11 +23,11 @@ async fn list_proofs(
     for (i, (mint_url, proofs)) in wallets_proofs.iter().enumerate() {
         let mint_url = mint_url.clone();
         println!("{i}: {mint_url}");
-        // TODO make this try to format this to a more readable format.
-        println!("|Amount |Unit\t| Secret\t\t\t\t\t\t\t\t| Dleq proof included(bool)");
+        println!("|   Amount | Unit | Secret                                                           | DLEQ proof included");
+        println!("|----------|------|------------------------------------------------------------------|--------------------");
         for proof in &proofs.0 {
             println!(
-                "|{}\t|{}\t| {}\t| {:#?}",
+                "| {:8} | {:4} | {:64} | {}",
                 proof.amount,
                 proofs.1,
                 proof.secret,
diff --git a/crates/cdk/src/amount.rs b/crates/cdk/src/amount.rs
index 7e2d4e2..2d9fa34 100644
--- a/crates/cdk/src/amount.rs
+++ b/crates/cdk/src/amount.rs
@@ -138,7 +138,11 @@ impl Default for &Amount {
 
 impl fmt::Display for Amount {
     fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
-        write!(f, "{}", self.0)
+        if let Some(width) = f.width() {
+            write!(f, "{:width$}", self.0, width = width)
+        } else {
+            write!(f, "{}", self.0)
+        }
     }
 }
 
diff --git a/crates/cdk/src/nuts/nut00/mod.rs b/crates/cdk/src/nuts/nut00/mod.rs
index 58fff63..9822379 100644
--- a/crates/cdk/src/nuts/nut00/mod.rs
+++ b/crates/cdk/src/nuts/nut00/mod.rs
@@ -378,11 +378,16 @@ impl FromStr for CurrencyUnit {
 
 impl fmt::Display for CurrencyUnit {
     fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
-        match self {
-            CurrencyUnit::Sat => write!(f, "sat"),
-            CurrencyUnit::Msat => write!(f, "msat"),
-            CurrencyUnit::Usd => write!(f, "usd"),
-            CurrencyUnit::Eur => write!(f, "eur"),
+        let s = match self {
+            CurrencyUnit::Sat => "sat",
+            CurrencyUnit::Msat => "msat",
+            CurrencyUnit::Usd => "usd",
+            CurrencyUnit::Eur => "eur",
+        };
+        if let Some(width) = f.width() {
+            write!(f, "{:width$}", s, width = width)
+        } else {
+            write!(f, "{}", s)
         }
     }
 }

Thank you! This was way simpler updated with c57c292.

Copy link
Collaborator

@thesimplekid thesimplekid left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, thank you. Can you just fix the clippy errors then squash the commits

@thesimplekid thesimplekid added this to the v0.5.0 milestone Oct 12, 2024
fix typo

make output more readable.

Co-authored-by: Pavol Rusnak <[email protected]>
@ubbabeck ubbabeck force-pushed the proofs-command branch 2 times, most recently from e019a22 to a2190ab Compare October 12, 2024 08:32
@thesimplekid thesimplekid merged commit e0f5344 into cashubtc:main Oct 13, 2024
84 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants