From fd598d6e28aef481f15ece7788db092c075b8a4a Mon Sep 17 00:00:00 2001 From: Jacinta Ferrant Date: Wed, 18 Dec 2024 14:35:52 -0500 Subject: [PATCH] CRC: cleanup some logic in AssetMap Signed-off-by: Jacinta Ferrant --- clarity/src/vm/contexts.rs | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/clarity/src/vm/contexts.rs b/clarity/src/vm/contexts.rs index e0189458dd..4f3a478949 100644 --- a/clarity/src/vm/contexts.rs +++ b/clarity/src/vm/contexts.rs @@ -282,11 +282,11 @@ impl AssetMap { asset: &AssetIdentifier, amount: u128, ) -> Result { - 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()) @@ -443,10 +443,8 @@ impl AssetMap { principal: &PrincipalData, asset_identifier: &AssetIdentifier, ) -> Option { - 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( @@ -454,13 +452,8 @@ impl AssetMap { principal: &PrincipalData, asset_identifier: &AssetIdentifier, ) -> Option<&Vec> { - 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) } }