Fix formatting

This commit is contained in:
Cesar Rodas
2025-04-22 10:36:58 -03:00
parent 5505f0b5d7
commit 25fad98aa8
4 changed files with 16 additions and 14 deletions

View File

@@ -16,8 +16,6 @@ pub use mint::{
#[cfg(feature = "wallet")] #[cfg(feature = "wallet")]
pub use wallet::Database as WalletDatabase; pub use wallet::Database as WalletDatabase;
use crate::state;
/// CDK_database error /// CDK_database error
#[derive(Debug, thiserror::Error)] #[derive(Debug, thiserror::Error)]
pub enum Error { pub enum Error {
@@ -55,15 +53,17 @@ pub enum Error {
/// Invalid keyset /// Invalid keyset
#[error("Unknown or invalid keyset")] #[error("Unknown or invalid keyset")]
InvalidKeysetId, InvalidKeysetId,
#[cfg(feature = "mint")]
/// Invalid state transition /// Invalid state transition
#[error("Invalid state transition")] #[error("Invalid state transition")]
InvalidStateTransition(state::Error), InvalidStateTransition(crate::state::Error),
} }
impl From<state::Error> for Error { #[cfg(feature = "mint")]
fn from(state: state::Error) -> Self { impl From<crate::state::Error> for Error {
fn from(state: crate::state::Error) -> Self {
match state { match state {
state::Error::AlreadySpent => Error::AttemptUpdateSpentProof, crate::state::Error::AlreadySpent => Error::AttemptUpdateSpentProof,
_ => Error::InvalidStateTransition(state), _ => Error::InvalidStateTransition(state),
} }
} }

View File

@@ -502,6 +502,7 @@ impl From<Error> for ErrorResponse {
} }
} }
#[cfg(feature = "mint")]
impl From<crate::database::Error> for Error { impl From<crate::database::Error> for Error {
fn from(db_error: crate::database::Error) -> Self { fn from(db_error: crate::database::Error) -> Self {
match db_error { match db_error {
@@ -515,6 +516,13 @@ impl From<crate::database::Error> for Error {
} }
} }
#[cfg(not(feature = "mint"))]
impl From<crate::database::Error> for Error {
fn from(db_error: crate::database::Error) -> Self {
Self::Database(db_error)
}
}
impl From<ErrorResponse> for Error { impl From<ErrorResponse> for Error {
fn from(err: ErrorResponse) -> Error { fn from(err: ErrorResponse) -> Error {
match err.code { match err.code {

View File

@@ -20,10 +20,7 @@ pub enum Error {
/// Check if the state transition is allowed /// Check if the state transition is allowed
pub fn check_state_transition(current_state: State, new_state: State) -> Result<(), Error> { pub fn check_state_transition(current_state: State, new_state: State) -> Result<(), Error> {
let is_valid_transition = match current_state { let is_valid_transition = match current_state {
State::Unspent => matches!( State::Unspent => matches!(new_state, State::Pending | State::Spent),
new_state,
State::Pending | State::Spent
),
State::Pending => matches!(new_state, State::Unspent | State::Spent), State::Pending => matches!(new_state, State::Unspent | State::Spent),
// Any other state shouldn't be updated by the mint, and the wallet does not use this // Any other state shouldn't be updated by the mint, and the wallet does not use this
// function // function

View File

@@ -1962,10 +1962,7 @@ mod tests {
// Try to update both proofs - should fail because one is spent // Try to update both proofs - should fail because one is spent
let result = db let result = db
.update_proofs_states( .update_proofs_states(&[proofs[0].y().unwrap()], State::Unspent)
&[proofs[0].y().unwrap(), proofs[1].y().unwrap()],
State::Reserved,
)
.await; .await;
assert!(result.is_err()); assert!(result.is_err());