pallet_vesting/
migrations.rs1use super::*;
21use alloc::vec;
22
23pub mod v1 {
25 use super::*;
26
27 #[cfg(feature = "try-runtime")]
28 pub fn pre_migrate<T: Config>() -> Result<(), &'static str> {
29 assert!(StorageVersion::<T>::get() == Releases::V0, "Storage version too high.");
30
31 log::debug!(
32 target: "runtime::vesting",
33 "migration: Vesting storage version v1 PRE migration checks successful!"
34 );
35
36 Ok(())
37 }
38
39 pub fn migrate<T: Config>() -> Weight {
42 let mut reads_writes = 0;
43
44 Vesting::<T>::translate::<VestingInfo<BalanceOf<T>, BlockNumberFor<T>>, _>(
45 |_key, vesting_info| {
46 reads_writes += 1;
47 let v: Option<
48 BoundedVec<
49 VestingInfo<BalanceOf<T>, BlockNumberFor<T>>,
50 MaxVestingSchedulesGet<T>,
51 >,
52 > = vec![vesting_info].try_into().ok();
53
54 if v.is_none() {
55 log::warn!(
56 target: "runtime::vesting",
57 "migration: Failed to move a vesting schedule into a BoundedVec"
58 );
59 }
60
61 v
62 },
63 );
64
65 T::DbWeight::get().reads_writes(reads_writes, reads_writes)
66 }
67
68 #[cfg(feature = "try-runtime")]
69 pub fn post_migrate<T: Config>() -> Result<(), &'static str> {
70 assert_eq!(StorageVersion::<T>::get(), Releases::V1);
71
72 for (_key, schedules) in Vesting::<T>::iter() {
73 assert!(
74 schedules.len() >= 1,
75 "A bounded vec with incorrect count of items was created."
76 );
77
78 for s in schedules {
79 if !s.is_valid() {
82 log::warn!(
83 target: "runtime::vesting",
84 "migration: A schedule does not pass new validation logic.",
85 )
86 }
87 }
88 }
89
90 log::debug!(
91 target: "runtime::vesting",
92 "migration: Vesting storage version v1 POST migration checks successful!"
93 );
94 Ok(())
95 }
96}