I'm currently attempting to perform a migration process that involves querying events emitted from a specific pallet. The objective of this migration is to extract relevant data from these events and store it within the updated storage system. However, I've run into an error during this process.
pub fn migrate_to_v2<T: Config>() -> Weight {
let onchain_version = Pallet::<T>::on_chain_storage_version();
if onchain_version < 2 {
Pallet::<T>::events().iter().for_each(|event| {
info!(" >>> Event: {:?}", event);
});
Weight::zero()
} else {
info!(" >>> Unused migration!");
Weight::zero()
}
}
Am I doing anything wrong?
Additionally, I need to query events from a specific block. Is this feasible from a storage migration?
Edit: I'm modifying an item in my storage, switching from StorageMap
to DoubleStorageMap
, which necessitates a migration. The new key value used in the double map is derived from events emitted in the past. If querying past events is not possible, is there another way to achieve this?