Bläddra i källkod

chore: remove unwraps

thesimplekid 1 månad sedan
förälder
incheckning
310b99b28c
3 ändrade filer med 7 tillägg och 10 borttagningar
  1. 2 2
      Cargo.toml
  2. 3 5
      crates/cashu/src/nuts/nut10.rs
  3. 2 3
      crates/cashu/src/nuts/nut11/mod.rs

+ 2 - 2
Cargo.toml

@@ -10,13 +10,13 @@ unreachable_pub = "warn"
 missing_debug_implementations = "warn"
 
 [workspace.lints.clippy]
-pedantic = { level = "warn", priority = -1 }
+# pedantic = { level = "warn", priority = -1 }
 unwrap_used = "deny"
 clone_on_ref_ptr = "warn"
 missing_errors_doc = "warn"
 missing_panics_doc = "warn"
 missing_safety_doc = "warn"
-nursery = { level = "warn", priority = -1 }
+# nursery = { level = "warn", priority = -1 }
 redundant_else = "warn"
 redundant_closure_for_method_calls = "warn"
 unneeded_field_pattern = "warn"

+ 3 - 5
crates/cashu/src/nuts/nut10.rs

@@ -302,12 +302,10 @@ pub trait SpendingConditionVerification {
     fn verify_all_inputs_match_for_sig_all(&self) -> Result<(), super::nut11::Error> {
         let inputs = self.inputs();
 
-        if inputs.is_empty() {
-            return Err(super::nut11::Error::SpendConditionsNotMet);
-        }
-
         // Get first input's properties
-        let first_input = inputs.first().unwrap();
+        let first_input = inputs
+            .first()
+            .ok_or(super::nut11::Error::SpendConditionsNotMet)?;
         let first_secret = Secret::try_from(&first_input.secret)
             .map_err(|_| super::nut11::Error::IncorrectSecretKind)?;
         let first_kind = first_secret.kind();

+ 2 - 3
crates/cashu/src/nuts/nut11/mod.rs

@@ -531,9 +531,8 @@ impl TryFrom<Vec<Vec<String>>> for Conditions {
     fn try_from(tags: Vec<Vec<String>>) -> Result<Conditions, Self::Error> {
         let tags: HashMap<TagKind, Tag> = tags
             .into_iter()
-            .map(|t| Tag::try_from(t).unwrap())
-            .map(|t| (t.kind(), t))
-            .collect();
+            .map(|t| Tag::try_from(t).map(|tag| (tag.kind(), tag)))
+            .collect::<Result<_, _>>()?;
 
         let pubkeys = match tags.get(&TagKind::Pubkeys) {
             Some(Tag::PubKeys(pubkeys)) => Some(pubkeys.clone()),