Skip to content

Commit

Permalink
CRC: revert fallible ClarityName::from uses
Browse files Browse the repository at this point in the history
Signed-off-by: Jacinta Ferrant <[email protected]>
  • Loading branch information
jferrant committed Dec 18, 2024
1 parent fd598d6 commit 66502b1
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 14 deletions.
2 changes: 1 addition & 1 deletion clarity/src/vm/contexts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
24 changes: 15 additions & 9 deletions clarity/src/vm/database/clarity_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -755,16 +755,14 @@ impl<'a> ClarityDatabase<'a> {
&mut self,
contract_identifier: &QualifiedContractIdentifier,
) -> Result<Option<ContractAnalysis>> {
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(
Expand Down Expand Up @@ -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,
Expand All @@ -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()))?,
);
Expand Down
16 changes: 13 additions & 3 deletions clarity/src/vm/functions/assets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion clarity/src/vm/types/serialization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 66502b1

Please sign in to comment.