Skip to content

Commit fd598d6

Browse files
committed
CRC: cleanup some logic in AssetMap
Signed-off-by: Jacinta Ferrant <[email protected]>
1 parent c234c27 commit fd598d6

File tree

1 file changed

+9
-16
lines changed

1 file changed

+9
-16
lines changed

clarity/src/vm/contexts.rs

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -282,11 +282,11 @@ impl AssetMap {
282282
asset: &AssetIdentifier,
283283
amount: u128,
284284
) -> Result<u128> {
285-
let current_amount = match self.token_map.get(principal) {
286-
Some(principal_map) => *principal_map.get(asset).unwrap_or(&0),
287-
None => 0,
288-
};
289-
285+
let current_amount = self
286+
.token_map
287+
.get(principal)
288+
.map(|x| x.get(asset).unwrap_or(&0))
289+
.unwrap_or(&0);
290290
current_amount
291291
.checked_add(amount)
292292
.ok_or(RuntimeErrorType::ArithmeticOverflow.into())
@@ -443,24 +443,17 @@ impl AssetMap {
443443
principal: &PrincipalData,
444444
asset_identifier: &AssetIdentifier,
445445
) -> Option<u128> {
446-
match self.token_map.get(principal) {
447-
Some(assets) => assets.get(asset_identifier).copied(),
448-
None => None,
449-
}
446+
let assets = self.token_map.get(principal)?;
447+
assets.get(asset_identifier).copied()
450448
}
451449

452450
pub fn get_nonfungible_tokens(
453451
&self,
454452
principal: &PrincipalData,
455453
asset_identifier: &AssetIdentifier,
456454
) -> Option<&Vec<Value>> {
457-
match self.asset_map.get(principal) {
458-
Some(assets) => match assets.get(asset_identifier) {
459-
Some(values) => Some(values),
460-
None => None,
461-
},
462-
None => None,
463-
}
455+
let assets = self.asset_map.get(principal)?;
456+
assets.get(asset_identifier)
464457
}
465458
}
466459

0 commit comments

Comments
 (0)