diff --git a/clarity/src/vm/contexts.rs b/clarity/src/vm/contexts.rs index 4f3a478949..b3eb8c9fe5 100644 --- a/clarity/src/vm/contexts.rs +++ b/clarity/src/vm/contexts.rs @@ -285,7 +285,7 @@ impl AssetMap { let current_amount = self .token_map .get(principal) - .map(|x| x.get(asset).unwrap_or(&0)) + .and_then(|x| x.get(asset)) .unwrap_or(&0); current_amount .checked_add(amount) diff --git a/clarity/src/vm/database/clarity_db.rs b/clarity/src/vm/database/clarity_db.rs index 6e1a14ec20..cbb8bcb4de 100644 --- a/clarity/src/vm/database/clarity_db.rs +++ b/clarity/src/vm/database/clarity_db.rs @@ -755,16 +755,14 @@ impl<'a> ClarityDatabase<'a> { &mut self, contract_identifier: &QualifiedContractIdentifier, ) -> Result> { - let x_opt = self - .store + self.store .get_metadata(contract_identifier, AnalysisDatabase::storage_key()) // treat NoSuchContract error thrown by get_metadata as an Option::None -- // the analysis will propagate that as a CheckError anyways. - .ok(); - match x_opt.flatten() { - None => Ok(None), - Some(x) => ContractAnalysis::deserialize(&x).map(Some), - } + .ok() + .flatten() + .map(|x| ContractAnalysis::deserialize(&x)) + .transpose() } pub fn get_contract_size( @@ -1357,6 +1355,7 @@ impl ClarityDatabase<'_> { self.store.get_cc_special_cases_handler() } + #[allow(clippy::unnecessary_fallible_conversions)] pub fn insert_microblock_poison( &mut self, height: u32, @@ -1367,10 +1366,17 @@ impl ClarityDatabase<'_> { let value = Value::Tuple( TupleData::from_data(vec![ ( - ClarityName::from("reporter"), + ClarityName::try_from("reporter").map_err(|_| { + InterpreterError::Expect("BUG: valid string representation".into()) + })?, Value::Principal(PrincipalData::Standard(reporter.clone())), ), - (ClarityName::from("sequence"), Value::UInt(seq as u128)), + ( + ClarityName::try_from("sequence").map_err(|_| { + InterpreterError::Expect("BUG: valid string representation".into()) + })?, + Value::UInt(seq as u128), + ), ]) .map_err(|_| InterpreterError::Expect("BUG: valid tuple representation".into()))?, ); diff --git a/clarity/src/vm/functions/assets.rs b/clarity/src/vm/functions/assets.rs index 608701b1f9..3dca730928 100644 --- a/clarity/src/vm/functions/assets.rs +++ b/clarity/src/vm/functions/assets.rs @@ -210,6 +210,7 @@ pub fn special_stx_transfer_memo( } } +#[allow(clippy::unnecessary_fallible_conversions)] pub fn special_stx_account( args: &[SymbolicExpression], env: &mut Environment, @@ -237,12 +238,21 @@ pub fn special_stx_account( TupleData::from_data(vec![ ( - "unlocked".into(), + "unlocked" + .try_into() + .map_err(|_| InterpreterError::Expect("Bad special tuple name".into()))?, Value::UInt(stx_balance.amount_unlocked()), ), - ("locked".into(), Value::UInt(stx_balance.amount_locked())), ( - "unlock-height".into(), + "locked" + .try_into() + .map_err(|_| InterpreterError::Expect("Bad special tuple name".into()))?, + Value::UInt(stx_balance.amount_locked()), + ), + ( + "unlock-height" + .try_into() + .map_err(|_| InterpreterError::Expect("Bad special tuple name".into()))?, Value::UInt(u128::from(stx_balance.effective_unlock_height( v1_unlock_ht, v2_unlock_ht, diff --git a/clarity/src/vm/types/serialization.rs b/clarity/src/vm/types/serialization.rs index 630a6c28ad..48030519c8 100644 --- a/clarity/src/vm/types/serialization.rs +++ b/clarity/src/vm/types/serialization.rs @@ -782,7 +782,7 @@ impl Value { expected_type.unwrap(), )); } - } else if len as u64 != tuple_type.len() { + } else if u64::from(len) != tuple_type.len() { // unwrap is safe because of the match condition #[allow(clippy::unwrap_used)] return Err(SerializationError::DeserializeExpected(