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 HerveouandAlexander Theißen authored and GitHub committed 2024-04-09 10:22:54 +00:00
1 parent 10ed76437f
commit b6231c79ca
12 files changed
+177 -152

No files matched your search

@@ -36,6 +36,7 @@ use frame_support::{
tokens::{fungible::Inspect, Fortitude::Polite, Preservation::Preserve},
ExistenceRequirement, ReservableCurrency,
},
weights::WeightMeter,
DefaultNoBound,
};
use sp_core::hexdisplay::HexDisplay;
@@ -160,7 +161,7 @@ where
T::WeightInfo::v10_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() {
v9::ContractInfoOf::<T, OldCurrency>::iter_from(
v9::ContractInfoOf::<T, OldCurrency>::hashed_key_for(last_account),
@@ -267,10 +268,12 @@ where
// Store last key for next migration step
self.last_account = Some(account);
(IsFinished::No, T::WeightInfo::v10_migration_step())
meter.consume(T::WeightInfo::v10_migration_step());
IsFinished::No
} else {
log::debug!(target: LOG_TARGET, "Done Migrating contract info");
(IsFinished::Yes, T::WeightInfo::v10_migration_step())
meter.consume(T::WeightInfo::v10_migration_step());
IsFinished::Yes
}
}