Skip to content

Commit

Permalink
fix: approve benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
Daanvdplas committed Jul 24, 2024
1 parent 8bc6576 commit ddc445e
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions pallets/api/src/fungibles/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ pub mod pallet {
let id: AssetIdParameterOf<T> = id.into();
// If the new value is equal to the current allowance, do nothing.
if value == current_allowance {
return Ok(().into());
return Ok(Some(T::DbWeight::get().reads(1)).into());
}
// If the new value is greater than the current allowance, approve the difference
// because `approve_transfer` works additively (see pallet-assets).
Expand All @@ -132,6 +132,7 @@ pub mod pallet {
T::DbWeight::get().reads(1) + AssetsWeightInfoOf::<T>::approve_transfer(),
)
})?;
Ok(Some(AssetsWeightInfoOf::<T>::approve_transfer()).into())
} else {
// If the new value is less than the current allowance, cancel the approval and set the new value
AssetsOf::<T>::cancel_approval(origin.clone(), id.clone(), spender.clone())
Expand All @@ -142,8 +143,8 @@ pub mod pallet {
)
})?;
AssetsOf::<T>::approve_transfer(origin, id, spender, value)?;
Ok(().into())
}
Ok(().into())
}

/// Increases the allowance of a spender.
Expand Down

0 comments on commit ddc445e

Please sign in to comment.