pallet_multisig/
migrations.rs1use crate::*;
21use frame::prelude::*;
22
23pub mod v1 {
24 use super::*;
25
26 type OpaqueCall<T> = frame::traits::WrapperKeepOpaque<<T as Config>::RuntimeCall>;
27
28 #[frame::storage_alias]
29 type Calls<T: Config> = StorageMap<
30 Pallet<T>,
31 Identity,
32 [u8; 32],
33 (OpaqueCall<T>, <T as frame_system::Config>::AccountId, BalanceOf<T>),
34 >;
35
36 pub struct MigrateToV1<T>(core::marker::PhantomData<T>);
37 impl<T: Config> OnRuntimeUpgrade for MigrateToV1<T> {
38 #[cfg(feature = "try-runtime")]
39 fn pre_upgrade() -> Result<Vec<u8>, frame::try_runtime::TryRuntimeError> {
40 log!(info, "Number of calls to refund and delete: {}", Calls::<T>::iter().count());
41
42 Ok(Vec::new())
43 }
44
45 fn on_runtime_upgrade() -> Weight {
46 use frame::traits::ReservableCurrency as _;
47 let current = Pallet::<T>::in_code_storage_version();
48 let onchain = Pallet::<T>::on_chain_storage_version();
49
50 if onchain > 0 {
51 log!(info, "MigrateToV1 should be removed");
52 return T::DbWeight::get().reads(1)
53 }
54
55 let mut call_count = 0u64;
56 Calls::<T>::drain().for_each(|(_call_hash, (_data, caller, deposit))| {
57 T::Currency::unreserve(&caller, deposit);
58 call_count.saturating_inc();
59 });
60
61 current.put::<Pallet<T>>();
62
63 T::DbWeight::get().reads_writes(
64 call_count.saturating_add(1),
66 call_count.saturating_mul(2).saturating_add(1),
68 )
69 }
70
71 #[cfg(feature = "try-runtime")]
72 fn post_upgrade(_state: Vec<u8>) -> Result<(), frame::try_runtime::TryRuntimeError> {
73 ensure!(
74 Calls::<T>::iter().count() == 0,
75 "there are some dangling calls that need to be destroyed and refunded"
76 );
77 Ok(())
78 }
79 }
80}