difftreelog
refactor move foreign flag to collection struct
in: master
9 files changed
Cargo.lockdiffbeforeafterboth696 "once_cell",696 "once_cell",697]697]698699[[package]]700name = "bondrewd"701version = "0.1.14"702source = "registry+https://github.com/rust-lang/crates.io-index"703checksum = "6d1660fac8d3acced44dac64453fafedf5aab2de196b932c727e63e4ae42d1cc"704dependencies = [705 "bondrewd-derive",706]707708[[package]]709name = "bondrewd-derive"710version = "0.3.18"711source = "registry+https://github.com/rust-lang/crates.io-index"712checksum = "723da0dee1eef38edc021b0793f892bdc024500c6a5b0727a2efe16f0e0a6977"713dependencies = [714 "proc-macro2",715 "quote",716 "syn",717]698718699[[package]]719[[package]]700name = "bounded-vec"720name = "bounded-vec"5892name = "pallet-foreign-assets"5912name = "pallet-foreign-assets"5893version = "0.1.0"5913version = "0.1.0"5894dependencies = [5914dependencies = [5915 "frame-benchmarking",5895 "frame-support",5916 "frame-support",5896 "frame-system",5917 "frame-system",5897 "hex",5918 "hex",660066216601[[package]]6622[[package]]6602name = "pallet-unique"6623name = "pallet-unique"6603version = "0.1.4"6624version = "0.2.0"6604dependencies = [6625dependencies = [6605 "ethereum",6626 "ethereum",6606 "evm-coder",6627 "evm-coder",12634name = "up-data-structs"12655name = "up-data-structs"12635version = "0.2.2"12656version = "0.2.2"12636dependencies = [12657dependencies = [12658 "bondrewd",12637 "derivative",12659 "derivative",12638 "frame-support",12660 "frame-support",12639 "frame-system",12661 "frame-system",pallets/common/src/lib.rsdiffbeforeafterboth70 COLLECTION_NUMBER_LIMIT,70 COLLECTION_NUMBER_LIMIT,71 Collection,71 Collection,72 RpcCollection,72 RpcCollection,73 CollectionFlags,73 CollectionId,74 CollectionId,74 CreateItemData,75 CreateItemData,75 MAX_TOKEN_PREFIX_LENGTH,76 MAX_TOKEN_PREFIX_LENGTH,252 }253 }253254254 /// Checks that the collection was created with, and must be operated upon through **Unique API**.255 /// Checks that the collection was created with, and must be operated upon through **Unique API**.255 /// Now check only the `external_collection` flag and if it's **true**, then return [`Error::CollectionIsExternal`] error.256 /// Now check only the `external` flag and if it's **true**, then return [`Error::CollectionIsExternal`] error.256 pub fn check_is_internal(&self) -> DispatchResult {257 pub fn check_is_internal(&self) -> DispatchResult {257 if self.external_collection {258 if self.flags.external {258 return Err(<Error<T>>::CollectionIsExternal)?;259 return Err(<Error<T>>::CollectionIsExternal)?;259 }260 }260261261 Ok(())262 Ok(())262 }263 }263264264 /// Checks that the collection was created with, and must be operated upon through an **assimilated API**.265 /// Checks that the collection was created with, and must be operated upon through an **assimilated API**.265 /// Now check only the `external_collection` flag and if it's **false**, then return [`Error::CollectionIsInternal`] error.266 /// Now check only the `external` flag and if it's **false**, then return [`Error::CollectionIsInternal`] error.266 pub fn check_is_external(&self) -> DispatchResult {267 pub fn check_is_external(&self) -> DispatchResult {267 if !self.external_collection {268 if !self.flags.external {268 return Err(<Error<T>>::CollectionIsInternal)?;269 return Err(<Error<T>>::CollectionIsInternal)?;269 }270 }270271345 use frame_support::{Blake2_128Concat, pallet_prelude::*, storage::Key, traits::StorageVersion};346 use frame_support::{Blake2_128Concat, pallet_prelude::*, storage::Key, traits::StorageVersion};346 use frame_system::pallet_prelude::*;347 use frame_system::pallet_prelude::*;347 use frame_support::traits::Currency;348 use frame_support::traits::Currency;348 use up_data_structs::{TokenId, mapping::TokenAddressMapping};349 use up_data_structs::{TokenId, mapping::TokenAddressMapping, CollectionFlags};349 use scale_info::TypeInfo;350 use scale_info::TypeInfo;350 use weights::WeightInfo;351 use weights::WeightInfo;351352792 sponsorship,793 sponsorship,793 limits,794 limits,794 permissions,795 permissions,795 external_collection,796 flags,796 } = <CollectionById<T>>::get(collection)?;797 } = <CollectionById<T>>::get(collection)?;797798798 let token_property_permissions = <CollectionPropertyPermissions<T>>::get(collection)799 let token_property_permissions = <CollectionPropertyPermissions<T>>::get(collection)822 permissions,823 permissions,823 token_property_permissions,824 token_property_permissions,824 properties,825 properties,825 read_only: external_collection,826 read_only: flags.external,827 foreign: flags.foreign,826 })828 })827 }829 }828}830}861 ///863 ///862 /// * `owner` - The owner of the collection.864 /// * `owner` - The owner of the collection.863 /// * `data` - Description of the created collection.865 /// * `data` - Description of the created collection.864 /// * `is_external` - Marks that collection managet by not "Unique network".866 /// * `flags` - Extra flags to store.865 pub fn init_collection(867 pub fn init_collection(866 owner: T::CrossAccountId,868 owner: T::CrossAccountId,867 data: CreateCollectionData<T::AccountId>,869 data: CreateCollectionData<T::AccountId>,868 is_external: bool,870 flags: CollectionFlags,869 ) -> Result<CollectionId, DispatchError> {871 ) -> Result<CollectionId, DispatchError> {870 {872 {871 ensure!(873 ensure!(909 Self::clamp_permissions(data.mode.clone(), &Default::default(), permissions)911 Self::clamp_permissions(data.mode.clone(), &Default::default(), permissions)910 })912 })911 .unwrap_or_else(|| Ok(CollectionPermissions::default()))?,913 .unwrap_or_else(|| Ok(CollectionPermissions::default()))?,912 external_collection: is_external,914 flags,913 };915 };914916915 let mut collection_properties = up_data_structs::CollectionProperties::get();917 let mut collection_properties = up_data_structs::CollectionProperties::get();pallets/fungible/src/lib.rsdiffbeforeafterboth83use frame_support::{ensure};83use frame_support::{ensure};84use pallet_evm::account::CrossAccountId;84use pallet_evm::account::CrossAccountId;85use up_data_structs::{85use up_data_structs::{86 AccessMode, CollectionId, TokenId, CreateCollectionData, mapping::TokenAddressMapping,86 AccessMode, CollectionId, CollectionFlags, TokenId, CreateCollectionData,87 budget::Budget,87 mapping::TokenAddressMapping, budget::Budget,88};88};89use pallet_common::{89use pallet_common::{168 QueryKind = ValueQuery,168 QueryKind = ValueQuery,169 >;169 >;170171 /// Foreign collection flag172 #[pallet::storage]173 pub type ForeignCollection<T: Config> =174 StorageMap<Hasher = Twox64Concat, Key = CollectionId, Value = bool, QueryKind = ValueQuery>;175}170}176171177/// Wrapper around untyped collection handle, asserting inner collection is of fungible type.172/// Wrapper around untyped collection handle, asserting inner collection is of fungible type.217 owner: T::CrossAccountId,212 owner: T::CrossAccountId,218 data: CreateCollectionData<T::AccountId>,213 data: CreateCollectionData<T::AccountId>,219 ) -> Result<CollectionId, DispatchError> {214 ) -> Result<CollectionId, DispatchError> {220 <PalletCommon<T>>::init_collection(owner, data, false)215 <PalletCommon<T>>::init_collection(owner, data, CollectionFlags::default())221 }216 }222217223 /// Initializes the collection with ForeignCollection flag. Returns [CollectionId] on success, [DispatchError] otherwise.218 /// Initializes the collection with ForeignCollection flag. Returns [CollectionId] on success, [DispatchError] otherwise.224 pub fn init_foreign_collection(219 pub fn init_foreign_collection(225 owner: T::CrossAccountId,220 owner: T::CrossAccountId,226 data: CreateCollectionData<T::AccountId>,221 data: CreateCollectionData<T::AccountId>,227 ) -> Result<CollectionId, DispatchError> {222 ) -> Result<CollectionId, DispatchError> {228 let id = <PalletCommon<T>>::init_collection(owner, data, false)?;223 let id = <PalletCommon<T>>::init_collection(229 <ForeignCollection<T>>::insert(id, true);224 owner,225 data,226 CollectionFlags {227 foreign: true,228 ..Default::default()229 },230 )?;230 Ok(id)231 Ok(id)231 }232 }245246246 PalletCommon::destroy_collection(collection.0, sender)?;247 PalletCommon::destroy_collection(collection.0, sender)?;247248248 <ForeignCollection<T>>::remove(id);249 <TotalSupply<T>>::remove(id);249 <TotalSupply<T>>::remove(id);250 let _ = <Balance<T>>::clear_prefix((id,), u32::MAX, None);250 let _ = <Balance<T>>::clear_prefix((id,), u32::MAX, None);251 let _ = <Allowance<T>>::clear_prefix((id,), u32::MAX, None);251 let _ = <Allowance<T>>::clear_prefix((id,), u32::MAX, None);274 .ok_or(<CommonError<T>>::TokenValueTooLow)?;274 .ok_or(<CommonError<T>>::TokenValueTooLow)?;275275276 // Foreign collection check276 // Foreign collection check277 ensure!(277 ensure!(!collection.flags.foreign, <CommonError<T>>::NoPermission);278 !<ForeignCollection<T>>::get(collection.id),279 <CommonError<T>>::NoPermission280 );281278502 nesting_budget: &dyn Budget,499 nesting_budget: &dyn Budget,503 ) -> DispatchResult {500 ) -> DispatchResult {504 // Foreign collection check501 // Foreign collection check505 ensure!(502 ensure!(!collection.flags.foreign, <CommonError<T>>::NoPermission);506 !<ForeignCollection<T>>::get(collection.id),507 <CommonError<T>>::NoPermission508 );509503pallets/nonfungible/src/lib.rsdiffbeforeafterboth100 weights::{PostDispatchInfo, Pays},100 weights::{PostDispatchInfo, Pays},101};101};102use up_data_structs::{102use up_data_structs::{103 AccessMode, CollectionId, CustomDataLimit, TokenId, CreateCollectionData, CreateNftExData,103 AccessMode, CollectionId, CollectionFlags, CustomDataLimit, TokenId, CreateCollectionData,104 mapping::TokenAddressMapping, budget::Budget, Property, PropertyPermission, PropertyKey,104 CreateNftExData, mapping::TokenAddressMapping, budget::Budget, Property, PropertyPermission,105 PropertyValue, PropertyKeyPermission, Properties, PropertyScope, TrySetProperty, TokenChild,105 PropertyKey, PropertyValue, PropertyKeyPermission, Properties, PropertyScope, TrySetProperty,106 AuxPropertyValue,106 TokenChild, AuxPropertyValue,411 <PalletCommon<T>>::init_collection(owner, data, is_external)411 <PalletCommon<T>>::init_collection(412 owner,413 data,414 CollectionFlags {415 external: is_external,416 ..Default::default()417 },418 )412 }419 }413420pallets/refungible/src/lib.rsdiffbeforeafterboth112use sp_runtime::{ArithmeticError, DispatchError, DispatchResult, TransactionOutcome};112use sp_runtime::{ArithmeticError, DispatchError, DispatchResult, TransactionOutcome};113use sp_std::{vec::Vec, vec, collections::btree_map::BTreeMap};113use sp_std::{vec::Vec, vec, collections::btree_map::BTreeMap};114use up_data_structs::{114use up_data_structs::{115 AccessMode, budget::Budget, CollectionId, CollectionMode, CollectionPropertiesVec,115 AccessMode, budget::Budget, CollectionId, CollectionMode, CollectionFlags,116 CreateCollectionData, CustomDataLimit, mapping::TokenAddressMapping, MAX_ITEMS_PER_BATCH,116 CollectionPropertiesVec, CreateCollectionData, CustomDataLimit, mapping::TokenAddressMapping,117 MAX_REFUNGIBLE_PIECES, Property, PropertyKey, PropertyKeyPermission, PropertyPermission,117 MAX_ITEMS_PER_BATCH, MAX_REFUNGIBLE_PIECES, Property, PropertyKey, PropertyKeyPermission,118 PropertyScope, PropertyValue, TokenId, TrySetProperty,118 PropertyPermission, PropertyScope, PropertyValue, TokenId, TrySetProperty,375 owner: T::CrossAccountId,375 owner: T::CrossAccountId,376 data: CreateCollectionData<T::AccountId>,376 data: CreateCollectionData<T::AccountId>,377 ) -> Result<CollectionId, DispatchError> {377 ) -> Result<CollectionId, DispatchError> {378 <PalletCommon<T>>::init_collection(owner, data, false)378 <PalletCommon<T>>::init_collection(owner, data, CollectionFlags::default())379 }379 }380380381 /// Destroy RFT collection381 /// Destroy RFT collectionprimitives/data-structs/Cargo.tomldiffbeforeafterboth27struct-versioning = { path = "../../crates/struct-versioning" }27struct-versioning = { path = "../../crates/struct-versioning" }28pallet-evm = { default-features = false, git = "https://github.com/uniquenetwork/frontier", branch = "unique-polkadot-v0.9.27-fee-limit" }28pallet-evm = { default-features = false, git = "https://github.com/uniquenetwork/frontier", branch = "unique-polkadot-v0.9.27-fee-limit" }29rmrk-traits = { default-features = false, path = "../rmrk-traits" }29rmrk-traits = { default-features = false, path = "../rmrk-traits" }30bondrewd = { version = "0.1.14", features = ["derive"], default-features = false }303131[features]32[features]32default = ["std"]33default = ["std"]primitives/data-structs/src/bondrewd_codec.rsdiffbeforeafterbothno changes
primitives/data-structs/src/lib.rsdiffbeforeafterboth36use sp_core::U256;36use sp_core::U256;37use sp_runtime::{ArithmeticError, sp_std::prelude::Vec, Permill};37use sp_runtime::{ArithmeticError, sp_std::prelude::Vec, Permill};38use codec::{Decode, Encode, EncodeLike, MaxEncodedLen};38use codec::{Decode, Encode, EncodeLike, MaxEncodedLen};39use bondrewd::Bitfields;39use frame_support::{BoundedVec, traits::ConstU32};40use frame_support::{BoundedVec, traits::ConstU32};40use derivative::Derivative;41use derivative::Derivative;41use scale_info::TypeInfo;42use scale_info::TypeInfo;54 FixedPart as RmrkFixedPart, SlotPart as RmrkSlotPart,55 FixedPart as RmrkFixedPart, SlotPart as RmrkSlotPart,55};56};565758mod bondrewd_codec;57mod bounded;59mod bounded;58pub mod budget;60pub mod budget;59pub mod mapping;61pub mod mapping;357pub type CollectionDescription = BoundedVec<u16, ConstU32<MAX_COLLECTION_DESCRIPTION_LENGTH>>;359pub type CollectionDescription = BoundedVec<u16, ConstU32<MAX_COLLECTION_DESCRIPTION_LENGTH>>;358pub type CollectionTokenPrefix = BoundedVec<u8, ConstU32<MAX_TOKEN_PREFIX_LENGTH>>;360pub type CollectionTokenPrefix = BoundedVec<u8, ConstU32<MAX_TOKEN_PREFIX_LENGTH>>;361362#[derive(Bitfields, Clone, Copy, PartialEq, Eq, Debug, Default)]363#[bondrewd(enforce_bytes = 1)]364pub struct CollectionFlags {365 /// Tokens in foreign collections can be transferred, but not burnt366 #[bondrewd(bits = "0..1")]367 pub foreign: bool,368 /// External collections can't be managed using `unique` api369 #[bondrewd(bits = "7..8")]370 pub external: bool,371372 #[bondrewd(reserve, bits = "1..7")]373 pub reserved: u8,374}375bondrewd_codec!(CollectionFlags);359376360/// Base structure for represent collection.377/// Base structure for represent collection.361///378///404 #[version(2.., upper(Default::default()))]421 #[version(2.., upper(Default::default()))]405 pub permissions: CollectionPermissions,422 pub permissions: CollectionPermissions,406423407 /// Marks that this collection is not "unique", and managed from external.408 #[version(2.., upper(false))]424 #[version(2.., upper(Default::default()))]409 pub external_collection: bool,425 pub flags: CollectionFlags,410426411 #[version(..2)]427 #[version(..2)]412 pub variable_on_chain_schema: BoundedVec<u8, ConstU32<VARIABLE_ON_CHAIN_SCHEMA_LIMIT>>,428 pub variable_on_chain_schema: BoundedVec<u8, ConstU32<VARIABLE_ON_CHAIN_SCHEMA_LIMIT>>,455 /// Is collection read only.471 /// Is collection read only.456 pub read_only: bool,472 pub read_only: bool,473474 /// Is collection is foreign.475 pub foreign: bool,457}476}458477459/// Data used for create collection.478/// Data used for create collection.primitives/data-structs/src/migration.rsdiffbeforeafterboth39 test_to_option(SponsoringRateLimit::Blocks(10));39 test_to_option(SponsoringRateLimit::Blocks(10));40}40}4142#[test]43fn collection_flags_have_same_encoding_as_bool() {44 use crate::CollectionFlags;45 use codec::Encode;4647 assert_eq!(48 true.encode(),49 CollectionFlags {50 external: true,51 ..Default::default()52 }53 .encode()54 );55 assert_eq!(56 false.encode(),57 CollectionFlags {58 external: false,59 ..Default::default()60 }61 .encode()62 );63}4164