Skip to content

Commit

Permalink
CRC: cleanup some logic in AssetMap
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 c234c27 commit fd598d6
Showing 1 changed file with 9 additions and 16 deletions.
25 changes: 9 additions & 16 deletions clarity/src/vm/contexts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,11 +282,11 @@ impl AssetMap {
asset: &AssetIdentifier,
amount: u128,
) -> Result<u128> {
let current_amount = match self.token_map.get(principal) {
Some(principal_map) => *principal_map.get(asset).unwrap_or(&0),
None => 0,
};

let current_amount = self
.token_map
.get(principal)
.map(|x| x.get(asset).unwrap_or(&0))
.unwrap_or(&0);
current_amount
.checked_add(amount)
.ok_or(RuntimeErrorType::ArithmeticOverflow.into())
Expand Down Expand Up @@ -443,24 +443,17 @@ impl AssetMap {
principal: &PrincipalData,
asset_identifier: &AssetIdentifier,
) -> Option<u128> {
match self.token_map.get(principal) {
Some(assets) => assets.get(asset_identifier).copied(),
None => None,
}
let assets = self.token_map.get(principal)?;
assets.get(asset_identifier).copied()
}

pub fn get_nonfungible_tokens(
&self,
principal: &PrincipalData,
asset_identifier: &AssetIdentifier,
) -> Option<&Vec<Value>> {
match self.asset_map.get(principal) {
Some(assets) => match assets.get(asset_identifier) {
Some(values) => Some(values),
None => None,
},
None => None,
}
let assets = self.asset_map.get(principal)?;
assets.get(asset_identifier)
}
}

Expand Down

0 comments on commit fd598d6

Please sign in to comment.