mirror of
https://github.com/aljazceru/cdk.git
synced 2025-12-24 08:05:02 +01:00
Fix formatting
This commit is contained in:
@@ -16,8 +16,6 @@ pub use mint::{
|
||||
#[cfg(feature = "wallet")]
|
||||
pub use wallet::Database as WalletDatabase;
|
||||
|
||||
use crate::state;
|
||||
|
||||
/// CDK_database error
|
||||
#[derive(Debug, thiserror::Error)]
|
||||
pub enum Error {
|
||||
@@ -55,15 +53,17 @@ pub enum Error {
|
||||
/// Invalid keyset
|
||||
#[error("Unknown or invalid keyset")]
|
||||
InvalidKeysetId,
|
||||
#[cfg(feature = "mint")]
|
||||
/// Invalid state transition
|
||||
#[error("Invalid state transition")]
|
||||
InvalidStateTransition(state::Error),
|
||||
InvalidStateTransition(crate::state::Error),
|
||||
}
|
||||
|
||||
impl From<state::Error> for Error {
|
||||
fn from(state: state::Error) -> Self {
|
||||
#[cfg(feature = "mint")]
|
||||
impl From<crate::state::Error> for Error {
|
||||
fn from(state: crate::state::Error) -> Self {
|
||||
match state {
|
||||
state::Error::AlreadySpent => Error::AttemptUpdateSpentProof,
|
||||
crate::state::Error::AlreadySpent => Error::AttemptUpdateSpentProof,
|
||||
_ => Error::InvalidStateTransition(state),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -502,6 +502,7 @@ impl From<Error> for ErrorResponse {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "mint")]
|
||||
impl From<crate::database::Error> for Error {
|
||||
fn from(db_error: crate::database::Error) -> Self {
|
||||
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 {
|
||||
fn from(err: ErrorResponse) -> Error {
|
||||
match err.code {
|
||||
|
||||
@@ -20,10 +20,7 @@ pub enum Error {
|
||||
/// Check if the state transition is allowed
|
||||
pub fn check_state_transition(current_state: State, new_state: State) -> Result<(), Error> {
|
||||
let is_valid_transition = match current_state {
|
||||
State::Unspent => matches!(
|
||||
new_state,
|
||||
State::Pending | State::Spent
|
||||
),
|
||||
State::Unspent => matches!(new_state, State::Pending | 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
|
||||
// function
|
||||
|
||||
@@ -1962,10 +1962,7 @@ mod tests {
|
||||
|
||||
// Try to update both proofs - should fail because one is spent
|
||||
let result = db
|
||||
.update_proofs_states(
|
||||
&[proofs[0].y().unwrap(), proofs[1].y().unwrap()],
|
||||
State::Reserved,
|
||||
)
|
||||
.update_proofs_states(&[proofs[0].y().unwrap()], State::Unspent)
|
||||
.await;
|
||||
|
||||
assert!(result.is_err());
|
||||
|
||||
Reference in New Issue
Block a user