|
1 | 1 | pub mod v4 { |
| 2 | + use num_traits::Zero; |
2 | 3 | use polkadot_sdk::{ |
3 | 4 | frame_support::{migrations::VersionedMigration, traits::UncheckedOnRuntimeUpgrade}, |
| 5 | + sp_tracing::warn, |
4 | 6 | sp_weights::Weight, |
5 | 7 | }; |
6 | 8 |
|
7 | | - use crate::{Config, Pallet}; |
| 9 | + use crate::{Config, EmissionAllocation, Pallet, PermissionScope}; |
8 | 10 |
|
9 | 11 | pub type Migration<T, W> = VersionedMigration<3, 4, MigrateToV6<T>, Pallet<T>, W>; |
10 | 12 | pub struct MigrateToV6<T>(core::marker::PhantomData<T>); |
@@ -83,9 +85,37 @@ pub mod v4 { |
83 | 85 | let _ = old_storage::PermissionsByGrantor::<T>::clear(u32::MAX, None); |
84 | 86 | let _ = old_storage::PermissionsByGrantee::<T>::clear(u32::MAX, None); |
85 | 87 |
|
86 | | - for (id, contract) in old_storage::Permissions::<T>::iter() { |
| 88 | + for (pid, contract) in old_storage::Permissions::<T>::iter() { |
| 89 | + if let PermissionScope::Emission(scope) = &contract.scope { |
| 90 | + if let EmissionAllocation::Streams(streams) = &scope.allocation { |
| 91 | + for stream in streams.keys() { |
| 92 | + if !crate::AccumulatedStreamAmounts::<T>::contains_key(( |
| 93 | + &contract.grantor, |
| 94 | + &stream, |
| 95 | + &pid, |
| 96 | + )) { |
| 97 | + warn!( |
| 98 | + "inserting accumulated stream value for broken contract: {pid}, stream: {stream}" |
| 99 | + ); |
| 100 | + crate::AccumulatedStreamAmounts::<T>::set( |
| 101 | + (&contract.grantor, &stream, &pid), |
| 102 | + Some(Zero::zero()), |
| 103 | + ); |
| 104 | + } |
| 105 | + } |
| 106 | + } |
| 107 | + } |
| 108 | + |
| 109 | + crate::PermissionsByDelegator::<T>::mutate(&contract.grantor, |pids| { |
| 110 | + let _ = pids.try_push(pid); |
| 111 | + }); |
| 112 | + |
| 113 | + crate::PermissionsByRecipient::<T>::mutate(&contract.grantee, |pids| { |
| 114 | + let _ = pids.try_push(pid); |
| 115 | + }); |
| 116 | + |
87 | 117 | crate::Permissions::<T>::set( |
88 | | - id, |
| 118 | + pid, |
89 | 119 | Some(crate::PermissionContract { |
90 | 120 | delegator: contract.grantor, |
91 | 121 | recipient: contract.grantee, |
|
0 commit comments