Skip to content

Commit 66502b1

Browse files
committed
CRC: revert fallible ClarityName::from uses
Signed-off-by: Jacinta Ferrant <[email protected]>
1 parent fd598d6 commit 66502b1

File tree

4 files changed

+30
-14
lines changed

4 files changed

+30
-14
lines changed

clarity/src/vm/contexts.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ impl AssetMap {
285285
let current_amount = self
286286
.token_map
287287
.get(principal)
288-
.map(|x| x.get(asset).unwrap_or(&0))
288+
.and_then(|x| x.get(asset))
289289
.unwrap_or(&0);
290290
current_amount
291291
.checked_add(amount)

clarity/src/vm/database/clarity_db.rs

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -755,16 +755,14 @@ impl<'a> ClarityDatabase<'a> {
755755
&mut self,
756756
contract_identifier: &QualifiedContractIdentifier,
757757
) -> Result<Option<ContractAnalysis>> {
758-
let x_opt = self
759-
.store
758+
self.store
760759
.get_metadata(contract_identifier, AnalysisDatabase::storage_key())
761760
// treat NoSuchContract error thrown by get_metadata as an Option::None --
762761
// the analysis will propagate that as a CheckError anyways.
763-
.ok();
764-
match x_opt.flatten() {
765-
None => Ok(None),
766-
Some(x) => ContractAnalysis::deserialize(&x).map(Some),
767-
}
762+
.ok()
763+
.flatten()
764+
.map(|x| ContractAnalysis::deserialize(&x))
765+
.transpose()
768766
}
769767

770768
pub fn get_contract_size(
@@ -1357,6 +1355,7 @@ impl ClarityDatabase<'_> {
13571355
self.store.get_cc_special_cases_handler()
13581356
}
13591357

1358+
#[allow(clippy::unnecessary_fallible_conversions)]
13601359
pub fn insert_microblock_poison(
13611360
&mut self,
13621361
height: u32,
@@ -1367,10 +1366,17 @@ impl ClarityDatabase<'_> {
13671366
let value = Value::Tuple(
13681367
TupleData::from_data(vec![
13691368
(
1370-
ClarityName::from("reporter"),
1369+
ClarityName::try_from("reporter").map_err(|_| {
1370+
InterpreterError::Expect("BUG: valid string representation".into())
1371+
})?,
13711372
Value::Principal(PrincipalData::Standard(reporter.clone())),
13721373
),
1373-
(ClarityName::from("sequence"), Value::UInt(seq as u128)),
1374+
(
1375+
ClarityName::try_from("sequence").map_err(|_| {
1376+
InterpreterError::Expect("BUG: valid string representation".into())
1377+
})?,
1378+
Value::UInt(seq as u128),
1379+
),
13741380
])
13751381
.map_err(|_| InterpreterError::Expect("BUG: valid tuple representation".into()))?,
13761382
);

clarity/src/vm/functions/assets.rs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@ pub fn special_stx_transfer_memo(
210210
}
211211
}
212212

213+
#[allow(clippy::unnecessary_fallible_conversions)]
213214
pub fn special_stx_account(
214215
args: &[SymbolicExpression],
215216
env: &mut Environment,
@@ -237,12 +238,21 @@ pub fn special_stx_account(
237238

238239
TupleData::from_data(vec![
239240
(
240-
"unlocked".into(),
241+
"unlocked"
242+
.try_into()
243+
.map_err(|_| InterpreterError::Expect("Bad special tuple name".into()))?,
241244
Value::UInt(stx_balance.amount_unlocked()),
242245
),
243-
("locked".into(), Value::UInt(stx_balance.amount_locked())),
244246
(
245-
"unlock-height".into(),
247+
"locked"
248+
.try_into()
249+
.map_err(|_| InterpreterError::Expect("Bad special tuple name".into()))?,
250+
Value::UInt(stx_balance.amount_locked()),
251+
),
252+
(
253+
"unlock-height"
254+
.try_into()
255+
.map_err(|_| InterpreterError::Expect("Bad special tuple name".into()))?,
246256
Value::UInt(u128::from(stx_balance.effective_unlock_height(
247257
v1_unlock_ht,
248258
v2_unlock_ht,

clarity/src/vm/types/serialization.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -782,7 +782,7 @@ impl Value {
782782
expected_type.unwrap(),
783783
));
784784
}
785-
} else if len as u64 != tuple_type.len() {
785+
} else if u64::from(len) != tuple_type.len() {
786786
// unwrap is safe because of the match condition
787787
#[allow(clippy::unwrap_used)]
788788
return Err(SerializationError::DeserializeExpected(

0 commit comments

Comments
 (0)