difftreelog
Remove variableOnChainSchema
in: master
12 files changed
pallets/common/src/benchmarking.rsdiffbeforeafterboth19use up_data_structs::{19use up_data_structs::{20 CollectionMode, CreateCollectionData, CollectionId, MAX_COLLECTION_NAME_LENGTH,20 CollectionMode, CreateCollectionData, CollectionId, MAX_COLLECTION_NAME_LENGTH,21 MAX_COLLECTION_DESCRIPTION_LENGTH, MAX_TOKEN_PREFIX_LENGTH, OFFCHAIN_SCHEMA_LIMIT,21 MAX_COLLECTION_DESCRIPTION_LENGTH, MAX_TOKEN_PREFIX_LENGTH, OFFCHAIN_SCHEMA_LIMIT,22 VARIABLE_ON_CHAIN_SCHEMA_LIMIT, CONST_ON_CHAIN_SCHEMA_LIMIT,22 CONST_ON_CHAIN_SCHEMA_LIMIT,23};23};24use frame_support::{24use frame_support::{25 traits::{Currency, Get},25 traits::{Currency, Get},67 let description = create_u16_data::<MAX_COLLECTION_DESCRIPTION_LENGTH>();67 let description = create_u16_data::<MAX_COLLECTION_DESCRIPTION_LENGTH>();68 let token_prefix = create_data::<MAX_TOKEN_PREFIX_LENGTH>();68 let token_prefix = create_data::<MAX_TOKEN_PREFIX_LENGTH>();69 let offchain_schema = create_data::<OFFCHAIN_SCHEMA_LIMIT>();69 let offchain_schema = create_data::<OFFCHAIN_SCHEMA_LIMIT>();70 let variable_on_chain_schema = create_data::<VARIABLE_ON_CHAIN_SCHEMA_LIMIT>();71 let const_on_chain_schema = create_data::<CONST_ON_CHAIN_SCHEMA_LIMIT>();70 let const_on_chain_schema = create_data::<CONST_ON_CHAIN_SCHEMA_LIMIT>();72 handler(71 handler(73 owner,72 owner,77 description,76 description,78 token_prefix,77 token_prefix,79 offchain_schema,78 offchain_schema,80 variable_on_chain_schema,81 const_on_chain_schema,79 const_on_chain_schema,82 ..Default::default()80 ..Default::default()83 },81 },pallets/common/src/lib.rsdiffbeforeafterboth480 v.offchain_schema.clone().into_inner(),480 v.offchain_schema.clone().into_inner(),481 )481 )482 .expect("data has lower bounds than field");482 .expect("data has lower bounds than field");483 Self::set_field_raw(484 id,485 CollectionField::VariableOnChainSchema,486 v.variable_on_chain_schema.clone().into_inner(),487 )488 .expect("data has lower bounds than field");489 Self::set_field_raw(483 Self::set_field_raw(490 id,484 id,491 CollectionField::ConstOnChainSchema,485 CollectionField::ConstOnChainSchema,621 CollectionField::ConstOnChainSchema,615 CollectionField::ConstOnChainSchema,622 ))616 ))623 .into_inner(),617 .into_inner(),624 variable_on_chain_schema: <CollectionData<T>>::get((625 collection,626 CollectionField::VariableOnChainSchema,627 ))628 .into_inner(),629 token_property_permissions,618 token_property_permissions,630 properties,619 properties,631 })620 })725 data.offchain_schema.into_inner(),714 data.offchain_schema.into_inner(),726 )715 )727 .expect("data has lower bounds than field");716 .expect("data has lower bounds than field");728 Self::set_field_raw(729 id,730 CollectionField::VariableOnChainSchema,731 data.variable_on_chain_schema.into_inner(),732 )733 .expect("data has lower bounds than field");734 Self::set_field_raw(717 Self::set_field_raw(735 id,718 id,736 CollectionField::ConstOnChainSchema,719 CollectionField::ConstOnChainSchema,pallets/unique/src/benchmarking.rsdiffbeforeafterboth146 let data = create_var_data(b);146 let data = create_var_data(b);147 }: set_const_on_chain_schema(RawOrigin::Signed(caller.clone()), collection, data)147 }: set_const_on_chain_schema(RawOrigin::Signed(caller.clone()), collection, data)148149 set_variable_on_chain_schema {150 let b in 0..VARIABLE_ON_CHAIN_SCHEMA_LIMIT;151152 let caller: T::AccountId = account("caller", 0, SEED);153 let collection = create_nft_collection::<T>(caller.clone())?;154 let data = create_var_data(b);155 }: set_variable_on_chain_schema(RawOrigin::Signed(caller.clone()), collection, data)156148157 set_schema_version {149 set_schema_version {158 let caller: T::AccountId = account("caller", 0, SEED);150 let caller: T::AccountId = account("caller", 0, SEED);pallets/unique/src/lib.rsdiffbeforeafterboth35use frame_system::{self as system, ensure_signed};35use frame_system::{self as system, ensure_signed};36use sp_runtime::{sp_std::prelude::Vec};36use sp_runtime::{sp_std::prelude::Vec};37use up_data_structs::{37use up_data_structs::{38 VARIABLE_ON_CHAIN_SCHEMA_LIMIT, CONST_ON_CHAIN_SCHEMA_LIMIT, OFFCHAIN_SCHEMA_LIMIT,38 CONST_ON_CHAIN_SCHEMA_LIMIT, OFFCHAIN_SCHEMA_LIMIT,39 MAX_COLLECTION_NAME_LENGTH, MAX_COLLECTION_DESCRIPTION_LENGTH, MAX_TOKEN_PREFIX_LENGTH,39 MAX_COLLECTION_NAME_LENGTH, MAX_COLLECTION_DESCRIPTION_LENGTH, MAX_TOKEN_PREFIX_LENGTH,40 AccessMode, CreateItemData, CollectionLimits, CollectionId, CollectionMode, TokenId,40 AccessMode, CreateItemData, CollectionLimits, CollectionId, CollectionMode, TokenId,41 SchemaVersion, SponsorshipState, MetaUpdatePermission, CreateCollectionData, CustomDataLimit,41 SchemaVersion, SponsorshipState, MetaUpdatePermission, CreateCollectionData, CustomDataLimit,192 /// * collection_id: Globally unique collection identifier.192 /// * collection_id: Globally unique collection identifier.193 SchemaVersionSet(CollectionId),193 SchemaVersionSet(CollectionId),194195 /// Variable on chain schema was set196 ///197 /// # Arguments198 ///199 /// * collection_id: Globally unique collection identifier.200 VariableOnChainSchemaSet(CollectionId),201 }194 }202}195}2031961088 Ok(())1081 Ok(())1089 }1082 }10901091 /// Set variable on-chain data schema.1092 ///1093 /// # Permissions1094 ///1095 /// * Collection Owner1096 /// * Collection Admin1097 ///1098 /// # Arguments1099 ///1100 /// * collection_id.1101 ///1102 /// * schema: String representing the variable on-chain data schema.1103 #[weight = <SelfWeightOf<T>>::set_const_on_chain_schema(schema.len() as u32)]1104 #[transactional]1105 pub fn set_variable_on_chain_schema (1106 origin,1107 collection_id: CollectionId,1108 schema: BoundedVec<u8, ConstU32<VARIABLE_ON_CHAIN_SCHEMA_LIMIT>>1109 ) -> DispatchResult {1110 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);1111 let collection = <CollectionHandle<T>>::try_get(collection_id)?;11121113 // =========11141115 <PalletCommon<T>>::set_field(&collection, &sender, CollectionField::VariableOnChainSchema, schema.into_inner())?;11161117 <Pallet<T>>::deposit_event(Event::<T>::VariableOnChainSchemaSet(1118 collection_id1119 ));1120 Ok(())1121 }112210831123 #[weight = <SelfWeightOf<T>>::set_collection_limits()]1084 #[weight = <SelfWeightOf<T>>::set_collection_limits()]1124 #[transactional]1085 #[transactional]pallets/unique/src/weights.rsdiffbeforeafterboth47 fn set_transfers_enabled_flag() -> Weight;47 fn set_transfers_enabled_flag() -> Weight;48 fn set_offchain_schema(b: u32, ) -> Weight;48 fn set_offchain_schema(b: u32, ) -> Weight;49 fn set_const_on_chain_schema(b: u32, ) -> Weight;49 fn set_const_on_chain_schema(b: u32, ) -> Weight;50 fn set_variable_on_chain_schema(b: u32, ) -> Weight;51 fn set_schema_version() -> Weight;50 fn set_schema_version() -> Weight;52 fn set_collection_limits() -> Weight;51 fn set_collection_limits() -> Weight;53 fn set_meta_update_permission_flag() -> Weight;52 fn set_meta_update_permission_flag() -> Weight;159 .saturating_add(T::DbWeight::get().reads(1 as Weight))158 .saturating_add(T::DbWeight::get().reads(1 as Weight))160 .saturating_add(T::DbWeight::get().writes(1 as Weight))159 .saturating_add(T::DbWeight::get().writes(1 as Weight))161 }160 }162 // Storage: Common CollectionById (r:1 w:1)163 fn set_variable_on_chain_schema(_b: u32, ) -> Weight {164 (15_196_000 as Weight)165 .saturating_add(T::DbWeight::get().reads(1 as Weight))166 .saturating_add(T::DbWeight::get().writes(1 as Weight))167 }168 // Storage: Common CollectionById (r:1 w:1)161 // Storage: Common CollectionById (r:1 w:1)169 fn set_schema_version() -> Weight {162 fn set_schema_version() -> Weight {170 (14_596_000 as Weight)163 (14_596_000 as Weight)290 .saturating_add(RocksDbWeight::get().reads(1 as Weight))283 .saturating_add(RocksDbWeight::get().reads(1 as Weight))291 .saturating_add(RocksDbWeight::get().writes(1 as Weight))284 .saturating_add(RocksDbWeight::get().writes(1 as Weight))292 }285 }293 // Storage: Common CollectionById (r:1 w:1)294 fn set_variable_on_chain_schema(_b: u32, ) -> Weight {295 (15_196_000 as Weight)296 .saturating_add(RocksDbWeight::get().reads(1 as Weight))297 .saturating_add(RocksDbWeight::get().writes(1 as Weight))298 }299 // Storage: Common CollectionById (r:1 w:1)286 // Storage: Common CollectionById (r:1 w:1)300 fn set_schema_version() -> Weight {287 fn set_schema_version() -> Weight {301 (14_596_000 as Weight)288 (14_596_000 as Weight)primitives/data-structs/src/lib.rsdiffbeforeafterboth767677// Schema limits77// Schema limits78pub const OFFCHAIN_SCHEMA_LIMIT: u32 = 8192;78pub const OFFCHAIN_SCHEMA_LIMIT: u32 = 8192;79pub const VARIABLE_ON_CHAIN_SCHEMA_LIMIT: u32 = 8192;80pub const CONST_ON_CHAIN_SCHEMA_LIMIT: u32 = 32768;79pub const CONST_ON_CHAIN_SCHEMA_LIMIT: u32 = 32768;818082pub const COLLECTION_FIELD_LIMIT: u32 = CONST_ON_CHAIN_SCHEMA_LIMIT;81pub const COLLECTION_FIELD_LIMIT: u32 = CONST_ON_CHAIN_SCHEMA_LIMIT;83// u32::max is not const: OFFCHAIN_SCHEMA_LIMIT.max(VARIABLE_ON_CHAIN_SCHEMA_LIMIT).max(CONST_ON_CHAIN_SCHEMA_LIMIT);848285pub const MAX_COLLECTION_NAME_LENGTH: u32 = 64;83pub const MAX_COLLECTION_NAME_LENGTH: u32 = 64;86pub const MAX_COLLECTION_DESCRIPTION_LENGTH: u32 = 256;84pub const MAX_COLLECTION_DESCRIPTION_LENGTH: u32 = 256;303 #[version(2.., upper(limits.into()))]301 #[version(2.., upper(limits.into()))]304 pub limits: CollectionLimitsVersion2,302 pub limits: CollectionLimitsVersion2,305303306 #[version(..2)]307 pub variable_on_chain_schema: BoundedVec<u8, ConstU32<VARIABLE_ON_CHAIN_SCHEMA_LIMIT>>,308 #[version(..2)]304 #[version(..2)]309 pub const_on_chain_schema: BoundedVec<u8, ConstU32<CONST_ON_CHAIN_SCHEMA_LIMIT>>,305 pub const_on_chain_schema: BoundedVec<u8, ConstU32<CONST_ON_CHAIN_SCHEMA_LIMIT>>,310306326 pub schema_version: SchemaVersion,322 pub schema_version: SchemaVersion,327 pub sponsorship: SponsorshipState<AccountId>,323 pub sponsorship: SponsorshipState<AccountId>,328 pub limits: CollectionLimits,324 pub limits: CollectionLimits,329 pub variable_on_chain_schema: Vec<u8>,330 pub const_on_chain_schema: Vec<u8>,325 pub const_on_chain_schema: Vec<u8>,331 pub meta_update_permission: MetaUpdatePermission,326 pub meta_update_permission: MetaUpdatePermission,332 pub token_property_permissions: Vec<PropertyKeyPermission>,327 pub token_property_permissions: Vec<PropertyKeyPermission>,336#[derive(Encode, Decode, Clone, PartialEq, TypeInfo, MaxEncodedLen)]331#[derive(Encode, Decode, Clone, PartialEq, TypeInfo, MaxEncodedLen)]337#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]332#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]338pub enum CollectionField {333pub enum CollectionField {339 VariableOnChainSchema,340 ConstOnChainSchema,334 ConstOnChainSchema,341 OffchainSchema,335 OffchainSchema,342}336}354 pub schema_version: Option<SchemaVersion>,348 pub schema_version: Option<SchemaVersion>,355 pub pending_sponsor: Option<AccountId>,349 pub pending_sponsor: Option<AccountId>,356 pub limits: Option<CollectionLimits>,350 pub limits: Option<CollectionLimits>,357 pub variable_on_chain_schema: BoundedVec<u8, ConstU32<VARIABLE_ON_CHAIN_SCHEMA_LIMIT>>,358 pub const_on_chain_schema: BoundedVec<u8, ConstU32<CONST_ON_CHAIN_SCHEMA_LIMIT>>,351 pub const_on_chain_schema: BoundedVec<u8, ConstU32<CONST_ON_CHAIN_SCHEMA_LIMIT>>,359 pub meta_update_permission: Option<MetaUpdatePermission>,352 pub meta_update_permission: Option<MetaUpdatePermission>,360 pub token_property_permissions: CollectionPropertiesPermissionsVec,353 pub token_property_permissions: CollectionPropertiesPermissionsVec,runtime/tests/src/tests.rsdiffbeforeafterboth2423 )),2423 )),2424 b"test const on chain schema".to_vec()2424 b"test const on chain schema".to_vec()2425 );2425 );2426 assert_eq!(2427 <pallet_common::CollectionData<Test>>::get((2428 collection_id,2429 CollectionField::VariableOnChainSchema2430 )),2431 b"".to_vec()2432 );2433 });2426 });2434}2427}24352436#[test]2437fn set_variable_on_chain_schema() {2438 new_test_ext().execute_with(|| {2439 let collection_id = create_test_collection(&CollectionMode::NFT, CollectionId(1));24402441 let origin1 = Origin::signed(1);2442 assert_ok!(Unique::set_variable_on_chain_schema(2443 origin1,2444 collection_id,2445 b"test variable on chain schema"2446 .to_vec()2447 .try_into()2448 .unwrap()2449 ));24502451 assert_eq!(2452 <pallet_common::CollectionData<Test>>::get((2453 collection_id,2454 CollectionField::ConstOnChainSchema2455 )),2456 b"".to_vec()2457 );2458 assert_eq!(2459 <pallet_common::CollectionData<Test>>::get((2460 collection_id,2461 CollectionField::VariableOnChainSchema2462 )),2463 b"test variable on chain schema".to_vec()2464 );2465 });2466}246724282468#[test]2429#[test]2469fn set_variable_meta_data_on_nft_token_stores_variable_meta_data() {2430fn set_variable_meta_data_on_nft_token_stores_variable_meta_data() {tests/src/createCollection.test.tsdiffbeforeafterboth73 limits: {73 limits: {74 accountTokenOwnershipLimit: 3,74 accountTokenOwnershipLimit: 3,75 },75 },76 variableOnChainSchema: '0x222222',77 constOnChainSchema: '0x333333',76 constOnChainSchema: '0x333333',78 metaUpdatePermission: 'Admin',77 metaUpdatePermission: 'Admin',79 });78 });91 expect(collection.schemaVersion.isUnique).to.be.true;90 expect(collection.schemaVersion.isUnique).to.be.true;92 expect(collection.sponsorship.asUnconfirmed.toString()).to.equal(bob.address);91 expect(collection.sponsorship.asUnconfirmed.toString()).to.equal(bob.address);93 expect(collection.limits.accountTokenOwnershipLimit.unwrap().toNumber()).to.equal(3);92 expect(collection.limits.accountTokenOwnershipLimit.unwrap().toNumber()).to.equal(3);94 expect(collection.variableOnChainSchema.toString()).to.equal('0x222222');95 expect(collection.constOnChainSchema.toString()).to.equal('0x333333');93 expect(collection.constOnChainSchema.toString()).to.equal('0x333333');96 expect(collection.metaUpdatePermission.isAdmin).to.be.true;94 expect(collection.metaUpdatePermission.isAdmin).to.be.true;97 });95 });tests/src/nesting/migration-check.test.tsdiffbeforeafterboth36 limits: {36 limits: {37 accountTokenOwnershipLimit: 3,37 accountTokenOwnershipLimit: 3,38 },38 },39 variableOnChainSchema: '0x222222',40 constOnChainSchema: '0x333333',39 constOnChainSchema: '0x333333',41 metaUpdatePermission: 'Admin',40 metaUpdatePermission: 'Admin',42 });41 });80 const collectionNew = (await api.query.common.collectionById(collectionId)).toJSON() as any;79 const collectionNew = (await api.query.common.collectionById(collectionId)).toJSON() as any;81 8082 // Make sure the extra fields are what they should be81 // Make sure the extra fields are what they should be83 const variableOnChainSchema = await api.query.common.collectionData(collectionId, 'VariableOnChainSchema');84 const constOnChainSchema = await api.query.common.collectionData(collectionId, 'ConstOnChainSchema');82 const constOnChainSchema = await api.query.common.collectionData(collectionId, 'ConstOnChainSchema');85 const offchainSchema = await api.query.common.collectionData(collectionId, 'OffchainSchema');83 const offchainSchema = await api.query.common.collectionData(collectionId, 'OffchainSchema');868487 expect(variableOnChainSchema.toHex()).to.be.deep.equal((collectionOld.variableOnChainSchema));88 expect(constOnChainSchema.toHex()).to.be.deep.equal(collectionOld.constOnChainSchema);85 expect(constOnChainSchema.toHex()).to.be.deep.equal(collectionOld.constOnChainSchema);89 expect(offchainSchema.toHex()).to.be.deep.equal(collectionOld.offchainSchema);86 expect(offchainSchema.toHex()).to.be.deep.equal(collectionOld.offchainSchema);90 expect(collectionNew).to.have.nested.property('limits.nestingRule');87 expect(collectionNew).to.have.nested.property('limits.nestingRule');93 delete collectionNew.limits.nestingRule;90 delete collectionNew.limits.nestingRule;94 delete collectionOld.constOnChainSchema;91 delete collectionOld.constOnChainSchema;95 delete collectionOld.offchainSchema;92 delete collectionOld.offchainSchema;96 delete collectionOld.variableOnChainSchema;979398 expect(collectionNew).to.be.deep.equal(collectionOld);94 expect(collectionNew).to.be.deep.equal(collectionOld);99 });95 });tests/src/setChainLimits.test.tsdiffbeforeafterboth44 fungibleSponsorTransferTimeout: 1,44 fungibleSponsorTransferTimeout: 1,45 refungibleSponsorTransferTimeout: 1,45 refungibleSponsorTransferTimeout: 1,46 offchainSchemaLimit: 1,46 offchainSchemaLimit: 1,47 variableOnChainSchemaLimit: 1,48 constOnChainSchemaLimit: 1,47 constOnChainSchemaLimit: 1,49 };48 };50 });49 });tests/src/setVariableOnChainSchema.test.tsdiffbeforeafterbothno changes
tests/src/util/helpers.tsdiffbeforeafterboth136 fungibleSponsorTransferTimeout: number;136 fungibleSponsorTransferTimeout: number;137 refungibleSponsorTransferTimeout: number;137 refungibleSponsorTransferTimeout: number;138 offchainSchemaLimit: number;138 offchainSchemaLimit: number;139 variableOnChainSchemaLimit: number;140 constOnChainSchemaLimit: number;139 constOnChainSchemaLimit: number;141}140}142141