Cesar Rodas преди 2 дни
родител
ревизия
25fad98aa8
променени са 4 файла, в които са добавени 16 реда и са изтрити 14 реда
  1. 6 6
      crates/cdk-common/src/database/mod.rs
  2. 8 0
      crates/cdk-common/src/error.rs
  3. 1 4
      crates/cdk-common/src/state.rs
  4. 1 4
      crates/cdk-sqlite/src/mint/mod.rs

+ 6 - 6
crates/cdk-common/src/database/mod.rs

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

+ 8 - 0
crates/cdk-common/src/error.rs

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

+ 1 - 4
crates/cdk-common/src/state.rs

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

+ 1 - 4
crates/cdk-sqlite/src/mint/mod.rs

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