Skip to content

Commit

Permalink
fixup! vp/multitoken: refactor maps and sets usage
Browse files Browse the repository at this point in the history
  • Loading branch information
tzemanovic committed Jan 25, 2024
1 parent bcf4d5d commit 52b9943
Showing 1 changed file with 18 additions and 16 deletions.
34 changes: 18 additions & 16 deletions crates/namada/src/ledger/native_vp/multitoken.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,27 +63,29 @@ where
Some(diff) => {
let change =
inc_changes.entry(token.clone()).or_default();
change.checked_add(diff).ok_or_else(|| {
Error::NativeVpError(
native_vp::Error::SimpleMessage(
"Overflowed in balance check",
),
)
})?;
*change =
change.checked_add(diff).ok_or_else(|| {
Error::NativeVpError(
native_vp::Error::SimpleMessage(
"Overflowed in balance check",
),
)
})?;
}
None => {
let diff = pre
.checked_sub(post)
.expect("Underflow shouldn't happen here");
let change =
dec_changes.entry(token.clone()).or_default();
change.checked_add(diff).ok_or_else(|| {
Error::NativeVpError(
native_vp::Error::SimpleMessage(
"Overflowed in balance check",
),
)
})?;
*change =
change.checked_add(diff).ok_or_else(|| {
Error::NativeVpError(
native_vp::Error::SimpleMessage(
"Overflowed in balance check",
),
)
})?;
}
}
} else if let Some(token) = is_any_minted_balance_key(key) {
Expand All @@ -92,7 +94,7 @@ where
match post.checked_sub(pre) {
Some(diff) => {
let mint = inc_mints.entry(token.clone()).or_default();
mint.checked_add(diff).ok_or_else(|| {
*mint = mint.checked_add(diff).ok_or_else(|| {
Error::NativeVpError(
native_vp::Error::SimpleMessage(
"Overflowed in balance check",
Expand All @@ -105,7 +107,7 @@ where
.checked_sub(post)
.expect("Underflow shouldn't happen here");
let mint = dec_mints.entry(token.clone()).or_default();
mint.checked_add(diff).ok_or_else(|| {
*mint = mint.checked_add(diff).ok_or_else(|| {
Error::NativeVpError(
native_vp::Error::SimpleMessage(
"Overflowed in balance check",
Expand Down

0 comments on commit 52b9943

Please sign in to comment.