11pub mod v7 {
22 use polkadot_sdk:: {
33 frame_support:: { migrations:: VersionedMigration , traits:: UncheckedOnRuntimeUpgrade } ,
4- sp_std:: { vec, vec:: Vec } ,
4+ sp_runtime:: BoundedBTreeSet ,
5+ sp_std:: vec:: Vec ,
56 sp_tracing:: { error, info, warn} ,
67 sp_weights:: Weight ,
78 } ;
89
910 use crate :: {
1011 Config , Pallet , PermissionContract , PermissionScope , Permissions , PermissionsByDelegator ,
1112 PermissionsByParticipants , PermissionsByRecipient , StreamScope ,
12- permission:: add_permission_indices,
13- permission:: { CuratorScope , NamespaceScope } ,
13+ permission:: {
14+ CuratorScope , NamespaceScope , add_permission_indices, remove_permission_from_indices,
15+ } ,
1416 } ;
1517
16- pub type Migration < T , W > = VersionedMigration < 6 , 7 , MigrateToV7 < T > , Pallet < T > , W > ;
18+ pub type Migration < T , W > = VersionedMigration < 5 , 7 , MigrateToV7 < T > , Pallet < T > , W > ;
1719 pub struct MigrateToV7 < T > ( core:: marker:: PhantomData < T > ) ;
1820
1921 mod old_storage {
@@ -28,8 +30,8 @@ pub mod v7 {
2830 use scale_info:: TypeInfo ;
2931
3032 use crate :: {
31- AccountIdOf , Config , CuratorPermissions , EnforcementAuthority , Pallet ,
32- PermissionDuration , PermissionId , RevocationTerms , StreamScope ,
33+ AccountIdOf , Config , CuratorPermissions , DistributionControl , EnforcementAuthority ,
34+ Pallet , PermissionDuration , PermissionId , RevocationTerms , StreamAllocation ,
3335 } ;
3436
3537 #[ storage_alias]
@@ -63,10 +65,18 @@ pub mod v7 {
6365 ValueQuery ,
6466 > ;
6567
68+ #[ derive( Encode , Decode , TypeInfo , MaxEncodedLen ) ]
69+ #[ scale_info( skip_type_params( T ) ) ]
70+ pub struct OldEmissionScope < T : Config > {
71+ pub allocation : StreamAllocation < T > ,
72+ pub distribution : DistributionControl < T > ,
73+ pub targets : BoundedBTreeMap < T :: AccountId , u16 , T :: MaxRecipientsPerPermission > ,
74+ pub accumulating : bool ,
75+ }
76+
6677 #[ derive( Encode , Decode , TypeInfo , MaxEncodedLen ) ]
6778 #[ scale_info( skip_type_params( T ) ) ]
6879 pub struct OldCuratorScope < T : Config > {
69- pub recipient : T :: AccountId ,
7080 pub flags : BoundedBTreeMap <
7181 Option < PermissionId > ,
7282 CuratorPermissions ,
@@ -78,7 +88,6 @@ pub mod v7 {
7888 #[ derive( Encode , Decode , TypeInfo , MaxEncodedLen ) ]
7989 #[ scale_info( skip_type_params( T ) ) ]
8090 pub struct OldNamespaceScope < T : Config > {
81- pub recipient : T :: AccountId ,
8291 pub paths : BoundedBTreeMap <
8392 Option < PermissionId > ,
8493 BoundedBTreeSet < NamespacePath , T :: MaxNamespacesPerPermission > ,
@@ -89,7 +98,7 @@ pub mod v7 {
8998 #[ derive( Encode , Decode , TypeInfo , MaxEncodedLen ) ]
9099 #[ scale_info( skip_type_params( T ) ) ]
91100 pub enum OldPermissionScope < T : Config > {
92- Stream ( StreamScope < T > ) ,
101+ Emission ( OldEmissionScope < T > ) ,
93102 Curator ( OldCuratorScope < T > ) ,
94103 Namespace ( OldNamespaceScope < T > ) ,
95104 }
@@ -98,13 +107,12 @@ pub mod v7 {
98107 #[ scale_info( skip_type_params( T ) ) ]
99108 pub struct OldPermissionContract < T : Config > {
100109 pub delegator : T :: AccountId ,
110+ pub recipient : T :: AccountId ,
101111 pub scope : OldPermissionScope < T > ,
102112 pub duration : PermissionDuration < T > ,
103113 pub revocation : RevocationTerms < T > ,
104114 /// Enforcement authority that can toggle the permission
105115 pub enforcement : EnforcementAuthority < T > ,
106- /// Last update block
107- pub last_update : BlockNumberFor < T > ,
108116 /// Last execution block
109117 #[ doc( hidden) ]
110118 pub last_execution : Option < BlockNumberFor < T > > ,
@@ -132,58 +140,83 @@ pub mod v7 {
132140
133141 for ( permission_id, old_contract) in old_storage:: Permissions :: < T > :: iter ( ) {
134142 let new_scope = match old_contract. scope {
135- old_storage:: OldPermissionScope :: Stream ( stream) => {
143+ old_storage:: OldPermissionScope :: Emission ( old_emission) => {
144+ // For emission permissions, we need to update storage indices:
145+ // 1. Remove the old recipient index (permission recipient)
146+ // 2. Add indices for all the emission targets
147+
148+ // Remove old recipient index
149+ remove_permission_from_indices :: < T > (
150+ & old_contract. delegator ,
151+ core:: iter:: once ( & old_contract. recipient ) ,
152+ permission_id,
153+ ) ;
154+
155+ let mut managers = BoundedBTreeSet :: new ( ) ;
156+ let _ = managers. try_insert ( old_contract. delegator . clone ( ) ) ;
157+
158+ let stream = StreamScope :: < T > {
159+ recipients : old_emission. targets , // Field renamed from targets to recipients
160+ allocation : old_emission. allocation ,
161+ distribution : old_emission. distribution ,
162+ accumulating : old_emission. accumulating ,
163+ // New manager fields introduced in v6
164+ recipient_managers : managers. clone ( ) ,
165+ weight_setters : managers,
166+ } ;
167+
168+ // Add new indices for all emission targets
136169 if let Err ( e) = add_permission_indices :: < T > (
137170 & old_contract. delegator ,
138171 stream. recipients . keys ( ) ,
139172 permission_id,
140173 ) {
141174 error ! (
142- "Failed to add permission indices for stream permission {permission_id:?}: {e:?}"
175+ "Failed to add permission indices for emission permission {permission_id:?}: {e:?}"
143176 ) ;
144177 }
145178
146179 PermissionScope :: Stream ( stream)
147180 }
148181 old_storage:: OldPermissionScope :: Curator ( old_curator) => {
182+ let new_curator = crate :: permission:: CuratorScope :: < T > {
183+ recipient : old_contract. recipient ,
184+ flags : old_curator. flags ,
185+ cooldown : old_curator. cooldown ,
186+ max_instances : old_contract. max_instances ,
187+ children : old_contract. children ,
188+ } ;
189+
149190 if let Err ( e) = add_permission_indices :: < T > (
150191 & old_contract. delegator ,
151- core:: iter:: once ( & old_curator . recipient ) ,
192+ core:: iter:: once ( & new_curator . recipient ) ,
152193 permission_id,
153194 ) {
154195 error ! (
155196 "Failed to add permission indices for curator permission {permission_id:?}: {e:?}"
156197 ) ;
157198 }
158199
159- let new_curator = crate :: permission:: CuratorScope :: < T > {
160- recipient : old_curator. recipient ,
161- flags : old_curator. flags ,
162- cooldown : old_curator. cooldown ,
200+ PermissionScope :: Curator ( new_curator)
201+ }
202+ old_storage:: OldPermissionScope :: Namespace ( old_namespace) => {
203+ let new_namespace = crate :: permission:: NamespaceScope :: < T > {
204+ recipient : old_contract. recipient ,
205+ paths : old_namespace. paths ,
163206 max_instances : old_contract. max_instances ,
164207 children : old_contract. children ,
165208 } ;
166209
167- PermissionScope :: Curator ( new_curator)
168- }
169- old_storage:: OldPermissionScope :: Namespace ( old_namespace) => {
170210 if let Err ( e) = add_permission_indices :: < T > (
171211 & old_contract. delegator ,
172- core:: iter:: once ( & old_namespace . recipient ) ,
212+ core:: iter:: once ( & new_namespace . recipient ) ,
173213 permission_id,
174214 ) {
175215 error ! (
176216 "Failed to add permission indices for namespace permission {permission_id:?}: {e:?}"
177217 ) ;
178218 }
179219
180- let new_namespace = crate :: permission:: NamespaceScope :: < T > {
181- recipient : old_namespace. recipient ,
182- paths : old_namespace. paths ,
183- max_instances : old_contract. max_instances ,
184- children : old_contract. children ,
185- } ;
186-
187220 PermissionScope :: Namespace ( new_namespace)
188221 }
189222 } ;
@@ -395,7 +428,7 @@ pub mod v7 {
395428 }
396429 PermissionScope :: Curator ( CuratorScope { recipient, .. } )
397430 | PermissionScope :: Namespace ( NamespaceScope { recipient, .. } ) => {
398- vec ! [ recipient. clone( ) ]
431+ polkadot_sdk :: sp_std :: vec![ recipient. clone( ) ]
399432 }
400433 } ;
401434
0 commit comments