difftreelog
remove events fro unique pallete
in: master
3 files changed
pallets/unique/src/lib.rsdiffbeforeafterboth1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617//! # Unique Pallet18//!19//! A pallet governing Unique transactions.20//!21//! - [`Config`]22//! - [`Call`]23//! - [`Pallet`]24//!25//! ## Overview26//!27//! The Unique pallet's purpose is to be the primary interface between28//! external users and the inner structure of the Unique chains.29//!30//! It also contains an implementation of [`CollectionHelpers`][`eth`],31//! an Ethereum contract dealing with collection operations.32//!33//! ## Interface34//!35//! ### Dispatchables36//!37//! - `create_collection` - Create a collection of tokens. **Deprecated**, use `create_collection_ex`.38//! - `create_collection_ex` - Create a collection of tokens with explicit parameters.39//! - `destroy_collection` - Destroy a collection if no tokens exist within.40//! - `add_to_allow_list` - Add an address to allow list.41//! - `remove_from_allow_list` - Remove an address from allow list.42//! - `change_collection_owner` - Change the owner of the collection.43//! - `add_collection_admin` - Add an admin to a collection.44//! - `remove_collection_admin` - Remove admin of a collection.45//! - `set_collection_sponsor` - Invite a new collection sponsor.46//! - `confirm_sponsorship` - Confirm own sponsorship of a collection, becoming the sponsor.47//! - `remove_collection_sponsor` - Remove a sponsor from a collection.48//! - `create_item` - Create an item within a collection.49//! - `create_multiple_items` - Create multiple items within a collection.50//! - `set_collection_properties` - Add or change collection properties.51//! - `delete_collection_properties` - Delete specified collection properties.52//! - `set_token_properties` - Add or change token properties.53//! - `delete_token_properties` - Delete token properties.54//! - `set_token_property_permissions` - Add or change token property permissions of a collection.55//! - `create_multiple_items_ex` - Create multiple items within a collection with explicitly specified initial parameters.56//! - `set_transfers_enabled_flag` - Completely allow or disallow transfers for a particular collection.57//! - `burn_item` - Destroy an item.58//! - `burn_from` - Destroy an item on behalf of the owner as a non-owner account.59//! - `transfer` - Change ownership of the token.60//! - `transfer_from` - Change ownership of the token on behalf of the owner as a non-owner account.61//! - `approve` - Allow a non-permissioned address to transfer or burn an item.62//! - `set_collection_limits` - Set specific limits of a collection.63//! - `set_collection_permissions` - Set specific permissions of a collection.64//! - `repartition` - Re-partition a refungible token, while owning all of its parts.6566#![recursion_limit = "1024"]67#![cfg_attr(not(feature = "std"), no_std)]68#![allow(69 clippy::too_many_arguments,70 clippy::unnecessary_mut_passed,71 clippy::unused_unit72)]7374extern crate alloc;7576use frame_support::{77 decl_module, decl_storage, decl_error, decl_event,78 dispatch::DispatchResult,79 ensure, fail,80 weights::{Weight},81 pallet_prelude::{DispatchResultWithPostInfo, ConstU32},82 BoundedVec,83};84use scale_info::TypeInfo;85use frame_system::{self as system, ensure_signed};86use sp_std::{vec, vec::Vec};87use up_data_structs::{88 MAX_COLLECTION_NAME_LENGTH, MAX_COLLECTION_DESCRIPTION_LENGTH, MAX_TOKEN_PREFIX_LENGTH,89 MAX_PROPERTIES_PER_ITEM, MAX_PROPERTY_KEY_LENGTH, MAX_PROPERTY_VALUE_LENGTH,90 MAX_COLLECTION_PROPERTIES_SIZE, COLLECTION_ADMINS_LIMIT, MAX_TOKEN_PROPERTIES_SIZE,91 CreateItemData, CollectionLimits, CollectionPermissions, CollectionId, CollectionMode, TokenId,92 CreateCollectionData, CreateItemExData, budget, Property, PropertyKey, PropertyKeyPermission,93};94use pallet_evm::{account::CrossAccountId};95use pallet_common::{96 CollectionHandle, Pallet as PalletCommon, CommonWeightInfo, dispatch::dispatch_tx,97 dispatch::CollectionDispatch, RefungibleExtensionsWeightInfo,98};99pub mod eth;100101#[cfg(feature = "runtime-benchmarks")]102pub mod benchmarking;103pub mod weights;104use weights::WeightInfo;105106/// A maximum number of levels of depth in the token nesting tree.107pub const NESTING_BUDGET: u32 = 5;108109decl_error! {110 /// Errors for the common Unique transactions.111 pub enum Error for Module<T: Config> {112 /// Decimal_points parameter must be lower than [`up_data_structs::MAX_DECIMAL_POINTS`].113 CollectionDecimalPointLimitExceeded,114 /// Length of items properties must be greater than 0.115 EmptyArgument,116 /// Repertition is only supported by refungible collection.117 RepartitionCalledOnNonRefungibleCollection,118 }119}120121/// Configuration trait of this pallet.122pub trait Config: system::Config + pallet_common::Config + Sized + TypeInfo {123 /// Overarching event type.124 type RuntimeEvent: From<Event<Self>> + Into<<Self as frame_system::Config>::RuntimeEvent>;125126 /// Weight information for extrinsics in this pallet.127 type WeightInfo: WeightInfo;128129 /// Weight information for common pallet operations.130 type CommonWeightInfo: CommonWeightInfo<Self::CrossAccountId>;131132 /// Weight info information for extra refungible pallet operations.133 type RefungibleExtensionsWeightInfo: RefungibleExtensionsWeightInfo;134}135136decl_event! {137 pub enum Event<T>138 where139 <T as frame_system::Config>::AccountId,140 {141 /// Collection sponsor was removed142 ///143 /// # Arguments144 /// * collection_id: ID of the affected collection.145 CollectionSponsorRemoved(CollectionId),146147 /// Collection sponsor was set148 ///149 /// # Arguments150 /// * collection_id: ID of the affected collection.151 /// * owner: New sponsor address.152 CollectionSponsorSet(CollectionId, AccountId),153154 }155}156157type SelfWeightOf<T> = <T as Config>::WeightInfo;158159// # Used definitions160//161// ## User control levels162//163// chain-controlled - key is uncontrolled by user164// i.e autoincrementing index165// can use non-cryptographic hash166// real - key is controlled by user167// but it is hard to generate enough colliding values, i.e owner of signed txs168// can use non-cryptographic hash169// controlled - key is completly controlled by users170// i.e maps with mutable keys171// should use cryptographic hash172//173// ## User control level downgrade reasons174//175// ?1 - chain-controlled -> controlled176// collections/tokens can be destroyed, resulting in massive holes177// ?2 - chain-controlled -> controlled178// same as ?1, but can be only added, resulting in easier exploitation179// ?3 - real -> controlled180// no confirmation required, so addresses can be easily generated181decl_storage! {182 trait Store for Module<T: Config> as Unique {183184 //#region Private members185 /// Used for migrations186 ChainVersion: u64;187 //#endregion188189 //#region Tokens transfer sponosoring rate limit baskets190 /// (Collection id (controlled?2), who created (real))191 /// TODO: Off chain worker should remove from this map when collection gets removed192 pub CreateItemBasket get(fn create_item_basket): map hasher(blake2_128_concat) (CollectionId, T::AccountId) => Option<T::BlockNumber>;193 /// Collection id (controlled?2), token id (controlled?2)194 pub NftTransferBasket get(fn nft_transfer_basket): double_map hasher(blake2_128_concat) CollectionId, hasher(blake2_128_concat) TokenId => Option<T::BlockNumber>;195 /// Collection id (controlled?2), owning user (real)196 pub FungibleTransferBasket get(fn fungible_transfer_basket): double_map hasher(blake2_128_concat) CollectionId, hasher(twox_64_concat) T::AccountId => Option<T::BlockNumber>;197 /// Collection id (controlled?2), token id (controlled?2)198 pub ReFungibleTransferBasket get(fn refungible_transfer_basket): nmap hasher(blake2_128_concat) CollectionId, hasher(blake2_128_concat) TokenId, hasher(twox_64_concat) T::AccountId => Option<T::BlockNumber>;199 //#endregion200201 /// Variable metadata sponsoring202 /// Collection id (controlled?2), token id (controlled?2)203 #[deprecated]204 pub VariableMetaDataBasket get(fn variable_meta_data_basket): double_map hasher(blake2_128_concat) CollectionId, hasher(blake2_128_concat) TokenId => Option<T::BlockNumber>;205 /// Last sponsoring of token property setting // todo:doc rephrase this and the following206 pub TokenPropertyBasket get(fn token_property_basket): double_map hasher(blake2_128_concat) CollectionId, hasher(blake2_128_concat) TokenId => Option<T::BlockNumber>;207208 /// Last sponsoring of NFT approval in a collection209 pub NftApproveBasket get(fn nft_approve_basket): double_map hasher(blake2_128_concat) CollectionId, hasher(blake2_128_concat) TokenId => Option<T::BlockNumber>;210 /// Last sponsoring of fungible tokens approval in a collection211 pub FungibleApproveBasket get(fn fungible_approve_basket): double_map hasher(blake2_128_concat) CollectionId, hasher(twox_64_concat) T::AccountId => Option<T::BlockNumber>;212 /// Last sponsoring of RFT approval in a collection213 pub RefungibleApproveBasket get(fn refungible_approve_basket): nmap hasher(blake2_128_concat) CollectionId, hasher(blake2_128_concat) TokenId, hasher(twox_64_concat) T::AccountId => Option<T::BlockNumber>;214 }215}216217decl_module! {218 /// Type alias to Pallet, to be used by construct_runtime.219 pub struct Module<T: Config> for enum Call220 where221 origin: T::RuntimeOrigin222 {223 type Error = Error<T>;224225 #[doc = "A maximum number of levels of depth in the token nesting tree."]226 const NESTING_BUDGET: u32 = NESTING_BUDGET;227228 #[doc = "Maximal length of a collection name."]229 const MAX_COLLECTION_NAME_LENGTH: u32 = MAX_COLLECTION_NAME_LENGTH;230231 #[doc = "Maximal length of a collection description."]232 const MAX_COLLECTION_DESCRIPTION_LENGTH: u32 = MAX_COLLECTION_DESCRIPTION_LENGTH;233234 #[doc = "Maximal length of a token prefix."]235 const MAX_TOKEN_PREFIX_LENGTH: u32 = MAX_TOKEN_PREFIX_LENGTH;236237 #[doc = "Maximum admins per collection."]238 const COLLECTION_ADMINS_LIMIT: u32 = COLLECTION_ADMINS_LIMIT;239240 #[doc = "Maximal length of a property key."]241 const MAX_PROPERTY_KEY_LENGTH: u32 = MAX_PROPERTY_KEY_LENGTH;242243 #[doc = "Maximal length of a property value."]244 const MAX_PROPERTY_VALUE_LENGTH: u32 = MAX_PROPERTY_VALUE_LENGTH;245246 #[doc = "A maximum number of token properties."]247 const MAX_PROPERTIES_PER_ITEM: u32 = MAX_PROPERTIES_PER_ITEM;248249 #[doc = "Maximum size for all collection properties."]250 const MAX_COLLECTION_PROPERTIES_SIZE: u32 = MAX_COLLECTION_PROPERTIES_SIZE;251252 #[doc = "Maximum size of all token properties."]253 const MAX_TOKEN_PROPERTIES_SIZE: u32 = MAX_TOKEN_PROPERTIES_SIZE;254255 #[doc = "Default NFT collection limit."]256 const NFT_DEFAULT_COLLECTION_LIMITS: CollectionLimits = CollectionLimits::with_default_limits(CollectionMode::NFT);257258 #[doc = "Default RFT collection limit."]259 const RFT_DEFAULT_COLLECTION_LIMITS: CollectionLimits = CollectionLimits::with_default_limits(CollectionMode::ReFungible);260261 #[doc = "Default FT collection limit."]262 const FT_DEFAULT_COLLECTION_LIMITS: CollectionLimits = CollectionLimits::with_default_limits(CollectionMode::Fungible(0));263264265 pub fn deposit_event() = default;266267 fn on_initialize(_now: T::BlockNumber) -> Weight {268 Weight::zero()269 }270271 fn on_runtime_upgrade() -> Weight {272 Weight::zero()273 }274275 /// Create a collection of tokens.276 ///277 /// Each Token may have multiple properties encoded as an array of bytes278 /// of certain length. The initial owner of the collection is set279 /// to the address that signed the transaction and can be changed later.280 ///281 /// Prefer the more advanced [`create_collection_ex`][`Pallet::create_collection_ex`] instead.282 ///283 /// # Permissions284 ///285 /// * Anyone - becomes the owner of the new collection.286 ///287 /// # Arguments288 ///289 /// * `collection_name`: Wide-character string with collection name290 /// (limit [`MAX_COLLECTION_NAME_LENGTH`]).291 /// * `collection_description`: Wide-character string with collection description292 /// (limit [`MAX_COLLECTION_DESCRIPTION_LENGTH`]).293 /// * `token_prefix`: Byte string containing the token prefix to mark a collection294 /// to which a token belongs (limit [`MAX_TOKEN_PREFIX_LENGTH`]).295 /// * `mode`: Type of items stored in the collection and type dependent data.296 // returns collection ID297 #[weight = <SelfWeightOf<T>>::create_collection()]298 #[deprecated(note = "`create_collection_ex` is more up-to-date and advanced, prefer it instead")]299 pub fn create_collection(300 origin,301 collection_name: BoundedVec<u16, ConstU32<MAX_COLLECTION_NAME_LENGTH>>,302 collection_description: BoundedVec<u16, ConstU32<MAX_COLLECTION_DESCRIPTION_LENGTH>>,303 token_prefix: BoundedVec<u8, ConstU32<MAX_TOKEN_PREFIX_LENGTH>>,304 mode: CollectionMode305 ) -> DispatchResult {306 let data: CreateCollectionData<T::AccountId> = CreateCollectionData {307 name: collection_name,308 description: collection_description,309 token_prefix,310 mode,311 ..Default::default()312 };313 Self::create_collection_ex(origin, data)314 }315316 /// Create a collection with explicit parameters.317 ///318 /// Prefer it to the deprecated [`create_collection`][`Pallet::create_collection`] method.319 ///320 /// # Permissions321 ///322 /// * Anyone - becomes the owner of the new collection.323 ///324 /// # Arguments325 ///326 /// * `data`: Explicit data of a collection used for its creation.327 #[weight = <SelfWeightOf<T>>::create_collection()]328 pub fn create_collection_ex(origin, data: CreateCollectionData<T::AccountId>) -> DispatchResult {329 let sender = ensure_signed(origin)?;330331 // =========332 let sender = T::CrossAccountId::from_sub(sender);333 let _id = T::CollectionDispatch::create(sender.clone(), sender, data, Default::default())?;334335 Ok(())336 }337338 /// Destroy a collection if no tokens exist within.339 ///340 /// # Permissions341 ///342 /// * Collection owner343 ///344 /// # Arguments345 ///346 /// * `collection_id`: Collection to destroy.347 #[weight = <SelfWeightOf<T>>::destroy_collection()]348 pub fn destroy_collection(origin, collection_id: CollectionId) -> DispatchResult {349 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);350351 Self::destroy_collection_internal(sender, collection_id)352 }353354 /// Add an address to allow list.355 ///356 /// # Permissions357 ///358 /// * Collection owner359 /// * Collection admin360 ///361 /// # Arguments362 ///363 /// * `collection_id`: ID of the modified collection.364 /// * `address`: ID of the address to be added to the allowlist.365 #[weight = <SelfWeightOf<T>>::add_to_allow_list()]366 pub fn add_to_allow_list(origin, collection_id: CollectionId, address: T::CrossAccountId) -> DispatchResult{367368 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);369 let collection = <CollectionHandle<T>>::try_get(collection_id)?;370 collection.check_is_internal()?;371372 <PalletCommon<T>>::toggle_allowlist(373 &collection,374 &sender,375 &address,376 true,377 )?;378379 Ok(())380 }381382 /// Remove an address from allow list.383 ///384 /// # Permissions385 ///386 /// * Collection owner387 /// * Collection admin388 ///389 /// # Arguments390 ///391 /// * `collection_id`: ID of the modified collection.392 /// * `address`: ID of the address to be removed from the allowlist.393 #[weight = <SelfWeightOf<T>>::remove_from_allow_list()]394 pub fn remove_from_allow_list(origin, collection_id: CollectionId, address: T::CrossAccountId) -> DispatchResult{395396 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);397 let collection = <CollectionHandle<T>>::try_get(collection_id)?;398 collection.check_is_internal()?;399400 <PalletCommon<T>>::toggle_allowlist(401 &collection,402 &sender,403 &address,404 false,405 )?;406407 Ok(())408 }409410 /// Change the owner of the collection.411 ///412 /// # Permissions413 ///414 /// * Collection owner415 ///416 /// # Arguments417 ///418 /// * `collection_id`: ID of the modified collection.419 /// * `new_owner`: ID of the account that will become the owner.420 #[weight = <SelfWeightOf<T>>::change_collection_owner()]421 pub fn change_collection_owner(origin, collection_id: CollectionId, new_owner: T::AccountId) -> DispatchResult {422 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);423 let new_owner = T::CrossAccountId::from_sub(new_owner);424 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;425 target_collection.change_owner(sender, new_owner.clone())426 }427428 /// Add an admin to a collection.429 ///430 /// NFT Collection can be controlled by multiple admin addresses431 /// (some which can also be servers, for example). Admins can issue432 /// and burn NFTs, as well as add and remove other admins,433 /// but cannot change NFT or Collection ownership.434 ///435 /// # Permissions436 ///437 /// * Collection owner438 /// * Collection admin439 ///440 /// # Arguments441 ///442 /// * `collection_id`: ID of the Collection to add an admin for.443 /// * `new_admin`: Address of new admin to add.444 #[weight = <SelfWeightOf<T>>::add_collection_admin()]445 pub fn add_collection_admin(origin, collection_id: CollectionId, new_admin_id: T::CrossAccountId) -> DispatchResult {446 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);447 let collection = <CollectionHandle<T>>::try_get(collection_id)?;448 <PalletCommon<T>>::toggle_admin(&collection, &sender, &new_admin_id, true)449 }450451 /// Remove admin of a collection.452 ///453 /// An admin address can remove itself. List of admins may become empty,454 /// in which case only Collection Owner will be able to add an Admin.455 ///456 /// # Permissions457 ///458 /// * Collection owner459 /// * Collection admin460 ///461 /// # Arguments462 ///463 /// * `collection_id`: ID of the collection to remove the admin for.464 /// * `account_id`: Address of the admin to remove.465 #[weight = <SelfWeightOf<T>>::remove_collection_admin()]466 pub fn remove_collection_admin(origin, collection_id: CollectionId, account_id: T::CrossAccountId) -> DispatchResult {467 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);468 let collection = <CollectionHandle<T>>::try_get(collection_id)?;469 <PalletCommon<T>>::toggle_admin(&collection, &sender, &account_id, false)470 }471472 /// Set (invite) a new collection sponsor.473 ///474 /// If successful, confirmation from the sponsor-to-be will be pending.475 ///476 /// # Permissions477 ///478 /// * Collection owner479 /// * Collection admin480 ///481 /// # Arguments482 ///483 /// * `collection_id`: ID of the modified collection.484 /// * `new_sponsor`: ID of the account of the sponsor-to-be.485 #[weight = <SelfWeightOf<T>>::set_collection_sponsor()]486 pub fn set_collection_sponsor(origin, collection_id: CollectionId, new_sponsor: T::AccountId) -> DispatchResult {487 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);488 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;489 target_collection.set_sponsor(&sender, new_sponsor.clone())490 }491492 /// Confirm own sponsorship of a collection, becoming the sponsor.493 ///494 /// An invitation must be pending, see [`set_collection_sponsor`][`Pallet::set_collection_sponsor`].495 /// Sponsor can pay the fees of a transaction instead of the sender,496 /// but only within specified limits.497 ///498 /// # Permissions499 ///500 /// * Sponsor-to-be501 ///502 /// # Arguments503 ///504 /// * `collection_id`: ID of the collection with the pending sponsor.505 #[weight = <SelfWeightOf<T>>::confirm_sponsorship()]506 pub fn confirm_sponsorship(origin, collection_id: CollectionId) -> DispatchResult {507 let sender = ensure_signed(origin)?;508 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;509 target_collection.confirm_sponsorship(&sender)510 }511512 /// Remove a collection's a sponsor, making everyone pay for their own transactions.513 ///514 /// # Permissions515 ///516 /// * Collection owner517 ///518 /// # Arguments519 ///520 /// * `collection_id`: ID of the collection with the sponsor to remove.521 #[weight = <SelfWeightOf<T>>::remove_collection_sponsor()]522 pub fn remove_collection_sponsor(origin, collection_id: CollectionId) -> DispatchResult {523 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);524 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;525 target_collection.remove_sponsor(&sender)526 }527528 /// Mint an item within a collection.529 ///530 /// A collection must exist first, see [`create_collection_ex`][`Pallet::create_collection_ex`].531 ///532 /// # Permissions533 ///534 /// * Collection owner535 /// * Collection admin536 /// * Anyone if537 /// * Allow List is enabled, and538 /// * Address is added to allow list, and539 /// * MintPermission is enabled (see [`set_collection_permissions`][`Pallet::set_collection_permissions`])540 ///541 /// # Arguments542 ///543 /// * `collection_id`: ID of the collection to which an item would belong.544 /// * `owner`: Address of the initial owner of the item.545 /// * `data`: Token data describing the item to store on chain.546 #[weight = T::CommonWeightInfo::create_item()]547 pub fn create_item(origin, collection_id: CollectionId, owner: T::CrossAccountId, data: CreateItemData) -> DispatchResultWithPostInfo {548 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);549 let budget = budget::Value::new(NESTING_BUDGET);550551 dispatch_tx::<T, _>(collection_id, |d| d.create_item(sender, owner, data, &budget))552 }553554 /// Create multiple items within a collection.555 ///556 /// A collection must exist first, see [`create_collection_ex`][`Pallet::create_collection_ex`].557 ///558 /// # Permissions559 ///560 /// * Collection owner561 /// * Collection admin562 /// * Anyone if563 /// * Allow List is enabled, and564 /// * Address is added to the allow list, and565 /// * MintPermission is enabled (see [`set_collection_permissions`][`Pallet::set_collection_permissions`])566 ///567 /// # Arguments568 ///569 /// * `collection_id`: ID of the collection to which the tokens would belong.570 /// * `owner`: Address of the initial owner of the tokens.571 /// * `items_data`: Vector of data describing each item to be created.572 #[weight = T::CommonWeightInfo::create_multiple_items(&items_data)]573 pub fn create_multiple_items(origin, collection_id: CollectionId, owner: T::CrossAccountId, items_data: Vec<CreateItemData>) -> DispatchResultWithPostInfo {574 ensure!(!items_data.is_empty(), Error::<T>::EmptyArgument);575 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);576 let budget = budget::Value::new(NESTING_BUDGET);577578 dispatch_tx::<T, _>(collection_id, |d| d.create_multiple_items(sender, owner, items_data, &budget))579 }580581 /// Add or change collection properties.582 ///583 /// # Permissions584 ///585 /// * Collection owner586 /// * Collection admin587 ///588 /// # Arguments589 ///590 /// * `collection_id`: ID of the modified collection.591 /// * `properties`: Vector of key-value pairs stored as the collection's metadata.592 /// Keys support Latin letters, `-`, `_`, and `.` as symbols.593 #[weight = T::CommonWeightInfo::set_collection_properties(properties.len() as u32)]594 pub fn set_collection_properties(595 origin,596 collection_id: CollectionId,597 properties: Vec<Property>598 ) -> DispatchResultWithPostInfo {599 ensure!(!properties.is_empty(), Error::<T>::EmptyArgument);600601 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);602603 dispatch_tx::<T, _>(collection_id, |d| d.set_collection_properties(sender, properties))604 }605606 /// Delete specified collection properties.607 ///608 /// # Permissions609 ///610 /// * Collection Owner611 /// * Collection Admin612 ///613 /// # Arguments614 ///615 /// * `collection_id`: ID of the modified collection.616 /// * `property_keys`: Vector of keys of the properties to be deleted.617 /// Keys support Latin letters, `-`, `_`, and `.` as symbols.618 #[weight = T::CommonWeightInfo::delete_collection_properties(property_keys.len() as u32)]619 pub fn delete_collection_properties(620 origin,621 collection_id: CollectionId,622 property_keys: Vec<PropertyKey>,623 ) -> DispatchResultWithPostInfo {624 ensure!(!property_keys.is_empty(), Error::<T>::EmptyArgument);625626 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);627628 dispatch_tx::<T, _>(collection_id, |d| d.delete_collection_properties(&sender, property_keys))629 }630631 /// Add or change token properties according to collection's permissions.632 /// Currently properties only work with NFTs.633 ///634 /// # Permissions635 ///636 /// * Depends on collection's token property permissions and specified property mutability:637 /// * Collection owner638 /// * Collection admin639 /// * Token owner640 ///641 /// See [`set_token_property_permissions`][`Pallet::set_token_property_permissions`].642 ///643 /// # Arguments644 ///645 /// * `collection_id: ID of the collection to which the token belongs.646 /// * `token_id`: ID of the modified token.647 /// * `properties`: Vector of key-value pairs stored as the token's metadata.648 /// Keys support Latin letters, `-`, `_`, and `.` as symbols.649 #[weight = T::CommonWeightInfo::set_token_properties(properties.len() as u32)]650 pub fn set_token_properties(651 origin,652 collection_id: CollectionId,653 token_id: TokenId,654 properties: Vec<Property>655 ) -> DispatchResultWithPostInfo {656 ensure!(!properties.is_empty(), Error::<T>::EmptyArgument);657658 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);659 let budget = budget::Value::new(NESTING_BUDGET);660661 dispatch_tx::<T, _>(collection_id, |d| d.set_token_properties(sender, token_id, properties, &budget))662 }663664 /// Delete specified token properties. Currently properties only work with NFTs.665 ///666 /// # Permissions667 ///668 /// * Depends on collection's token property permissions and specified property mutability:669 /// * Collection owner670 /// * Collection admin671 /// * Token owner672 ///673 /// # Arguments674 ///675 /// * `collection_id`: ID of the collection to which the token belongs.676 /// * `token_id`: ID of the modified token.677 /// * `property_keys`: Vector of keys of the properties to be deleted.678 /// Keys support Latin letters, `-`, `_`, and `.` as symbols.679 #[weight = T::CommonWeightInfo::delete_token_properties(property_keys.len() as u32)]680 pub fn delete_token_properties(681 origin,682 collection_id: CollectionId,683 token_id: TokenId,684 property_keys: Vec<PropertyKey>685 ) -> DispatchResultWithPostInfo {686 ensure!(!property_keys.is_empty(), Error::<T>::EmptyArgument);687688 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);689 let budget = budget::Value::new(NESTING_BUDGET);690691 dispatch_tx::<T, _>(collection_id, |d| d.delete_token_properties(sender, token_id, property_keys, &budget))692 }693694 /// Add or change token property permissions of a collection.695 ///696 /// Without a permission for a particular key, a property with that key697 /// cannot be created in a token.698 ///699 /// # Permissions700 ///701 /// * Collection owner702 /// * Collection admin703 ///704 /// # Arguments705 ///706 /// * `collection_id`: ID of the modified collection.707 /// * `property_permissions`: Vector of permissions for property keys.708 /// Keys support Latin letters, `-`, `_`, and `.` as symbols.709 #[weight = T::CommonWeightInfo::set_token_property_permissions(property_permissions.len() as u32)]710 pub fn set_token_property_permissions(711 origin,712 collection_id: CollectionId,713 property_permissions: Vec<PropertyKeyPermission>,714 ) -> DispatchResultWithPostInfo {715 ensure!(!property_permissions.is_empty(), Error::<T>::EmptyArgument);716717 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);718719 dispatch_tx::<T, _>(collection_id, |d| d.set_token_property_permissions(&sender, property_permissions))720 }721722 /// Create multiple items within a collection with explicitly specified initial parameters.723 ///724 /// # Permissions725 ///726 /// * Collection owner727 /// * Collection admin728 /// * Anyone if729 /// * Allow List is enabled, and730 /// * Address is added to allow list, and731 /// * MintPermission is enabled (see [`set_collection_permissions`][`Pallet::set_collection_permissions`])732 ///733 /// # Arguments734 ///735 /// * `collection_id`: ID of the collection to which the tokens would belong.736 /// * `data`: Explicit item creation data.737 #[weight = T::CommonWeightInfo::create_multiple_items_ex(&data)]738 pub fn create_multiple_items_ex(origin, collection_id: CollectionId, data: CreateItemExData<T::CrossAccountId>) -> DispatchResultWithPostInfo {739 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);740 let budget = budget::Value::new(NESTING_BUDGET);741742 dispatch_tx::<T, _>(collection_id, |d| d.create_multiple_items_ex(sender, data, &budget))743 }744745 /// Completely allow or disallow transfers for a particular collection.746 ///747 /// # Permissions748 ///749 /// * Collection owner750 ///751 /// # Arguments752 ///753 /// * `collection_id`: ID of the collection.754 /// * `value`: New value of the flag, are transfers allowed?755 #[weight = <SelfWeightOf<T>>::set_transfers_enabled_flag()]756 pub fn set_transfers_enabled_flag(origin, collection_id: CollectionId, value: bool) -> DispatchResult {757 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);758 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;759 target_collection.check_is_internal()?;760 target_collection.check_is_owner(&sender)?;761762 // =========763764 target_collection.limits.transfers_enabled = Some(value);765 target_collection.save()766 }767768 /// Destroy an item.769 ///770 /// # Permissions771 ///772 /// * Collection owner773 /// * Collection admin774 /// * Current item owner775 ///776 /// # Arguments777 ///778 /// * `collection_id`: ID of the collection to which the item belongs.779 /// * `item_id`: ID of item to burn.780 /// * `value`: Number of pieces of the item to destroy.781 /// * Non-Fungible Mode: An NFT is indivisible, there is always 1 corresponding to an ID.782 /// * Fungible Mode: The desired number of pieces to burn.783 /// * Re-Fungible Mode: The desired number of pieces to burn.784 #[weight = T::CommonWeightInfo::burn_item()]785 pub fn burn_item(origin, collection_id: CollectionId, item_id: TokenId, value: u128) -> DispatchResultWithPostInfo {786 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);787788 let post_info = dispatch_tx::<T, _>(collection_id, |d| d.burn_item(sender, item_id, value))?;789 if value == 1 {790 <NftTransferBasket<T>>::remove(collection_id, item_id);791 <NftApproveBasket<T>>::remove(collection_id, item_id);792 }793 // Those maps should be cleared only if token disappears completly, need to move this part of logic to pallets?794 // <FungibleApproveBasket<T>>::remove(collection_id, sender.as_sub());795 // <RefungibleApproveBasket<T>>::remove((collection_id, item_id, sender.as_sub()));796 Ok(post_info)797 }798799 /// Destroy a token on behalf of the owner as a non-owner account.800 ///801 /// See also: [`approve`][`Pallet::approve`].802 ///803 /// After this method executes, one approval is removed from the total so that804 /// the approved address will not be able to transfer this item again from this owner.805 ///806 /// # Permissions807 ///808 /// * Collection owner809 /// * Collection admin810 /// * Current token owner811 /// * Address approved by current item owner812 ///813 /// # Arguments814 ///815 /// * `from`: The owner of the burning item.816 /// * `collection_id`: ID of the collection to which the item belongs.817 /// * `item_id`: ID of item to burn.818 /// * `value`: Number of pieces to burn.819 /// * Non-Fungible Mode: An NFT is indivisible, there is always 1 corresponding to an ID.820 /// * Fungible Mode: The desired number of pieces to burn.821 /// * Re-Fungible Mode: The desired number of pieces to burn.822 #[weight = T::CommonWeightInfo::burn_from()]823 pub fn burn_from(origin, collection_id: CollectionId, from: T::CrossAccountId, item_id: TokenId, value: u128) -> DispatchResultWithPostInfo {824 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);825 let budget = budget::Value::new(NESTING_BUDGET);826827 dispatch_tx::<T, _>(collection_id, |d| d.burn_from(sender, from, item_id, value, &budget))828 }829830 /// Change ownership of the token.831 ///832 /// # Permissions833 ///834 /// * Collection owner835 /// * Collection admin836 /// * Current token owner837 ///838 /// # Arguments839 ///840 /// * `recipient`: Address of token recipient.841 /// * `collection_id`: ID of the collection the item belongs to.842 /// * `item_id`: ID of the item.843 /// * Non-Fungible Mode: Required.844 /// * Fungible Mode: Ignored.845 /// * Re-Fungible Mode: Required.846 ///847 /// * `value`: Amount to transfer.848 /// * Non-Fungible Mode: An NFT is indivisible, there is always 1 corresponding to an ID.849 /// * Fungible Mode: The desired number of pieces to transfer.850 /// * Re-Fungible Mode: The desired number of pieces to transfer.851 #[weight = T::CommonWeightInfo::transfer()]852 pub fn transfer(origin, recipient: T::CrossAccountId, collection_id: CollectionId, item_id: TokenId, value: u128) -> DispatchResultWithPostInfo {853 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);854 let budget = budget::Value::new(NESTING_BUDGET);855856 dispatch_tx::<T, _>(collection_id, |d| d.transfer(sender, recipient, item_id, value, &budget))857 }858859 /// Allow a non-permissioned address to transfer or burn an item.860 ///861 /// # Permissions862 ///863 /// * Collection owner864 /// * Collection admin865 /// * Current item owner866 ///867 /// # Arguments868 ///869 /// * `spender`: Account to be approved to make specific transactions on non-owned tokens.870 /// * `collection_id`: ID of the collection the item belongs to.871 /// * `item_id`: ID of the item transactions on which are now approved.872 /// * `amount`: Number of pieces of the item approved for a transaction (maximum of 1 for NFTs).873 /// Set to 0 to revoke the approval.874 #[weight = T::CommonWeightInfo::approve()]875 pub fn approve(origin, spender: T::CrossAccountId, collection_id: CollectionId, item_id: TokenId, amount: u128) -> DispatchResultWithPostInfo {876 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);877878 dispatch_tx::<T, _>(collection_id, |d| d.approve(sender, spender, item_id, amount))879 }880881 /// Change ownership of an item on behalf of the owner as a non-owner account.882 ///883 /// See the [`approve`][`Pallet::approve`] method for additional information.884 ///885 /// After this method executes, one approval is removed from the total so that886 /// the approved address will not be able to transfer this item again from this owner.887 ///888 /// # Permissions889 ///890 /// * Collection owner891 /// * Collection admin892 /// * Current item owner893 /// * Address approved by current item owner894 ///895 /// # Arguments896 ///897 /// * `from`: Address that currently owns the token.898 /// * `recipient`: Address of the new token-owner-to-be.899 /// * `collection_id`: ID of the collection the item.900 /// * `item_id`: ID of the item to be transferred.901 /// * `value`: Amount to transfer.902 /// * Non-Fungible Mode: An NFT is indivisible, there is always 1 corresponding to an ID.903 /// * Fungible Mode: The desired number of pieces to transfer.904 /// * Re-Fungible Mode: The desired number of pieces to transfer.905 #[weight = T::CommonWeightInfo::transfer_from()]906 pub fn transfer_from(origin, from: T::CrossAccountId, recipient: T::CrossAccountId, collection_id: CollectionId, item_id: TokenId, value: u128 ) -> DispatchResultWithPostInfo {907 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);908 let budget = budget::Value::new(NESTING_BUDGET);909910 dispatch_tx::<T, _>(collection_id, |d| d.transfer_from(sender, from, recipient, item_id, value, &budget))911 }912913 /// Set specific limits of a collection. Empty, or None fields mean chain default.914 ///915 /// # Permissions916 ///917 /// * Collection owner918 /// * Collection admin919 ///920 /// # Arguments921 ///922 /// * `collection_id`: ID of the modified collection.923 /// * `new_limit`: New limits of the collection. Fields that are not set (None)924 /// will not overwrite the old ones.925 #[weight = <SelfWeightOf<T>>::set_collection_limits()]926 pub fn set_collection_limits(927 origin,928 collection_id: CollectionId,929 new_limit: CollectionLimits,930 ) -> DispatchResult {931 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);932 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;933 <PalletCommon<T>>::update_limits(&sender, &mut target_collection, new_limit)934 }935936 /// Set specific permissions of a collection. Empty, or None fields mean chain default.937 ///938 /// # Permissions939 ///940 /// * Collection owner941 /// * Collection admin942 ///943 /// # Arguments944 ///945 /// * `collection_id`: ID of the modified collection.946 /// * `new_permission`: New permissions of the collection. Fields that are not set (None)947 /// will not overwrite the old ones.948 #[weight = <SelfWeightOf<T>>::set_collection_limits()]949 pub fn set_collection_permissions(950 origin,951 collection_id: CollectionId,952 new_permission: CollectionPermissions,953 ) -> DispatchResult {954 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);955 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;956 <PalletCommon<T>>::update_permissions(957 &sender,958 &mut target_collection,959 new_permission960 )961 }962963 /// Re-partition a refungible token, while owning all of its parts/pieces.964 ///965 /// # Permissions966 ///967 /// * Token owner (must own every part)968 ///969 /// # Arguments970 ///971 /// * `collection_id`: ID of the collection the RFT belongs to.972 /// * `token_id`: ID of the RFT.973 /// * `amount`: New number of parts/pieces into which the token shall be partitioned.974 #[weight = T::RefungibleExtensionsWeightInfo::repartition()]975 pub fn repartition(976 origin,977 collection_id: CollectionId,978 token_id: TokenId,979 amount: u128,980 ) -> DispatchResultWithPostInfo {981 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);982 dispatch_tx::<T, _>(collection_id, |d| {983 if let Some(refungible_extensions) = d.refungible_extensions() {984 refungible_extensions.repartition(&sender, token_id, amount)985 } else {986 fail!(<Error<T>>::RepartitionCalledOnNonRefungibleCollection)987 }988 })989 }990991 /// Sets or unsets the approval of a given operator.992 ///993 /// The `operator` is allowed to transfer all tokens of the `owner` on their behalf.994 ///995 /// # Arguments996 ///997 /// * `owner`: Token owner998 /// * `operator`: Operator999 /// * `approve`: Should operator status be granted or revoked?1000 #[weight = T::CommonWeightInfo::set_allowance_for_all()]1001 pub fn set_allowance_for_all(1002 origin,1003 collection_id: CollectionId,1004 operator: T::CrossAccountId,1005 approve: bool,1006 ) -> DispatchResultWithPostInfo {1007 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);1008 dispatch_tx::<T, _>(collection_id, |d| {1009 d.set_allowance_for_all(sender, operator, approve)1010 })1011 }1012 }1013}10141015impl<T: Config> Pallet<T> {1016 /// Force set `sponsor` for `collection`.1017 ///1018 /// Differs from [`set_collection_sponsor`][`Pallet::set_collection_sponsor`] in that confirmation1019 /// from the `sponsor` is not required.1020 ///1021 /// # Arguments1022 ///1023 /// * `sponsor`: ID of the account of the sponsor-to-be.1024 /// * `collection_id`: ID of the modified collection.1025 pub fn force_set_sponsor(sponsor: T::AccountId, collection_id: CollectionId) -> DispatchResult {1026 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;1027 target_collection.force_set_sponsor(sponsor.clone())1028 }10291030 /// Force remove `sponsor` for `collection`.1031 ///1032 /// Differs from `remove_sponsor` in that1033 /// it doesn't require consent from the `owner` of the collection.1034 ///1035 /// # Arguments1036 ///1037 /// * `collection_id`: ID of the modified collection.1038 pub fn force_remove_collection_sponsor(collection_id: CollectionId) -> DispatchResult {1039 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;1040 target_collection.force_remove_sponsor()1041 }10421043 #[inline(always)]1044 pub(crate) fn destroy_collection_internal(1045 sender: T::CrossAccountId,1046 collection_id: CollectionId,1047 ) -> DispatchResult {1048 let collection = <CollectionHandle<T>>::try_get(collection_id)?;1049 collection.check_is_internal()?;10501051 T::CollectionDispatch::destroy(sender, collection)?;10521053 // TODO: basket cleanup should be moved elsewhere1054 // Maybe runtime dispatch.rs should perform it?10551056 let _ = <NftTransferBasket<T>>::clear_prefix(collection_id, u32::MAX, None);1057 let _ = <FungibleTransferBasket<T>>::clear_prefix(collection_id, u32::MAX, None);1058 let _ = <ReFungibleTransferBasket<T>>::clear_prefix((collection_id,), u32::MAX, None);10591060 let _ = <NftApproveBasket<T>>::clear_prefix(collection_id, u32::MAX, None);1061 let _ = <FungibleApproveBasket<T>>::clear_prefix(collection_id, u32::MAX, None);1062 let _ = <RefungibleApproveBasket<T>>::clear_prefix((collection_id,), u32::MAX, None);10631064 Ok(())1065 }1066}runtime/common/config/pallets/mod.rsdiffbeforeafterboth--- a/runtime/common/config/pallets/mod.rs
+++ b/runtime/common/config/pallets/mod.rs
@@ -93,7 +93,6 @@
}
impl pallet_unique::Config for Runtime {
- type RuntimeEvent = RuntimeEvent;
type WeightInfo = pallet_unique::weights::SubstrateWeight<Self>;
type CommonWeightInfo = CommonWeights<Self>;
type RefungibleExtensionsWeightInfo = CommonWeights<Self>;
runtime/common/construct_runtime/mod.rsdiffbeforeafterboth--- a/runtime/common/construct_runtime/mod.rs
+++ b/runtime/common/construct_runtime/mod.rs
@@ -55,7 +55,7 @@
// Unique Pallets
Inflation: pallet_inflation::{Pallet, Call, Storage} = 60,
- Unique: pallet_unique::{Pallet, Call, Storage, Event<T>} = 61,
+ Unique: pallet_unique::{Pallet, Call, Storage} = 61,
#[runtimes(opal)]
Scheduler: pallet_unique_scheduler_v2::{Pallet, Call, Storage, Event<T>} = 62,