Skip to content

Commit

Permalink
feat(common): force storage version
Browse files Browse the repository at this point in the history
  • Loading branch information
CertainLach authored Jul 8, 2022
1 parent 71d423f commit 9fdfa58
Showing 1 changed file with 1 addition and 59 deletions.
60 changes: 1 addition & 59 deletions pallets/common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -553,65 +553,7 @@ pub mod pallet {
#[pallet::hooks]
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {
fn on_runtime_upgrade() -> Weight {
if StorageVersion::get::<Pallet<T>>() < StorageVersion::new(1) {
use up_data_structs::{CollectionVersion1, CollectionVersion2};
<CollectionById<T>>::translate::<CollectionVersion1<T::AccountId>, _>(|id, v| {
let mut props = Vec::new();
if !v.offchain_schema.is_empty() {
props.push(Property {
key: b"_old_offchainSchema".to_vec().try_into().unwrap(),
value: v
.offchain_schema
.clone()
.into_inner()
.try_into()
.expect("offchain schema too big"),
});
}
if !v.variable_on_chain_schema.is_empty() {
props.push(Property {
key: b"_old_variableOnChainSchema".to_vec().try_into().unwrap(),
value: v
.variable_on_chain_schema
.clone()
.into_inner()
.try_into()
.expect("offchain schema too big"),
});
}
if !v.const_on_chain_schema.is_empty() {
props.push(Property {
key: b"_old_constOnChainSchema".to_vec().try_into().unwrap(),
value: v
.const_on_chain_schema
.clone()
.into_inner()
.try_into()
.expect("offchain schema too big"),
});
}
props.push(Property {
key: b"_old_schemaVersion".to_vec().try_into().unwrap(),
value: match v.schema_version {
SchemaVersion::ImageURL => b"ImageUrl".as_slice(),
SchemaVersion::Unique => b"Unique".as_slice(),
}
.to_vec()
.try_into()
.unwrap(),
});
Self::set_scoped_collection_properties(
id,
PropertyScope::None,
props.into_iter(),
)
.expect("existing data larger than properties");
let mut new = CollectionVersion2::from(v.clone());
new.permissions.access = Some(v.access);
new.permissions.mint_mode = Some(v.mint_mode);
Some(new)
});
}
StorageVersion::new(1).put::<Pallet<T>>();

0
}
Expand Down

0 comments on commit 9fdfa58

Please sign in to comment.