Contracts: Refactor API to use WeightMeter (#2943)

Update the Contracts API to use `WeightMeter`, as it simplifies the code
and makes it easier to reason about, rather than taking a mutable weight
or returning a tuple with the weight consumed

---------

Co-authored-by: Alexander Theißen <alex.theissen@me.com>
This commit is contained in:
PG Herveou
2024-04-09 12:22:54 +02:00
committed by GitHub
parent 10ed76437f
commit b6231c79ca
12 changed files with 177 additions and 152 deletions
@@ -36,6 +36,7 @@ use frame_support::{
fungible::{Mutate, MutateHold},
tokens::{fungible::Inspect, Fortitude, Preservation},
},
weights::WeightMeter,
BoundedBTreeMap, DefaultNoBound,
};
use frame_system::Pallet as System;
@@ -125,7 +126,7 @@ impl<T: Config> MigrationStep for Migration<T> {
T::WeightInfo::v15_migration_step()
}
fn step(&mut self) -> (IsFinished, Weight) {
fn step(&mut self, meter: &mut WeightMeter) -> IsFinished {
let mut iter = if let Some(last_account) = self.last_account.take() {
v14::ContractInfoOf::<T>::iter_from(v14::ContractInfoOf::<T>::hashed_key_for(
last_account,
@@ -234,10 +235,12 @@ impl<T: Config> MigrationStep for Migration<T> {
// Store last key for next migration step
self.last_account = Some(account);
(IsFinished::No, T::WeightInfo::v15_migration_step())
meter.consume(T::WeightInfo::v15_migration_step());
IsFinished::No
} else {
log::info!(target: LOG_TARGET, "Done Migrating Storage Deposits.");
(IsFinished::Yes, T::WeightInfo::v15_migration_step())
meter.consume(T::WeightInfo::v15_migration_step());
IsFinished::Yes
}
}