mirror of
https://github.com/aljazceru/cdk.git
synced 2025-12-24 08:05:02 +01:00
mint error
This commit is contained in:
@@ -10,8 +10,9 @@ use crate::{
|
||||
keyset::{Keys, MintKeySets},
|
||||
types::{
|
||||
BlindedMessage, BlindedMessages, CheckFeesRequest, CheckFeesResponse,
|
||||
CheckSpendableRequest, CheckSpendableResponse, MeltRequest, MeltResponse, MintInfo,
|
||||
MintRequest, PostMintResponse, Proof, RequestMintResponse, SplitRequest, SplitResponse,
|
||||
CheckSpendableRequest, CheckSpendableResponse, MeltRequest, MeltResponse, MintError,
|
||||
MintInfo, MintRequest, PostMintResponse, Proof, RequestMintResponse, SplitRequest,
|
||||
SplitResponse,
|
||||
},
|
||||
};
|
||||
|
||||
@@ -114,7 +115,7 @@ impl Client {
|
||||
|
||||
match response {
|
||||
Ok(res) => Ok(res),
|
||||
Err(_) => Err(Error::CustomError(res.to_string())),
|
||||
Err(_) => Err(MintError::from_json(&res.to_string())?.into()),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -134,7 +135,7 @@ impl Client {
|
||||
|
||||
match response {
|
||||
Ok(res) => Ok(res),
|
||||
Err(_) => Err(Error::CustomError(res.to_string())),
|
||||
Err(_) => Err(MintError::from_json(&res.to_string())?.into()),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -164,7 +165,7 @@ impl Client {
|
||||
|
||||
match response {
|
||||
Ok(res) => Ok(res),
|
||||
Err(_) => Err(Error::CustomError(value.to_string())),
|
||||
Err(_) => Err(MintError::from_json(&value.to_string())?.into()),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -182,7 +183,7 @@ impl Client {
|
||||
|
||||
match response {
|
||||
Ok(res) => Ok(res),
|
||||
Err(_) => Err(Error::CustomError(res.to_string())),
|
||||
Err(_) => Err(MintError::from_json(&res.to_string())?.into()),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -206,7 +207,7 @@ impl Client {
|
||||
|
||||
match response {
|
||||
Ok(res) => Ok(res),
|
||||
Err(_) => Err(Error::CustomError(res.to_string())),
|
||||
Err(_) => Err(MintError::from_json(&res.to_string())?.into()),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -219,7 +220,7 @@ impl Client {
|
||||
|
||||
match response {
|
||||
Ok(res) => Ok(res),
|
||||
Err(_) => Err(Error::CustomError(res.to_string())),
|
||||
Err(_) => Err(MintError::from_json(&res.to_string())?.into()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
use std::string::FromUtf8Error;
|
||||
|
||||
use crate::types::MintError;
|
||||
|
||||
#[derive(Debug, thiserror::Error)]
|
||||
pub enum Error {
|
||||
/// Min req error
|
||||
@@ -31,4 +33,6 @@ pub enum Error {
|
||||
/// From elliptic curve
|
||||
#[error("From Elliptic: {0}")]
|
||||
EllipticError(#[from] k256::elliptic_curve::Error),
|
||||
#[error("Mint Error: {0}")]
|
||||
MintError(#[from] MintError),
|
||||
}
|
||||
|
||||
39
src/types.rs
39
src/types.rs
@@ -1,5 +1,7 @@
|
||||
//! Types for `cashu-rs`
|
||||
//! Types for `cashu-crab`
|
||||
|
||||
use std::error::Error as StdError;
|
||||
use std::fmt;
|
||||
use std::str::FromStr;
|
||||
|
||||
use base64::{engine::general_purpose, Engine as _};
|
||||
@@ -14,6 +16,41 @@ use crate::{
|
||||
dhke::blind_message, error::Error, serde_utils, serde_utils::serde_url, utils::split_amount,
|
||||
};
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
pub enum MintError {
|
||||
InvoiceNotPaid,
|
||||
Custom(String),
|
||||
}
|
||||
|
||||
impl StdError for MintError {}
|
||||
|
||||
impl fmt::Display for MintError {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
match self {
|
||||
MintError::InvoiceNotPaid => write!(f, "Invoice not paid"),
|
||||
MintError::Custom(message) => write!(f, "{}", message),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
pub struct MintErrorResponse {
|
||||
code: u32,
|
||||
error: String,
|
||||
}
|
||||
|
||||
impl MintError {
|
||||
pub fn from_json(json: &str) -> Result<Self, Error> {
|
||||
let mint_res: MintErrorResponse = serde_json::from_str(json)?;
|
||||
|
||||
let mint_error = match mint_res.error.as_str() {
|
||||
"Lightning invoice not paid yet." => MintError::InvoiceNotPaid,
|
||||
_ => MintError::Custom(mint_res.error),
|
||||
};
|
||||
Ok(mint_error)
|
||||
}
|
||||
}
|
||||
|
||||
/// Blinded Message [NUT-00]
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
pub struct BlindedMessage {
|
||||
|
||||
Reference in New Issue
Block a user