fix: fix amount ordering error

This commit is contained in:
thesimplekid
2023-07-18 12:04:06 -04:00
parent 4b4999057f
commit 373f8d7947
4 changed files with 10 additions and 7 deletions

View File

@@ -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"

View File

@@ -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"),
}

View File

@@ -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)

View File

@@ -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 {