Browse Source

fix: fix amount ordering error

thesimplekid 1 year ago
parent
commit
373f8d7947
4 changed files with 10 additions and 7 deletions
  1. 1 1
      Cargo.toml
  2. 2 0
      src/error.rs
  3. 2 5
      src/mint.rs
  4. 5 1
      src/wallet.rs

+ 1 - 1
Cargo.toml

@@ -1,6 +1,6 @@
 [package]
 name = "cashu-crab"
-version = "0.3.0"
+version = "0.4.0-ALPHA"
 edition = "2021"
 authors = ["thesimplekid"]
 license = "BSD-3-Clause"

+ 2 - 0
src/error.rs

@@ -158,6 +158,7 @@ pub mod mint {
         EllipticError(k256::elliptic_curve::Error),
         TokenNotVerifed,
         InvoiceAmountUndefined,
+        CustomError(String),
     }
 
     impl StdError for Error {}
@@ -169,6 +170,7 @@ pub mod mint {
                 Error::Amount => write!(f, "Amount miss match"),
                 Error::TokenSpent => write!(f, "Token Spent"),
                 Error::EllipticError(err) => write!(f, "{}", err),
+                Error::CustomError(err) => write!(f, "{}", err),
                 Error::TokenNotVerifed => write!(f, "Token Not Verified"),
                 Error::InvoiceAmountUndefined => write!(f, "Invoice without amount"),
             }

+ 2 - 5
src/mint.rs

@@ -103,6 +103,7 @@ impl Mint {
         let proofs_total = split_request.proofs_amount();
 
         let output_total = split_request.output_amount();
+
         if proofs_total != output_total {
             return Err(Error::Amount);
         }
@@ -124,10 +125,6 @@ impl Mint {
                 Ok(SplitResponse::new(promises))
             }
             Some(amount) => {
-                if proofs_total.le(amount) {
-                    return Err(Error::Amount);
-                }
-
                 let outs_fst = (proofs_total.to_owned() - amount.to_owned()).split();
 
                 // Blinded change messages
@@ -141,7 +138,7 @@ impl Mint {
                 let split_response = SplitResponse::new_from_amount(fst, snd);
 
                 if split_response.target_amount() != split_request.amount {
-                    return Err(Error::OutputOrdering);
+                    return Err(Error::CustomError("Output order".to_string()));
                 }
 
                 Ok(split_response)

+ 5 - 1
src/wallet.rs

@@ -13,7 +13,11 @@ use crate::nuts::nut06::{SplitPayload, SplitRequest};
 use crate::types::{Melted, ProofsStatus, SendProofs};
 use crate::Amount;
 pub use crate::Invoice;
-use crate::{client::Client, dhke::construct_proofs, error};
+use crate::{
+    client::Client,
+    dhke::construct_proofs,
+    error::{self, wallet::Error},
+};
 
 #[derive(Clone, Debug)]
 pub struct Wallet {