mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-17 05:31:02 +00:00
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:
@@ -25,7 +25,8 @@ use crate::{
|
||||
};
|
||||
use codec::{Decode, Encode};
|
||||
use frame_support::{
|
||||
pallet_prelude::*, storage_alias, traits::ReservableCurrency, DefaultNoBound, Identity,
|
||||
pallet_prelude::*, storage_alias, traits::ReservableCurrency, weights::WeightMeter,
|
||||
DefaultNoBound, Identity,
|
||||
};
|
||||
use scale_info::prelude::format;
|
||||
use sp_core::hexdisplay::HexDisplay;
|
||||
@@ -146,7 +147,7 @@ where
|
||||
T::WeightInfo::v12_migration_step(T::MaxCodeLen::get())
|
||||
}
|
||||
|
||||
fn step(&mut self) -> (IsFinished, Weight) {
|
||||
fn step(&mut self, meter: &mut WeightMeter) -> IsFinished {
|
||||
let mut iter = if let Some(last_key) = self.last_code_hash.take() {
|
||||
v11::OwnerInfoOf::<T, OldCurrency>::iter_from(
|
||||
v11::OwnerInfoOf::<T, OldCurrency>::hashed_key_for(last_key),
|
||||
@@ -230,10 +231,12 @@ where
|
||||
|
||||
self.last_code_hash = Some(hash);
|
||||
|
||||
(IsFinished::No, T::WeightInfo::v12_migration_step(code_len as u32))
|
||||
meter.consume(T::WeightInfo::v12_migration_step(code_len as u32));
|
||||
IsFinished::No
|
||||
} else {
|
||||
log::debug!(target: LOG_TARGET, "No more OwnerInfo to migrate");
|
||||
(IsFinished::Yes, T::WeightInfo::v12_migration_step(0))
|
||||
meter.consume(T::WeightInfo::v12_migration_step(0));
|
||||
IsFinished::Yes
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user