diff --git a/substrate/bin/node/runtime/src/lib.rs b/substrate/bin/node/runtime/src/lib.rs index 019c14b2c7..1257aabb9d 100644 --- a/substrate/bin/node/runtime/src/lib.rs +++ b/substrate/bin/node/runtime/src/lib.rs @@ -1414,12 +1414,12 @@ parameter_types! { impl pallet_uniques::Config for Runtime { type Event = Event; - type ClassId = u32; - type InstanceId = u32; + type CollectionId = u32; + type ItemId = u32; type Currency = Balances; type ForceOrigin = frame_system::EnsureRoot; - type ClassDeposit = ClassDeposit; - type InstanceDeposit = InstanceDeposit; + type CollectionDeposit = ClassDeposit; + type ItemDeposit = InstanceDeposit; type MetadataDepositBase = MetadataDepositBase; type AttributeDepositBase = MetadataDepositBase; type DepositPerByte = MetadataDepositPerByte; diff --git a/substrate/frame/support/src/traits/tokens/misc.rs b/substrate/frame/support/src/traits/tokens/misc.rs index dd87fe36cd..fbbef6c318 100644 --- a/substrate/frame/support/src/traits/tokens/misc.rs +++ b/substrate/frame/support/src/traits/tokens/misc.rs @@ -182,16 +182,16 @@ pub trait BalanceConversion { /// Trait to handle asset locking mechanism to ensure interactions with the asset can be implemented /// downstream to extend logic of Uniques current functionality. -pub trait Locker { +pub trait Locker { /// Check if the asset should be locked and prevent interactions with the asset from executing. - fn is_locked(class: ClassId, instance: InstanceId) -> bool; + fn is_locked(collection: CollectionId, item: ItemId) -> bool; } -impl Locker for () { +impl Locker for () { // Default will be false if not implemented downstream. // Note: The logic check in this function must be constant time and consistent for benchmarks // to work. - fn is_locked(_class: ClassId, _instance: InstanceId) -> bool { + fn is_locked(_collection: CollectionId, _item: ItemId) -> bool { false } } diff --git a/substrate/frame/support/src/traits/tokens/nonfungible.rs b/substrate/frame/support/src/traits/tokens/nonfungible.rs index 5cf9638131..fe0d2e7299 100644 --- a/substrate/frame/support/src/traits/tokens/nonfungible.rs +++ b/substrate/frame/support/src/traits/tokens/nonfungible.rs @@ -15,9 +15,9 @@ // See the License for the specific language governing permissions and // limitations under the License. -//! Traits for dealing with a single non-fungible asset class. +//! Traits for dealing with a single non-fungible collection of items. //! -//! This assumes a single level namespace identified by `Inspect::InstanceId`, and could +//! This assumes a single level namespace identified by `Inspect::ItemId`, and could //! reasonably be implemented by pallets which wants to expose a single collection of NFT-like //! objects. //! @@ -30,167 +30,164 @@ use codec::{Decode, Encode}; use sp_runtime::TokenError; use sp_std::prelude::*; -/// Trait for providing an interface to a read-only NFT-like set of asset instances. +/// Trait for providing an interface to a read-only NFT-like set of items. pub trait Inspect { - /// Type for identifying an asset instance. - type InstanceId; + /// Type for identifying an item. + type ItemId; - /// Returns the owner of asset `instance`, or `None` if the asset doesn't exist or has no + /// Returns the owner of `item`, or `None` if the item doesn't exist or has no /// owner. - fn owner(instance: &Self::InstanceId) -> Option; + fn owner(item: &Self::ItemId) -> Option; - /// Returns the attribute value of `instance` corresponding to `key`. + /// Returns the attribute value of `item` corresponding to `key`. /// /// By default this is `None`; no attributes are defined. - fn attribute(_instance: &Self::InstanceId, _key: &[u8]) -> Option> { + fn attribute(_item: &Self::ItemId, _key: &[u8]) -> Option> { None } - /// Returns the strongly-typed attribute value of `instance` corresponding to `key`. + /// Returns the strongly-typed attribute value of `item` corresponding to `key`. /// /// By default this just attempts to use `attribute`. - fn typed_attribute(instance: &Self::InstanceId, key: &K) -> Option { - key.using_encoded(|d| Self::attribute(instance, d)) + fn typed_attribute(item: &Self::ItemId, key: &K) -> Option { + key.using_encoded(|d| Self::attribute(item, d)) .and_then(|v| V::decode(&mut &v[..]).ok()) } - /// Returns `true` if the asset `instance` may be transferred. + /// Returns `true` if the `item` may be transferred. /// - /// Default implementation is that all assets are transferable. - fn can_transfer(_instance: &Self::InstanceId) -> bool { + /// Default implementation is that all items are transferable. + fn can_transfer(_item: &Self::ItemId) -> bool { true } } -/// Interface for enumerating assets in existence or owned by a given account over a collection +/// Interface for enumerating items in existence or owned by a given account over a collection /// of NFTs. pub trait InspectEnumerable: Inspect { - /// Returns an iterator of the instances of an asset `class` in existence. - fn instances() -> Box>; + /// Returns an iterator of the items within a `collection` in existence. + fn items() -> Box>; - /// Returns an iterator of the asset instances of all classes owned by `who`. - fn owned(who: &AccountId) -> Box>; + /// Returns an iterator of the items of all collections owned by `who`. + fn owned(who: &AccountId) -> Box>; } -/// Trait for providing an interface for NFT-like assets which may be minted, burned and/or have +/// Trait for providing an interface for NFT-like items which may be minted, burned and/or have /// attributes set on them. pub trait Mutate: Inspect { - /// Mint some asset `instance` to be owned by `who`. + /// Mint some `item` to be owned by `who`. /// /// By default, this is not a supported operation. - fn mint_into(_instance: &Self::InstanceId, _who: &AccountId) -> DispatchResult { + fn mint_into(_item: &Self::ItemId, _who: &AccountId) -> DispatchResult { Err(TokenError::Unsupported.into()) } - /// Burn some asset `instance`. + /// Burn some `item`. /// /// By default, this is not a supported operation. - fn burn( - _instance: &Self::InstanceId, - _maybe_check_owner: Option<&AccountId>, - ) -> DispatchResult { + fn burn(_item: &Self::ItemId, _maybe_check_owner: Option<&AccountId>) -> DispatchResult { Err(TokenError::Unsupported.into()) } - /// Set attribute `value` of asset `instance`'s `key`. + /// Set attribute `value` of `item`'s `key`. /// /// By default, this is not a supported operation. - fn set_attribute(_instance: &Self::InstanceId, _key: &[u8], _value: &[u8]) -> DispatchResult { + fn set_attribute(_item: &Self::ItemId, _key: &[u8], _value: &[u8]) -> DispatchResult { Err(TokenError::Unsupported.into()) } - /// Attempt to set the strongly-typed attribute `value` of `instance`'s `key`. + /// Attempt to set the strongly-typed attribute `value` of `item`'s `key`. /// /// By default this just attempts to use `set_attribute`. fn set_typed_attribute( - instance: &Self::InstanceId, + item: &Self::ItemId, key: &K, value: &V, ) -> DispatchResult { - key.using_encoded(|k| value.using_encoded(|v| Self::set_attribute(instance, k, v))) + key.using_encoded(|k| value.using_encoded(|v| Self::set_attribute(item, k, v))) } } -/// Trait for providing a non-fungible set of assets which can only be transferred. +/// Trait for providing a non-fungible set of items which can only be transferred. pub trait Transfer: Inspect { - /// Transfer asset `instance` into `destination` account. - fn transfer(instance: &Self::InstanceId, destination: &AccountId) -> DispatchResult; + /// Transfer `item` into `destination` account. + fn transfer(item: &Self::ItemId, destination: &AccountId) -> DispatchResult; } /// Convert a `fungibles` trait implementation into a `fungible` trait implementation by identifying /// a single item. pub struct ItemOf< F: nonfungibles::Inspect, - A: Get<>::ClassId>, + A: Get<>::CollectionId>, AccountId, >(sp_std::marker::PhantomData<(F, A, AccountId)>); impl< F: nonfungibles::Inspect, - A: Get<>::ClassId>, + A: Get<>::CollectionId>, AccountId, > Inspect for ItemOf { - type InstanceId = >::InstanceId; - fn owner(instance: &Self::InstanceId) -> Option { - >::owner(&A::get(), instance) + type ItemId = >::ItemId; + fn owner(item: &Self::ItemId) -> Option { + >::owner(&A::get(), item) } - fn attribute(instance: &Self::InstanceId, key: &[u8]) -> Option> { - >::attribute(&A::get(), instance, key) + fn attribute(item: &Self::ItemId, key: &[u8]) -> Option> { + >::attribute(&A::get(), item, key) } - fn typed_attribute(instance: &Self::InstanceId, key: &K) -> Option { - >::typed_attribute(&A::get(), instance, key) + fn typed_attribute(item: &Self::ItemId, key: &K) -> Option { + >::typed_attribute(&A::get(), item, key) } - fn can_transfer(instance: &Self::InstanceId) -> bool { - >::can_transfer(&A::get(), instance) + fn can_transfer(item: &Self::ItemId) -> bool { + >::can_transfer(&A::get(), item) } } impl< F: nonfungibles::InspectEnumerable, - A: Get<>::ClassId>, + A: Get<>::CollectionId>, AccountId, > InspectEnumerable for ItemOf { - fn instances() -> Box> { - >::instances(&A::get()) + fn items() -> Box> { + >::items(&A::get()) } - fn owned(who: &AccountId) -> Box> { - >::owned_in_class(&A::get(), who) + fn owned(who: &AccountId) -> Box> { + >::owned_in_collection(&A::get(), who) } } impl< F: nonfungibles::Mutate, - A: Get<>::ClassId>, + A: Get<>::CollectionId>, AccountId, > Mutate for ItemOf { - fn mint_into(instance: &Self::InstanceId, who: &AccountId) -> DispatchResult { - >::mint_into(&A::get(), instance, who) + fn mint_into(item: &Self::ItemId, who: &AccountId) -> DispatchResult { + >::mint_into(&A::get(), item, who) } - fn burn(instance: &Self::InstanceId, maybe_check_owner: Option<&AccountId>) -> DispatchResult { - >::burn(&A::get(), instance, maybe_check_owner) + fn burn(item: &Self::ItemId, maybe_check_owner: Option<&AccountId>) -> DispatchResult { + >::burn(&A::get(), item, maybe_check_owner) } - fn set_attribute(instance: &Self::InstanceId, key: &[u8], value: &[u8]) -> DispatchResult { - >::set_attribute(&A::get(), instance, key, value) + fn set_attribute(item: &Self::ItemId, key: &[u8], value: &[u8]) -> DispatchResult { + >::set_attribute(&A::get(), item, key, value) } fn set_typed_attribute( - instance: &Self::InstanceId, + item: &Self::ItemId, key: &K, value: &V, ) -> DispatchResult { - >::set_typed_attribute(&A::get(), instance, key, value) + >::set_typed_attribute(&A::get(), item, key, value) } } impl< F: nonfungibles::Transfer, - A: Get<>::ClassId>, + A: Get<>::CollectionId>, AccountId, > Transfer for ItemOf { - fn transfer(instance: &Self::InstanceId, destination: &AccountId) -> DispatchResult { - >::transfer(&A::get(), instance, destination) + fn transfer(item: &Self::ItemId, destination: &AccountId) -> DispatchResult { + >::transfer(&A::get(), item, destination) } } diff --git a/substrate/frame/support/src/traits/tokens/nonfungibles.rs b/substrate/frame/support/src/traits/tokens/nonfungibles.rs index 8bd731b203..d043a87ce7 100644 --- a/substrate/frame/support/src/traits/tokens/nonfungibles.rs +++ b/substrate/frame/support/src/traits/tokens/nonfungibles.rs @@ -15,9 +15,9 @@ // See the License for the specific language governing permissions and // limitations under the License. -//! Traits for dealing with multiple collections of non-fungible assets. +//! Traits for dealing with multiple collections of non-fungible items. //! -//! This assumes a dual-level namespace identified by `Inspect::InstanceId`, and could +//! This assumes a dual-level namespace identified by `Inspect::ItemId`, and could //! reasonably be implemented by pallets which want to expose multiple independent collections of //! NFT-like objects. //! @@ -32,196 +32,210 @@ use codec::{Decode, Encode}; use sp_runtime::TokenError; use sp_std::prelude::*; -/// Trait for providing an interface to many read-only NFT-like sets of asset instances. +/// Trait for providing an interface to many read-only NFT-like sets of items. pub trait Inspect { - /// Type for identifying an asset instance. - type InstanceId; + /// Type for identifying an item. + type ItemId; - /// Type for identifying an asset class (an identifier for an independent collection of asset - /// instances). - type ClassId; + /// Type for identifying a collection (an identifier for an independent collection of + /// items). + type CollectionId; - /// Returns the owner of asset `instance` of `class`, or `None` if the asset doesn't exist (or - /// somehow has no owner). - fn owner(class: &Self::ClassId, instance: &Self::InstanceId) -> Option; + /// Returns the owner of `item` of `collection`, or `None` if the item doesn't exist + /// (or somehow has no owner). + fn owner(collection: &Self::CollectionId, item: &Self::ItemId) -> Option; - /// Returns the owner of the asset `class`, if there is one. For many NFTs this may not make - /// any sense, so users of this API should not be surprised to find an asset class results in - /// `None` here. - fn class_owner(_class: &Self::ClassId) -> Option { + /// Returns the owner of the `collection`, if there is one. For many NFTs this may not + /// make any sense, so users of this API should not be surprised to find a collection + /// results in `None` here. + fn collection_owner(_collection: &Self::CollectionId) -> Option { None } - /// Returns the attribute value of `instance` of `class` corresponding to `key`. + /// Returns the attribute value of `item` of `collection` corresponding to `key`. /// /// By default this is `None`; no attributes are defined. fn attribute( - _class: &Self::ClassId, - _instance: &Self::InstanceId, + _collection: &Self::CollectionId, + _item: &Self::ItemId, _key: &[u8], ) -> Option> { None } - /// Returns the strongly-typed attribute value of `instance` of `class` corresponding to `key`. + /// Returns the strongly-typed attribute value of `item` of `collection` corresponding to + /// `key`. /// /// By default this just attempts to use `attribute`. fn typed_attribute( - class: &Self::ClassId, - instance: &Self::InstanceId, + collection: &Self::CollectionId, + item: &Self::ItemId, key: &K, ) -> Option { - key.using_encoded(|d| Self::attribute(class, instance, d)) + key.using_encoded(|d| Self::attribute(collection, item, d)) .and_then(|v| V::decode(&mut &v[..]).ok()) } - /// Returns the attribute value of `class` corresponding to `key`. + /// Returns the attribute value of `collection` corresponding to `key`. /// /// By default this is `None`; no attributes are defined. - fn class_attribute(_class: &Self::ClassId, _key: &[u8]) -> Option> { + fn collection_attribute(_collection: &Self::CollectionId, _key: &[u8]) -> Option> { None } - /// Returns the strongly-typed attribute value of `class` corresponding to `key`. + /// Returns the strongly-typed attribute value of `collection` corresponding to `key`. /// - /// By default this just attempts to use `class_attribute`. - fn typed_class_attribute(class: &Self::ClassId, key: &K) -> Option { - key.using_encoded(|d| Self::class_attribute(class, d)) + /// By default this just attempts to use `collection_attribute`. + fn typed_collection_attribute( + collection: &Self::CollectionId, + key: &K, + ) -> Option { + key.using_encoded(|d| Self::collection_attribute(collection, d)) .and_then(|v| V::decode(&mut &v[..]).ok()) } - /// Returns `true` if the asset `instance` of `class` may be transferred. + /// Returns `true` if the `item` of `collection` may be transferred. /// - /// Default implementation is that all assets are transferable. - fn can_transfer(_class: &Self::ClassId, _instance: &Self::InstanceId) -> bool { + /// Default implementation is that all items are transferable. + fn can_transfer(_collection: &Self::CollectionId, _item: &Self::ItemId) -> bool { true } } -/// Interface for enumerating assets in existence or owned by a given account over many collections +/// Interface for enumerating items in existence or owned by a given account over many collections /// of NFTs. pub trait InspectEnumerable: Inspect { - /// Returns an iterator of the asset classes in existence. - fn classes() -> Box>; + /// Returns an iterator of the collections in existence. + fn collections() -> Box>; - /// Returns an iterator of the instances of an asset `class` in existence. - fn instances(class: &Self::ClassId) -> Box>; + /// Returns an iterator of the items of a `collection` in existence. + fn items(collection: &Self::CollectionId) -> Box>; - /// Returns an iterator of the asset instances of all classes owned by `who`. - fn owned(who: &AccountId) -> Box>; + /// Returns an iterator of the items of all collections owned by `who`. + fn owned(who: &AccountId) -> Box>; - /// Returns an iterator of the asset instances of `class` owned by `who`. - fn owned_in_class( - class: &Self::ClassId, + /// Returns an iterator of the items of `collection` owned by `who`. + fn owned_in_collection( + collection: &Self::CollectionId, who: &AccountId, - ) -> Box>; + ) -> Box>; } -/// Trait for providing the ability to create classes of nonfungible assets. +/// Trait for providing the ability to create collections of nonfungible items. pub trait Create: Inspect { - /// Create a `class` of nonfungible assets to be owned by `who` and managed by `admin`. - fn create_class(class: &Self::ClassId, who: &AccountId, admin: &AccountId) -> DispatchResult; + /// Create a `collection` of nonfungible items to be owned by `who` and managed by `admin`. + fn create_collection( + collection: &Self::CollectionId, + who: &AccountId, + admin: &AccountId, + ) -> DispatchResult; } -/// Trait for providing the ability to destroy classes of nonfungible assets. +/// Trait for providing the ability to destroy collections of nonfungible items. pub trait Destroy: Inspect { - /// The witness data needed to destroy an asset. + /// The witness data needed to destroy an item. type DestroyWitness; - /// Provide the appropriate witness data needed to destroy an asset. - fn get_destroy_witness(class: &Self::ClassId) -> Option; + /// Provide the appropriate witness data needed to destroy an item. + fn get_destroy_witness(collection: &Self::CollectionId) -> Option; - /// Destroy an existing fungible asset. - /// * `class`: The `ClassId` to be destroyed. + /// Destroy an existing fungible item. + /// * `collection`: The `CollectionId` to be destroyed. /// * `witness`: Any witness data that needs to be provided to complete the operation /// successfully. /// * `maybe_check_owner`: An optional account id that can be used to authorize the destroy /// command. If not provided, we will not do any authorization checks before destroying the - /// asset. + /// item. /// - /// If successful, this function will return the actual witness data from the destroyed asset. + /// If successful, this function will return the actual witness data from the destroyed item. /// This may be different than the witness data provided, and can be used to refund weight. fn destroy( - class: Self::ClassId, + collection: Self::CollectionId, witness: Self::DestroyWitness, maybe_check_owner: Option, ) -> Result; } -/// Trait for providing an interface for multiple classes of NFT-like assets which may be minted, -/// burned and/or have attributes set on them. +/// Trait for providing an interface for multiple collections of NFT-like items which may be +/// minted, burned and/or have attributes set on them. pub trait Mutate: Inspect { - /// Mint some asset `instance` of `class` to be owned by `who`. + /// Mint some `item` of `collection` to be owned by `who`. /// /// By default, this is not a supported operation. fn mint_into( - _class: &Self::ClassId, - _instance: &Self::InstanceId, + _collection: &Self::CollectionId, + _item: &Self::ItemId, _who: &AccountId, ) -> DispatchResult { Err(TokenError::Unsupported.into()) } - /// Burn some asset `instance` of `class`. + /// Burn some `item` of `collection`. /// /// By default, this is not a supported operation. fn burn( - _class: &Self::ClassId, - _instance: &Self::InstanceId, + _collection: &Self::CollectionId, + _item: &Self::ItemId, _maybe_check_owner: Option<&AccountId>, ) -> DispatchResult { Err(TokenError::Unsupported.into()) } - /// Set attribute `value` of asset `instance` of `class`'s `key`. + /// Set attribute `value` of `item` of `collection`'s `key`. /// /// By default, this is not a supported operation. fn set_attribute( - _class: &Self::ClassId, - _instance: &Self::InstanceId, + _collection: &Self::CollectionId, + _item: &Self::ItemId, _key: &[u8], _value: &[u8], ) -> DispatchResult { Err(TokenError::Unsupported.into()) } - /// Attempt to set the strongly-typed attribute `value` of `instance` of `class`'s `key`. + /// Attempt to set the strongly-typed attribute `value` of `item` of `collection`'s `key`. /// /// By default this just attempts to use `set_attribute`. fn set_typed_attribute( - class: &Self::ClassId, - instance: &Self::InstanceId, + collection: &Self::CollectionId, + item: &Self::ItemId, key: &K, value: &V, ) -> DispatchResult { - key.using_encoded(|k| value.using_encoded(|v| Self::set_attribute(class, instance, k, v))) + key.using_encoded(|k| value.using_encoded(|v| Self::set_attribute(collection, item, k, v))) } - /// Set attribute `value` of asset `class`'s `key`. + /// Set attribute `value` of `collection`'s `key`. /// /// By default, this is not a supported operation. - fn set_class_attribute(_class: &Self::ClassId, _key: &[u8], _value: &[u8]) -> DispatchResult { + fn set_collection_attribute( + _collection: &Self::CollectionId, + _key: &[u8], + _value: &[u8], + ) -> DispatchResult { Err(TokenError::Unsupported.into()) } - /// Attempt to set the strongly-typed attribute `value` of `class`'s `key`. + /// Attempt to set the strongly-typed attribute `value` of `collection`'s `key`. /// /// By default this just attempts to use `set_attribute`. - fn set_typed_class_attribute( - class: &Self::ClassId, + fn set_typed_collection_attribute( + collection: &Self::CollectionId, key: &K, value: &V, ) -> DispatchResult { - key.using_encoded(|k| value.using_encoded(|v| Self::set_class_attribute(class, k, v))) + key.using_encoded(|k| { + value.using_encoded(|v| Self::set_collection_attribute(collection, k, v)) + }) } } -/// Trait for providing a non-fungible sets of assets which can only be transferred. +/// Trait for providing a non-fungible sets of items which can only be transferred. pub trait Transfer: Inspect { - /// Transfer asset `instance` of `class` into `destination` account. + /// Transfer `item` of `collection` into `destination` account. fn transfer( - class: &Self::ClassId, - instance: &Self::InstanceId, + collection: &Self::CollectionId, + item: &Self::ItemId, destination: &AccountId, ) -> DispatchResult; } diff --git a/substrate/frame/uniques/src/benchmarking.rs b/substrate/frame/uniques/src/benchmarking.rs index b743ca1291..cd66d03922 100644 --- a/substrate/frame/uniques/src/benchmarking.rs +++ b/substrate/frame/uniques/src/benchmarking.rs @@ -15,7 +15,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -//! Assets pallet benchmarking. +//! Uniques pallet benchmarking. #![cfg(feature = "runtime-benchmarks")] @@ -36,32 +36,32 @@ use crate::Pallet as Uniques; const SEED: u32 = 0; -fn create_class, I: 'static>( -) -> (T::ClassId, T::AccountId, ::Source) { +fn create_collection, I: 'static>( +) -> (T::CollectionId, T::AccountId, ::Source) { let caller: T::AccountId = whitelisted_caller(); let caller_lookup = T::Lookup::unlookup(caller.clone()); - let class = T::Helper::class(0); + let collection = T::Helper::collection(0); T::Currency::make_free_balance_be(&caller, DepositBalanceOf::::max_value()); assert!(Uniques::::force_create( SystemOrigin::Root.into(), - class, + collection, caller_lookup.clone(), false, ) .is_ok()); - (class, caller, caller_lookup) + (collection, caller, caller_lookup) } -fn add_class_metadata, I: 'static>( +fn add_collection_metadata, I: 'static>( ) -> (T::AccountId, ::Source) { - let caller = Class::::get(T::Helper::class(0)).unwrap().owner; + let caller = Collection::::get(T::Helper::collection(0)).unwrap().owner; if caller != whitelisted_caller() { whitelist_account!(caller); } let caller_lookup = T::Lookup::unlookup(caller.clone()); - assert!(Uniques::::set_class_metadata( + assert!(Uniques::::set_collection_metadata( SystemOrigin::Signed(caller.clone()).into(), - T::Helper::class(0), + T::Helper::collection(0), vec![0; T::StringLimit::get() as usize].try_into().unwrap(), false, ) @@ -69,37 +69,37 @@ fn add_class_metadata, I: 'static>( (caller, caller_lookup) } -fn mint_instance, I: 'static>( +fn mint_item, I: 'static>( index: u16, -) -> (T::InstanceId, T::AccountId, ::Source) { - let caller = Class::::get(T::Helper::class(0)).unwrap().admin; +) -> (T::ItemId, T::AccountId, ::Source) { + let caller = Collection::::get(T::Helper::collection(0)).unwrap().admin; if caller != whitelisted_caller() { whitelist_account!(caller); } let caller_lookup = T::Lookup::unlookup(caller.clone()); - let instance = T::Helper::instance(index); + let item = T::Helper::item(index); assert!(Uniques::::mint( SystemOrigin::Signed(caller.clone()).into(), - T::Helper::class(0), - instance, + T::Helper::collection(0), + item, caller_lookup.clone(), ) .is_ok()); - (instance, caller, caller_lookup) + (item, caller, caller_lookup) } -fn add_instance_metadata, I: 'static>( - instance: T::InstanceId, +fn add_item_metadata, I: 'static>( + item: T::ItemId, ) -> (T::AccountId, ::Source) { - let caller = Class::::get(T::Helper::class(0)).unwrap().owner; + let caller = Collection::::get(T::Helper::collection(0)).unwrap().owner; if caller != whitelisted_caller() { whitelist_account!(caller); } let caller_lookup = T::Lookup::unlookup(caller.clone()); assert!(Uniques::::set_metadata( SystemOrigin::Signed(caller.clone()).into(), - T::Helper::class(0), - instance, + T::Helper::collection(0), + item, vec![0; T::StringLimit::get() as usize].try_into().unwrap(), false, ) @@ -107,10 +107,10 @@ fn add_instance_metadata, I: 'static>( (caller, caller_lookup) } -fn add_instance_attribute, I: 'static>( - instance: T::InstanceId, +fn add_item_attribute, I: 'static>( + item: T::ItemId, ) -> (BoundedVec, T::AccountId, ::Source) { - let caller = Class::::get(T::Helper::class(0)).unwrap().owner; + let caller = Collection::::get(T::Helper::collection(0)).unwrap().owner; if caller != whitelisted_caller() { whitelist_account!(caller); } @@ -118,8 +118,8 @@ fn add_instance_attribute, I: 'static>( let key: BoundedVec<_, _> = vec![0; T::KeyLimit::get() as usize].try_into().unwrap(); assert!(Uniques::::set_attribute( SystemOrigin::Signed(caller.clone()).into(), - T::Helper::class(0), - Some(instance), + T::Helper::collection(0), + Some(item), key.clone(), vec![0; T::ValueLimit::get() as usize].try_into().unwrap(), ) @@ -137,24 +137,24 @@ fn assert_last_event, I: 'static>(generic_event: >:: benchmarks_instance_pallet! { create { - let class = T::Helper::class(0); - let origin = T::CreateOrigin::successful_origin(&class); - let caller = T::CreateOrigin::ensure_origin(origin.clone(), &class).unwrap(); + let collection = T::Helper::collection(0); + let origin = T::CreateOrigin::successful_origin(&collection); + let caller = T::CreateOrigin::ensure_origin(origin.clone(), &collection).unwrap(); whitelist_account!(caller); let admin = T::Lookup::unlookup(caller.clone()); T::Currency::make_free_balance_be(&caller, DepositBalanceOf::::max_value()); - let call = Call::::create { class, admin }; + let call = Call::::create { collection, admin }; }: { call.dispatch_bypass_filter(origin)? } verify { - assert_last_event::(Event::Created { class: T::Helper::class(0), creator: caller.clone(), owner: caller }.into()); + assert_last_event::(Event::Created { collection: T::Helper::collection(0), creator: caller.clone(), owner: caller }.into()); } force_create { let caller: T::AccountId = whitelisted_caller(); let caller_lookup = T::Lookup::unlookup(caller.clone()); - }: _(SystemOrigin::Root, T::Helper::class(0), caller_lookup, true) + }: _(SystemOrigin::Root, T::Helper::collection(0), caller_lookup, true) verify { - assert_last_event::(Event::ForceCreated { class: T::Helper::class(0), owner: caller }.into()); + assert_last_event::(Event::ForceCreated { collection: T::Helper::collection(0), owner: caller }.into()); } destroy { @@ -162,57 +162,57 @@ benchmarks_instance_pallet! { let m in 0 .. 1_000; let a in 0 .. 1_000; - let (class, caller, caller_lookup) = create_class::(); - add_class_metadata::(); + let (collection, caller, caller_lookup) = create_collection::(); + add_collection_metadata::(); for i in 0..n { - mint_instance::(i as u16); + mint_item::(i as u16); } for i in 0..m { - add_instance_metadata::(T::Helper::instance(i as u16)); + add_item_metadata::(T::Helper::item(i as u16)); } for i in 0..a { - add_instance_attribute::(T::Helper::instance(i as u16)); + add_item_attribute::(T::Helper::item(i as u16)); } - let witness = Class::::get(class).unwrap().destroy_witness(); - }: _(SystemOrigin::Signed(caller), class, witness) + let witness = Collection::::get(collection).unwrap().destroy_witness(); + }: _(SystemOrigin::Signed(caller), collection, witness) verify { - assert_last_event::(Event::Destroyed { class }.into()); + assert_last_event::(Event::Destroyed { collection }.into()); } mint { - let (class, caller, caller_lookup) = create_class::(); - let instance = T::Helper::instance(0); - }: _(SystemOrigin::Signed(caller.clone()), class, instance, caller_lookup) + let (collection, caller, caller_lookup) = create_collection::(); + let item = T::Helper::item(0); + }: _(SystemOrigin::Signed(caller.clone()), collection, item, caller_lookup) verify { - assert_last_event::(Event::Issued { class, instance, owner: caller }.into()); + assert_last_event::(Event::Issued { collection, item, owner: caller }.into()); } burn { - let (class, caller, caller_lookup) = create_class::(); - let (instance, ..) = mint_instance::(0); - }: _(SystemOrigin::Signed(caller.clone()), class, instance, Some(caller_lookup)) + let (collection, caller, caller_lookup) = create_collection::(); + let (item, ..) = mint_item::(0); + }: _(SystemOrigin::Signed(caller.clone()), collection, item, Some(caller_lookup)) verify { - assert_last_event::(Event::Burned { class, instance, owner: caller }.into()); + assert_last_event::(Event::Burned { collection, item, owner: caller }.into()); } transfer { - let (class, caller, caller_lookup) = create_class::(); - let (instance, ..) = mint_instance::(0); + let (collection, caller, caller_lookup) = create_collection::(); + let (item, ..) = mint_item::(0); let target: T::AccountId = account("target", 0, SEED); let target_lookup = T::Lookup::unlookup(target.clone()); - }: _(SystemOrigin::Signed(caller.clone()), class, instance, target_lookup) + }: _(SystemOrigin::Signed(caller.clone()), collection, item, target_lookup) verify { - assert_last_event::(Event::Transferred { class, instance, from: caller, to: target }.into()); + assert_last_event::(Event::Transferred { collection, item, from: caller, to: target }.into()); } redeposit { let i in 0 .. 5_000; - let (class, caller, caller_lookup) = create_class::(); - let instances = (0..i).map(|x| mint_instance::(x as u16).0).collect::>(); - Uniques::::force_asset_status( + let (collection, caller, caller_lookup) = create_collection::(); + let items = (0..i).map(|x| mint_item::(x as u16).0).collect::>(); + Uniques::::force_item_status( SystemOrigin::Root.into(), - class, + collection, caller_lookup.clone(), caller_lookup.clone(), caller_lookup.clone(), @@ -220,80 +220,80 @@ benchmarks_instance_pallet! { true, false, )?; - }: _(SystemOrigin::Signed(caller.clone()), class, instances.clone()) + }: _(SystemOrigin::Signed(caller.clone()), collection, items.clone()) verify { - assert_last_event::(Event::Redeposited { class, successful_instances: instances }.into()); + assert_last_event::(Event::Redeposited { collection, successful_items: items }.into()); } freeze { - let (class, caller, caller_lookup) = create_class::(); - let (instance, ..) = mint_instance::(0); - }: _(SystemOrigin::Signed(caller.clone()), T::Helper::class(0), T::Helper::instance(0)) + let (collection, caller, caller_lookup) = create_collection::(); + let (item, ..) = mint_item::(0); + }: _(SystemOrigin::Signed(caller.clone()), T::Helper::collection(0), T::Helper::item(0)) verify { - assert_last_event::(Event::Frozen { class: T::Helper::class(0), instance: T::Helper::instance(0) }.into()); + assert_last_event::(Event::Frozen { collection: T::Helper::collection(0), item: T::Helper::item(0) }.into()); } thaw { - let (class, caller, caller_lookup) = create_class::(); - let (instance, ..) = mint_instance::(0); + let (collection, caller, caller_lookup) = create_collection::(); + let (item, ..) = mint_item::(0); Uniques::::freeze( SystemOrigin::Signed(caller.clone()).into(), - class, - instance, + collection, + item, )?; - }: _(SystemOrigin::Signed(caller.clone()), class, instance) + }: _(SystemOrigin::Signed(caller.clone()), collection, item) verify { - assert_last_event::(Event::Thawed { class, instance }.into()); + assert_last_event::(Event::Thawed { collection, item }.into()); } - freeze_class { - let (class, caller, caller_lookup) = create_class::(); - }: _(SystemOrigin::Signed(caller.clone()), class) + freeze_collection { + let (collection, caller, caller_lookup) = create_collection::(); + }: _(SystemOrigin::Signed(caller.clone()), collection) verify { - assert_last_event::(Event::ClassFrozen { class }.into()); + assert_last_event::(Event::CollectionFrozen { collection }.into()); } - thaw_class { - let (class, caller, caller_lookup) = create_class::(); + thaw_collection { + let (collection, caller, caller_lookup) = create_collection::(); let origin = SystemOrigin::Signed(caller.clone()).into(); - Uniques::::freeze_class(origin, class)?; - }: _(SystemOrigin::Signed(caller.clone()), class) + Uniques::::freeze_collection(origin, collection)?; + }: _(SystemOrigin::Signed(caller.clone()), collection) verify { - assert_last_event::(Event::ClassThawed { class }.into()); + assert_last_event::(Event::CollectionThawed { collection }.into()); } transfer_ownership { - let (class, caller, _) = create_class::(); + let (collection, caller, _) = create_collection::(); let target: T::AccountId = account("target", 0, SEED); let target_lookup = T::Lookup::unlookup(target.clone()); T::Currency::make_free_balance_be(&target, T::Currency::minimum_balance()); let origin = SystemOrigin::Signed(target.clone()).into(); - Uniques::::set_accept_ownership(origin, Some(class))?; - }: _(SystemOrigin::Signed(caller), class, target_lookup) + Uniques::::set_accept_ownership(origin, Some(collection))?; + }: _(SystemOrigin::Signed(caller), collection, target_lookup) verify { - assert_last_event::(Event::OwnerChanged { class, new_owner: target }.into()); + assert_last_event::(Event::OwnerChanged { collection, new_owner: target }.into()); } set_team { - let (class, caller, _) = create_class::(); + let (collection, caller, _) = create_collection::(); let target0 = T::Lookup::unlookup(account("target", 0, SEED)); let target1 = T::Lookup::unlookup(account("target", 1, SEED)); let target2 = T::Lookup::unlookup(account("target", 2, SEED)); - }: _(SystemOrigin::Signed(caller), class, target0, target1, target2) + }: _(SystemOrigin::Signed(caller), collection, target0, target1, target2) verify { assert_last_event::(Event::TeamChanged{ - class, + collection, issuer: account("target", 0, SEED), admin: account("target", 1, SEED), freezer: account("target", 2, SEED), }.into()); } - force_asset_status { - let (class, caller, caller_lookup) = create_class::(); + force_item_status { + let (collection, caller, caller_lookup) = create_collection::(); let origin = T::ForceOrigin::successful_origin(); - let call = Call::::force_asset_status { - class, + let call = Call::::force_item_status { + collection, owner: caller_lookup.clone(), issuer: caller_lookup.clone(), admin: caller_lookup.clone(), @@ -303,98 +303,98 @@ benchmarks_instance_pallet! { }; }: { call.dispatch_bypass_filter(origin)? } verify { - assert_last_event::(Event::AssetStatusChanged { class }.into()); + assert_last_event::(Event::ItemStatusChanged { collection }.into()); } set_attribute { let key: BoundedVec<_, _> = vec![0u8; T::KeyLimit::get() as usize].try_into().unwrap(); let value: BoundedVec<_, _> = vec![0u8; T::ValueLimit::get() as usize].try_into().unwrap(); - let (class, caller, _) = create_class::(); - let (instance, ..) = mint_instance::(0); - add_instance_metadata::(instance); - }: _(SystemOrigin::Signed(caller), class, Some(instance), key.clone(), value.clone()) + let (collection, caller, _) = create_collection::(); + let (item, ..) = mint_item::(0); + add_item_metadata::(item); + }: _(SystemOrigin::Signed(caller), collection, Some(item), key.clone(), value.clone()) verify { - assert_last_event::(Event::AttributeSet { class, maybe_instance: Some(instance), key, value }.into()); + assert_last_event::(Event::AttributeSet { collection, maybe_item: Some(item), key, value }.into()); } clear_attribute { - let (class, caller, _) = create_class::(); - let (instance, ..) = mint_instance::(0); - add_instance_metadata::(instance); - let (key, ..) = add_instance_attribute::(instance); - }: _(SystemOrigin::Signed(caller), class, Some(instance), key.clone()) + let (collection, caller, _) = create_collection::(); + let (item, ..) = mint_item::(0); + add_item_metadata::(item); + let (key, ..) = add_item_attribute::(item); + }: _(SystemOrigin::Signed(caller), collection, Some(item), key.clone()) verify { - assert_last_event::(Event::AttributeCleared { class, maybe_instance: Some(instance), key }.into()); + assert_last_event::(Event::AttributeCleared { collection, maybe_item: Some(item), key }.into()); } set_metadata { let data: BoundedVec<_, _> = vec![0u8; T::StringLimit::get() as usize].try_into().unwrap(); - let (class, caller, _) = create_class::(); - let (instance, ..) = mint_instance::(0); - }: _(SystemOrigin::Signed(caller), class, instance, data.clone(), false) + let (collection, caller, _) = create_collection::(); + let (item, ..) = mint_item::(0); + }: _(SystemOrigin::Signed(caller), collection, item, data.clone(), false) verify { - assert_last_event::(Event::MetadataSet { class, instance, data, is_frozen: false }.into()); + assert_last_event::(Event::MetadataSet { collection, item, data, is_frozen: false }.into()); } clear_metadata { - let (class, caller, _) = create_class::(); - let (instance, ..) = mint_instance::(0); - add_instance_metadata::(instance); - }: _(SystemOrigin::Signed(caller), class, instance) + let (collection, caller, _) = create_collection::(); + let (item, ..) = mint_item::(0); + add_item_metadata::(item); + }: _(SystemOrigin::Signed(caller), collection, item) verify { - assert_last_event::(Event::MetadataCleared { class, instance }.into()); + assert_last_event::(Event::MetadataCleared { collection, item }.into()); } - set_class_metadata { + set_collection_metadata { let data: BoundedVec<_, _> = vec![0u8; T::StringLimit::get() as usize].try_into().unwrap(); - let (class, caller, _) = create_class::(); - }: _(SystemOrigin::Signed(caller), class, data.clone(), false) + let (collection, caller, _) = create_collection::(); + }: _(SystemOrigin::Signed(caller), collection, data.clone(), false) verify { - assert_last_event::(Event::ClassMetadataSet { class, data, is_frozen: false }.into()); + assert_last_event::(Event::CollectionMetadataSet { collection, data, is_frozen: false }.into()); } - clear_class_metadata { - let (class, caller, _) = create_class::(); - add_class_metadata::(); - }: _(SystemOrigin::Signed(caller), class) + clear_collection_metadata { + let (collection, caller, _) = create_collection::(); + add_collection_metadata::(); + }: _(SystemOrigin::Signed(caller), collection) verify { - assert_last_event::(Event::ClassMetadataCleared { class }.into()); + assert_last_event::(Event::CollectionMetadataCleared { collection }.into()); } approve_transfer { - let (class, caller, _) = create_class::(); - let (instance, ..) = mint_instance::(0); + let (collection, caller, _) = create_collection::(); + let (item, ..) = mint_item::(0); let delegate: T::AccountId = account("delegate", 0, SEED); let delegate_lookup = T::Lookup::unlookup(delegate.clone()); - }: _(SystemOrigin::Signed(caller.clone()), class, instance, delegate_lookup) + }: _(SystemOrigin::Signed(caller.clone()), collection, item, delegate_lookup) verify { - assert_last_event::(Event::ApprovedTransfer { class, instance, owner: caller, delegate }.into()); + assert_last_event::(Event::ApprovedTransfer { collection, item, owner: caller, delegate }.into()); } cancel_approval { - let (class, caller, _) = create_class::(); - let (instance, ..) = mint_instance::(0); + let (collection, caller, _) = create_collection::(); + let (item, ..) = mint_item::(0); let delegate: T::AccountId = account("delegate", 0, SEED); let delegate_lookup = T::Lookup::unlookup(delegate.clone()); let origin = SystemOrigin::Signed(caller.clone()).into(); - Uniques::::approve_transfer(origin, class, instance, delegate_lookup.clone())?; - }: _(SystemOrigin::Signed(caller.clone()), class, instance, Some(delegate_lookup)) + Uniques::::approve_transfer(origin, collection, item, delegate_lookup.clone())?; + }: _(SystemOrigin::Signed(caller.clone()), collection, item, Some(delegate_lookup)) verify { - assert_last_event::(Event::ApprovalCancelled { class, instance, owner: caller, delegate }.into()); + assert_last_event::(Event::ApprovalCancelled { collection, item, owner: caller, delegate }.into()); } set_accept_ownership { let caller: T::AccountId = whitelisted_caller(); T::Currency::make_free_balance_be(&caller, DepositBalanceOf::::max_value()); - let class = T::Helper::class(0); - }: _(SystemOrigin::Signed(caller.clone()), Some(class)) + let collection = T::Helper::collection(0); + }: _(SystemOrigin::Signed(caller.clone()), Some(collection)) verify { assert_last_event::(Event::OwnershipAcceptanceChanged { who: caller, - maybe_class: Some(class), + maybe_collection: Some(collection), }.into()); } diff --git a/substrate/frame/uniques/src/functions.rs b/substrate/frame/uniques/src/functions.rs index ea9eecd767..20e1410a8a 100644 --- a/substrate/frame/uniques/src/functions.rs +++ b/substrate/frame/uniques/src/functions.rs @@ -23,168 +23,174 @@ use sp_runtime::{DispatchError, DispatchResult}; impl, I: 'static> Pallet { pub fn do_transfer( - class: T::ClassId, - instance: T::InstanceId, + collection: T::CollectionId, + item: T::ItemId, dest: T::AccountId, with_details: impl FnOnce( - &ClassDetailsFor, - &mut InstanceDetailsFor, + &CollectionDetailsFor, + &mut ItemDetailsFor, ) -> DispatchResult, ) -> DispatchResult { - let class_details = Class::::get(&class).ok_or(Error::::UnknownClass)?; - ensure!(!class_details.is_frozen, Error::::Frozen); - ensure!(!T::Locker::is_locked(class, instance), Error::::Locked); + let collection_details = + Collection::::get(&collection).ok_or(Error::::UnknownCollection)?; + ensure!(!collection_details.is_frozen, Error::::Frozen); + ensure!(!T::Locker::is_locked(collection, item), Error::::Locked); let mut details = - Asset::::get(&class, &instance).ok_or(Error::::UnknownClass)?; + Item::::get(&collection, &item).ok_or(Error::::UnknownCollection)?; ensure!(!details.is_frozen, Error::::Frozen); - with_details(&class_details, &mut details)?; + with_details(&collection_details, &mut details)?; - Account::::remove((&details.owner, &class, &instance)); - Account::::insert((&dest, &class, &instance), ()); + Account::::remove((&details.owner, &collection, &item)); + Account::::insert((&dest, &collection, &item), ()); let origin = details.owner; details.owner = dest; - Asset::::insert(&class, &instance, &details); + Item::::insert(&collection, &item, &details); Self::deposit_event(Event::Transferred { - class, - instance, + collection, + item, from: origin, to: details.owner, }); Ok(()) } - pub fn do_create_class( - class: T::ClassId, + pub fn do_create_collection( + collection: T::CollectionId, owner: T::AccountId, admin: T::AccountId, deposit: DepositBalanceOf, free_holding: bool, event: Event, ) -> DispatchResult { - ensure!(!Class::::contains_key(class), Error::::InUse); + ensure!(!Collection::::contains_key(collection), Error::::InUse); T::Currency::reserve(&owner, deposit)?; - Class::::insert( - class, - ClassDetails { + Collection::::insert( + collection, + CollectionDetails { owner: owner.clone(), issuer: admin.clone(), admin: admin.clone(), freezer: admin, total_deposit: deposit, free_holding, - instances: 0, - instance_metadatas: 0, + items: 0, + item_metadatas: 0, attributes: 0, is_frozen: false, }, ); - ClassAccount::::insert(&owner, &class, ()); + CollectionAccount::::insert(&owner, &collection, ()); Self::deposit_event(event); Ok(()) } - pub fn do_destroy_class( - class: T::ClassId, + pub fn do_destroy_collection( + collection: T::CollectionId, witness: DestroyWitness, maybe_check_owner: Option, ) -> Result { - Class::::try_mutate_exists(class, |maybe_details| { - let class_details = maybe_details.take().ok_or(Error::::UnknownClass)?; + Collection::::try_mutate_exists(collection, |maybe_details| { + let collection_details = + maybe_details.take().ok_or(Error::::UnknownCollection)?; if let Some(check_owner) = maybe_check_owner { - ensure!(class_details.owner == check_owner, Error::::NoPermission); + ensure!(collection_details.owner == check_owner, Error::::NoPermission); } - ensure!(class_details.instances == witness.instances, Error::::BadWitness); + ensure!(collection_details.items == witness.items, Error::::BadWitness); ensure!( - class_details.instance_metadatas == witness.instance_metadatas, + collection_details.item_metadatas == witness.item_metadatas, Error::::BadWitness ); - ensure!(class_details.attributes == witness.attributes, Error::::BadWitness); + ensure!(collection_details.attributes == witness.attributes, Error::::BadWitness); - for (instance, details) in Asset::::drain_prefix(&class) { - Account::::remove((&details.owner, &class, &instance)); + for (item, details) in Item::::drain_prefix(&collection) { + Account::::remove((&details.owner, &collection, &item)); } - InstanceMetadataOf::::remove_prefix(&class, None); - ClassMetadataOf::::remove(&class); - Attribute::::remove_prefix((&class,), None); - ClassAccount::::remove(&class_details.owner, &class); - T::Currency::unreserve(&class_details.owner, class_details.total_deposit); + ItemMetadataOf::::remove_prefix(&collection, None); + CollectionMetadataOf::::remove(&collection); + Attribute::::remove_prefix((&collection,), None); + CollectionAccount::::remove(&collection_details.owner, &collection); + T::Currency::unreserve(&collection_details.owner, collection_details.total_deposit); - Self::deposit_event(Event::Destroyed { class }); + Self::deposit_event(Event::Destroyed { collection }); Ok(DestroyWitness { - instances: class_details.instances, - instance_metadatas: class_details.instance_metadatas, - attributes: class_details.attributes, + items: collection_details.items, + item_metadatas: collection_details.item_metadatas, + attributes: collection_details.attributes, }) }) } pub fn do_mint( - class: T::ClassId, - instance: T::InstanceId, + collection: T::CollectionId, + item: T::ItemId, owner: T::AccountId, - with_details: impl FnOnce(&ClassDetailsFor) -> DispatchResult, + with_details: impl FnOnce(&CollectionDetailsFor) -> DispatchResult, ) -> DispatchResult { - ensure!(!Asset::::contains_key(class, instance), Error::::AlreadyExists); + ensure!(!Item::::contains_key(collection, item), Error::::AlreadyExists); - Class::::try_mutate(&class, |maybe_class_details| -> DispatchResult { - let class_details = maybe_class_details.as_mut().ok_or(Error::::UnknownClass)?; + Collection::::try_mutate( + &collection, + |maybe_collection_details| -> DispatchResult { + let collection_details = + maybe_collection_details.as_mut().ok_or(Error::::UnknownCollection)?; - with_details(class_details)?; + with_details(collection_details)?; - let instances = - class_details.instances.checked_add(1).ok_or(ArithmeticError::Overflow)?; - class_details.instances = instances; + let items = + collection_details.items.checked_add(1).ok_or(ArithmeticError::Overflow)?; + collection_details.items = items; - let deposit = match class_details.free_holding { - true => Zero::zero(), - false => T::InstanceDeposit::get(), - }; - T::Currency::reserve(&class_details.owner, deposit)?; - class_details.total_deposit += deposit; + let deposit = match collection_details.free_holding { + true => Zero::zero(), + false => T::ItemDeposit::get(), + }; + T::Currency::reserve(&collection_details.owner, deposit)?; + collection_details.total_deposit += deposit; - let owner = owner.clone(); - Account::::insert((&owner, &class, &instance), ()); - let details = InstanceDetails { owner, approved: None, is_frozen: false, deposit }; - Asset::::insert(&class, &instance, details); - Ok(()) - })?; + let owner = owner.clone(); + Account::::insert((&owner, &collection, &item), ()); + let details = ItemDetails { owner, approved: None, is_frozen: false, deposit }; + Item::::insert(&collection, &item, details); + Ok(()) + }, + )?; - Self::deposit_event(Event::Issued { class, instance, owner }); + Self::deposit_event(Event::Issued { collection, item, owner }); Ok(()) } pub fn do_burn( - class: T::ClassId, - instance: T::InstanceId, - with_details: impl FnOnce(&ClassDetailsFor, &InstanceDetailsFor) -> DispatchResult, + collection: T::CollectionId, + item: T::ItemId, + with_details: impl FnOnce(&CollectionDetailsFor, &ItemDetailsFor) -> DispatchResult, ) -> DispatchResult { - let owner = Class::::try_mutate( - &class, - |maybe_class_details| -> Result { - let class_details = - maybe_class_details.as_mut().ok_or(Error::::UnknownClass)?; - let details = - Asset::::get(&class, &instance).ok_or(Error::::UnknownClass)?; - with_details(class_details, &details)?; + let owner = Collection::::try_mutate( + &collection, + |maybe_collection_details| -> Result { + let collection_details = + maybe_collection_details.as_mut().ok_or(Error::::UnknownCollection)?; + let details = Item::::get(&collection, &item) + .ok_or(Error::::UnknownCollection)?; + with_details(collection_details, &details)?; // Return the deposit. - T::Currency::unreserve(&class_details.owner, details.deposit); - class_details.total_deposit.saturating_reduce(details.deposit); - class_details.instances.saturating_dec(); + T::Currency::unreserve(&collection_details.owner, details.deposit); + collection_details.total_deposit.saturating_reduce(details.deposit); + collection_details.items.saturating_dec(); Ok(details.owner) }, )?; - Asset::::remove(&class, &instance); - Account::::remove((&owner, &class, &instance)); + Item::::remove(&collection, &item); + Account::::remove((&owner, &collection, &item)); - Self::deposit_event(Event::Burned { class, instance, owner }); + Self::deposit_event(Event::Burned { collection, item, owner }); Ok(()) } } diff --git a/substrate/frame/uniques/src/impl_nonfungibles.rs b/substrate/frame/uniques/src/impl_nonfungibles.rs index 492befc469..cead6f562a 100644 --- a/substrate/frame/uniques/src/impl_nonfungibles.rs +++ b/substrate/frame/uniques/src/impl_nonfungibles.rs @@ -26,59 +26,59 @@ use sp_runtime::{DispatchError, DispatchResult}; use sp_std::prelude::*; impl, I: 'static> Inspect<::AccountId> for Pallet { - type InstanceId = T::InstanceId; - type ClassId = T::ClassId; + type ItemId = T::ItemId; + type CollectionId = T::CollectionId; fn owner( - class: &Self::ClassId, - instance: &Self::InstanceId, + collection: &Self::CollectionId, + item: &Self::ItemId, ) -> Option<::AccountId> { - Asset::::get(class, instance).map(|a| a.owner) + Item::::get(collection, item).map(|a| a.owner) } - fn class_owner(class: &Self::ClassId) -> Option<::AccountId> { - Class::::get(class).map(|a| a.owner) + fn collection_owner(collection: &Self::CollectionId) -> Option<::AccountId> { + Collection::::get(collection).map(|a| a.owner) } - /// Returns the attribute value of `instance` of `class` corresponding to `key`. + /// Returns the attribute value of `item` of `collection` corresponding to `key`. /// - /// When `key` is empty, we return the instance metadata value. + /// When `key` is empty, we return the item metadata value. /// /// By default this is `None`; no attributes are defined. fn attribute( - class: &Self::ClassId, - instance: &Self::InstanceId, + collection: &Self::CollectionId, + item: &Self::ItemId, key: &[u8], ) -> Option> { if key.is_empty() { - // We make the empty key map to the instance metadata value. - InstanceMetadataOf::::get(class, instance).map(|m| m.data.into()) + // We make the empty key map to the item metadata value. + ItemMetadataOf::::get(collection, item).map(|m| m.data.into()) } else { let key = BoundedSlice::<_, _>::try_from(key).ok()?; - Attribute::::get((class, Some(instance), key)).map(|a| a.0.into()) + Attribute::::get((collection, Some(item), key)).map(|a| a.0.into()) } } - /// Returns the attribute value of `instance` of `class` corresponding to `key`. + /// Returns the attribute value of `item` of `collection` corresponding to `key`. /// - /// When `key` is empty, we return the instance metadata value. + /// When `key` is empty, we return the item metadata value. /// /// By default this is `None`; no attributes are defined. - fn class_attribute(class: &Self::ClassId, key: &[u8]) -> Option> { + fn collection_attribute(collection: &Self::CollectionId, key: &[u8]) -> Option> { if key.is_empty() { - // We make the empty key map to the instance metadata value. - ClassMetadataOf::::get(class).map(|m| m.data.into()) + // We make the empty key map to the item metadata value. + CollectionMetadataOf::::get(collection).map(|m| m.data.into()) } else { let key = BoundedSlice::<_, _>::try_from(key).ok()?; - Attribute::::get((class, Option::::None, key)).map(|a| a.0.into()) + Attribute::::get((collection, Option::::None, key)).map(|a| a.0.into()) } } - /// Returns `true` if the asset `instance` of `class` may be transferred. + /// Returns `true` if the `item` of `collection` may be transferred. /// - /// Default implementation is that all assets are transferable. - fn can_transfer(class: &Self::ClassId, instance: &Self::InstanceId) -> bool { - match (Class::::get(class), Asset::::get(class, instance)) { + /// Default implementation is that all items are transferable. + fn can_transfer(collection: &Self::CollectionId, item: &Self::ItemId) -> bool { + match (Collection::::get(collection), Item::::get(collection, item)) { (Some(cd), Some(id)) if !cd.is_frozen && !id.is_frozen => true, _ => false, } @@ -86,19 +86,19 @@ impl, I: 'static> Inspect<::AccountId> for Palle } impl, I: 'static> Create<::AccountId> for Pallet { - /// Create a `class` of nonfungible assets to be owned by `who` and managed by `admin`. - fn create_class( - class: &Self::ClassId, + /// Create a `collection` of nonfungible items to be owned by `who` and managed by `admin`. + fn create_collection( + collection: &Self::CollectionId, who: &T::AccountId, admin: &T::AccountId, ) -> DispatchResult { - Self::do_create_class( - *class, + Self::do_create_collection( + *collection, who.clone(), admin.clone(), - T::ClassDeposit::get(), + T::CollectionDeposit::get(), false, - Event::Created { class: *class, creator: who.clone(), owner: admin.clone() }, + Event::Created { collection: *collection, creator: who.clone(), owner: admin.clone() }, ) } } @@ -106,34 +106,34 @@ impl, I: 'static> Create<::AccountId> for Pallet impl, I: 'static> Destroy<::AccountId> for Pallet { type DestroyWitness = DestroyWitness; - fn get_destroy_witness(class: &Self::ClassId) -> Option { - Class::::get(class).map(|a| a.destroy_witness()) + fn get_destroy_witness(collection: &Self::CollectionId) -> Option { + Collection::::get(collection).map(|a| a.destroy_witness()) } fn destroy( - class: Self::ClassId, + collection: Self::CollectionId, witness: Self::DestroyWitness, maybe_check_owner: Option, ) -> Result { - Self::do_destroy_class(class, witness, maybe_check_owner) + Self::do_destroy_collection(collection, witness, maybe_check_owner) } } impl, I: 'static> Mutate<::AccountId> for Pallet { fn mint_into( - class: &Self::ClassId, - instance: &Self::InstanceId, + collection: &Self::CollectionId, + item: &Self::ItemId, who: &T::AccountId, ) -> DispatchResult { - Self::do_mint(*class, *instance, who.clone(), |_| Ok(())) + Self::do_mint(*collection, *item, who.clone(), |_| Ok(())) } fn burn( - class: &Self::ClassId, - instance: &Self::InstanceId, + collection: &Self::CollectionId, + item: &Self::ItemId, maybe_check_owner: Option<&T::AccountId>, ) -> DispatchResult { - Self::do_burn(*class, *instance, |_, d| { + Self::do_burn(*collection, *item, |_, d| { if let Some(check_owner) = maybe_check_owner { if &d.owner != check_owner { return Err(Error::::NoPermission.into()) @@ -146,43 +146,43 @@ impl, I: 'static> Mutate<::AccountId> for Pallet impl, I: 'static> Transfer for Pallet { fn transfer( - class: &Self::ClassId, - instance: &Self::InstanceId, + collection: &Self::CollectionId, + item: &Self::ItemId, destination: &T::AccountId, ) -> DispatchResult { - Self::do_transfer(*class, *instance, destination.clone(), |_, _| Ok(())) + Self::do_transfer(*collection, *item, destination.clone(), |_, _| Ok(())) } } impl, I: 'static> InspectEnumerable for Pallet { - /// Returns an iterator of the asset classes in existence. + /// Returns an iterator of the collections in existence. /// /// NOTE: iterating this list invokes a storage read per item. - fn classes() -> Box> { - Box::new(ClassMetadataOf::::iter_keys()) + fn collections() -> Box> { + Box::new(CollectionMetadataOf::::iter_keys()) } - /// Returns an iterator of the instances of an asset `class` in existence. + /// Returns an iterator of the items of a `collection` in existence. /// /// NOTE: iterating this list invokes a storage read per item. - fn instances(class: &Self::ClassId) -> Box> { - Box::new(InstanceMetadataOf::::iter_key_prefix(class)) + fn items(collection: &Self::CollectionId) -> Box> { + Box::new(ItemMetadataOf::::iter_key_prefix(collection)) } - /// Returns an iterator of the asset instances of all classes owned by `who`. + /// Returns an iterator of the items of all collections owned by `who`. /// /// NOTE: iterating this list invokes a storage read per item. - fn owned(who: &T::AccountId) -> Box> { + fn owned(who: &T::AccountId) -> Box> { Box::new(Account::::iter_key_prefix((who,))) } - /// Returns an iterator of the asset instances of `class` owned by `who`. + /// Returns an iterator of the items of `collection` owned by `who`. /// /// NOTE: iterating this list invokes a storage read per item. - fn owned_in_class( - class: &Self::ClassId, + fn owned_in_collection( + collection: &Self::CollectionId, who: &T::AccountId, - ) -> Box> { - Box::new(Account::::iter_key_prefix((who, class))) + ) -> Box> { + Box::new(Account::::iter_key_prefix((who, collection))) } } diff --git a/substrate/frame/uniques/src/lib.rs b/substrate/frame/uniques/src/lib.rs index a360a02ebc..0a8cf20141 100644 --- a/substrate/frame/uniques/src/lib.rs +++ b/substrate/frame/uniques/src/lib.rs @@ -15,9 +15,9 @@ // See the License for the specific language governing permissions and // limitations under the License. -//! # Unique (Assets) Module +//! # Unique (Items) Module //! -//! A simple, secure module for dealing with non-fungible assets. +//! A simple, secure module for dealing with non-fungible items. //! //! ## Related Modules //! @@ -67,16 +67,16 @@ pub mod pallet { pub struct Pallet(_); #[cfg(feature = "runtime-benchmarks")] - pub trait BenchmarkHelper { - fn class(i: u16) -> ClassId; - fn instance(i: u16) -> InstanceId; + pub trait BenchmarkHelper { + fn collection(i: u16) -> CollectionId; + fn item(i: u16) -> ItemId; } #[cfg(feature = "runtime-benchmarks")] - impl, InstanceId: From> BenchmarkHelper for () { - fn class(i: u16) -> ClassId { + impl, ItemId: From> BenchmarkHelper for () { + fn collection(i: u16) -> CollectionId { i.into() } - fn instance(i: u16) -> InstanceId { + fn item(i: u16) -> ItemId { i.into() } } @@ -87,43 +87,43 @@ pub mod pallet { /// The overarching event type. type Event: From> + IsType<::Event>; - /// Identifier for the class of asset. - type ClassId: Member + Parameter + MaxEncodedLen + Copy; + /// Identifier for the collection of item. + type CollectionId: Member + Parameter + MaxEncodedLen + Copy; - /// The type used to identify a unique asset within an asset class. - type InstanceId: Member + Parameter + MaxEncodedLen + Copy; + /// The type used to identify a unique item within a collection. + type ItemId: Member + Parameter + MaxEncodedLen + Copy; /// The currency mechanism, used for paying for reserves. type Currency: ReservableCurrency; - /// The origin which may forcibly create or destroy an asset or otherwise alter privileged + /// The origin which may forcibly create or destroy an item or otherwise alter privileged /// attributes. type ForceOrigin: EnsureOrigin; - /// Standard class creation is only allowed if the origin attempting it and the class are - /// in this set. + /// Standard collection creation is only allowed if the origin attempting it and the + /// collection are in this set. type CreateOrigin: EnsureOriginWithArg< Success = Self::AccountId, Self::Origin, - Self::ClassId, + Self::CollectionId, >; /// Locker trait to enable Locking mechanism downstream. - type Locker: Locker; + type Locker: Locker; - /// The basic amount of funds that must be reserved for an asset class. + /// The basic amount of funds that must be reserved for collection. #[pallet::constant] - type ClassDeposit: Get>; + type CollectionDeposit: Get>; - /// The basic amount of funds that must be reserved for an asset instance. + /// The basic amount of funds that must be reserved for an item. #[pallet::constant] - type InstanceDeposit: Get>; + type ItemDeposit: Get>; - /// The basic amount of funds that must be reserved when adding metadata to your asset. + /// The basic amount of funds that must be reserved when adding metadata to your item. #[pallet::constant] type MetadataDepositBase: Get>; - /// The basic amount of funds that must be reserved when adding an attribute to an asset. + /// The basic amount of funds that must be reserved when adding an attribute to an item. #[pallet::constant] type AttributeDepositBase: Get>; @@ -146,94 +146,99 @@ pub mod pallet { #[cfg(feature = "runtime-benchmarks")] /// A set of helper functions for benchmarking. - type Helper: BenchmarkHelper; + type Helper: BenchmarkHelper; /// Weight information for extrinsics in this pallet. type WeightInfo: WeightInfo; } #[pallet::storage] - /// Details of an asset class. - pub(super) type Class, I: 'static = ()> = StorageMap< + #[pallet::storage_prefix = "Class"] + /// Details of a collection. + pub(super) type Collection, I: 'static = ()> = StorageMap< _, Blake2_128Concat, - T::ClassId, - ClassDetails>, + T::CollectionId, + CollectionDetails>, >; #[pallet::storage] - /// The class, if any, of which an account is willing to take ownership. + /// The collection, if any, of which an account is willing to take ownership. pub(super) type OwnershipAcceptance, I: 'static = ()> = - StorageMap<_, Blake2_128Concat, T::AccountId, T::ClassId>; + StorageMap<_, Blake2_128Concat, T::AccountId, T::CollectionId>; #[pallet::storage] - /// The assets held by any given account; set out this way so that assets owned by a single + /// The items held by any given account; set out this way so that items owned by a single /// account can be enumerated. pub(super) type Account, I: 'static = ()> = StorageNMap< _, ( NMapKey, // owner - NMapKey, - NMapKey, + NMapKey, + NMapKey, ), (), OptionQuery, >; #[pallet::storage] - /// The classes owned by any given account; set out this way so that classes owned by a single - /// account can be enumerated. - pub(super) type ClassAccount, I: 'static = ()> = StorageDoubleMap< + #[pallet::storage_prefix = "ClassAccount"] + /// The collections owned by any given account; set out this way so that collections owned by + /// a single account can be enumerated. + pub(super) type CollectionAccount, I: 'static = ()> = StorageDoubleMap< _, Blake2_128Concat, T::AccountId, Blake2_128Concat, - T::ClassId, + T::CollectionId, (), OptionQuery, >; #[pallet::storage] - /// The assets in existence and their ownership details. - pub(super) type Asset, I: 'static = ()> = StorageDoubleMap< + #[pallet::storage_prefix = "Asset"] + /// The items in existence and their ownership details. + pub(super) type Item, I: 'static = ()> = StorageDoubleMap< _, Blake2_128Concat, - T::ClassId, + T::CollectionId, Blake2_128Concat, - T::InstanceId, - InstanceDetails>, + T::ItemId, + ItemDetails>, OptionQuery, >; #[pallet::storage] - /// Metadata of an asset class. - pub(super) type ClassMetadataOf, I: 'static = ()> = StorageMap< + #[pallet::storage_prefix = "ClassMetadataOf"] + /// Metadata of a collection. + pub(super) type CollectionMetadataOf, I: 'static = ()> = StorageMap< _, Blake2_128Concat, - T::ClassId, - ClassMetadata, T::StringLimit>, + T::CollectionId, + CollectionMetadata, T::StringLimit>, OptionQuery, >; #[pallet::storage] - /// Metadata of an asset instance. - pub(super) type InstanceMetadataOf, I: 'static = ()> = StorageDoubleMap< + #[pallet::storage_prefix = "InstanceMetadataOf"] + /// Metadata of an item. + pub(super) type ItemMetadataOf, I: 'static = ()> = StorageDoubleMap< _, Blake2_128Concat, - T::ClassId, + T::CollectionId, Blake2_128Concat, - T::InstanceId, - InstanceMetadata, T::StringLimit>, + T::ItemId, + ItemMetadata, T::StringLimit>, OptionQuery, >; #[pallet::storage] - /// Metadata of an asset class. + /// Attributes of a collection. pub(super) type Attribute, I: 'static = ()> = StorageNMap< _, ( - NMapKey, - NMapKey>, + NMapKey, + NMapKey>, NMapKey>, ), (BoundedVec, DepositBalanceOf), @@ -243,109 +248,109 @@ pub mod pallet { #[pallet::event] #[pallet::generate_deposit(pub(super) fn deposit_event)] pub enum Event, I: 'static = ()> { - /// An asset class was created. - Created { class: T::ClassId, creator: T::AccountId, owner: T::AccountId }, - /// An asset class was force-created. - ForceCreated { class: T::ClassId, owner: T::AccountId }, - /// An asset `class` was destroyed. - Destroyed { class: T::ClassId }, - /// An asset `instance` was issued. - Issued { class: T::ClassId, instance: T::InstanceId, owner: T::AccountId }, - /// An asset `instance` was transferred. + /// A `collection` was created. + Created { collection: T::CollectionId, creator: T::AccountId, owner: T::AccountId }, + /// A `collection` was force-created. + ForceCreated { collection: T::CollectionId, owner: T::AccountId }, + /// A `collection` was destroyed. + Destroyed { collection: T::CollectionId }, + /// An `item` was issued. + Issued { collection: T::CollectionId, item: T::ItemId, owner: T::AccountId }, + /// An `item` was transferred. Transferred { - class: T::ClassId, - instance: T::InstanceId, + collection: T::CollectionId, + item: T::ItemId, from: T::AccountId, to: T::AccountId, }, - /// An asset `instance` was destroyed. - Burned { class: T::ClassId, instance: T::InstanceId, owner: T::AccountId }, - /// Some asset `instance` was frozen. - Frozen { class: T::ClassId, instance: T::InstanceId }, - /// Some asset `instance` was thawed. - Thawed { class: T::ClassId, instance: T::InstanceId }, - /// Some asset `class` was frozen. - ClassFrozen { class: T::ClassId }, - /// Some asset `class` was thawed. - ClassThawed { class: T::ClassId }, + /// An `item` was destroyed. + Burned { collection: T::CollectionId, item: T::ItemId, owner: T::AccountId }, + /// Some `item` was frozen. + Frozen { collection: T::CollectionId, item: T::ItemId }, + /// Some `item` was thawed. + Thawed { collection: T::CollectionId, item: T::ItemId }, + /// Some `collection` was frozen. + CollectionFrozen { collection: T::CollectionId }, + /// Some `collection` was thawed. + CollectionThawed { collection: T::CollectionId }, /// The owner changed. - OwnerChanged { class: T::ClassId, new_owner: T::AccountId }, + OwnerChanged { collection: T::CollectionId, new_owner: T::AccountId }, /// The management team changed. TeamChanged { - class: T::ClassId, + collection: T::CollectionId, issuer: T::AccountId, admin: T::AccountId, freezer: T::AccountId, }, - /// An `instance` of an asset `class` has been approved by the `owner` for transfer by a - /// `delegate`. + /// An `item` of a `collection` has been approved by the `owner` for transfer by + /// a `delegate`. ApprovedTransfer { - class: T::ClassId, - instance: T::InstanceId, + collection: T::CollectionId, + item: T::ItemId, owner: T::AccountId, delegate: T::AccountId, }, - /// An approval for a `delegate` account to transfer the `instance` of an asset `class` was - /// cancelled by its `owner`. + /// An approval for a `delegate` account to transfer the `item` of an item + /// `collection` was cancelled by its `owner`. ApprovalCancelled { - class: T::ClassId, - instance: T::InstanceId, + collection: T::CollectionId, + item: T::ItemId, owner: T::AccountId, delegate: T::AccountId, }, - /// An asset `class` has had its attributes changed by the `Force` origin. - AssetStatusChanged { class: T::ClassId }, - /// New metadata has been set for an asset class. - ClassMetadataSet { - class: T::ClassId, + /// A `collection` has had its attributes changed by the `Force` origin. + ItemStatusChanged { collection: T::CollectionId }, + /// New metadata has been set for a `collection`. + CollectionMetadataSet { + collection: T::CollectionId, data: BoundedVec, is_frozen: bool, }, - /// Metadata has been cleared for an asset class. - ClassMetadataCleared { class: T::ClassId }, - /// New metadata has been set for an asset instance. + /// Metadata has been cleared for a `collection`. + CollectionMetadataCleared { collection: T::CollectionId }, + /// New metadata has been set for an item. MetadataSet { - class: T::ClassId, - instance: T::InstanceId, + collection: T::CollectionId, + item: T::ItemId, data: BoundedVec, is_frozen: bool, }, - /// Metadata has been cleared for an asset instance. - MetadataCleared { class: T::ClassId, instance: T::InstanceId }, - /// Metadata has been cleared for an asset instance. - Redeposited { class: T::ClassId, successful_instances: Vec }, - /// New attribute metadata has been set for an asset class or instance. + /// Metadata has been cleared for an item. + MetadataCleared { collection: T::CollectionId, item: T::ItemId }, + /// Metadata has been cleared for an item. + Redeposited { collection: T::CollectionId, successful_items: Vec }, + /// New attribute metadata has been set for a `collection` or `item`. AttributeSet { - class: T::ClassId, - maybe_instance: Option, + collection: T::CollectionId, + maybe_item: Option, key: BoundedVec, value: BoundedVec, }, - /// Attribute metadata has been cleared for an asset class or instance. + /// Attribute metadata has been cleared for a `collection` or `item`. AttributeCleared { - class: T::ClassId, - maybe_instance: Option, + collection: T::CollectionId, + maybe_item: Option, key: BoundedVec, }, /// Ownership acceptance has changed for an account. - OwnershipAcceptanceChanged { who: T::AccountId, maybe_class: Option }, + OwnershipAcceptanceChanged { who: T::AccountId, maybe_collection: Option }, } #[pallet::error] pub enum Error { /// The signing account has no permission to do the operation. NoPermission, - /// The given asset ID is unknown. - UnknownClass, - /// The asset instance ID has already been used for an asset. + /// The given item ID is unknown. + UnknownCollection, + /// The item ID has already been used for an item. AlreadyExists, /// The owner turned out to be different to what was expected. WrongOwner, /// Invalid witness data given. BadWitness, - /// The asset ID is already taken. + /// The item ID is already taken. InUse, - /// The asset instance or class is frozen. + /// The item or collection is frozen. Frozen, /// The delegate turned out to be different to what was expected. WrongDelegate, @@ -353,38 +358,38 @@ pub mod pallet { NoDelegate, /// No approval exists that would allow the transfer. Unapproved, - /// The named owner has not signed ownership of the class is acceptable. + /// The named owner has not signed ownership of the collection is acceptable. Unaccepted, - /// The asset instance is locked. + /// The item is locked. Locked, } impl, I: 'static> Pallet { - /// Get the owner of the asset instance, if the asset exists. - pub fn owner(class: T::ClassId, instance: T::InstanceId) -> Option { - Asset::::get(class, instance).map(|i| i.owner) + /// Get the owner of the item, if the item exists. + pub fn owner(collection: T::CollectionId, item: T::ItemId) -> Option { + Item::::get(collection, item).map(|i| i.owner) } - /// Get the owner of the asset instance, if the asset exists. - pub fn class_owner(class: T::ClassId) -> Option { - Class::::get(class).map(|i| i.owner) + /// Get the owner of the item, if the item exists. + pub fn collection_owner(collection: T::CollectionId) -> Option { + Collection::::get(collection).map(|i| i.owner) } } #[pallet::call] impl, I: 'static> Pallet { - /// Issue a new class of non-fungible assets from a public origin. + /// Issue a new collection of non-fungible items from a public origin. /// - /// This new asset class has no assets initially and its owner is the origin. + /// This new collection has no items initially and its owner is the origin. /// /// The origin must be Signed and the sender must have sufficient funds free. /// - /// `AssetDeposit` funds of sender are reserved. + /// `ItemDeposit` funds of sender are reserved. /// /// Parameters: - /// - `class`: The identifier of the new asset class. This must not be currently in use. - /// - `admin`: The admin of this class of assets. The admin is the initial address of each - /// member of the asset class's admin team. + /// - `collection`: The identifier of the new collection. This must not be currently in use. + /// - `admin`: The admin of this collection. The admin is the initial address of each + /// member of the collection's admin team. /// /// Emits `Created` event when successful. /// @@ -392,33 +397,34 @@ pub mod pallet { #[pallet::weight(T::WeightInfo::create())] pub fn create( origin: OriginFor, - class: T::ClassId, + collection: T::CollectionId, admin: ::Source, ) -> DispatchResult { - let owner = T::CreateOrigin::ensure_origin(origin, &class)?; + let owner = T::CreateOrigin::ensure_origin(origin, &collection)?; let admin = T::Lookup::lookup(admin)?; - Self::do_create_class( - class, + Self::do_create_collection( + collection, owner.clone(), admin.clone(), - T::ClassDeposit::get(), + T::CollectionDeposit::get(), false, - Event::Created { class, creator: owner, owner: admin }, + Event::Created { collection, creator: owner, owner: admin }, ) } - /// Issue a new class of non-fungible assets from a privileged origin. + /// Issue a new collection of non-fungible items from a privileged origin. /// - /// This new asset class has no assets initially. + /// This new collection has no items initially. /// /// The origin must conform to `ForceOrigin`. /// /// Unlike `create`, no funds are reserved. /// - /// - `class`: The identifier of the new asset. This must not be currently in use. - /// - `owner`: The owner of this class of assets. The owner has full superuser permissions - /// over this asset, but may later change and configure the permissions using + /// - `collection`: The identifier of the new item. This must not be currently in use. + /// - `owner`: The owner of this collection of items. The owner has full superuser + /// permissions + /// over this item, but may later change and configure the permissions using /// `transfer_ownership` and `set_team`. /// /// Emits `ForceCreated` event when successful. @@ -427,69 +433,69 @@ pub mod pallet { #[pallet::weight(T::WeightInfo::force_create())] pub fn force_create( origin: OriginFor, - class: T::ClassId, + collection: T::CollectionId, owner: ::Source, free_holding: bool, ) -> DispatchResult { T::ForceOrigin::ensure_origin(origin)?; let owner = T::Lookup::lookup(owner)?; - Self::do_create_class( - class, + Self::do_create_collection( + collection, owner.clone(), owner.clone(), Zero::zero(), free_holding, - Event::ForceCreated { class, owner }, + Event::ForceCreated { collection, owner }, ) } - /// Destroy a class of fungible assets. + /// Destroy a collection of fungible items. /// /// The origin must conform to `ForceOrigin` or must be `Signed` and the sender must be the - /// owner of the asset `class`. + /// owner of the `collection`. /// - /// - `class`: The identifier of the asset class to be destroyed. - /// - `witness`: Information on the instances minted in the asset class. This must be + /// - `collection`: The identifier of the collection to be destroyed. + /// - `witness`: Information on the items minted in the collection. This must be /// correct. /// /// Emits `Destroyed` event when successful. /// /// Weight: `O(n + m)` where: - /// - `n = witness.instances` - /// - `m = witness.instance_metadatas` + /// - `n = witness.items` + /// - `m = witness.item_metadatas` /// - `a = witness.attributes` #[pallet::weight(T::WeightInfo::destroy( - witness.instances, - witness.instance_metadatas, + witness.items, + witness.item_metadatas, witness.attributes, ))] pub fn destroy( origin: OriginFor, - class: T::ClassId, + collection: T::CollectionId, witness: DestroyWitness, ) -> DispatchResultWithPostInfo { let maybe_check_owner = match T::ForceOrigin::try_origin(origin) { Ok(_) => None, Err(origin) => Some(ensure_signed(origin)?), }; - let details = Self::do_destroy_class(class, witness, maybe_check_owner)?; + let details = Self::do_destroy_collection(collection, witness, maybe_check_owner)?; Ok(Some(T::WeightInfo::destroy( - details.instances, - details.instance_metadatas, + details.items, + details.item_metadatas, details.attributes, )) .into()) } - /// Mint an asset instance of a particular class. + /// Mint an item of a particular collection. /// - /// The origin must be Signed and the sender must be the Issuer of the asset `class`. + /// The origin must be Signed and the sender must be the Issuer of the `collection`. /// - /// - `class`: The class of the asset to be minted. - /// - `instance`: The instance value of the asset to be minted. - /// - `beneficiary`: The initial owner of the minted asset. + /// - `collection`: The collection of the item to be minted. + /// - `item`: The item value of the item to be minted. + /// - `beneficiary`: The initial owner of the minted item. /// /// Emits `Issued` event when successful. /// @@ -497,27 +503,27 @@ pub mod pallet { #[pallet::weight(T::WeightInfo::mint())] pub fn mint( origin: OriginFor, - class: T::ClassId, - instance: T::InstanceId, + collection: T::CollectionId, + item: T::ItemId, owner: ::Source, ) -> DispatchResult { let origin = ensure_signed(origin)?; let owner = T::Lookup::lookup(owner)?; - Self::do_mint(class, instance, owner, |class_details| { - ensure!(class_details.issuer == origin, Error::::NoPermission); + Self::do_mint(collection, item, owner, |collection_details| { + ensure!(collection_details.issuer == origin, Error::::NoPermission); Ok(()) }) } - /// Destroy a single asset instance. + /// Destroy a single item. /// - /// Origin must be Signed and the sender should be the Admin of the asset `class`. + /// Origin must be Signed and the sender should be the Admin of the `collection`. /// - /// - `class`: The class of the asset to be burned. - /// - `instance`: The instance of the asset to be burned. + /// - `collection`: The collection of the item to be burned. + /// - `item`: The item of the item to be burned. /// - `check_owner`: If `Some` then the operation will fail with `WrongOwner` unless the - /// asset is owned by this value. + /// item is owned by this value. /// /// Emits `Burned` with the actual amount burned. /// @@ -526,15 +532,15 @@ pub mod pallet { #[pallet::weight(T::WeightInfo::burn())] pub fn burn( origin: OriginFor, - class: T::ClassId, - instance: T::InstanceId, + collection: T::CollectionId, + item: T::ItemId, check_owner: Option<::Source>, ) -> DispatchResult { let origin = ensure_signed(origin)?; let check_owner = check_owner.map(T::Lookup::lookup).transpose()?; - Self::do_burn(class, instance, |class_details, details| { - let is_permitted = class_details.admin == origin || details.owner == origin; + Self::do_burn(collection, item, |collection_details, details| { + let is_permitted = collection_details.admin == origin || details.owner == origin; ensure!(is_permitted, Error::::NoPermission); ensure!( check_owner.map_or(true, |o| o == details.owner), @@ -544,17 +550,17 @@ pub mod pallet { }) } - /// Move an asset from the sender account to another. + /// Move an item from the sender account to another. /// /// Origin must be Signed and the signing account must be either: - /// - the Admin of the asset `class`; - /// - the Owner of the asset `instance`; - /// - the approved delegate for the asset `instance` (in this case, the approval is reset). + /// - the Admin of the `collection`; + /// - the Owner of the `item`; + /// - the approved delegate for the `item` (in this case, the approval is reset). /// /// Arguments: - /// - `class`: The class of the asset to be transferred. - /// - `instance`: The instance of the asset to be transferred. - /// - `dest`: The account to receive ownership of the asset. + /// - `collection`: The collection of the item to be transferred. + /// - `item`: The item of the item to be transferred. + /// - `dest`: The account to receive ownership of the item. /// /// Emits `Transferred`. /// @@ -562,15 +568,15 @@ pub mod pallet { #[pallet::weight(T::WeightInfo::transfer())] pub fn transfer( origin: OriginFor, - class: T::ClassId, - instance: T::InstanceId, + collection: T::CollectionId, + item: T::ItemId, dest: ::Source, ) -> DispatchResult { let origin = ensure_signed(origin)?; let dest = T::Lookup::lookup(dest)?; - Self::do_transfer(class, instance, dest, |class_details, details| { - if details.owner != origin && class_details.admin != origin { + Self::do_transfer(collection, item, dest, |collection_details, details| { + if details.owner != origin && collection_details.admin != origin { let approved = details.approved.take().map_or(false, |i| i == origin); ensure!(approved, Error::::NoPermission); } @@ -578,79 +584,79 @@ pub mod pallet { }) } - /// Reevaluate the deposits on some assets. + /// Reevaluate the deposits on some items. /// - /// Origin must be Signed and the sender should be the Owner of the asset `class`. + /// Origin must be Signed and the sender should be the Owner of the `collection`. /// - /// - `class`: The class of the asset to be frozen. - /// - `instances`: The instances of the asset class whose deposits will be reevaluated. + /// - `collection`: The collection to be frozen. + /// - `items`: The items of the collection whose deposits will be reevaluated. /// - /// NOTE: This exists as a best-effort function. Any asset instances which are unknown or + /// NOTE: This exists as a best-effort function. Any items which are unknown or /// in the case that the owner account does not have reservable funds to pay for a - /// deposit increase are ignored. Generally the owner isn't going to call this on instances + /// deposit increase are ignored. Generally the owner isn't going to call this on items /// whose existing deposit is less than the refreshed deposit as it would only cost them, /// so it's of little consequence. /// - /// It will still return an error in the case that the class is unknown of the signer is - /// not permitted to call it. + /// It will still return an error in the case that the collection is unknown of the signer + /// is not permitted to call it. /// - /// Weight: `O(instances.len())` - #[pallet::weight(T::WeightInfo::redeposit(instances.len() as u32))] + /// Weight: `O(items.len())` + #[pallet::weight(T::WeightInfo::redeposit(items.len() as u32))] pub fn redeposit( origin: OriginFor, - class: T::ClassId, - instances: Vec, + collection: T::CollectionId, + items: Vec, ) -> DispatchResult { let origin = ensure_signed(origin)?; - let mut class_details = - Class::::get(&class).ok_or(Error::::UnknownClass)?; - ensure!(class_details.owner == origin, Error::::NoPermission); - let deposit = match class_details.free_holding { + let mut collection_details = + Collection::::get(&collection).ok_or(Error::::UnknownCollection)?; + ensure!(collection_details.owner == origin, Error::::NoPermission); + let deposit = match collection_details.free_holding { true => Zero::zero(), - false => T::InstanceDeposit::get(), + false => T::ItemDeposit::get(), }; - let mut successful = Vec::with_capacity(instances.len()); - for instance in instances.into_iter() { - let mut details = match Asset::::get(&class, &instance) { + let mut successful = Vec::with_capacity(items.len()); + for item in items.into_iter() { + let mut details = match Item::::get(&collection, &item) { Some(x) => x, None => continue, }; let old = details.deposit; if old > deposit { - T::Currency::unreserve(&class_details.owner, old - deposit); + T::Currency::unreserve(&collection_details.owner, old - deposit); } else if deposit > old { - if T::Currency::reserve(&class_details.owner, deposit - old).is_err() { - // NOTE: No alterations made to class_details in this iteration so far, so - // this is OK to do. + if T::Currency::reserve(&collection_details.owner, deposit - old).is_err() { + // NOTE: No alterations made to collection_details in this iteration so far, + // so this is OK to do. continue } } else { continue } - class_details.total_deposit.saturating_accrue(deposit); - class_details.total_deposit.saturating_reduce(old); + collection_details.total_deposit.saturating_accrue(deposit); + collection_details.total_deposit.saturating_reduce(old); details.deposit = deposit; - Asset::::insert(&class, &instance, &details); - successful.push(instance); + Item::::insert(&collection, &item, &details); + successful.push(item); } - Class::::insert(&class, &class_details); + Collection::::insert(&collection, &collection_details); Self::deposit_event(Event::::Redeposited { - class, - successful_instances: successful, + collection, + successful_items: successful, }); Ok(()) } - /// Disallow further unprivileged transfer of an asset instance. + /// Disallow further unprivileged transfer of an item. /// - /// Origin must be Signed and the sender should be the Freezer of the asset `class`. + /// Origin must be Signed and the sender should be the Freezer of the `collection`. /// - /// - `class`: The class of the asset to be frozen. - /// - `instance`: The instance of the asset to be frozen. + /// - `collection`: The collection of the item to be frozen. + /// - `item`: The item of the item to be frozen. /// /// Emits `Frozen`. /// @@ -658,29 +664,30 @@ pub mod pallet { #[pallet::weight(T::WeightInfo::freeze())] pub fn freeze( origin: OriginFor, - class: T::ClassId, - instance: T::InstanceId, + collection: T::CollectionId, + item: T::ItemId, ) -> DispatchResult { let origin = ensure_signed(origin)?; let mut details = - Asset::::get(&class, &instance).ok_or(Error::::UnknownClass)?; - let class_details = Class::::get(&class).ok_or(Error::::UnknownClass)?; - ensure!(class_details.freezer == origin, Error::::NoPermission); + Item::::get(&collection, &item).ok_or(Error::::UnknownCollection)?; + let collection_details = + Collection::::get(&collection).ok_or(Error::::UnknownCollection)?; + ensure!(collection_details.freezer == origin, Error::::NoPermission); details.is_frozen = true; - Asset::::insert(&class, &instance, &details); + Item::::insert(&collection, &item, &details); - Self::deposit_event(Event::::Frozen { class, instance }); + Self::deposit_event(Event::::Frozen { collection, item }); Ok(()) } - /// Re-allow unprivileged transfer of an asset instance. + /// Re-allow unprivileged transfer of an item. /// - /// Origin must be Signed and the sender should be the Freezer of the asset `class`. + /// Origin must be Signed and the sender should be the Freezer of the `collection`. /// - /// - `class`: The class of the asset to be thawed. - /// - `instance`: The instance of the asset to be thawed. + /// - `collection`: The collection of the item to be thawed. + /// - `item`: The item of the item to be thawed. /// /// Emits `Thawed`. /// @@ -688,78 +695,85 @@ pub mod pallet { #[pallet::weight(T::WeightInfo::thaw())] pub fn thaw( origin: OriginFor, - class: T::ClassId, - instance: T::InstanceId, + collection: T::CollectionId, + item: T::ItemId, ) -> DispatchResult { let origin = ensure_signed(origin)?; let mut details = - Asset::::get(&class, &instance).ok_or(Error::::UnknownClass)?; - let class_details = Class::::get(&class).ok_or(Error::::UnknownClass)?; - ensure!(class_details.admin == origin, Error::::NoPermission); + Item::::get(&collection, &item).ok_or(Error::::UnknownCollection)?; + let collection_details = + Collection::::get(&collection).ok_or(Error::::UnknownCollection)?; + ensure!(collection_details.admin == origin, Error::::NoPermission); details.is_frozen = false; - Asset::::insert(&class, &instance, &details); + Item::::insert(&collection, &item, &details); - Self::deposit_event(Event::::Thawed { class, instance }); + Self::deposit_event(Event::::Thawed { collection, item }); Ok(()) } - /// Disallow further unprivileged transfers for a whole asset class. + /// Disallow further unprivileged transfers for a whole collection. /// - /// Origin must be Signed and the sender should be the Freezer of the asset `class`. + /// Origin must be Signed and the sender should be the Freezer of the `collection`. /// - /// - `class`: The asset class to be frozen. + /// - `collection`: The collection to be frozen. /// - /// Emits `ClassFrozen`. + /// Emits `CollectionFrozen`. /// /// Weight: `O(1)` - #[pallet::weight(T::WeightInfo::freeze_class())] - pub fn freeze_class(origin: OriginFor, class: T::ClassId) -> DispatchResult { + #[pallet::weight(T::WeightInfo::freeze_collection())] + pub fn freeze_collection( + origin: OriginFor, + collection: T::CollectionId, + ) -> DispatchResult { let origin = ensure_signed(origin)?; - Class::::try_mutate(class, |maybe_details| { - let details = maybe_details.as_mut().ok_or(Error::::UnknownClass)?; + Collection::::try_mutate(collection, |maybe_details| { + let details = maybe_details.as_mut().ok_or(Error::::UnknownCollection)?; ensure!(origin == details.freezer, Error::::NoPermission); details.is_frozen = true; - Self::deposit_event(Event::::ClassFrozen { class }); + Self::deposit_event(Event::::CollectionFrozen { collection }); Ok(()) }) } - /// Re-allow unprivileged transfers for a whole asset class. + /// Re-allow unprivileged transfers for a whole collection. /// - /// Origin must be Signed and the sender should be the Admin of the asset `class`. + /// Origin must be Signed and the sender should be the Admin of the `collection`. /// - /// - `class`: The class to be thawed. + /// - `collection`: The collection to be thawed. /// - /// Emits `ClassThawed`. + /// Emits `CollectionThawed`. /// /// Weight: `O(1)` - #[pallet::weight(T::WeightInfo::thaw_class())] - pub fn thaw_class(origin: OriginFor, class: T::ClassId) -> DispatchResult { + #[pallet::weight(T::WeightInfo::thaw_collection())] + pub fn thaw_collection( + origin: OriginFor, + collection: T::CollectionId, + ) -> DispatchResult { let origin = ensure_signed(origin)?; - Class::::try_mutate(class, |maybe_details| { - let details = maybe_details.as_mut().ok_or(Error::::UnknownClass)?; + Collection::::try_mutate(collection, |maybe_details| { + let details = maybe_details.as_mut().ok_or(Error::::UnknownCollection)?; ensure!(origin == details.admin, Error::::NoPermission); details.is_frozen = false; - Self::deposit_event(Event::::ClassThawed { class }); + Self::deposit_event(Event::::CollectionThawed { collection }); Ok(()) }) } - /// Change the Owner of an asset class. + /// Change the Owner of a collection. /// - /// Origin must be Signed and the sender should be the Owner of the asset `class`. + /// Origin must be Signed and the sender should be the Owner of the `collection`. /// - /// - `class`: The asset class whose owner should be changed. - /// - `owner`: The new Owner of this asset class. They must have called - /// `set_accept_ownership` with `class` in order for this operation to succeed. + /// - `collection`: The collection whose owner should be changed. + /// - `owner`: The new Owner of this collection. They must have called + /// `set_accept_ownership` with `collection` in order for this operation to succeed. /// /// Emits `OwnerChanged`. /// @@ -767,17 +781,17 @@ pub mod pallet { #[pallet::weight(T::WeightInfo::transfer_ownership())] pub fn transfer_ownership( origin: OriginFor, - class: T::ClassId, + collection: T::CollectionId, owner: ::Source, ) -> DispatchResult { let origin = ensure_signed(origin)?; let owner = T::Lookup::lookup(owner)?; - let acceptable_class = OwnershipAcceptance::::get(&owner); - ensure!(acceptable_class.as_ref() == Some(&class), Error::::Unaccepted); + let acceptable_collection = OwnershipAcceptance::::get(&owner); + ensure!(acceptable_collection.as_ref() == Some(&collection), Error::::Unaccepted); - Class::::try_mutate(class, |maybe_details| { - let details = maybe_details.as_mut().ok_or(Error::::UnknownClass)?; + Collection::::try_mutate(collection, |maybe_details| { + let details = maybe_details.as_mut().ok_or(Error::::UnknownCollection)?; ensure!(origin == details.owner, Error::::NoPermission); if details.owner == owner { return Ok(()) @@ -790,24 +804,24 @@ pub mod pallet { details.total_deposit, Reserved, )?; - ClassAccount::::remove(&details.owner, &class); - ClassAccount::::insert(&owner, &class, ()); + CollectionAccount::::remove(&details.owner, &collection); + CollectionAccount::::insert(&owner, &collection, ()); details.owner = owner.clone(); OwnershipAcceptance::::remove(&owner); - Self::deposit_event(Event::OwnerChanged { class, new_owner: owner }); + Self::deposit_event(Event::OwnerChanged { collection, new_owner: owner }); Ok(()) }) } - /// Change the Issuer, Admin and Freezer of an asset class. + /// Change the Issuer, Admin and Freezer of a collection. /// - /// Origin must be Signed and the sender should be the Owner of the asset `class`. + /// Origin must be Signed and the sender should be the Owner of the `collection`. /// - /// - `class`: The asset class whose team should be changed. - /// - `issuer`: The new Issuer of this asset class. - /// - `admin`: The new Admin of this asset class. - /// - `freezer`: The new Freezer of this asset class. + /// - `collection`: The collection whose team should be changed. + /// - `issuer`: The new Issuer of this collection. + /// - `admin`: The new Admin of this collection. + /// - `freezer`: The new Freezer of this collection. /// /// Emits `TeamChanged`. /// @@ -815,7 +829,7 @@ pub mod pallet { #[pallet::weight(T::WeightInfo::set_team())] pub fn set_team( origin: OriginFor, - class: T::ClassId, + collection: T::CollectionId, issuer: ::Source, admin: ::Source, freezer: ::Source, @@ -825,26 +839,26 @@ pub mod pallet { let admin = T::Lookup::lookup(admin)?; let freezer = T::Lookup::lookup(freezer)?; - Class::::try_mutate(class, |maybe_details| { - let details = maybe_details.as_mut().ok_or(Error::::UnknownClass)?; + Collection::::try_mutate(collection, |maybe_details| { + let details = maybe_details.as_mut().ok_or(Error::::UnknownCollection)?; ensure!(origin == details.owner, Error::::NoPermission); details.issuer = issuer.clone(); details.admin = admin.clone(); details.freezer = freezer.clone(); - Self::deposit_event(Event::TeamChanged { class, issuer, admin, freezer }); + Self::deposit_event(Event::TeamChanged { collection, issuer, admin, freezer }); Ok(()) }) } - /// Approve an instance to be transferred by a delegated third-party account. + /// Approve an item to be transferred by a delegated third-party account. /// - /// Origin must be Signed and must be the owner of the asset `instance`. + /// Origin must be Signed and must be the owner of the `item`. /// - /// - `class`: The class of the asset to be approved for delegated transfer. - /// - `instance`: The instance of the asset to be approved for delegated transfer. - /// - `delegate`: The account to delegate permission to transfer the asset. + /// - `collection`: The collection of the item to be approved for delegated transfer. + /// - `item`: The item of the item to be approved for delegated transfer. + /// - `delegate`: The account to delegate permission to transfer the item. /// /// Emits `ApprovedTransfer` on success. /// @@ -852,8 +866,8 @@ pub mod pallet { #[pallet::weight(T::WeightInfo::approve_transfer())] pub fn approve_transfer( origin: OriginFor, - class: T::ClassId, - instance: T::InstanceId, + collection: T::CollectionId, + item: T::ItemId, delegate: ::Source, ) -> DispatchResult { let maybe_check: Option = T::ForceOrigin::try_origin(origin) @@ -862,22 +876,23 @@ pub mod pallet { let delegate = T::Lookup::lookup(delegate)?; - let class_details = Class::::get(&class).ok_or(Error::::UnknownClass)?; + let collection_details = + Collection::::get(&collection).ok_or(Error::::UnknownCollection)?; let mut details = - Asset::::get(&class, &instance).ok_or(Error::::UnknownClass)?; + Item::::get(&collection, &item).ok_or(Error::::UnknownCollection)?; if let Some(check) = maybe_check { - let permitted = check == class_details.admin || check == details.owner; + let permitted = check == collection_details.admin || check == details.owner; ensure!(permitted, Error::::NoPermission); } details.approved = Some(delegate); - Asset::::insert(&class, &instance, &details); + Item::::insert(&collection, &item, &details); let delegate = details.approved.expect("set as Some above; qed"); Self::deposit_event(Event::ApprovedTransfer { - class, - instance, + collection, + item, owner: details.owner, delegate, }); @@ -885,16 +900,16 @@ pub mod pallet { Ok(()) } - /// Cancel the prior approval for the transfer of an asset by a delegate. + /// Cancel the prior approval for the transfer of an item by a delegate. /// /// Origin must be either: /// - the `Force` origin; - /// - `Signed` with the signer being the Admin of the asset `class`; - /// - `Signed` with the signer being the Owner of the asset `instance`; + /// - `Signed` with the signer being the Admin of the `collection`; + /// - `Signed` with the signer being the Owner of the `item`; /// /// Arguments: - /// - `class`: The class of the asset of whose approval will be cancelled. - /// - `instance`: The instance of the asset of whose approval will be cancelled. + /// - `collection`: The collection of the item of whose approval will be cancelled. + /// - `item`: The item of the item of whose approval will be cancelled. /// - `maybe_check_delegate`: If `Some` will ensure that the given account is the one to /// which permission of transfer is delegated. /// @@ -904,19 +919,20 @@ pub mod pallet { #[pallet::weight(T::WeightInfo::cancel_approval())] pub fn cancel_approval( origin: OriginFor, - class: T::ClassId, - instance: T::InstanceId, + collection: T::CollectionId, + item: T::ItemId, maybe_check_delegate: Option<::Source>, ) -> DispatchResult { let maybe_check: Option = T::ForceOrigin::try_origin(origin) .map(|_| None) .or_else(|origin| ensure_signed(origin).map(Some).map_err(DispatchError::from))?; - let class_details = Class::::get(&class).ok_or(Error::::UnknownClass)?; + let collection_details = + Collection::::get(&collection).ok_or(Error::::UnknownCollection)?; let mut details = - Asset::::get(&class, &instance).ok_or(Error::::UnknownClass)?; + Item::::get(&collection, &item).ok_or(Error::::UnknownCollection)?; if let Some(check) = maybe_check { - let permitted = check == class_details.admin || check == details.owner; + let permitted = check == collection_details.admin || check == details.owner; ensure!(permitted, Error::::NoPermission); } let maybe_check_delegate = maybe_check_delegate.map(T::Lookup::lookup).transpose()?; @@ -925,10 +941,10 @@ pub mod pallet { ensure!(check_delegate == old, Error::::WrongDelegate); } - Asset::::insert(&class, &instance, &details); + Item::::insert(&collection, &item, &details); Self::deposit_event(Event::ApprovalCancelled { - class, - instance, + collection, + item, owner: details.owner, delegate: old, }); @@ -936,27 +952,26 @@ pub mod pallet { Ok(()) } - /// Alter the attributes of a given asset. + /// Alter the attributes of a given item. /// /// Origin must be `ForceOrigin`. /// - /// - `class`: The identifier of the asset. - /// - `owner`: The new Owner of this asset. - /// - `issuer`: The new Issuer of this asset. - /// - `admin`: The new Admin of this asset. - /// - `freezer`: The new Freezer of this asset. - /// - `free_holding`: Whether a deposit is taken for holding an instance of this asset - /// class. - /// - `is_frozen`: Whether this asset class is frozen except for permissioned/admin + /// - `collection`: The identifier of the item. + /// - `owner`: The new Owner of this item. + /// - `issuer`: The new Issuer of this item. + /// - `admin`: The new Admin of this item. + /// - `freezer`: The new Freezer of this item. + /// - `free_holding`: Whether a deposit is taken for holding an item of this collection. + /// - `is_frozen`: Whether this collection is frozen except for permissioned/admin /// instructions. /// - /// Emits `AssetStatusChanged` with the identity of the asset. + /// Emits `ItemStatusChanged` with the identity of the item. /// /// Weight: `O(1)` - #[pallet::weight(T::WeightInfo::force_asset_status())] - pub fn force_asset_status( + #[pallet::weight(T::WeightInfo::force_item_status())] + pub fn force_item_status( origin: OriginFor, - class: T::ClassId, + collection: T::CollectionId, owner: ::Source, issuer: ::Source, admin: ::Source, @@ -966,36 +981,36 @@ pub mod pallet { ) -> DispatchResult { T::ForceOrigin::ensure_origin(origin)?; - Class::::try_mutate(class, |maybe_asset| { - let mut asset = maybe_asset.take().ok_or(Error::::UnknownClass)?; - let old_owner = asset.owner; + Collection::::try_mutate(collection, |maybe_item| { + let mut item = maybe_item.take().ok_or(Error::::UnknownCollection)?; + let old_owner = item.owner; let new_owner = T::Lookup::lookup(owner)?; - asset.owner = new_owner.clone(); - asset.issuer = T::Lookup::lookup(issuer)?; - asset.admin = T::Lookup::lookup(admin)?; - asset.freezer = T::Lookup::lookup(freezer)?; - asset.free_holding = free_holding; - asset.is_frozen = is_frozen; - *maybe_asset = Some(asset); - ClassAccount::::remove(&old_owner, &class); - ClassAccount::::insert(&new_owner, &class, ()); + item.owner = new_owner.clone(); + item.issuer = T::Lookup::lookup(issuer)?; + item.admin = T::Lookup::lookup(admin)?; + item.freezer = T::Lookup::lookup(freezer)?; + item.free_holding = free_holding; + item.is_frozen = is_frozen; + *maybe_item = Some(item); + CollectionAccount::::remove(&old_owner, &collection); + CollectionAccount::::insert(&new_owner, &collection, ()); - Self::deposit_event(Event::AssetStatusChanged { class }); + Self::deposit_event(Event::ItemStatusChanged { collection }); Ok(()) }) } - /// Set an attribute for an asset class or instance. + /// Set an attribute for a collection or item. /// /// Origin must be either `ForceOrigin` or Signed and the sender should be the Owner of the - /// asset `class`. + /// `collection`. /// /// If the origin is Signed, then funds of signer are reserved according to the formula: /// `MetadataDepositBase + DepositPerByte * (key.len + value.len)` taking into /// account any already reserved funds. /// - /// - `class`: The identifier of the asset class whose instance's metadata to set. - /// - `maybe_instance`: The identifier of the asset instance whose metadata to set. + /// - `collection`: The identifier of the collection whose item's metadata to set. + /// - `maybe_item`: The identifier of the item whose metadata to set. /// - `key`: The key of the attribute. /// - `value`: The value to which to set the attribute. /// @@ -1005,8 +1020,8 @@ pub mod pallet { #[pallet::weight(T::WeightInfo::set_attribute())] pub fn set_attribute( origin: OriginFor, - class: T::ClassId, - maybe_instance: Option, + collection: T::CollectionId, + maybe_item: Option, key: BoundedVec, value: BoundedVec, ) -> DispatchResult { @@ -1014,52 +1029,51 @@ pub mod pallet { .map(|_| None) .or_else(|origin| ensure_signed(origin).map(Some))?; - let mut class_details = - Class::::get(&class).ok_or(Error::::UnknownClass)?; + let mut collection_details = + Collection::::get(&collection).ok_or(Error::::UnknownCollection)?; if let Some(check_owner) = &maybe_check_owner { - ensure!(check_owner == &class_details.owner, Error::::NoPermission); + ensure!(check_owner == &collection_details.owner, Error::::NoPermission); } - let maybe_is_frozen = match maybe_instance { - None => ClassMetadataOf::::get(class).map(|v| v.is_frozen), - Some(instance) => - InstanceMetadataOf::::get(class, instance).map(|v| v.is_frozen), + let maybe_is_frozen = match maybe_item { + None => CollectionMetadataOf::::get(collection).map(|v| v.is_frozen), + Some(item) => ItemMetadataOf::::get(collection, item).map(|v| v.is_frozen), }; ensure!(!maybe_is_frozen.unwrap_or(false), Error::::Frozen); - let attribute = Attribute::::get((class, maybe_instance, &key)); + let attribute = Attribute::::get((collection, maybe_item, &key)); if attribute.is_none() { - class_details.attributes.saturating_inc(); + collection_details.attributes.saturating_inc(); } let old_deposit = attribute.map_or(Zero::zero(), |m| m.1); - class_details.total_deposit.saturating_reduce(old_deposit); + collection_details.total_deposit.saturating_reduce(old_deposit); let mut deposit = Zero::zero(); - if !class_details.free_holding && maybe_check_owner.is_some() { + if !collection_details.free_holding && maybe_check_owner.is_some() { deposit = T::DepositPerByte::get() .saturating_mul(((key.len() + value.len()) as u32).into()) .saturating_add(T::AttributeDepositBase::get()); } - class_details.total_deposit.saturating_accrue(deposit); + collection_details.total_deposit.saturating_accrue(deposit); if deposit > old_deposit { - T::Currency::reserve(&class_details.owner, deposit - old_deposit)?; + T::Currency::reserve(&collection_details.owner, deposit - old_deposit)?; } else if deposit < old_deposit { - T::Currency::unreserve(&class_details.owner, old_deposit - deposit); + T::Currency::unreserve(&collection_details.owner, old_deposit - deposit); } - Attribute::::insert((&class, maybe_instance, &key), (&value, deposit)); - Class::::insert(class, &class_details); - Self::deposit_event(Event::AttributeSet { class, maybe_instance, key, value }); + Attribute::::insert((&collection, maybe_item, &key), (&value, deposit)); + Collection::::insert(collection, &collection_details); + Self::deposit_event(Event::AttributeSet { collection, maybe_item, key, value }); Ok(()) } - /// Clear an attribute for an asset class or instance. + /// Clear an attribute for a collection or item. /// /// Origin must be either `ForceOrigin` or Signed and the sender should be the Owner of the - /// asset `class`. + /// `collection`. /// - /// Any deposit is freed for the asset class owner. + /// Any deposit is freed for the collection's owner. /// - /// - `class`: The identifier of the asset class whose instance's metadata to clear. - /// - `maybe_instance`: The identifier of the asset instance whose metadata to clear. + /// - `collection`: The identifier of the collection whose item's metadata to clear. + /// - `maybe_item`: The identifier of the item whose metadata to clear. /// - `key`: The key of the attribute. /// /// Emits `AttributeCleared`. @@ -1068,48 +1082,47 @@ pub mod pallet { #[pallet::weight(T::WeightInfo::clear_attribute())] pub fn clear_attribute( origin: OriginFor, - class: T::ClassId, - maybe_instance: Option, + collection: T::CollectionId, + maybe_item: Option, key: BoundedVec, ) -> DispatchResult { let maybe_check_owner = T::ForceOrigin::try_origin(origin) .map(|_| None) .or_else(|origin| ensure_signed(origin).map(Some))?; - let mut class_details = - Class::::get(&class).ok_or(Error::::UnknownClass)?; + let mut collection_details = + Collection::::get(&collection).ok_or(Error::::UnknownCollection)?; if let Some(check_owner) = &maybe_check_owner { - ensure!(check_owner == &class_details.owner, Error::::NoPermission); + ensure!(check_owner == &collection_details.owner, Error::::NoPermission); } - let maybe_is_frozen = match maybe_instance { - None => ClassMetadataOf::::get(class).map(|v| v.is_frozen), - Some(instance) => - InstanceMetadataOf::::get(class, instance).map(|v| v.is_frozen), + let maybe_is_frozen = match maybe_item { + None => CollectionMetadataOf::::get(collection).map(|v| v.is_frozen), + Some(item) => ItemMetadataOf::::get(collection, item).map(|v| v.is_frozen), }; ensure!(!maybe_is_frozen.unwrap_or(false), Error::::Frozen); - if let Some((_, deposit)) = Attribute::::take((class, maybe_instance, &key)) { - class_details.attributes.saturating_dec(); - class_details.total_deposit.saturating_reduce(deposit); - T::Currency::unreserve(&class_details.owner, deposit); - Class::::insert(class, &class_details); - Self::deposit_event(Event::AttributeCleared { class, maybe_instance, key }); + if let Some((_, deposit)) = Attribute::::take((collection, maybe_item, &key)) { + collection_details.attributes.saturating_dec(); + collection_details.total_deposit.saturating_reduce(deposit); + T::Currency::unreserve(&collection_details.owner, deposit); + Collection::::insert(collection, &collection_details); + Self::deposit_event(Event::AttributeCleared { collection, maybe_item, key }); } Ok(()) } - /// Set the metadata for an asset instance. + /// Set the metadata for an item. /// /// Origin must be either `ForceOrigin` or Signed and the sender should be the Owner of the - /// asset `class`. + /// `collection`. /// /// If the origin is Signed, then funds of signer are reserved according to the formula: /// `MetadataDepositBase + DepositPerByte * data.len` taking into /// account any already reserved funds. /// - /// - `class`: The identifier of the asset class whose instance's metadata to set. - /// - `instance`: The identifier of the asset instance whose metadata to set. - /// - `data`: The general information of this asset. Limited in length by `StringLimit`. + /// - `collection`: The identifier of the collection whose item's metadata to set. + /// - `item`: The identifier of the item whose metadata to set. + /// - `data`: The general information of this item. Limited in length by `StringLimit`. /// - `is_frozen`: Whether the metadata should be frozen against further changes. /// /// Emits `MetadataSet`. @@ -1118,8 +1131,8 @@ pub mod pallet { #[pallet::weight(T::WeightInfo::set_metadata())] pub fn set_metadata( origin: OriginFor, - class: T::ClassId, - instance: T::InstanceId, + collection: T::CollectionId, + item: T::ItemId, data: BoundedVec, is_frozen: bool, ) -> DispatchResult { @@ -1127,52 +1140,52 @@ pub mod pallet { .map(|_| None) .or_else(|origin| ensure_signed(origin).map(Some))?; - let mut class_details = - Class::::get(&class).ok_or(Error::::UnknownClass)?; + let mut collection_details = + Collection::::get(&collection).ok_or(Error::::UnknownCollection)?; if let Some(check_owner) = &maybe_check_owner { - ensure!(check_owner == &class_details.owner, Error::::NoPermission); + ensure!(check_owner == &collection_details.owner, Error::::NoPermission); } - InstanceMetadataOf::::try_mutate_exists(class, instance, |metadata| { + ItemMetadataOf::::try_mutate_exists(collection, item, |metadata| { let was_frozen = metadata.as_ref().map_or(false, |m| m.is_frozen); ensure!(maybe_check_owner.is_none() || !was_frozen, Error::::Frozen); if metadata.is_none() { - class_details.instance_metadatas.saturating_inc(); + collection_details.item_metadatas.saturating_inc(); } let old_deposit = metadata.take().map_or(Zero::zero(), |m| m.deposit); - class_details.total_deposit.saturating_reduce(old_deposit); + collection_details.total_deposit.saturating_reduce(old_deposit); let mut deposit = Zero::zero(); - if !class_details.free_holding && maybe_check_owner.is_some() { + if !collection_details.free_holding && maybe_check_owner.is_some() { deposit = T::DepositPerByte::get() .saturating_mul(((data.len()) as u32).into()) .saturating_add(T::MetadataDepositBase::get()); } if deposit > old_deposit { - T::Currency::reserve(&class_details.owner, deposit - old_deposit)?; + T::Currency::reserve(&collection_details.owner, deposit - old_deposit)?; } else if deposit < old_deposit { - T::Currency::unreserve(&class_details.owner, old_deposit - deposit); + T::Currency::unreserve(&collection_details.owner, old_deposit - deposit); } - class_details.total_deposit.saturating_accrue(deposit); + collection_details.total_deposit.saturating_accrue(deposit); - *metadata = Some(InstanceMetadata { deposit, data: data.clone(), is_frozen }); + *metadata = Some(ItemMetadata { deposit, data: data.clone(), is_frozen }); - Class::::insert(&class, &class_details); - Self::deposit_event(Event::MetadataSet { class, instance, data, is_frozen }); + Collection::::insert(&collection, &collection_details); + Self::deposit_event(Event::MetadataSet { collection, item, data, is_frozen }); Ok(()) }) } - /// Clear the metadata for an asset instance. + /// Clear the metadata for an item. /// /// Origin must be either `ForceOrigin` or Signed and the sender should be the Owner of the - /// asset `instance`. + /// `item`. /// - /// Any deposit is freed for the asset class owner. + /// Any deposit is freed for the collection's owner. /// - /// - `class`: The identifier of the asset class whose instance's metadata to clear. - /// - `instance`: The identifier of the asset instance whose metadata to clear. + /// - `collection`: The identifier of the collection whose item's metadata to clear. + /// - `item`: The identifier of the item whose metadata to clear. /// /// Emits `MetadataCleared`. /// @@ -1180,56 +1193,56 @@ pub mod pallet { #[pallet::weight(T::WeightInfo::clear_metadata())] pub fn clear_metadata( origin: OriginFor, - class: T::ClassId, - instance: T::InstanceId, + collection: T::CollectionId, + item: T::ItemId, ) -> DispatchResult { let maybe_check_owner = T::ForceOrigin::try_origin(origin) .map(|_| None) .or_else(|origin| ensure_signed(origin).map(Some))?; - let mut class_details = - Class::::get(&class).ok_or(Error::::UnknownClass)?; + let mut collection_details = + Collection::::get(&collection).ok_or(Error::::UnknownCollection)?; if let Some(check_owner) = &maybe_check_owner { - ensure!(check_owner == &class_details.owner, Error::::NoPermission); + ensure!(check_owner == &collection_details.owner, Error::::NoPermission); } - InstanceMetadataOf::::try_mutate_exists(class, instance, |metadata| { + ItemMetadataOf::::try_mutate_exists(collection, item, |metadata| { let was_frozen = metadata.as_ref().map_or(false, |m| m.is_frozen); ensure!(maybe_check_owner.is_none() || !was_frozen, Error::::Frozen); if metadata.is_some() { - class_details.instance_metadatas.saturating_dec(); + collection_details.item_metadatas.saturating_dec(); } - let deposit = metadata.take().ok_or(Error::::UnknownClass)?.deposit; - T::Currency::unreserve(&class_details.owner, deposit); - class_details.total_deposit.saturating_reduce(deposit); + let deposit = metadata.take().ok_or(Error::::UnknownCollection)?.deposit; + T::Currency::unreserve(&collection_details.owner, deposit); + collection_details.total_deposit.saturating_reduce(deposit); - Class::::insert(&class, &class_details); - Self::deposit_event(Event::MetadataCleared { class, instance }); + Collection::::insert(&collection, &collection_details); + Self::deposit_event(Event::MetadataCleared { collection, item }); Ok(()) }) } - /// Set the metadata for an asset class. + /// Set the metadata for a collection. /// /// Origin must be either `ForceOrigin` or `Signed` and the sender should be the Owner of - /// the asset `class`. + /// the `collection`. /// /// If the origin is `Signed`, then funds of signer are reserved according to the formula: /// `MetadataDepositBase + DepositPerByte * data.len` taking into /// account any already reserved funds. /// - /// - `class`: The identifier of the asset whose metadata to update. - /// - `data`: The general information of this asset. Limited in length by `StringLimit`. + /// - `collection`: The identifier of the item whose metadata to update. + /// - `data`: The general information of this item. Limited in length by `StringLimit`. /// - `is_frozen`: Whether the metadata should be frozen against further changes. /// - /// Emits `ClassMetadataSet`. + /// Emits `CollectionMetadataSet`. /// /// Weight: `O(1)` - #[pallet::weight(T::WeightInfo::set_class_metadata())] - pub fn set_class_metadata( + #[pallet::weight(T::WeightInfo::set_collection_metadata())] + pub fn set_collection_metadata( origin: OriginFor, - class: T::ClassId, + collection: T::CollectionId, data: BoundedVec, is_frozen: bool, ) -> DispatchResult { @@ -1237,12 +1250,13 @@ pub mod pallet { .map(|_| None) .or_else(|origin| ensure_signed(origin).map(Some))?; - let mut details = Class::::get(&class).ok_or(Error::::UnknownClass)?; + let mut details = + Collection::::get(&collection).ok_or(Error::::UnknownCollection)?; if let Some(check_owner) = &maybe_check_owner { ensure!(check_owner == &details.owner, Error::::NoPermission); } - ClassMetadataOf::::try_mutate_exists(class, |metadata| { + CollectionMetadataOf::::try_mutate_exists(collection, |metadata| { let was_frozen = metadata.as_ref().map_or(false, |m| m.is_frozen); ensure!(maybe_check_owner.is_none() || !was_frozen, Error::::Frozen); @@ -1261,67 +1275,71 @@ pub mod pallet { } details.total_deposit.saturating_accrue(deposit); - Class::::insert(&class, details); + Collection::::insert(&collection, details); - *metadata = Some(ClassMetadata { deposit, data: data.clone(), is_frozen }); + *metadata = Some(CollectionMetadata { deposit, data: data.clone(), is_frozen }); - Self::deposit_event(Event::ClassMetadataSet { class, data, is_frozen }); + Self::deposit_event(Event::CollectionMetadataSet { collection, data, is_frozen }); Ok(()) }) } - /// Clear the metadata for an asset class. + /// Clear the metadata for a collection. /// /// Origin must be either `ForceOrigin` or `Signed` and the sender should be the Owner of - /// the asset `class`. + /// the `collection`. /// - /// Any deposit is freed for the asset class owner. + /// Any deposit is freed for the collection's owner. /// - /// - `class`: The identifier of the asset class whose metadata to clear. + /// - `collection`: The identifier of the collection whose metadata to clear. /// - /// Emits `ClassMetadataCleared`. + /// Emits `CollectionMetadataCleared`. /// /// Weight: `O(1)` - #[pallet::weight(T::WeightInfo::clear_class_metadata())] - pub fn clear_class_metadata(origin: OriginFor, class: T::ClassId) -> DispatchResult { + #[pallet::weight(T::WeightInfo::clear_collection_metadata())] + pub fn clear_collection_metadata( + origin: OriginFor, + collection: T::CollectionId, + ) -> DispatchResult { let maybe_check_owner = T::ForceOrigin::try_origin(origin) .map(|_| None) .or_else(|origin| ensure_signed(origin).map(Some))?; - let details = Class::::get(&class).ok_or(Error::::UnknownClass)?; + let details = + Collection::::get(&collection).ok_or(Error::::UnknownCollection)?; if let Some(check_owner) = &maybe_check_owner { ensure!(check_owner == &details.owner, Error::::NoPermission); } - ClassMetadataOf::::try_mutate_exists(class, |metadata| { + CollectionMetadataOf::::try_mutate_exists(collection, |metadata| { let was_frozen = metadata.as_ref().map_or(false, |m| m.is_frozen); ensure!(maybe_check_owner.is_none() || !was_frozen, Error::::Frozen); - let deposit = metadata.take().ok_or(Error::::UnknownClass)?.deposit; + let deposit = metadata.take().ok_or(Error::::UnknownCollection)?.deposit; T::Currency::unreserve(&details.owner, deposit); - Self::deposit_event(Event::ClassMetadataCleared { class }); + Self::deposit_event(Event::CollectionMetadataCleared { collection }); Ok(()) }) } /// Set (or reset) the acceptance of ownership for a particular account. /// - /// Origin must be `Signed` and if `maybe_class` is `Some`, then the signer must have a + /// Origin must be `Signed` and if `maybe_collection` is `Some`, then the signer must have a /// provider reference. /// - /// - `maybe_class`: The identifier of the asset class whose ownership the signer is willing - /// to accept, or if `None`, an indication that the signer is willing to accept no + /// - `maybe_collection`: The identifier of the collection whose ownership the signer is + /// willing to accept, or if `None`, an indication that the signer is willing to accept no /// ownership transferal. /// /// Emits `OwnershipAcceptanceChanged`. #[pallet::weight(T::WeightInfo::set_accept_ownership())] pub fn set_accept_ownership( origin: OriginFor, - maybe_class: Option, + maybe_collection: Option, ) -> DispatchResult { let who = ensure_signed(origin)?; let old = OwnershipAcceptance::::get(&who); - match (old.is_some(), maybe_class.is_some()) { + match (old.is_some(), maybe_collection.is_some()) { (false, true) => { frame_system::Pallet::::inc_consumers(&who)?; }, @@ -1330,12 +1348,12 @@ pub mod pallet { }, _ => {}, } - if let Some(class) = maybe_class.as_ref() { - OwnershipAcceptance::::insert(&who, class); + if let Some(collection) = maybe_collection.as_ref() { + OwnershipAcceptance::::insert(&who, collection); } else { OwnershipAcceptance::::remove(&who); } - Self::deposit_event(Event::OwnershipAcceptanceChanged { who, maybe_class }); + Self::deposit_event(Event::OwnershipAcceptanceChanged { who, maybe_collection }); Ok(()) } } diff --git a/substrate/frame/uniques/src/migration.rs b/substrate/frame/uniques/src/migration.rs index 2bacfc8f43..d301f0a3d1 100644 --- a/substrate/frame/uniques/src/migration.rs +++ b/substrate/frame/uniques/src/migration.rs @@ -34,8 +34,8 @@ pub fn migrate_to_v1, I: 'static, P: GetStorageVersion + PalletInfo if on_chain_storage_version < 1 { let mut count = 0; - for (class, detail) in Class::::iter() { - ClassAccount::::insert(&detail.owner, &class, ()); + for (collection, detail) in Collection::::iter() { + CollectionAccount::::insert(&detail.owner, &collection, ()); count += 1; } StorageVersion::new(1).put::

(); diff --git a/substrate/frame/uniques/src/mock.rs b/substrate/frame/uniques/src/mock.rs index f32540f6ef..ff7b791de4 100644 --- a/substrate/frame/uniques/src/mock.rs +++ b/substrate/frame/uniques/src/mock.rs @@ -15,7 +15,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -//! Test environment for Assets pallet. +//! Test environment for Uniques pallet. use super::*; use crate as pallet_uniques; @@ -86,14 +86,14 @@ impl pallet_balances::Config for Test { impl Config for Test { type Event = Event; - type ClassId = u32; - type InstanceId = u32; + type CollectionId = u32; + type ItemId = u32; type Currency = Balances; type CreateOrigin = AsEnsureOriginWithArg>; type ForceOrigin = frame_system::EnsureRoot; type Locker = (); - type ClassDeposit = ConstU64<2>; - type InstanceDeposit = ConstU64<1>; + type CollectionDeposit = ConstU64<2>; + type ItemDeposit = ConstU64<1>; type MetadataDepositBase = ConstU64<1>; type AttributeDepositBase = ConstU64<1>; type DepositPerByte = ConstU64<1>; diff --git a/substrate/frame/uniques/src/tests.rs b/substrate/frame/uniques/src/tests.rs index 364073ad37..6bd397eefa 100644 --- a/substrate/frame/uniques/src/tests.rs +++ b/substrate/frame/uniques/src/tests.rs @@ -23,13 +23,13 @@ use frame_support::{assert_noop, assert_ok, traits::Currency}; use pallet_balances::Error as BalancesError; use sp_std::prelude::*; -fn assets() -> Vec<(u64, u32, u32)> { +fn items() -> Vec<(u64, u32, u32)> { let mut r: Vec<_> = Account::::iter().map(|x| x.0).collect(); r.sort(); - let mut s: Vec<_> = Asset::::iter().map(|x| (x.2.owner, x.0, x.1)).collect(); + let mut s: Vec<_> = Item::::iter().map(|x| (x.2.owner, x.0, x.1)).collect(); s.sort(); assert_eq!(r, s); - for class in Asset::::iter() + for collection in Item::::iter() .map(|x| x.0) .scan(None, |s, item| { if s.map_or(false, |last| last == item) { @@ -41,17 +41,17 @@ fn assets() -> Vec<(u64, u32, u32)> { }) .flatten() { - let details = Class::::get(class).unwrap(); - let instances = Asset::::iter_prefix(class).count() as u32; - assert_eq!(details.instances, instances); + let details = Collection::::get(collection).unwrap(); + let items = Item::::iter_prefix(collection).count() as u32; + assert_eq!(details.items, items); } r } -fn classes() -> Vec<(u64, u32)> { - let mut r: Vec<_> = ClassAccount::::iter().map(|x| (x.0, x.1)).collect(); +fn collections() -> Vec<(u64, u32)> { + let mut r: Vec<_> = CollectionAccount::::iter().map(|x| (x.0, x.1)).collect(); r.sort(); - let mut s: Vec<_> = Class::::iter().map(|x| (x.1.owner, x.0)).collect(); + let mut s: Vec<_> = Collection::::iter().map(|x| (x.1.owner, x.0)).collect(); s.sort(); assert_eq!(r, s); r @@ -63,8 +63,8 @@ macro_rules! bvec { } } -fn attributes(class: u32) -> Vec<(Option, Vec, Vec)> { - let mut s: Vec<_> = Attribute::::iter_prefix((class,)) +fn attributes(collection: u32) -> Vec<(Option, Vec, Vec)> { + let mut s: Vec<_> = Attribute::::iter_prefix((collection,)) .map(|(k, v)| (k.0, k.1.into(), v.0.into())) .collect(); s.sort(); @@ -74,7 +74,7 @@ fn attributes(class: u32) -> Vec<(Option, Vec, Vec)> { #[test] fn basic_setup_works() { new_test_ext().execute_with(|| { - assert_eq!(assets(), vec![]); + assert_eq!(items(), vec![]); }); } @@ -82,14 +82,14 @@ fn basic_setup_works() { fn basic_minting_should_work() { new_test_ext().execute_with(|| { assert_ok!(Uniques::force_create(Origin::root(), 0, 1, true)); - assert_eq!(classes(), vec![(1, 0)]); + assert_eq!(collections(), vec![(1, 0)]); assert_ok!(Uniques::mint(Origin::signed(1), 0, 42, 1)); - assert_eq!(assets(), vec![(1, 0, 42)]); + assert_eq!(items(), vec![(1, 0, 42)]); assert_ok!(Uniques::force_create(Origin::root(), 1, 2, true)); - assert_eq!(classes(), vec![(1, 0), (2, 1)]); + assert_eq!(collections(), vec![(1, 0), (2, 1)]); assert_ok!(Uniques::mint(Origin::signed(2), 1, 69, 1)); - assert_eq!(assets(), vec![(1, 0, 42), (1, 1, 69)]); + assert_eq!(items(), vec![(1, 0, 42), (1, 1, 69)]); }); } @@ -99,40 +99,40 @@ fn lifecycle_should_work() { Balances::make_free_balance_be(&1, 100); assert_ok!(Uniques::create(Origin::signed(1), 0, 1)); assert_eq!(Balances::reserved_balance(&1), 2); - assert_eq!(classes(), vec![(1, 0)]); - assert_ok!(Uniques::set_class_metadata(Origin::signed(1), 0, bvec![0, 0], false)); + assert_eq!(collections(), vec![(1, 0)]); + assert_ok!(Uniques::set_collection_metadata(Origin::signed(1), 0, bvec![0, 0], false)); assert_eq!(Balances::reserved_balance(&1), 5); - assert!(ClassMetadataOf::::contains_key(0)); + assert!(CollectionMetadataOf::::contains_key(0)); assert_ok!(Uniques::mint(Origin::signed(1), 0, 42, 10)); assert_eq!(Balances::reserved_balance(&1), 6); assert_ok!(Uniques::mint(Origin::signed(1), 0, 69, 20)); assert_eq!(Balances::reserved_balance(&1), 7); - assert_eq!(assets(), vec![(10, 0, 42), (20, 0, 69)]); - assert_eq!(Class::::get(0).unwrap().instances, 2); - assert_eq!(Class::::get(0).unwrap().instance_metadatas, 0); + assert_eq!(items(), vec![(10, 0, 42), (20, 0, 69)]); + assert_eq!(Collection::::get(0).unwrap().items, 2); + assert_eq!(Collection::::get(0).unwrap().item_metadatas, 0); assert_ok!(Uniques::set_metadata(Origin::signed(1), 0, 42, bvec![42, 42], false)); assert_eq!(Balances::reserved_balance(&1), 10); - assert!(InstanceMetadataOf::::contains_key(0, 42)); + assert!(ItemMetadataOf::::contains_key(0, 42)); assert_ok!(Uniques::set_metadata(Origin::signed(1), 0, 69, bvec![69, 69], false)); assert_eq!(Balances::reserved_balance(&1), 13); - assert!(InstanceMetadataOf::::contains_key(0, 69)); + assert!(ItemMetadataOf::::contains_key(0, 69)); - let w = Class::::get(0).unwrap().destroy_witness(); - assert_eq!(w.instances, 2); - assert_eq!(w.instance_metadatas, 2); + let w = Collection::::get(0).unwrap().destroy_witness(); + assert_eq!(w.items, 2); + assert_eq!(w.item_metadatas, 2); assert_ok!(Uniques::destroy(Origin::signed(1), 0, w)); assert_eq!(Balances::reserved_balance(&1), 0); - assert!(!Class::::contains_key(0)); - assert!(!Asset::::contains_key(0, 42)); - assert!(!Asset::::contains_key(0, 69)); - assert!(!ClassMetadataOf::::contains_key(0)); - assert!(!InstanceMetadataOf::::contains_key(0, 42)); - assert!(!InstanceMetadataOf::::contains_key(0, 69)); - assert_eq!(classes(), vec![]); - assert_eq!(assets(), vec![]); + assert!(!Collection::::contains_key(0)); + assert!(!Item::::contains_key(0, 42)); + assert!(!Item::::contains_key(0, 69)); + assert!(!CollectionMetadataOf::::contains_key(0)); + assert!(!ItemMetadataOf::::contains_key(0, 42)); + assert!(!ItemMetadataOf::::contains_key(0, 69)); + assert_eq!(collections(), vec![]); + assert_eq!(items(), vec![]); }); } @@ -142,7 +142,7 @@ fn destroy_with_bad_witness_should_not_work() { Balances::make_free_balance_be(&1, 100); assert_ok!(Uniques::create(Origin::signed(1), 0, 1)); - let w = Class::::get(0).unwrap().destroy_witness(); + let w = Collection::::get(0).unwrap().destroy_witness(); assert_ok!(Uniques::mint(Origin::signed(1), 0, 42, 1)); assert_noop!(Uniques::destroy(Origin::signed(1), 0, w), Error::::BadWitness); }); @@ -154,8 +154,8 @@ fn mint_should_work() { assert_ok!(Uniques::force_create(Origin::root(), 0, 1, true)); assert_ok!(Uniques::mint(Origin::signed(1), 0, 42, 1)); assert_eq!(Uniques::owner(0, 42).unwrap(), 1); - assert_eq!(classes(), vec![(1, 0)]); - assert_eq!(assets(), vec![(1, 0, 42)]); + assert_eq!(collections(), vec![(1, 0)]); + assert_eq!(items(), vec![(1, 0, 42)]); }); } @@ -166,7 +166,7 @@ fn transfer_should_work() { assert_ok!(Uniques::mint(Origin::signed(1), 0, 42, 2)); assert_ok!(Uniques::transfer(Origin::signed(2), 0, 42, 3)); - assert_eq!(assets(), vec![(3, 0, 42)]); + assert_eq!(items(), vec![(3, 0, 42)]); assert_noop!(Uniques::transfer(Origin::signed(2), 0, 42, 4), Error::::NoPermission); assert_ok!(Uniques::approve_transfer(Origin::signed(3), 0, 42, 2)); @@ -183,10 +183,10 @@ fn freezing_should_work() { assert_noop!(Uniques::transfer(Origin::signed(1), 0, 42, 2), Error::::Frozen); assert_ok!(Uniques::thaw(Origin::signed(1), 0, 42)); - assert_ok!(Uniques::freeze_class(Origin::signed(1), 0)); + assert_ok!(Uniques::freeze_collection(Origin::signed(1), 0)); assert_noop!(Uniques::transfer(Origin::signed(1), 0, 42, 2), Error::::Frozen); - assert_ok!(Uniques::thaw_class(Origin::signed(1), 0)); + assert_ok!(Uniques::thaw_collection(Origin::signed(1), 0)); assert_ok!(Uniques::transfer(Origin::signed(1), 0, 42, 2)); }); } @@ -208,7 +208,7 @@ fn origin_guards_should_work() { assert_noop!(Uniques::thaw(Origin::signed(2), 0, 42), Error::::NoPermission); assert_noop!(Uniques::mint(Origin::signed(2), 0, 69, 2), Error::::NoPermission); assert_noop!(Uniques::burn(Origin::signed(2), 0, 42, None), Error::::NoPermission); - let w = Class::::get(0).unwrap().destroy_witness(); + let w = Collection::::get(0).unwrap().destroy_witness(); assert_noop!(Uniques::destroy(Origin::signed(2), 0, w), Error::::NoPermission); }); } @@ -220,7 +220,7 @@ fn transfer_owner_should_work() { Balances::make_free_balance_be(&2, 100); Balances::make_free_balance_be(&3, 100); assert_ok!(Uniques::create(Origin::signed(1), 0, 1)); - assert_eq!(classes(), vec![(1, 0)]); + assert_eq!(collections(), vec![(1, 0)]); assert_noop!( Uniques::transfer_ownership(Origin::signed(1), 0, 2), Error::::Unaccepted @@ -228,7 +228,7 @@ fn transfer_owner_should_work() { assert_ok!(Uniques::set_accept_ownership(Origin::signed(2), Some(0))); assert_ok!(Uniques::transfer_ownership(Origin::signed(1), 0, 2)); - assert_eq!(classes(), vec![(2, 0)]); + assert_eq!(collections(), vec![(2, 0)]); assert_eq!(Balances::total_balance(&1), 98); assert_eq!(Balances::total_balance(&2), 102); assert_eq!(Balances::reserved_balance(&1), 0); @@ -241,12 +241,12 @@ fn transfer_owner_should_work() { ); // Mint and set metadata now and make sure that deposit gets transferred back. - assert_ok!(Uniques::set_class_metadata(Origin::signed(2), 0, bvec![0u8; 20], false)); + assert_ok!(Uniques::set_collection_metadata(Origin::signed(2), 0, bvec![0u8; 20], false)); assert_ok!(Uniques::mint(Origin::signed(1), 0, 42, 1)); assert_ok!(Uniques::set_metadata(Origin::signed(2), 0, 42, bvec![0u8; 20], false)); assert_ok!(Uniques::set_accept_ownership(Origin::signed(3), Some(0))); assert_ok!(Uniques::transfer_ownership(Origin::signed(2), 0, 3)); - assert_eq!(classes(), vec![(3, 0)]); + assert_eq!(collections(), vec![(3, 0)]); assert_eq!(Balances::total_balance(&2), 57); assert_eq!(Balances::total_balance(&3), 145); assert_eq!(Balances::reserved_balance(&2), 0); @@ -276,73 +276,76 @@ fn set_team_should_work() { } #[test] -fn set_class_metadata_should_work() { +fn set_collection_metadata_should_work() { new_test_ext().execute_with(|| { - // Cannot add metadata to unknown asset + // Cannot add metadata to unknown item assert_noop!( - Uniques::set_class_metadata(Origin::signed(1), 0, bvec![0u8; 20], false), - Error::::UnknownClass, + Uniques::set_collection_metadata(Origin::signed(1), 0, bvec![0u8; 20], false), + Error::::UnknownCollection, ); assert_ok!(Uniques::force_create(Origin::root(), 0, 1, false)); - // Cannot add metadata to unowned asset + // Cannot add metadata to unowned item assert_noop!( - Uniques::set_class_metadata(Origin::signed(2), 0, bvec![0u8; 20], false), + Uniques::set_collection_metadata(Origin::signed(2), 0, bvec![0u8; 20], false), Error::::NoPermission, ); // Successfully add metadata and take deposit Balances::make_free_balance_be(&1, 30); - assert_ok!(Uniques::set_class_metadata(Origin::signed(1), 0, bvec![0u8; 20], false)); + assert_ok!(Uniques::set_collection_metadata(Origin::signed(1), 0, bvec![0u8; 20], false)); assert_eq!(Balances::free_balance(&1), 9); - assert!(ClassMetadataOf::::contains_key(0)); + assert!(CollectionMetadataOf::::contains_key(0)); // Force origin works, too. - assert_ok!(Uniques::set_class_metadata(Origin::root(), 0, bvec![0u8; 18], false)); + assert_ok!(Uniques::set_collection_metadata(Origin::root(), 0, bvec![0u8; 18], false)); // Update deposit - assert_ok!(Uniques::set_class_metadata(Origin::signed(1), 0, bvec![0u8; 15], false)); + assert_ok!(Uniques::set_collection_metadata(Origin::signed(1), 0, bvec![0u8; 15], false)); assert_eq!(Balances::free_balance(&1), 14); - assert_ok!(Uniques::set_class_metadata(Origin::signed(1), 0, bvec![0u8; 25], false)); + assert_ok!(Uniques::set_collection_metadata(Origin::signed(1), 0, bvec![0u8; 25], false)); assert_eq!(Balances::free_balance(&1), 4); // Cannot over-reserve assert_noop!( - Uniques::set_class_metadata(Origin::signed(1), 0, bvec![0u8; 40], false), + Uniques::set_collection_metadata(Origin::signed(1), 0, bvec![0u8; 40], false), BalancesError::::InsufficientBalance, ); // Can't set or clear metadata once frozen - assert_ok!(Uniques::set_class_metadata(Origin::signed(1), 0, bvec![0u8; 15], true)); + assert_ok!(Uniques::set_collection_metadata(Origin::signed(1), 0, bvec![0u8; 15], true)); assert_noop!( - Uniques::set_class_metadata(Origin::signed(1), 0, bvec![0u8; 15], false), + Uniques::set_collection_metadata(Origin::signed(1), 0, bvec![0u8; 15], false), Error::::Frozen, ); - assert_noop!(Uniques::clear_class_metadata(Origin::signed(1), 0), Error::::Frozen); + assert_noop!( + Uniques::clear_collection_metadata(Origin::signed(1), 0), + Error::::Frozen + ); // Clear Metadata - assert_ok!(Uniques::set_class_metadata(Origin::root(), 0, bvec![0u8; 15], false)); + assert_ok!(Uniques::set_collection_metadata(Origin::root(), 0, bvec![0u8; 15], false)); assert_noop!( - Uniques::clear_class_metadata(Origin::signed(2), 0), + Uniques::clear_collection_metadata(Origin::signed(2), 0), Error::::NoPermission ); assert_noop!( - Uniques::clear_class_metadata(Origin::signed(1), 1), - Error::::UnknownClass + Uniques::clear_collection_metadata(Origin::signed(1), 1), + Error::::UnknownCollection ); - assert_ok!(Uniques::clear_class_metadata(Origin::signed(1), 0)); - assert!(!ClassMetadataOf::::contains_key(0)); + assert_ok!(Uniques::clear_collection_metadata(Origin::signed(1), 0)); + assert!(!CollectionMetadataOf::::contains_key(0)); }); } #[test] -fn set_instance_metadata_should_work() { +fn set_item_metadata_should_work() { new_test_ext().execute_with(|| { Balances::make_free_balance_be(&1, 30); - // Cannot add metadata to unknown asset + // Cannot add metadata to unknown item assert_ok!(Uniques::force_create(Origin::root(), 0, 1, false)); assert_ok!(Uniques::mint(Origin::signed(1), 0, 42, 1)); - // Cannot add metadata to unowned asset + // Cannot add metadata to unowned item assert_noop!( Uniques::set_metadata(Origin::signed(2), 0, 42, bvec![0u8; 20], false), Error::::NoPermission, @@ -351,7 +354,7 @@ fn set_instance_metadata_should_work() { // Successfully add metadata and take deposit assert_ok!(Uniques::set_metadata(Origin::signed(1), 0, 42, bvec![0u8; 20], false)); assert_eq!(Balances::free_balance(&1), 8); - assert!(InstanceMetadataOf::::contains_key(0, 42)); + assert!(ItemMetadataOf::::contains_key(0, 42)); // Force origin works, too. assert_ok!(Uniques::set_metadata(Origin::root(), 0, 42, bvec![0u8; 18], false)); @@ -384,10 +387,10 @@ fn set_instance_metadata_should_work() { ); assert_noop!( Uniques::clear_metadata(Origin::signed(1), 1, 42), - Error::::UnknownClass + Error::::UnknownCollection ); assert_ok!(Uniques::clear_metadata(Origin::signed(1), 0, 42)); - assert!(!InstanceMetadataOf::::contains_key(0, 42)); + assert!(!ItemMetadataOf::::contains_key(0, 42)); }); } @@ -429,7 +432,7 @@ fn set_attribute_should_work() { ); assert_eq!(Balances::reserved_balance(1), 15); - let w = Class::::get(0).unwrap().destroy_witness(); + let w = Collection::::get(0).unwrap().destroy_witness(); assert_ok!(Uniques::destroy(Origin::signed(1), 0, w)); assert_eq!(attributes(0), vec![]); assert_eq!(Balances::reserved_balance(1), 0); @@ -456,7 +459,7 @@ fn set_attribute_should_respect_freeze() { ); assert_eq!(Balances::reserved_balance(1), 9); - assert_ok!(Uniques::set_class_metadata(Origin::signed(1), 0, bvec![], true)); + assert_ok!(Uniques::set_collection_metadata(Origin::signed(1), 0, bvec![], true)); let e = Error::::Frozen; assert_noop!(Uniques::set_attribute(Origin::signed(1), 0, None, bvec![0], bvec![0]), e); assert_ok!(Uniques::set_attribute(Origin::signed(1), 0, Some(0), bvec![0], bvec![1])); @@ -469,20 +472,20 @@ fn set_attribute_should_respect_freeze() { } #[test] -fn force_asset_status_should_work() { +fn force_item_status_should_work() { new_test_ext().execute_with(|| { Balances::make_free_balance_be(&1, 100); assert_ok!(Uniques::force_create(Origin::root(), 0, 1, false)); assert_ok!(Uniques::mint(Origin::signed(1), 0, 42, 1)); assert_ok!(Uniques::mint(Origin::signed(1), 0, 69, 2)); - assert_ok!(Uniques::set_class_metadata(Origin::signed(1), 0, bvec![0; 20], false)); + assert_ok!(Uniques::set_collection_metadata(Origin::signed(1), 0, bvec![0; 20], false)); assert_ok!(Uniques::set_metadata(Origin::signed(1), 0, 42, bvec![0; 20], false)); assert_ok!(Uniques::set_metadata(Origin::signed(1), 0, 69, bvec![0; 20], false)); assert_eq!(Balances::reserved_balance(1), 65); - // force asset status to be free holding - assert_ok!(Uniques::force_asset_status(Origin::root(), 0, 1, 1, 1, 1, true, false)); + // force item status to be free holding + assert_ok!(Uniques::force_item_status(Origin::root(), 0, 1, 1, 1, 1, true, false)); assert_ok!(Uniques::mint(Origin::signed(1), 0, 142, 1)); assert_ok!(Uniques::mint(Origin::signed(1), 0, 169, 2)); assert_ok!(Uniques::set_metadata(Origin::signed(1), 0, 142, bvec![0; 20], false)); @@ -498,7 +501,7 @@ fn force_asset_status_should_work() { assert_ok!(Uniques::set_metadata(Origin::signed(1), 0, 69, bvec![0; 20], false)); assert_eq!(Balances::reserved_balance(1), 21); - assert_ok!(Uniques::set_class_metadata(Origin::signed(1), 0, bvec![0; 20], false)); + assert_ok!(Uniques::set_collection_metadata(Origin::signed(1), 0, bvec![0; 20], false)); assert_eq!(Balances::reserved_balance(1), 0); }); } @@ -510,7 +513,10 @@ fn burn_works() { assert_ok!(Uniques::force_create(Origin::root(), 0, 1, false)); assert_ok!(Uniques::set_team(Origin::signed(1), 0, 2, 3, 4)); - assert_noop!(Uniques::burn(Origin::signed(5), 0, 42, Some(5)), Error::::UnknownClass); + assert_noop!( + Uniques::burn(Origin::signed(5), 0, 42, Some(5)), + Error::::UnknownCollection + ); assert_ok!(Uniques::mint(Origin::signed(2), 0, 42, 5)); assert_ok!(Uniques::mint(Origin::signed(2), 0, 69, 5)); @@ -533,7 +539,7 @@ fn approval_lifecycle_works() { assert_ok!(Uniques::approve_transfer(Origin::signed(2), 0, 42, 3)); assert_ok!(Uniques::transfer(Origin::signed(3), 0, 42, 4)); assert_noop!(Uniques::transfer(Origin::signed(3), 0, 42, 3), Error::::NoPermission); - assert!(Asset::::get(0, 42).unwrap().approved.is_none()); + assert!(Item::::get(0, 42).unwrap().approved.is_none()); assert_ok!(Uniques::approve_transfer(Origin::signed(4), 0, 42, 2)); assert_ok!(Uniques::transfer(Origin::signed(2), 0, 42, 2)); @@ -549,11 +555,11 @@ fn cancel_approval_works() { assert_ok!(Uniques::approve_transfer(Origin::signed(2), 0, 42, 3)); assert_noop!( Uniques::cancel_approval(Origin::signed(2), 1, 42, None), - Error::::UnknownClass + Error::::UnknownCollection ); assert_noop!( Uniques::cancel_approval(Origin::signed(2), 0, 43, None), - Error::::UnknownClass + Error::::UnknownCollection ); assert_noop!( Uniques::cancel_approval(Origin::signed(3), 0, 42, None), @@ -581,11 +587,11 @@ fn cancel_approval_works_with_admin() { assert_ok!(Uniques::approve_transfer(Origin::signed(2), 0, 42, 3)); assert_noop!( Uniques::cancel_approval(Origin::signed(1), 1, 42, None), - Error::::UnknownClass + Error::::UnknownCollection ); assert_noop!( Uniques::cancel_approval(Origin::signed(1), 0, 43, None), - Error::::UnknownClass + Error::::UnknownCollection ); assert_noop!( Uniques::cancel_approval(Origin::signed(1), 0, 42, Some(4)), @@ -609,11 +615,11 @@ fn cancel_approval_works_with_force() { assert_ok!(Uniques::approve_transfer(Origin::signed(2), 0, 42, 3)); assert_noop!( Uniques::cancel_approval(Origin::root(), 1, 42, None), - Error::::UnknownClass + Error::::UnknownCollection ); assert_noop!( Uniques::cancel_approval(Origin::root(), 0, 43, None), - Error::::UnknownClass + Error::::UnknownCollection ); assert_noop!( Uniques::cancel_approval(Origin::root(), 0, 42, Some(4)), diff --git a/substrate/frame/uniques/src/types.rs b/substrate/frame/uniques/src/types.rs index b5aee6912f..d7706fd7e3 100644 --- a/substrate/frame/uniques/src/types.rs +++ b/substrate/frame/uniques/src/types.rs @@ -15,7 +15,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -//! Various basic types for use in the assets pallet. +//! Various basic types for use in the Uniques pallet. use super::*; use frame_support::{ @@ -26,13 +26,13 @@ use scale_info::TypeInfo; pub(super) type DepositBalanceOf = <>::Currency as Currency<::AccountId>>::Balance; -pub(super) type ClassDetailsFor = - ClassDetails<::AccountId, DepositBalanceOf>; -pub(super) type InstanceDetailsFor = - InstanceDetails<::AccountId, DepositBalanceOf>; +pub(super) type CollectionDetailsFor = + CollectionDetails<::AccountId, DepositBalanceOf>; +pub(super) type ItemDetailsFor = + ItemDetails<::AccountId, DepositBalanceOf>; #[derive(Clone, Encode, Decode, Eq, PartialEq, RuntimeDebug, TypeInfo, MaxEncodedLen)] -pub struct ClassDetails { +pub struct CollectionDetails { /// Can change `owner`, `issuer`, `freezer` and `admin` accounts. pub(super) owner: AccountId, /// Can mint tokens. @@ -41,55 +41,55 @@ pub struct ClassDetails { pub(super) admin: AccountId, /// Can freeze tokens. pub(super) freezer: AccountId, - /// The total balance deposited for the all storage associated with this asset class. Used by - /// `destroy`. + /// The total balance deposited for the all storage associated with this collection. + /// Used by `destroy`. pub(super) total_deposit: DepositBalance, - /// If `true`, then no deposit is needed to hold instances of this class. + /// If `true`, then no deposit is needed to hold items of this collection. pub(super) free_holding: bool, - /// The total number of outstanding instances of this asset class. - pub(super) instances: u32, - /// The total number of outstanding instance metadata of this asset class. - pub(super) instance_metadatas: u32, - /// The total number of attributes for this asset class. + /// The total number of outstanding items of this collection. + pub(super) items: u32, + /// The total number of outstanding item metadata of this collection. + pub(super) item_metadatas: u32, + /// The total number of attributes for this collection. pub(super) attributes: u32, - /// Whether the asset is frozen for non-admin transfers. + /// Whether the collection is frozen for non-admin transfers. pub(super) is_frozen: bool, } /// Witness data for the destroy transactions. #[derive(Copy, Clone, Encode, Decode, Eq, PartialEq, RuntimeDebug, TypeInfo, MaxEncodedLen)] pub struct DestroyWitness { - /// The total number of outstanding instances of this asset class. + /// The total number of outstanding items of this collection. #[codec(compact)] - pub instances: u32, - /// The total number of outstanding instance metadata of this asset class. + pub items: u32, + /// The total number of items in this collection that have outstanding item metadata. #[codec(compact)] - pub instance_metadatas: u32, + pub item_metadatas: u32, #[codec(compact)] - /// The total number of attributes for this asset class. + /// The total number of attributes for this collection. pub attributes: u32, } -impl ClassDetails { +impl CollectionDetails { pub fn destroy_witness(&self) -> DestroyWitness { DestroyWitness { - instances: self.instances, - instance_metadatas: self.instance_metadatas, + items: self.items, + item_metadatas: self.item_metadatas, attributes: self.attributes, } } } -/// Information concerning the ownership of a single unique asset. +/// Information concerning the ownership of a single unique item. #[derive(Clone, Encode, Decode, Eq, PartialEq, RuntimeDebug, Default, TypeInfo, MaxEncodedLen)] -pub struct InstanceDetails { - /// The owner of this asset. +pub struct ItemDetails { + /// The owner of this item. pub(super) owner: AccountId, - /// The approved transferrer of this asset, if one is set. + /// The approved transferrer of this item, if one is set. pub(super) approved: Option, - /// Whether the asset can be transferred or not. + /// Whether the item can be transferred or not. pub(super) is_frozen: bool, - /// The amount held in the pallet's default account for this asset. Free-hold assets will have + /// The amount held in the pallet's default account for this item. Free-hold items will have /// this as zero. pub(super) deposit: DepositBalance, } @@ -97,31 +97,31 @@ pub struct InstanceDetails { #[derive(Clone, Encode, Decode, Eq, PartialEq, RuntimeDebug, Default, TypeInfo, MaxEncodedLen)] #[scale_info(skip_type_params(StringLimit))] #[codec(mel_bound(DepositBalance: MaxEncodedLen))] -pub struct ClassMetadata> { +pub struct CollectionMetadata> { /// The balance deposited for this metadata. /// /// This pays for the data stored in this struct. pub(super) deposit: DepositBalance, - /// General information concerning this asset. Limited in length by `StringLimit`. This will - /// generally be either a JSON dump or the hash of some JSON which can be found on a + /// General information concerning this collection. Limited in length by `StringLimit`. This + /// will generally be either a JSON dump or the hash of some JSON which can be found on a /// hash-addressable global publication system such as IPFS. pub(super) data: BoundedVec, - /// Whether the asset metadata may be changed by a non Force origin. + /// Whether the collection's metadata may be changed by a non Force origin. pub(super) is_frozen: bool, } #[derive(Clone, Encode, Decode, Eq, PartialEq, RuntimeDebug, Default, TypeInfo, MaxEncodedLen)] #[scale_info(skip_type_params(StringLimit))] #[codec(mel_bound(DepositBalance: MaxEncodedLen))] -pub struct InstanceMetadata> { +pub struct ItemMetadata> { /// The balance deposited for this metadata. /// /// This pays for the data stored in this struct. pub(super) deposit: DepositBalance, - /// General information concerning this asset. Limited in length by `StringLimit`. This will + /// General information concerning this item. Limited in length by `StringLimit`. This will /// generally be either a JSON dump or the hash of some JSON which can be found on a /// hash-addressable global publication system such as IPFS. pub(super) data: BoundedVec, - /// Whether the asset metadata may be changed by a non Force origin. + /// Whether the item metadata may be changed by a non Force origin. pub(super) is_frozen: bool, } diff --git a/substrate/frame/uniques/src/weights.rs b/substrate/frame/uniques/src/weights.rs index eb9067b713..9b0cbda423 100644 --- a/substrate/frame/uniques/src/weights.rs +++ b/substrate/frame/uniques/src/weights.rs @@ -18,12 +18,13 @@ //! Autogenerated weights for pallet_uniques //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2022-01-31, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2022-05-12, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]` //! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB CACHE: 1024 // Executed Command: -// ./target/production/substrate +// target/production/substrate // benchmark +// pallet // --chain=dev // --steps=50 // --repeat=20 @@ -33,9 +34,7 @@ // --wasm-execution=compiled // --heap-pages=4096 // --output=./frame/uniques/src/weights.rs -// --template=.maintain/frame-weight-template.hbs -// --header=HEADER-APACHE2 -// --raw +// --template=./.maintain/frame-weight-template.hbs #![cfg_attr(rustfmt, rustfmt_skip)] #![allow(unused_parens)] @@ -55,17 +54,17 @@ pub trait WeightInfo { fn redeposit(i: u32, ) -> Weight; fn freeze() -> Weight; fn thaw() -> Weight; - fn freeze_class() -> Weight; - fn thaw_class() -> Weight; + fn freeze_collection() -> Weight; + fn thaw_collection() -> Weight; fn transfer_ownership() -> Weight; fn set_team() -> Weight; - fn force_asset_status() -> Weight; + fn force_item_status() -> Weight; fn set_attribute() -> Weight; fn clear_attribute() -> Weight; fn set_metadata() -> Weight; fn clear_metadata() -> Weight; - fn set_class_metadata() -> Weight; - fn clear_class_metadata() -> Weight; + fn set_collection_metadata() -> Weight; + fn clear_collection_metadata() -> Weight; fn approve_transfer() -> Weight; fn cancel_approval() -> Weight; fn set_accept_ownership() -> Weight; @@ -77,14 +76,14 @@ impl WeightInfo for SubstrateWeight { // Storage: Uniques Class (r:1 w:1) // Storage: Uniques ClassAccount (r:0 w:1) fn create() -> Weight { - (24_063_000 as Weight) + (24_319_000 as Weight) .saturating_add(T::DbWeight::get().reads(1 as Weight)) .saturating_add(T::DbWeight::get().writes(2 as Weight)) } // Storage: Uniques Class (r:1 w:1) // Storage: Uniques ClassAccount (r:0 w:1) fn force_create() -> Weight { - (13_017_000 as Weight) + (13_572_000 as Weight) .saturating_add(T::DbWeight::get().reads(1 as Weight)) .saturating_add(T::DbWeight::get().writes(2 as Weight)) } @@ -97,12 +96,12 @@ impl WeightInfo for SubstrateWeight { // Storage: Uniques Account (r:0 w:20) fn destroy(n: u32, m: u32, a: u32, ) -> Weight { (0 as Weight) - // Standard Error: 14_000 - .saturating_add((9_248_000 as Weight).saturating_mul(n as Weight)) - // Standard Error: 14_000 - .saturating_add((854_000 as Weight).saturating_mul(m as Weight)) - // Standard Error: 14_000 - .saturating_add((758_000 as Weight).saturating_mul(a as Weight)) + // Standard Error: 15_000 + .saturating_add((9_433_000 as Weight).saturating_mul(n as Weight)) + // Standard Error: 15_000 + .saturating_add((980_000 as Weight).saturating_mul(m as Weight)) + // Standard Error: 15_000 + .saturating_add((852_000 as Weight).saturating_mul(a as Weight)) .saturating_add(T::DbWeight::get().reads(2 as Weight)) .saturating_add(T::DbWeight::get().reads((1 as Weight).saturating_mul(n as Weight))) .saturating_add(T::DbWeight::get().writes(3 as Weight)) @@ -114,7 +113,7 @@ impl WeightInfo for SubstrateWeight { // Storage: Uniques Class (r:1 w:1) // Storage: Uniques Account (r:0 w:1) fn mint() -> Weight { - (29_865_000 as Weight) + (29_884_000 as Weight) .saturating_add(T::DbWeight::get().reads(2 as Weight)) .saturating_add(T::DbWeight::get().writes(3 as Weight)) } @@ -122,7 +121,7 @@ impl WeightInfo for SubstrateWeight { // Storage: Uniques Asset (r:1 w:1) // Storage: Uniques Account (r:0 w:1) fn burn() -> Weight { - (31_603_000 as Weight) + (31_384_000 as Weight) .saturating_add(T::DbWeight::get().reads(2 as Weight)) .saturating_add(T::DbWeight::get().writes(3 as Weight)) } @@ -130,7 +129,7 @@ impl WeightInfo for SubstrateWeight { // Storage: Uniques Asset (r:1 w:1) // Storage: Uniques Account (r:0 w:2) fn transfer() -> Weight { - (23_331_000 as Weight) + (23_254_000 as Weight) .saturating_add(T::DbWeight::get().reads(2 as Weight)) .saturating_add(T::DbWeight::get().writes(3 as Weight)) } @@ -138,8 +137,8 @@ impl WeightInfo for SubstrateWeight { // Storage: Uniques Asset (r:100 w:100) fn redeposit(i: u32, ) -> Weight { (0 as Weight) - // Standard Error: 12_000 - .saturating_add((11_527_000 as Weight).saturating_mul(i as Weight)) + // Standard Error: 13_000 + .saturating_add((11_718_000 as Weight).saturating_mul(i as Weight)) .saturating_add(T::DbWeight::get().reads(1 as Weight)) .saturating_add(T::DbWeight::get().reads((1 as Weight).saturating_mul(i as Weight))) .saturating_add(T::DbWeight::get().writes(1 as Weight)) @@ -148,47 +147,47 @@ impl WeightInfo for SubstrateWeight { // Storage: Uniques Asset (r:1 w:1) // Storage: Uniques Class (r:1 w:0) fn freeze() -> Weight { - (18_617_000 as Weight) + (17_807_000 as Weight) .saturating_add(T::DbWeight::get().reads(2 as Weight)) .saturating_add(T::DbWeight::get().writes(1 as Weight)) } // Storage: Uniques Asset (r:1 w:1) // Storage: Uniques Class (r:1 w:0) fn thaw() -> Weight { - (18_618_000 as Weight) + (17_904_000 as Weight) .saturating_add(T::DbWeight::get().reads(2 as Weight)) .saturating_add(T::DbWeight::get().writes(1 as Weight)) } // Storage: Uniques Class (r:1 w:1) - fn freeze_class() -> Weight { - (13_570_000 as Weight) + fn freeze_collection() -> Weight { + (13_828_000 as Weight) .saturating_add(T::DbWeight::get().reads(1 as Weight)) .saturating_add(T::DbWeight::get().writes(1 as Weight)) } // Storage: Uniques Class (r:1 w:1) - fn thaw_class() -> Weight { - (13_937_000 as Weight) + fn thaw_collection() -> Weight { + (13_636_000 as Weight) .saturating_add(T::DbWeight::get().reads(1 as Weight)) .saturating_add(T::DbWeight::get().writes(1 as Weight)) } + // Storage: Uniques OwnershipAcceptance (r:1 w:1) // Storage: Uniques Class (r:1 w:1) - // Storage: System Account (r:1 w:1) // Storage: Uniques ClassAccount (r:0 w:2) fn transfer_ownership() -> Weight { - (31_021_000 as Weight) + (20_897_000 as Weight) .saturating_add(T::DbWeight::get().reads(2 as Weight)) .saturating_add(T::DbWeight::get().writes(4 as Weight)) } // Storage: Uniques Class (r:1 w:1) fn set_team() -> Weight { - (14_739_000 as Weight) + (14_340_000 as Weight) .saturating_add(T::DbWeight::get().reads(1 as Weight)) .saturating_add(T::DbWeight::get().writes(1 as Weight)) } // Storage: Uniques Class (r:1 w:1) // Storage: Uniques ClassAccount (r:0 w:1) - fn force_asset_status() -> Weight { - (16_826_000 as Weight) + fn force_item_status() -> Weight { + (16_355_000 as Weight) .saturating_add(T::DbWeight::get().reads(1 as Weight)) .saturating_add(T::DbWeight::get().writes(2 as Weight)) } @@ -196,7 +195,7 @@ impl WeightInfo for SubstrateWeight { // Storage: Uniques InstanceMetadataOf (r:1 w:0) // Storage: Uniques Attribute (r:1 w:1) fn set_attribute() -> Weight { - (37_010_000 as Weight) + (37_035_000 as Weight) .saturating_add(T::DbWeight::get().reads(3 as Weight)) .saturating_add(T::DbWeight::get().writes(2 as Weight)) } @@ -204,56 +203,55 @@ impl WeightInfo for SubstrateWeight { // Storage: Uniques InstanceMetadataOf (r:1 w:0) // Storage: Uniques Attribute (r:1 w:1) fn clear_attribute() -> Weight { - (34_432_000 as Weight) + (34_957_000 as Weight) .saturating_add(T::DbWeight::get().reads(3 as Weight)) .saturating_add(T::DbWeight::get().writes(2 as Weight)) } // Storage: Uniques Class (r:1 w:1) // Storage: Uniques InstanceMetadataOf (r:1 w:1) fn set_metadata() -> Weight { - (28_575_000 as Weight) + (28_337_000 as Weight) .saturating_add(T::DbWeight::get().reads(2 as Weight)) .saturating_add(T::DbWeight::get().writes(2 as Weight)) } // Storage: Uniques Class (r:1 w:1) // Storage: Uniques InstanceMetadataOf (r:1 w:1) fn clear_metadata() -> Weight { - (28_730_000 as Weight) + (29_166_000 as Weight) .saturating_add(T::DbWeight::get().reads(2 as Weight)) .saturating_add(T::DbWeight::get().writes(2 as Weight)) } // Storage: Uniques Class (r:1 w:1) // Storage: Uniques ClassMetadataOf (r:1 w:1) - fn set_class_metadata() -> Weight { - (28_225_000 as Weight) + fn set_collection_metadata() -> Weight { + (28_246_000 as Weight) .saturating_add(T::DbWeight::get().reads(2 as Weight)) .saturating_add(T::DbWeight::get().writes(2 as Weight)) } // Storage: Uniques Class (r:1 w:0) // Storage: Uniques ClassMetadataOf (r:1 w:1) - fn clear_class_metadata() -> Weight { - (26_455_000 as Weight) + fn clear_collection_metadata() -> Weight { + (26_637_000 as Weight) .saturating_add(T::DbWeight::get().reads(2 as Weight)) .saturating_add(T::DbWeight::get().writes(1 as Weight)) } // Storage: Uniques Class (r:1 w:0) // Storage: Uniques Asset (r:1 w:1) fn approve_transfer() -> Weight { - (19_587_000 as Weight) + (18_938_000 as Weight) .saturating_add(T::DbWeight::get().reads(2 as Weight)) .saturating_add(T::DbWeight::get().writes(1 as Weight)) } // Storage: Uniques Class (r:1 w:0) // Storage: Uniques Asset (r:1 w:1) fn cancel_approval() -> Weight { - (19_417_000 as Weight) + (18_465_000 as Weight) .saturating_add(T::DbWeight::get().reads(2 as Weight)) .saturating_add(T::DbWeight::get().writes(1 as Weight)) } - // Storage: Uniques Class (r:1 w:0) - // Storage: Uniques Asset (r:1 w:1) + // Storage: Uniques OwnershipAcceptance (r:1 w:1) fn set_accept_ownership() -> Weight { - (19_417_000 as Weight) + (16_675_000 as Weight) .saturating_add(T::DbWeight::get().reads(1 as Weight)) .saturating_add(T::DbWeight::get().writes(1 as Weight)) } @@ -264,14 +262,14 @@ impl WeightInfo for () { // Storage: Uniques Class (r:1 w:1) // Storage: Uniques ClassAccount (r:0 w:1) fn create() -> Weight { - (24_063_000 as Weight) + (24_319_000 as Weight) .saturating_add(RocksDbWeight::get().reads(1 as Weight)) .saturating_add(RocksDbWeight::get().writes(2 as Weight)) } // Storage: Uniques Class (r:1 w:1) // Storage: Uniques ClassAccount (r:0 w:1) fn force_create() -> Weight { - (13_017_000 as Weight) + (13_572_000 as Weight) .saturating_add(RocksDbWeight::get().reads(1 as Weight)) .saturating_add(RocksDbWeight::get().writes(2 as Weight)) } @@ -284,12 +282,12 @@ impl WeightInfo for () { // Storage: Uniques Account (r:0 w:20) fn destroy(n: u32, m: u32, a: u32, ) -> Weight { (0 as Weight) - // Standard Error: 14_000 - .saturating_add((9_248_000 as Weight).saturating_mul(n as Weight)) - // Standard Error: 14_000 - .saturating_add((854_000 as Weight).saturating_mul(m as Weight)) - // Standard Error: 14_000 - .saturating_add((758_000 as Weight).saturating_mul(a as Weight)) + // Standard Error: 15_000 + .saturating_add((9_433_000 as Weight).saturating_mul(n as Weight)) + // Standard Error: 15_000 + .saturating_add((980_000 as Weight).saturating_mul(m as Weight)) + // Standard Error: 15_000 + .saturating_add((852_000 as Weight).saturating_mul(a as Weight)) .saturating_add(RocksDbWeight::get().reads(2 as Weight)) .saturating_add(RocksDbWeight::get().reads((1 as Weight).saturating_mul(n as Weight))) .saturating_add(RocksDbWeight::get().writes(3 as Weight)) @@ -301,7 +299,7 @@ impl WeightInfo for () { // Storage: Uniques Class (r:1 w:1) // Storage: Uniques Account (r:0 w:1) fn mint() -> Weight { - (29_865_000 as Weight) + (29_884_000 as Weight) .saturating_add(RocksDbWeight::get().reads(2 as Weight)) .saturating_add(RocksDbWeight::get().writes(3 as Weight)) } @@ -309,7 +307,7 @@ impl WeightInfo for () { // Storage: Uniques Asset (r:1 w:1) // Storage: Uniques Account (r:0 w:1) fn burn() -> Weight { - (31_603_000 as Weight) + (31_384_000 as Weight) .saturating_add(RocksDbWeight::get().reads(2 as Weight)) .saturating_add(RocksDbWeight::get().writes(3 as Weight)) } @@ -317,7 +315,7 @@ impl WeightInfo for () { // Storage: Uniques Asset (r:1 w:1) // Storage: Uniques Account (r:0 w:2) fn transfer() -> Weight { - (23_331_000 as Weight) + (23_254_000 as Weight) .saturating_add(RocksDbWeight::get().reads(2 as Weight)) .saturating_add(RocksDbWeight::get().writes(3 as Weight)) } @@ -325,8 +323,8 @@ impl WeightInfo for () { // Storage: Uniques Asset (r:100 w:100) fn redeposit(i: u32, ) -> Weight { (0 as Weight) - // Standard Error: 12_000 - .saturating_add((11_527_000 as Weight).saturating_mul(i as Weight)) + // Standard Error: 13_000 + .saturating_add((11_718_000 as Weight).saturating_mul(i as Weight)) .saturating_add(RocksDbWeight::get().reads(1 as Weight)) .saturating_add(RocksDbWeight::get().reads((1 as Weight).saturating_mul(i as Weight))) .saturating_add(RocksDbWeight::get().writes(1 as Weight)) @@ -335,47 +333,47 @@ impl WeightInfo for () { // Storage: Uniques Asset (r:1 w:1) // Storage: Uniques Class (r:1 w:0) fn freeze() -> Weight { - (18_617_000 as Weight) + (17_807_000 as Weight) .saturating_add(RocksDbWeight::get().reads(2 as Weight)) .saturating_add(RocksDbWeight::get().writes(1 as Weight)) } // Storage: Uniques Asset (r:1 w:1) // Storage: Uniques Class (r:1 w:0) fn thaw() -> Weight { - (18_618_000 as Weight) + (17_904_000 as Weight) .saturating_add(RocksDbWeight::get().reads(2 as Weight)) .saturating_add(RocksDbWeight::get().writes(1 as Weight)) } // Storage: Uniques Class (r:1 w:1) - fn freeze_class() -> Weight { - (13_570_000 as Weight) + fn freeze_collection() -> Weight { + (13_828_000 as Weight) .saturating_add(RocksDbWeight::get().reads(1 as Weight)) .saturating_add(RocksDbWeight::get().writes(1 as Weight)) } // Storage: Uniques Class (r:1 w:1) - fn thaw_class() -> Weight { - (13_937_000 as Weight) + fn thaw_collection() -> Weight { + (13_636_000 as Weight) .saturating_add(RocksDbWeight::get().reads(1 as Weight)) .saturating_add(RocksDbWeight::get().writes(1 as Weight)) } + // Storage: Uniques OwnershipAcceptance (r:1 w:1) // Storage: Uniques Class (r:1 w:1) - // Storage: System Account (r:1 w:1) // Storage: Uniques ClassAccount (r:0 w:2) fn transfer_ownership() -> Weight { - (31_021_000 as Weight) + (20_897_000 as Weight) .saturating_add(RocksDbWeight::get().reads(2 as Weight)) .saturating_add(RocksDbWeight::get().writes(4 as Weight)) } // Storage: Uniques Class (r:1 w:1) fn set_team() -> Weight { - (14_739_000 as Weight) + (14_340_000 as Weight) .saturating_add(RocksDbWeight::get().reads(1 as Weight)) .saturating_add(RocksDbWeight::get().writes(1 as Weight)) } // Storage: Uniques Class (r:1 w:1) // Storage: Uniques ClassAccount (r:0 w:1) - fn force_asset_status() -> Weight { - (16_826_000 as Weight) + fn force_item_status() -> Weight { + (16_355_000 as Weight) .saturating_add(RocksDbWeight::get().reads(1 as Weight)) .saturating_add(RocksDbWeight::get().writes(2 as Weight)) } @@ -383,7 +381,7 @@ impl WeightInfo for () { // Storage: Uniques InstanceMetadataOf (r:1 w:0) // Storage: Uniques Attribute (r:1 w:1) fn set_attribute() -> Weight { - (37_010_000 as Weight) + (37_035_000 as Weight) .saturating_add(RocksDbWeight::get().reads(3 as Weight)) .saturating_add(RocksDbWeight::get().writes(2 as Weight)) } @@ -391,56 +389,55 @@ impl WeightInfo for () { // Storage: Uniques InstanceMetadataOf (r:1 w:0) // Storage: Uniques Attribute (r:1 w:1) fn clear_attribute() -> Weight { - (34_432_000 as Weight) + (34_957_000 as Weight) .saturating_add(RocksDbWeight::get().reads(3 as Weight)) .saturating_add(RocksDbWeight::get().writes(2 as Weight)) } // Storage: Uniques Class (r:1 w:1) // Storage: Uniques InstanceMetadataOf (r:1 w:1) fn set_metadata() -> Weight { - (28_575_000 as Weight) + (28_337_000 as Weight) .saturating_add(RocksDbWeight::get().reads(2 as Weight)) .saturating_add(RocksDbWeight::get().writes(2 as Weight)) } // Storage: Uniques Class (r:1 w:1) // Storage: Uniques InstanceMetadataOf (r:1 w:1) fn clear_metadata() -> Weight { - (28_730_000 as Weight) + (29_166_000 as Weight) .saturating_add(RocksDbWeight::get().reads(2 as Weight)) .saturating_add(RocksDbWeight::get().writes(2 as Weight)) } // Storage: Uniques Class (r:1 w:1) // Storage: Uniques ClassMetadataOf (r:1 w:1) - fn set_class_metadata() -> Weight { - (28_225_000 as Weight) + fn set_collection_metadata() -> Weight { + (28_246_000 as Weight) .saturating_add(RocksDbWeight::get().reads(2 as Weight)) .saturating_add(RocksDbWeight::get().writes(2 as Weight)) } // Storage: Uniques Class (r:1 w:0) // Storage: Uniques ClassMetadataOf (r:1 w:1) - fn clear_class_metadata() -> Weight { - (26_455_000 as Weight) + fn clear_collection_metadata() -> Weight { + (26_637_000 as Weight) .saturating_add(RocksDbWeight::get().reads(2 as Weight)) .saturating_add(RocksDbWeight::get().writes(1 as Weight)) } // Storage: Uniques Class (r:1 w:0) // Storage: Uniques Asset (r:1 w:1) fn approve_transfer() -> Weight { - (19_587_000 as Weight) + (18_938_000 as Weight) .saturating_add(RocksDbWeight::get().reads(2 as Weight)) .saturating_add(RocksDbWeight::get().writes(1 as Weight)) } // Storage: Uniques Class (r:1 w:0) // Storage: Uniques Asset (r:1 w:1) fn cancel_approval() -> Weight { - (19_417_000 as Weight) + (18_465_000 as Weight) .saturating_add(RocksDbWeight::get().reads(2 as Weight)) .saturating_add(RocksDbWeight::get().writes(1 as Weight)) } - // Storage: Uniques Class (r:1 w:0) - // Storage: Uniques Asset (r:1 w:1) + // Storage: Uniques OwnershipAcceptance (r:1 w:1) fn set_accept_ownership() -> Weight { - (19_417_000 as Weight) + (16_675_000 as Weight) .saturating_add(RocksDbWeight::get().reads(1 as Weight)) .saturating_add(RocksDbWeight::get().writes(1 as Weight)) }