1919//!
2020//! These represent the old storage layout before the v1 migration.
2121
22- use crate :: InheritanceOrder ;
2322use codec:: { Decode , Encode , MaxEncodedLen } ;
24- use frame:: deps:: sp_io:: hashing:: blake2_256;
25- use frame:: deps:: sp_runtime:: traits:: TrailingZeroInput ;
26- use frame:: traits:: BlockNumberProvider ;
23+ use frame:: {
24+ deps:: { sp_io:: hashing:: blake2_256, sp_runtime:: traits:: TrailingZeroInput } ,
25+ traits:: BlockNumberProvider ,
26+ } ;
2727use frame_support:: {
2828 storage_alias,
2929 traits:: { Currency , ReservableCurrency } ,
3030 Blake2_128Concat , BoundedVec , Twox64Concat ,
3131} ;
3232use scale_info:: TypeInfo ;
3333
34- /// Migration config - extends the new pallet Config with types needed for migration.
34+ /// Extended migration config for the migration.
3535pub trait MigrationConfig : crate :: pallet:: Config {
36- /// The currency type used in v0.
37- /// Must implement ReservableCurrency for unreserving deposits.
38- /// The Balance type must match the new pallet's Balance type.
36+ /// The currency to unreserve deposits.
3937 type Currency : ReservableCurrency < Self :: AccountId , Balance = crate :: BalanceOf < Self > > ;
4038}
4139
@@ -45,26 +43,30 @@ pub trait MigrationConfig: crate::pallet::Config {
4543/// will be the multisig account that the friends can control together.
4644///
4745/// NOTE: `who` must be sorted. If it is not, then you'll get the wrong answer.
48- pub fn multi_account_id < AccountId : Encode + Decode > ( who : & [ AccountId ] , threshold : u16 ) -> AccountId {
46+ pub fn multi_account_id < AccountId : Encode + Decode > (
47+ who : & [ AccountId ] ,
48+ threshold : u16 ,
49+ ) -> AccountId {
4950 let entropy = ( b"modlpy/utilisuba" , who, threshold) . using_encoded ( blake2_256) ;
5051 Decode :: decode ( & mut TrailingZeroInput :: new ( entropy. as_ref ( ) ) )
5152 . expect ( "infinite length input; no invalid inputs for type; qed" )
5253}
5354
54- /// Old balance type for v0 storage.
55+ /// Balance type for v0 storage.
5556pub type BalanceOf < T > =
5657 <<T as MigrationConfig >:: Currency as Currency < <T as frame_system:: Config >:: AccountId > >:: Balance ;
5758
58- /// Old block number type from provider.
59+ /// Block number type from provider.
5960pub type BlockNumberFromProviderOf < T > =
6061 <<T as crate :: pallet:: Config >:: BlockNumberProvider as BlockNumberProvider >:: BlockNumber ;
6162
62- /// Old friends bounded vec type.
63- /// Uses MaxFriendsPerConfig from the new pallet Config (assumes same as old MaxFriends).
64- pub type FriendsOf < T > =
65- BoundedVec < <T as frame_system:: Config >:: AccountId , <T as crate :: pallet:: Config >:: MaxFriendsPerConfig > ;
63+ /// Friends bounded vec type.
64+ pub type FriendsOf < T > = BoundedVec <
65+ <T as frame_system:: Config >:: AccountId ,
66+ <T as crate :: pallet:: Config >:: MaxFriendsPerConfig ,
67+ > ;
6668
67- /// Old recovery configuration structure from v0.
69+ /// Recovery configuration structure from v0.
6870#[ derive( Clone , Eq , PartialEq , Encode , Decode , Default , TypeInfo , MaxEncodedLen ) ]
6971pub struct RecoveryConfig < BlockNumber , Balance , Friends > {
7072 /// The minimum number of blocks since the start of the recovery process before the
@@ -79,25 +81,20 @@ pub struct RecoveryConfig<BlockNumber, Balance, Friends> {
7981 pub threshold : u16 ,
8082}
8183
82- impl < BlockNumber , Balance , Friends > RecoveryConfig < BlockNumber , Balance , Friends > {
83- /// Convert v0 RecoveryConfig to v1 FriendGroup.
84- ///
85- /// Since v0 didn't have `inheritor`, `inheritance_order`, or `cancel_delay`,
86- /// these must be provided as parameters.
84+ impl < BlockNumber : Clone , Balance , Friends > RecoveryConfig < BlockNumber , Balance , Friends > {
85+ /// Convert to a V1 `FriendGroup`.
8786 pub fn into_v1_friend_group < AccountId > (
8887 self ,
8988 inheritor : AccountId ,
90- inheritance_order : InheritanceOrder ,
91- cancel_delay : BlockNumber ,
9289 ) -> crate :: FriendGroup < BlockNumber , AccountId , Balance , Friends > {
9390 crate :: FriendGroup {
9491 deposit : self . deposit ,
9592 friends : self . friends ,
9693 friends_needed : self . threshold as u32 ,
9794 inheritor,
98- inheritance_delay : self . delay_period ,
99- inheritance_order,
100- cancel_delay,
95+ inheritance_delay : self . delay_period . clone ( ) ,
96+ inheritance_order : 0 ,
97+ cancel_delay : self . delay_period , // kinda random
10198 }
10299 }
103100}
@@ -114,7 +111,7 @@ pub struct ActiveRecovery<BlockNumber, Balance, Friends> {
114111 pub friends : Friends ,
115112}
116113
117- /// Old storage: The set of recoverable accounts and their recovery configuration.
114+ /// The set of recoverable accounts and their recovery configuration.
118115#[ storage_alias]
119116pub type Recoverable < T : MigrationConfig > = StorageMap <
120117 crate :: pallet:: Pallet < T > ,
0 commit comments