From f44d47929de81452324428686c65faed38afde21 Mon Sep 17 00:00:00 2001 From: Jegor Sidorenko Date: Tue, 10 May 2022 17:55:10 +0200 Subject: [PATCH 01/16] Rename class to collection --- .../support/src/traits/tokens/nonfungible.rs | 18 +- .../support/src/traits/tokens/nonfungibles.rs | 136 ++-- frame/uniques/src/benchmarking.rs | 194 ++--- frame/uniques/src/functions.rs | 169 ++--- frame/uniques/src/impl_nonfungibles.rs | 93 +-- frame/uniques/src/lib.rs | 661 +++++++++--------- frame/uniques/src/migration.rs | 4 +- frame/uniques/src/mock.rs | 4 +- frame/uniques/src/tests.rs | 124 ++-- frame/uniques/src/types.rs | 28 +- frame/uniques/src/weights.rs | 148 ++-- 11 files changed, 818 insertions(+), 761 deletions(-) diff --git a/frame/support/src/traits/tokens/nonfungible.rs b/frame/support/src/traits/tokens/nonfungible.rs index 5cf9638131b28..300eec54317ab 100644 --- a/frame/support/src/traits/tokens/nonfungible.rs +++ b/frame/support/src/traits/tokens/nonfungible.rs @@ -15,7 +15,7 @@ // 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 asset collection. //! //! This assumes a single level namespace identified by `Inspect::InstanceId`, and could //! reasonably be implemented by pallets which wants to expose a single collection of NFT-like @@ -65,10 +65,10 @@ pub trait Inspect { /// Interface for enumerating assets 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. + /// Returns an iterator of the instances of an asset `collection` in existence. fn instances() -> Box>; - /// Returns an iterator of the asset instances of all classes owned by `who`. + /// Returns an iterator of the asset instances of all collectiones owned by `who`. fn owned(who: &AccountId) -> Box>; } @@ -121,13 +121,13 @@ pub trait Transfer: Inspect { /// 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 { @@ -148,7 +148,7 @@ impl< impl< F: nonfungibles::InspectEnumerable, - A: Get<>::ClassId>, + A: Get<>::CollectionId>, AccountId, > InspectEnumerable for ItemOf { @@ -156,13 +156,13 @@ impl< >::instances(&A::get()) } fn owned(who: &AccountId) -> Box> { - >::owned_in_class(&A::get(), who) + >::owned_in_collection(&A::get(), who) } } impl< F: nonfungibles::Mutate, - A: Get<>::ClassId>, + A: Get<>::CollectionId>, AccountId, > Mutate for ItemOf { @@ -186,7 +186,7 @@ impl< impl< F: nonfungibles::Transfer, - A: Get<>::ClassId>, + A: Get<>::CollectionId>, AccountId, > Transfer for ItemOf { diff --git a/frame/support/src/traits/tokens/nonfungibles.rs b/frame/support/src/traits/tokens/nonfungibles.rs index 8bd731b20342c..36e3f4b1342a2 100644 --- a/frame/support/src/traits/tokens/nonfungibles.rs +++ b/frame/support/src/traits/tokens/nonfungibles.rs @@ -37,63 +37,67 @@ pub trait Inspect { /// Type for identifying an asset instance. type InstanceId; - /// Type for identifying an asset class (an identifier for an independent collection of asset - /// instances). - type ClassId; - - /// 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 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 { + /// Type for identifying an asset collection (an identifier for an independent collection of + /// asset instances). + type CollectionId; + + /// Returns the owner of asset `instance` of `collection`, or `None` if the asset doesn't exist + /// (or somehow has no owner). + fn owner(collection: &Self::CollectionId, instance: &Self::InstanceId) -> Option; + + /// Returns the owner of the asset `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 an asset 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 `instance` of `collection` corresponding to `key`. /// /// By default this is `None`; no attributes are defined. fn attribute( - _class: &Self::ClassId, + _collection: &Self::CollectionId, _instance: &Self::InstanceId, _key: &[u8], ) -> Option> { None } - /// Returns the strongly-typed attribute value of `instance` of `class` corresponding to `key`. + /// Returns the strongly-typed attribute value of `instance` of `collection` corresponding to + /// `key`. /// /// By default this just attempts to use `attribute`. fn typed_attribute( - class: &Self::ClassId, + collection: &Self::CollectionId, instance: &Self::InstanceId, key: &K, ) -> Option { - key.using_encoded(|d| Self::attribute(class, instance, d)) + key.using_encoded(|d| Self::attribute(collection, instance, 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 asset `instance` of `collection` may be transferred. /// /// Default implementation is that all assets are transferable. - fn can_transfer(_class: &Self::ClassId, _instance: &Self::InstanceId) -> bool { + fn can_transfer(_collection: &Self::CollectionId, _instance: &Self::InstanceId) -> bool { true } } @@ -101,38 +105,42 @@ pub trait Inspect { /// Interface for enumerating assets 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 asset collectiones in existence. + fn collectiones() -> Box>; - /// Returns an iterator of the instances of an asset `class` in existence. - fn instances(class: &Self::ClassId) -> Box>; + /// Returns an iterator of the instances of an asset `collection` in existence. + fn instances(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 asset instances of all collectiones 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 asset instances of `collection` owned by `who`. + fn owned_in_collection( + collection: &Self::CollectionId, who: &AccountId, ) -> Box>; } -/// Trait for providing the ability to create classes of nonfungible assets. +/// Trait for providing the ability to create collectiones of nonfungible assets. 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 assets 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 collectiones of nonfungible assets. pub trait Destroy: Inspect { /// The witness data needed to destroy an asset. type DestroyWitness; /// Provide the appropriate witness data needed to destroy an asset. - fn get_destroy_witness(class: &Self::ClassId) -> Option; + fn get_destroy_witness(collection: &Self::CollectionId) -> Option; /// Destroy an existing fungible asset. - /// * `class`: The `ClassId` to be destroyed. + /// * `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 @@ -142,42 +150,42 @@ pub trait Destroy: Inspect { /// If successful, this function will return the actual witness data from the destroyed asset. /// 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 collectiones of NFT-like assets 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 asset `instance` of `collection` to be owned by `who`. /// /// By default, this is not a supported operation. fn mint_into( - _class: &Self::ClassId, + _collection: &Self::CollectionId, _instance: &Self::InstanceId, _who: &AccountId, ) -> DispatchResult { Err(TokenError::Unsupported.into()) } - /// Burn some asset `instance` of `class`. + /// Burn some asset `instance` of `collection`. /// /// By default, this is not a supported operation. fn burn( - _class: &Self::ClassId, + _collection: &Self::CollectionId, _instance: &Self::InstanceId, _maybe_check_owner: Option<&AccountId>, ) -> DispatchResult { Err(TokenError::Unsupported.into()) } - /// Set attribute `value` of asset `instance` of `class`'s `key`. + /// Set attribute `value` of asset `instance` of `collection`'s `key`. /// /// By default, this is not a supported operation. fn set_attribute( - _class: &Self::ClassId, + _collection: &Self::CollectionId, _instance: &Self::InstanceId, _key: &[u8], _value: &[u8], @@ -185,42 +193,50 @@ pub trait Mutate: Inspect { 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 `instance` of `collection`'s `key`. /// /// By default this just attempts to use `set_attribute`. fn set_typed_attribute( - class: &Self::ClassId, + collection: &Self::CollectionId, instance: &Self::InstanceId, 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, instance, k, v)) + }) } - /// Set attribute `value` of asset `class`'s `key`. + /// Set attribute `value` of asset `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. pub trait Transfer: Inspect { - /// Transfer asset `instance` of `class` into `destination` account. + /// Transfer asset `instance` of `collection` into `destination` account. fn transfer( - class: &Self::ClassId, + collection: &Self::CollectionId, instance: &Self::InstanceId, destination: &AccountId, ) -> DispatchResult; diff --git a/frame/uniques/src/benchmarking.rs b/frame/uniques/src/benchmarking.rs index b743ca12913a3..f9770e38cb325 100644 --- a/frame/uniques/src/benchmarking.rs +++ b/frame/uniques/src/benchmarking.rs @@ -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, ) @@ -72,7 +72,7 @@ fn add_class_metadata, I: 'static>( fn mint_instance, I: 'static>( index: u16, ) -> (T::InstanceId, T::AccountId, ::Source) { - let caller = Class::::get(T::Helper::class(0)).unwrap().admin; + let caller = Collection::::get(T::Helper::collection(0)).unwrap().admin; if caller != whitelisted_caller() { whitelist_account!(caller); } @@ -80,7 +80,7 @@ fn mint_instance, I: 'static>( let instance = T::Helper::instance(index); assert!(Uniques::::mint( SystemOrigin::Signed(caller.clone()).into(), - T::Helper::class(0), + T::Helper::collection(0), instance, caller_lookup.clone(), ) @@ -91,14 +91,14 @@ fn mint_instance, I: 'static>( fn add_instance_metadata, I: 'static>( instance: T::InstanceId, ) -> (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), + T::Helper::collection(0), instance, vec![0; T::StringLimit::get() as usize].try_into().unwrap(), false, @@ -110,7 +110,7 @@ fn add_instance_metadata, I: 'static>( fn add_instance_attribute, I: 'static>( instance: T::InstanceId, ) -> (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,7 +118,7 @@ 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), + T::Helper::collection(0), Some(instance), 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,8 +162,8 @@ 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); } @@ -173,46 +173,46 @@ benchmarks_instance_pallet! { for i in 0..a { add_instance_attribute::(T::Helper::instance(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 (collection, caller, caller_lookup) = create_collection::(); let instance = T::Helper::instance(0); - }: _(SystemOrigin::Signed(caller.clone()), class, instance, caller_lookup) + }: _(SystemOrigin::Signed(caller.clone()), collection, instance, caller_lookup) verify { - assert_last_event::(Event::Issued { class, instance, owner: caller }.into()); + assert_last_event::(Event::Issued { collection, instance, owner: caller }.into()); } burn { - let (class, caller, caller_lookup) = create_class::(); + let (collection, caller, caller_lookup) = create_collection::(); let (instance, ..) = mint_instance::(0); - }: _(SystemOrigin::Signed(caller.clone()), class, instance, Some(caller_lookup)) + }: _(SystemOrigin::Signed(caller.clone()), collection, instance, Some(caller_lookup)) verify { - assert_last_event::(Event::Burned { class, instance, owner: caller }.into()); + assert_last_event::(Event::Burned { collection, instance, owner: caller }.into()); } transfer { - let (class, caller, caller_lookup) = create_class::(); + let (collection, caller, caller_lookup) = create_collection::(); let (instance, ..) = mint_instance::(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, instance, target_lookup) verify { - assert_last_event::(Event::Transferred { class, instance, from: caller, to: target }.into()); + assert_last_event::(Event::Transferred { collection, instance, from: caller, to: target }.into()); } redeposit { let i in 0 .. 5_000; - let (class, caller, caller_lookup) = create_class::(); + let (collection, caller, caller_lookup) = create_collection::(); let instances = (0..i).map(|x| mint_instance::(x as u16).0).collect::>(); Uniques::::force_asset_status( SystemOrigin::Root.into(), - class, + collection, caller_lookup.clone(), caller_lookup.clone(), caller_lookup.clone(), @@ -220,69 +220,69 @@ benchmarks_instance_pallet! { true, false, )?; - }: _(SystemOrigin::Signed(caller.clone()), class, instances.clone()) + }: _(SystemOrigin::Signed(caller.clone()), collection, instances.clone()) verify { - assert_last_event::(Event::Redeposited { class, successful_instances: instances }.into()); + assert_last_event::(Event::Redeposited { collection, successful_instances: instances }.into()); } freeze { - let (class, caller, caller_lookup) = create_class::(); + let (collection, caller, caller_lookup) = create_collection::(); let (instance, ..) = mint_instance::(0); - }: _(SystemOrigin::Signed(caller.clone()), T::Helper::class(0), T::Helper::instance(0)) + }: _(SystemOrigin::Signed(caller.clone()), T::Helper::collection(0), T::Helper::instance(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), instance: T::Helper::instance(0) }.into()); } thaw { - let (class, caller, caller_lookup) = create_class::(); + let (collection, caller, caller_lookup) = create_collection::(); let (instance, ..) = mint_instance::(0); Uniques::::freeze( SystemOrigin::Signed(caller.clone()).into(), - class, + collection, instance, )?; - }: _(SystemOrigin::Signed(caller.clone()), class, instance) + }: _(SystemOrigin::Signed(caller.clone()), collection, instance) verify { - assert_last_event::(Event::Thawed { class, instance }.into()); + assert_last_event::(Event::Thawed { collection, instance }.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), @@ -290,10 +290,10 @@ benchmarks_instance_pallet! { } force_asset_status { - let (class, caller, caller_lookup) = create_class::(); + let (collection, caller, caller_lookup) = create_collection::(); let origin = T::ForceOrigin::successful_origin(); let call = Call::::force_asset_status { - class, + 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::AssetStatusChanged { 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 (collection, caller, _) = create_collection::(); let (instance, ..) = mint_instance::(0); add_instance_metadata::(instance); - }: _(SystemOrigin::Signed(caller), class, Some(instance), key.clone(), value.clone()) + }: _(SystemOrigin::Signed(caller), collection, Some(instance), 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_instance: Some(instance), key, value }.into()); } clear_attribute { - let (class, caller, _) = create_class::(); + let (collection, caller, _) = create_collection::(); let (instance, ..) = mint_instance::(0); add_instance_metadata::(instance); let (key, ..) = add_instance_attribute::(instance); - }: _(SystemOrigin::Signed(caller), class, Some(instance), key.clone()) + }: _(SystemOrigin::Signed(caller), collection, Some(instance), key.clone()) verify { - assert_last_event::(Event::AttributeCleared { class, maybe_instance: Some(instance), key }.into()); + assert_last_event::(Event::AttributeCleared { collection, maybe_instance: Some(instance), key }.into()); } set_metadata { let data: BoundedVec<_, _> = vec![0u8; T::StringLimit::get() as usize].try_into().unwrap(); - let (class, caller, _) = create_class::(); + let (collection, caller, _) = create_collection::(); let (instance, ..) = mint_instance::(0); - }: _(SystemOrigin::Signed(caller), class, instance, data.clone(), false) + }: _(SystemOrigin::Signed(caller), collection, instance, data.clone(), false) verify { - assert_last_event::(Event::MetadataSet { class, instance, data, is_frozen: false }.into()); + assert_last_event::(Event::MetadataSet { collection, instance, data, is_frozen: false }.into()); } clear_metadata { - let (class, caller, _) = create_class::(); + let (collection, caller, _) = create_collection::(); let (instance, ..) = mint_instance::(0); add_instance_metadata::(instance); - }: _(SystemOrigin::Signed(caller), class, instance) + }: _(SystemOrigin::Signed(caller), collection, instance) verify { - assert_last_event::(Event::MetadataCleared { class, instance }.into()); + assert_last_event::(Event::MetadataCleared { collection, instance }.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 (collection, caller, _) = create_collection::(); let (instance, ..) = mint_instance::(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, instance, delegate_lookup) verify { - assert_last_event::(Event::ApprovedTransfer { class, instance, owner: caller, delegate }.into()); + assert_last_event::(Event::ApprovedTransfer { collection, instance, owner: caller, delegate }.into()); } cancel_approval { - let (class, caller, _) = create_class::(); + let (collection, caller, _) = create_collection::(); let (instance, ..) = mint_instance::(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, instance, delegate_lookup.clone())?; + }: _(SystemOrigin::Signed(caller.clone()), collection, instance, Some(delegate_lookup)) verify { - assert_last_event::(Event::ApprovalCancelled { class, instance, owner: caller, delegate }.into()); + assert_last_event::(Event::ApprovalCancelled { collection, instance, 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/frame/uniques/src/functions.rs b/frame/uniques/src/functions.rs index ea9eecd767dcf..eca72d6470b12 100644 --- a/frame/uniques/src/functions.rs +++ b/frame/uniques/src/functions.rs @@ -23,31 +23,32 @@ use sp_runtime::{DispatchError, DispatchResult}; impl, I: 'static> Pallet { pub fn do_transfer( - class: T::ClassId, + collection: T::CollectionId, instance: T::InstanceId, dest: T::AccountId, with_details: impl FnOnce( - &ClassDetailsFor, + &CollectionDetailsFor, &mut InstanceDetailsFor, ) -> 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, instance), Error::::Locked); let mut details = - Asset::::get(&class, &instance).ok_or(Error::::UnknownClass)?; + Asset::::get(&collection, &instance).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, &instance)); + Account::::insert((&dest, &collection, &instance), ()); let origin = details.owner; details.owner = dest; - Asset::::insert(&class, &instance, &details); + Asset::::insert(&collection, &instance, &details); Self::deposit_event(Event::Transferred { - class, + collection, instance, from: origin, to: details.owner, @@ -55,21 +56,21 @@ impl, I: 'static> Pallet { 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(), @@ -83,108 +84,116 @@ impl, I: 'static> Pallet { }, ); - 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.instances == witness.instances, Error::::BadWitness); ensure!( - class_details.instance_metadatas == witness.instance_metadatas, + collection_details.instance_metadatas == witness.instance_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 (instance, details) in Asset::::drain_prefix(&collection) { + Account::::remove((&details.owner, &collection, &instance)); } - 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); + InstanceMetadataOf::::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, + instances: collection_details.instances, + instance_metadatas: collection_details.instance_metadatas, + attributes: collection_details.attributes, }) }) } pub fn do_mint( - class: T::ClassId, + collection: T::CollectionId, instance: T::InstanceId, owner: T::AccountId, - with_details: impl FnOnce(&ClassDetailsFor) -> DispatchResult, + with_details: impl FnOnce(&CollectionDetailsFor) -> DispatchResult, ) -> DispatchResult { - ensure!(!Asset::::contains_key(class, instance), Error::::AlreadyExists); - - Class::::try_mutate(&class, |maybe_class_details| -> DispatchResult { - let class_details = maybe_class_details.as_mut().ok_or(Error::::UnknownClass)?; - - with_details(class_details)?; - - let instances = - class_details.instances.checked_add(1).ok_or(ArithmeticError::Overflow)?; - class_details.instances = instances; - - 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 owner = owner.clone(); - Account::::insert((&owner, &class, &instance), ()); - let details = InstanceDetails { owner, approved: None, is_frozen: false, deposit }; - Asset::::insert(&class, &instance, details); - Ok(()) - })?; + ensure!(!Asset::::contains_key(collection, instance), Error::::AlreadyExists); + + Collection::::try_mutate( + &collection, + |maybe_collection_details| -> DispatchResult { + let collection_details = + maybe_collection_details.as_mut().ok_or(Error::::UnknownCollection)?; + + with_details(collection_details)?; + + let instances = + collection_details.instances.checked_add(1).ok_or(ArithmeticError::Overflow)?; + collection_details.instances = instances; + + let deposit = match collection_details.free_holding { + true => Zero::zero(), + false => T::InstanceDeposit::get(), + }; + T::Currency::reserve(&collection_details.owner, deposit)?; + collection_details.total_deposit += deposit; + + let owner = owner.clone(); + Account::::insert((&owner, &collection, &instance), ()); + let details = InstanceDetails { owner, approved: None, is_frozen: false, deposit }; + Asset::::insert(&collection, &instance, details); + Ok(()) + }, + )?; - Self::deposit_event(Event::Issued { class, instance, owner }); + Self::deposit_event(Event::Issued { collection, instance, owner }); Ok(()) } pub fn do_burn( - class: T::ClassId, + collection: T::CollectionId, instance: T::InstanceId, - with_details: impl FnOnce(&ClassDetailsFor, &InstanceDetailsFor) -> DispatchResult, + with_details: impl FnOnce( + &CollectionDetailsFor, + &InstanceDetailsFor, + ) -> 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 = Asset::::get(&collection, &instance) + .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.instances.saturating_dec(); Ok(details.owner) }, )?; - Asset::::remove(&class, &instance); - Account::::remove((&owner, &class, &instance)); + Asset::::remove(&collection, &instance); + Account::::remove((&owner, &collection, &instance)); - Self::deposit_event(Event::Burned { class, instance, owner }); + Self::deposit_event(Event::Burned { collection, instance, owner }); Ok(()) } } diff --git a/frame/uniques/src/impl_nonfungibles.rs b/frame/uniques/src/impl_nonfungibles.rs index 492befc46967c..272277b3f42c3 100644 --- a/frame/uniques/src/impl_nonfungibles.rs +++ b/frame/uniques/src/impl_nonfungibles.rs @@ -27,58 +27,59 @@ use sp_std::prelude::*; impl, I: 'static> Inspect<::AccountId> for Pallet { type InstanceId = T::InstanceId; - type ClassId = T::ClassId; + type CollectionId = T::CollectionId; fn owner( - class: &Self::ClassId, + collection: &Self::CollectionId, instance: &Self::InstanceId, ) -> Option<::AccountId> { - Asset::::get(class, instance).map(|a| a.owner) + Asset::::get(collection, instance).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 `instance` of `collection` corresponding to `key`. /// /// When `key` is empty, we return the instance metadata value. /// /// By default this is `None`; no attributes are defined. fn attribute( - class: &Self::ClassId, + collection: &Self::CollectionId, instance: &Self::InstanceId, 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()) + InstanceMetadataOf::::get(collection, instance).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(instance), key)).map(|a| a.0.into()) } } - /// Returns the attribute value of `instance` of `class` corresponding to `key`. + /// Returns the attribute value of `instance` of `collection` corresponding to `key`. /// /// When `key` is empty, we return the instance 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()) + 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 asset `instance` 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)) { + fn can_transfer(collection: &Self::CollectionId, instance: &Self::InstanceId) -> bool { + match (Collection::::get(collection), Asset::::get(collection, instance)) { (Some(cd), Some(id)) if !cd.is_frozen && !id.is_frozen => true, _ => false, } @@ -86,19 +87,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 assets 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 +107,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, + collection: &Self::CollectionId, instance: &Self::InstanceId, who: &T::AccountId, ) -> DispatchResult { - Self::do_mint(*class, *instance, who.clone(), |_| Ok(())) + Self::do_mint(*collection, *instance, who.clone(), |_| Ok(())) } fn burn( - class: &Self::ClassId, + collection: &Self::CollectionId, instance: &Self::InstanceId, maybe_check_owner: Option<&T::AccountId>, ) -> DispatchResult { - Self::do_burn(*class, *instance, |_, d| { + Self::do_burn(*collection, *instance, |_, d| { if let Some(check_owner) = maybe_check_owner { if &d.owner != check_owner { return Err(Error::::NoPermission.into()) @@ -146,43 +147,45 @@ impl, I: 'static> Mutate<::AccountId> for Pallet impl, I: 'static> Transfer for Pallet { fn transfer( - class: &Self::ClassId, + collection: &Self::CollectionId, instance: &Self::InstanceId, destination: &T::AccountId, ) -> DispatchResult { - Self::do_transfer(*class, *instance, destination.clone(), |_, _| Ok(())) + Self::do_transfer(*collection, *instance, destination.clone(), |_, _| Ok(())) } } impl, I: 'static> InspectEnumerable for Pallet { - /// Returns an iterator of the asset classes in existence. + /// Returns an iterator of the asset collectiones in existence. /// /// NOTE: iterating this list invokes a storage read per item. - fn classes() -> Box> { - Box::new(ClassMetadataOf::::iter_keys()) + fn collectiones() -> Box> { + Box::new(CollectionMetadataOf::::iter_keys()) } - /// Returns an iterator of the instances of an asset `class` in existence. + /// Returns an iterator of the instances of an asset `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 instances(collection: &Self::CollectionId) -> Box> { + Box::new(InstanceMetadataOf::::iter_key_prefix(collection)) } - /// Returns an iterator of the asset instances of all classes owned by `who`. + /// Returns an iterator of the asset instances of all collectiones 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 asset instances 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::new(Account::::iter_key_prefix((who, collection))) } } diff --git a/frame/uniques/src/lib.rs b/frame/uniques/src/lib.rs index a360a02ebc702..e9dba61c741db 100644 --- a/frame/uniques/src/lib.rs +++ b/frame/uniques/src/lib.rs @@ -67,13 +67,15 @@ pub mod pallet { pub struct Pallet(_); #[cfg(feature = "runtime-benchmarks")] - pub trait BenchmarkHelper { - fn class(i: u16) -> ClassId; + pub trait BenchmarkHelper { + fn collection(i: u16) -> CollectionId; fn instance(i: u16) -> InstanceId; } #[cfg(feature = "runtime-benchmarks")] - impl, InstanceId: From> BenchmarkHelper for () { - fn class(i: u16) -> ClassId { + impl, InstanceId: From> BenchmarkHelper + for () + { + fn collection(i: u16) -> CollectionId { i.into() } fn instance(i: u16) -> InstanceId { @@ -87,10 +89,10 @@ 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 asset. + type CollectionId: Member + Parameter + MaxEncodedLen + Copy; - /// The type used to identify a unique asset within an asset class. + /// The type used to identify a unique asset within an asset collection. type InstanceId: Member + Parameter + MaxEncodedLen + Copy; /// The currency mechanism, used for paying for reserves. @@ -100,20 +102,20 @@ pub mod pallet { /// 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 an asset collection. #[pallet::constant] - type ClassDeposit: Get>; + type CollectionDeposit: Get>; /// The basic amount of funds that must be reserved for an asset instance. #[pallet::constant] @@ -146,25 +148,25 @@ 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< + /// Details of an asset 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 @@ -173,7 +175,7 @@ pub mod pallet { _, ( NMapKey, // owner - NMapKey, + NMapKey, NMapKey, ), (), @@ -181,14 +183,14 @@ pub mod pallet { >; #[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< + /// The collectiones owned by any given account; set out this way so that collectiones 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, >; @@ -198,7 +200,7 @@ pub mod pallet { pub(super) type Asset, I: 'static = ()> = StorageDoubleMap< _, Blake2_128Concat, - T::ClassId, + T::CollectionId, Blake2_128Concat, T::InstanceId, InstanceDetails>, @@ -206,12 +208,12 @@ pub mod pallet { >; #[pallet::storage] - /// Metadata of an asset class. - pub(super) type ClassMetadataOf, I: 'static = ()> = StorageMap< + /// Metadata of an asset collection. + pub(super) type CollectionMetadataOf, I: 'static = ()> = StorageMap< _, Blake2_128Concat, - T::ClassId, - ClassMetadata, T::StringLimit>, + T::CollectionId, + CollectionMetadata, T::StringLimit>, OptionQuery, >; @@ -220,7 +222,7 @@ pub mod pallet { pub(super) type InstanceMetadataOf, I: 'static = ()> = StorageDoubleMap< _, Blake2_128Concat, - T::ClassId, + T::CollectionId, Blake2_128Concat, T::InstanceId, InstanceMetadata, T::StringLimit>, @@ -228,11 +230,11 @@ pub mod pallet { >; #[pallet::storage] - /// Metadata of an asset class. + /// Metadata of an asset collection. pub(super) type Attribute, I: 'static = ()> = StorageNMap< _, ( - NMapKey, + NMapKey, NMapKey>, NMapKey>, ), @@ -243,92 +245,92 @@ 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 collection was created. + Created { collection: T::CollectionId, creator: T::AccountId, owner: T::AccountId }, + /// An asset collection was force-created. + ForceCreated { collection: T::CollectionId, owner: T::AccountId }, + /// An asset `collection` was destroyed. + Destroyed { collection: T::CollectionId }, /// An asset `instance` was issued. - Issued { class: T::ClassId, instance: T::InstanceId, owner: T::AccountId }, + Issued { collection: T::CollectionId, instance: T::InstanceId, owner: T::AccountId }, /// An asset `instance` was transferred. Transferred { - class: T::ClassId, + collection: T::CollectionId, instance: T::InstanceId, from: T::AccountId, to: T::AccountId, }, /// An asset `instance` was destroyed. - Burned { class: T::ClassId, instance: T::InstanceId, owner: T::AccountId }, + Burned { collection: T::CollectionId, instance: T::InstanceId, owner: T::AccountId }, /// Some asset `instance` was frozen. - Frozen { class: T::ClassId, instance: T::InstanceId }, + Frozen { collection: T::CollectionId, 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 }, + Thawed { collection: T::CollectionId, instance: T::InstanceId }, + /// Some asset `collection` was frozen. + CollectionFrozen { collection: T::CollectionId }, + /// Some asset `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 `instance` of an asset `collection` has been approved by the `owner` for transfer by + /// a `delegate`. ApprovedTransfer { - class: T::ClassId, + collection: T::CollectionId, instance: T::InstanceId, 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 `instance` of an asset + /// `collection` was cancelled by its `owner`. ApprovalCancelled { - class: T::ClassId, + collection: T::CollectionId, instance: T::InstanceId, 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, + /// An asset `collection` has had its attributes changed by the `Force` origin. + AssetStatusChanged { collection: T::CollectionId }, + /// New metadata has been set for an asset collection. + CollectionMetadataSet { + collection: T::CollectionId, data: BoundedVec, is_frozen: bool, }, - /// Metadata has been cleared for an asset class. - ClassMetadataCleared { class: T::ClassId }, + /// Metadata has been cleared for an asset collection. + CollectionMetadataCleared { collection: T::CollectionId }, /// New metadata has been set for an asset instance. MetadataSet { - class: T::ClassId, + collection: T::CollectionId, instance: T::InstanceId, data: BoundedVec, is_frozen: bool, }, /// Metadata has been cleared for an asset instance. - MetadataCleared { class: T::ClassId, instance: T::InstanceId }, + MetadataCleared { collection: T::CollectionId, 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. + Redeposited { collection: T::CollectionId, successful_instances: Vec }, + /// New attribute metadata has been set for an asset collection or instance. AttributeSet { - class: T::ClassId, + collection: T::CollectionId, maybe_instance: Option, key: BoundedVec, value: BoundedVec, }, - /// Attribute metadata has been cleared for an asset class or instance. + /// Attribute metadata has been cleared for an asset collection or instance. AttributeCleared { - class: T::ClassId, + collection: T::CollectionId, maybe_instance: 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] @@ -336,7 +338,7 @@ pub mod pallet { /// The signing account has no permission to do the operation. NoPermission, /// The given asset ID is unknown. - UnknownClass, + UnknownCollection, /// The asset instance ID has already been used for an asset. AlreadyExists, /// The owner turned out to be different to what was expected. @@ -345,7 +347,7 @@ pub mod pallet { BadWitness, /// The asset ID is already taken. InUse, - /// The asset instance or class is frozen. + /// The asset instance or collection is frozen. Frozen, /// The delegate turned out to be different to what was expected. WrongDelegate, @@ -353,7 +355,7 @@ 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. Locked, @@ -361,30 +363,32 @@ pub mod pallet { 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) + pub fn owner(collection: T::CollectionId, instance: T::InstanceId) -> Option { + Asset::::get(collection, instance).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) + 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 assets from a public origin. /// - /// This new asset class has no assets initially and its owner is the origin. + /// This new asset collection has no assets 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. /// /// 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 asset collection. This must not be currently + /// in use. + /// - `admin`: The admin of this collection of assets. The admin is the initial address of + /// each + /// member of the asset collection's admin team. /// /// Emits `Created` event when successful. /// @@ -392,32 +396,33 @@ 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 assets from a privileged origin. /// - /// This new asset class has no assets initially. + /// This new asset collection has no assets 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 + /// - `collection`: The identifier of the new asset. This must not be currently in use. + /// - `owner`: The owner of this collection of assets. The owner has full superuser + /// permissions /// over this asset, but may later change and configure the permissions using /// `transfer_ownership` and `set_team`. /// @@ -427,30 +432,30 @@ 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 assets. /// /// The origin must conform to `ForceOrigin` or must be `Signed` and the sender must be the - /// owner of the asset `class`. + /// owner of the asset `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 asset collection to be destroyed. + /// - `witness`: Information on the instances minted in the asset collection. This must be /// correct. /// /// Emits `Destroyed` event when successful. @@ -466,14 +471,14 @@ pub mod pallet { ))] 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, @@ -483,11 +488,11 @@ pub mod pallet { .into()) } - /// Mint an asset instance of a particular class. + /// Mint an asset instance 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 asset `collection`. /// - /// - `class`: The class of the asset to be minted. + /// - `collection`: The collection of the asset to be minted. /// - `instance`: The instance value of the asset to be minted. /// - `beneficiary`: The initial owner of the minted asset. /// @@ -497,24 +502,24 @@ pub mod pallet { #[pallet::weight(T::WeightInfo::mint())] pub fn mint( origin: OriginFor, - class: T::ClassId, + collection: T::CollectionId, instance: T::InstanceId, 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, instance, owner, |collection_details| { + ensure!(collection_details.issuer == origin, Error::::NoPermission); Ok(()) }) } /// Destroy a single asset instance. /// - /// 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 asset `collection`. /// - /// - `class`: The class of the asset to be burned. + /// - `collection`: The collection of the asset to be burned. /// - `instance`: The instance of the asset to be burned. /// - `check_owner`: If `Some` then the operation will fail with `WrongOwner` unless the /// asset is owned by this value. @@ -526,15 +531,15 @@ pub mod pallet { #[pallet::weight(T::WeightInfo::burn())] pub fn burn( origin: OriginFor, - class: T::ClassId, + collection: T::CollectionId, instance: T::InstanceId, 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, instance, |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), @@ -547,12 +552,12 @@ pub mod pallet { /// Move an asset from the sender account to another. /// /// Origin must be Signed and the signing account must be either: - /// - the Admin of the asset `class`; + /// - the Admin of the asset `collection`; /// - the Owner of the asset `instance`; /// - the approved delegate for the asset `instance` (in this case, the approval is reset). /// /// Arguments: - /// - `class`: The class of the asset to be transferred. + /// - `collection`: The collection of the asset to be transferred. /// - `instance`: The instance of the asset to be transferred. /// - `dest`: The account to receive ownership of the asset. /// @@ -562,15 +567,15 @@ pub mod pallet { #[pallet::weight(T::WeightInfo::transfer())] pub fn transfer( origin: OriginFor, - class: T::ClassId, + collection: T::CollectionId, instance: T::InstanceId, 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, instance, 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); } @@ -580,10 +585,10 @@ pub mod pallet { /// Reevaluate the deposits on some assets. /// - /// 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 asset `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 of the asset to be frozen. + /// - `instances`: The instances of the asset collection whose deposits will be reevaluated. /// /// NOTE: This exists as a best-effort function. Any asset instances which are unknown or /// in the case that the owner account does not have reservable funds to pay for a @@ -591,54 +596,54 @@ pub mod pallet { /// 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))] pub fn redeposit( origin: OriginFor, - class: T::ClassId, + collection: T::CollectionId, instances: 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(), }; let mut successful = Vec::with_capacity(instances.len()); for instance in instances.into_iter() { - let mut details = match Asset::::get(&class, &instance) { + let mut details = match Asset::::get(&collection, &instance) { 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); + Asset::::insert(&collection, &instance, &details); successful.push(instance); } - Class::::insert(&class, &class_details); + Collection::::insert(&collection, &collection_details); Self::deposit_event(Event::::Redeposited { - class, + collection, successful_instances: successful, }); @@ -647,9 +652,9 @@ pub mod pallet { /// Disallow further unprivileged transfer of an asset instance. /// - /// 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 asset `collection`. /// - /// - `class`: The class of the asset to be frozen. + /// - `collection`: The collection of the asset to be frozen. /// - `instance`: The instance of the asset to be frozen. /// /// Emits `Frozen`. @@ -658,28 +663,29 @@ pub mod pallet { #[pallet::weight(T::WeightInfo::freeze())] pub fn freeze( origin: OriginFor, - class: T::ClassId, + collection: T::CollectionId, instance: T::InstanceId, ) -> 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); + let mut details = Asset::::get(&collection, &instance) + .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); + Asset::::insert(&collection, &instance, &details); - Self::deposit_event(Event::::Frozen { class, instance }); + Self::deposit_event(Event::::Frozen { collection, instance }); Ok(()) } /// Re-allow unprivileged transfer of an asset instance. /// - /// 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 asset `collection`. /// - /// - `class`: The class of the asset to be thawed. + /// - `collection`: The collection of the asset to be thawed. /// - `instance`: The instance of the asset to be thawed. /// /// Emits `Thawed`. @@ -688,78 +694,85 @@ pub mod pallet { #[pallet::weight(T::WeightInfo::thaw())] pub fn thaw( origin: OriginFor, - class: T::ClassId, + collection: T::CollectionId, instance: T::InstanceId, ) -> 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); + let mut details = Asset::::get(&collection, &instance) + .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); + Asset::::insert(&collection, &instance, &details); - Self::deposit_event(Event::::Thawed { class, instance }); + Self::deposit_event(Event::::Thawed { collection, instance }); Ok(()) } - /// Disallow further unprivileged transfers for a whole asset class. + /// Disallow further unprivileged transfers for a whole asset 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 asset `collection`. /// - /// - `class`: The asset class to be frozen. + /// - `collection`: The asset 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 asset 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 asset `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 an asset 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 asset `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 asset collection whose owner should be changed. + /// - `owner`: The new Owner of this asset collection. They must have called + /// `set_accept_ownership` with `collection` in order for this operation to succeed. /// /// Emits `OwnerChanged`. /// @@ -767,17 +780,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 +803,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 an asset 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 asset `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 asset collection whose team should be changed. + /// - `issuer`: The new Issuer of this asset collection. + /// - `admin`: The new Admin of this asset collection. + /// - `freezer`: The new Freezer of this asset collection. /// /// Emits `TeamChanged`. /// @@ -815,7 +828,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,15 +838,15 @@ 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(()) }) } @@ -842,7 +855,7 @@ pub mod pallet { /// /// Origin must be Signed and must be the owner of the asset `instance`. /// - /// - `class`: The class of the asset to be approved for delegated transfer. + /// - `collection`: The collection 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. /// @@ -852,7 +865,7 @@ pub mod pallet { #[pallet::weight(T::WeightInfo::approve_transfer())] pub fn approve_transfer( origin: OriginFor, - class: T::ClassId, + collection: T::CollectionId, instance: T::InstanceId, delegate: ::Source, ) -> DispatchResult { @@ -862,21 +875,22 @@ pub mod pallet { let delegate = T::Lookup::lookup(delegate)?; - let class_details = Class::::get(&class).ok_or(Error::::UnknownClass)?; - let mut details = - Asset::::get(&class, &instance).ok_or(Error::::UnknownClass)?; + let collection_details = + Collection::::get(&collection).ok_or(Error::::UnknownCollection)?; + let mut details = Asset::::get(&collection, &instance) + .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); + Asset::::insert(&collection, &instance, &details); let delegate = details.approved.expect("set as Some above; qed"); Self::deposit_event(Event::ApprovedTransfer { - class, + collection, instance, owner: details.owner, delegate, @@ -889,11 +903,11 @@ pub mod pallet { /// /// Origin must be either: /// - the `Force` origin; - /// - `Signed` with the signer being the Admin of the asset `class`; + /// - `Signed` with the signer being the Admin of the asset `collection`; /// - `Signed` with the signer being the Owner of the asset `instance`; /// /// Arguments: - /// - `class`: The class of the asset of whose approval will be cancelled. + /// - `collection`: The collection of the asset of whose approval will be cancelled. /// - `instance`: The instance of the asset 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,7 +918,7 @@ pub mod pallet { #[pallet::weight(T::WeightInfo::cancel_approval())] pub fn cancel_approval( origin: OriginFor, - class: T::ClassId, + collection: T::CollectionId, instance: T::InstanceId, maybe_check_delegate: Option<::Source>, ) -> DispatchResult { @@ -912,11 +926,12 @@ pub mod pallet { .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 mut details = - Asset::::get(&class, &instance).ok_or(Error::::UnknownClass)?; + let collection_details = + Collection::::get(&collection).ok_or(Error::::UnknownCollection)?; + let mut details = Asset::::get(&collection, &instance) + .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,9 +940,9 @@ pub mod pallet { ensure!(check_delegate == old, Error::::WrongDelegate); } - Asset::::insert(&class, &instance, &details); + Asset::::insert(&collection, &instance, &details); Self::deposit_event(Event::ApprovalCancelled { - class, + collection, instance, owner: details.owner, delegate: old, @@ -940,14 +955,14 @@ pub mod pallet { /// /// Origin must be `ForceOrigin`. /// - /// - `class`: The identifier of the asset. + /// - `collection`: 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. + /// - `is_frozen`: Whether this asset collection is frozen except for permissioned/admin /// instructions. /// /// Emits `AssetStatusChanged` with the identity of the asset. @@ -956,7 +971,7 @@ pub mod pallet { #[pallet::weight(T::WeightInfo::force_asset_status())] pub fn force_asset_status( origin: OriginFor, - class: T::ClassId, + collection: T::CollectionId, owner: ::Source, issuer: ::Source, admin: ::Source, @@ -966,8 +981,8 @@ 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)?; + Collection::::try_mutate(collection, |maybe_asset| { + let mut asset = maybe_asset.take().ok_or(Error::::UnknownCollection)?; let old_owner = asset.owner; let new_owner = T::Lookup::lookup(owner)?; asset.owner = new_owner.clone(); @@ -977,24 +992,24 @@ pub mod pallet { asset.free_holding = free_holding; asset.is_frozen = is_frozen; *maybe_asset = Some(asset); - ClassAccount::::remove(&old_owner, &class); - ClassAccount::::insert(&new_owner, &class, ()); + CollectionAccount::::remove(&old_owner, &collection); + CollectionAccount::::insert(&new_owner, &collection, ()); - Self::deposit_event(Event::AssetStatusChanged { class }); + Self::deposit_event(Event::AssetStatusChanged { collection }); Ok(()) }) } - /// Set an attribute for an asset class or instance. + /// Set an attribute for an asset collection or instance. /// /// Origin must be either `ForceOrigin` or Signed and the sender should be the Owner of the - /// asset `class`. + /// asset `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. + /// - `collection`: The identifier of the asset collection whose instance's metadata to set. /// - `maybe_instance`: The identifier of the asset instance whose metadata to set. /// - `key`: The key of the attribute. /// - `value`: The value to which to set the attribute. @@ -1005,7 +1020,7 @@ pub mod pallet { #[pallet::weight(T::WeightInfo::set_attribute())] pub fn set_attribute( origin: OriginFor, - class: T::ClassId, + collection: T::CollectionId, maybe_instance: Option, key: BoundedVec, value: BoundedVec, @@ -1014,51 +1029,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); } let maybe_is_frozen = match maybe_instance { - None => ClassMetadataOf::::get(class).map(|v| v.is_frozen), + None => CollectionMetadataOf::::get(collection).map(|v| v.is_frozen), Some(instance) => - InstanceMetadataOf::::get(class, instance).map(|v| v.is_frozen), + InstanceMetadataOf::::get(collection, instance).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_instance, &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_instance, &key), (&value, deposit)); + Collection::::insert(collection, &collection_details); + Self::deposit_event(Event::AttributeSet { collection, maybe_instance, key, value }); Ok(()) } - /// Clear an attribute for an asset class or instance. + /// Clear an attribute for an asset collection or instance. /// /// Origin must be either `ForceOrigin` or Signed and the sender should be the Owner of the - /// asset `class`. + /// asset `collection`. /// - /// Any deposit is freed for the asset class owner. + /// Any deposit is freed for the asset collection owner. /// - /// - `class`: The identifier of the asset class whose instance's metadata to clear. + /// - `collection`: The identifier of the asset collection whose instance's metadata to + /// clear. /// - `maybe_instance`: The identifier of the asset instance whose metadata to clear. /// - `key`: The key of the attribute. /// @@ -1068,7 +1084,7 @@ pub mod pallet { #[pallet::weight(T::WeightInfo::clear_attribute())] pub fn clear_attribute( origin: OriginFor, - class: T::ClassId, + collection: T::CollectionId, maybe_instance: Option, key: BoundedVec, ) -> DispatchResult { @@ -1076,24 +1092,25 @@ 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), + None => CollectionMetadataOf::::get(collection).map(|v| v.is_frozen), Some(instance) => - InstanceMetadataOf::::get(class, instance).map(|v| v.is_frozen), + InstanceMetadataOf::::get(collection, instance).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_instance, &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_instance, key }); } Ok(()) } @@ -1101,13 +1118,13 @@ pub mod pallet { /// Set the metadata for an asset instance. /// /// Origin must be either `ForceOrigin` or Signed and the sender should be the Owner of the - /// asset `class`. + /// asset `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. + /// - `collection`: The identifier of the asset collection 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`. /// - `is_frozen`: Whether the metadata should be frozen against further changes. @@ -1118,7 +1135,7 @@ pub mod pallet { #[pallet::weight(T::WeightInfo::set_metadata())] pub fn set_metadata( origin: OriginFor, - class: T::ClassId, + collection: T::CollectionId, instance: T::InstanceId, data: BoundedVec, is_frozen: bool, @@ -1127,39 +1144,39 @@ 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| { + InstanceMetadataOf::::try_mutate_exists(collection, instance, |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.instance_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 }); - 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, instance, data, is_frozen }); Ok(()) }) } @@ -1169,9 +1186,10 @@ pub mod pallet { /// Origin must be either `ForceOrigin` or Signed and the sender should be the Owner of the /// asset `instance`. /// - /// Any deposit is freed for the asset class owner. + /// Any deposit is freed for the asset collection owner. /// - /// - `class`: The identifier of the asset class whose instance's metadata to clear. + /// - `collection`: The identifier of the asset collection whose instance's metadata to + /// clear. /// - `instance`: The identifier of the asset instance whose metadata to clear. /// /// Emits `MetadataCleared`. @@ -1180,56 +1198,56 @@ pub mod pallet { #[pallet::weight(T::WeightInfo::clear_metadata())] pub fn clear_metadata( origin: OriginFor, - class: T::ClassId, + collection: T::CollectionId, instance: T::InstanceId, ) -> 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| { + InstanceMetadataOf::::try_mutate_exists(collection, instance, |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.instance_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, instance }); Ok(()) }) } - /// Set the metadata for an asset class. + /// Set the metadata for an asset collection. /// /// Origin must be either `ForceOrigin` or `Signed` and the sender should be the Owner of - /// the asset `class`. + /// the asset `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. + /// - `collection`: The identifier of the asset whose metadata to update. /// - `data`: The general information of this asset. 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 +1255,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 +1280,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 an asset collection. /// /// Origin must be either `ForceOrigin` or `Signed` and the sender should be the Owner of - /// the asset `class`. + /// the asset `collection`. /// - /// Any deposit is freed for the asset class owner. + /// Any deposit is freed for the asset collection owner. /// - /// - `class`: The identifier of the asset class whose metadata to clear. + /// - `collection`: The identifier of the asset 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 - /// ownership transferal. + /// - `maybe_collection`: The identifier of the asset 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 +1353,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/frame/uniques/src/migration.rs b/frame/uniques/src/migration.rs index 2bacfc8f43b61..d301f0a3d1eb1 100644 --- a/frame/uniques/src/migration.rs +++ b/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/frame/uniques/src/mock.rs b/frame/uniques/src/mock.rs index f32540f6ef7ba..38a347b41087f 100644 --- a/frame/uniques/src/mock.rs +++ b/frame/uniques/src/mock.rs @@ -86,13 +86,13 @@ impl pallet_balances::Config for Test { impl Config for Test { type Event = Event; - type ClassId = u32; + type CollectionId = u32; type InstanceId = u32; type Currency = Balances; type CreateOrigin = AsEnsureOriginWithArg>; type ForceOrigin = frame_system::EnsureRoot; type Locker = (); - type ClassDeposit = ConstU64<2>; + type CollectionDeposit = ConstU64<2>; type InstanceDeposit = ConstU64<1>; type MetadataDepositBase = ConstU64<1>; type AttributeDepositBase = ConstU64<1>; diff --git a/frame/uniques/src/tests.rs b/frame/uniques/src/tests.rs index 364073ad37cde..20963a58f3b79 100644 --- a/frame/uniques/src/tests.rs +++ b/frame/uniques/src/tests.rs @@ -29,7 +29,7 @@ fn assets() -> Vec<(u64, u32, u32)> { let mut s: Vec<_> = Asset::::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 Asset::::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; + let details = Collection::::get(collection).unwrap(); + let instances = Asset::::iter_prefix(collection).count() as u32; assert_eq!(details.instances, instances); } r } -fn classes() -> Vec<(u64, u32)> { - let mut r: Vec<_> = ClassAccount::::iter().map(|x| (x.0, x.1)).collect(); +fn collectiones() -> 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(); @@ -82,12 +82,12 @@ 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!(collectiones(), vec![(1, 0)]); assert_ok!(Uniques::mint(Origin::signed(1), 0, 42, 1)); assert_eq!(assets(), vec![(1, 0, 42)]); assert_ok!(Uniques::force_create(Origin::root(), 1, 2, true)); - assert_eq!(classes(), vec![(1, 0), (2, 1)]); + assert_eq!(collectiones(), 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)]); }); @@ -99,18 +99,18 @@ 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!(collectiones(), 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!(Collection::::get(0).unwrap().instances, 2); + assert_eq!(Collection::::get(0).unwrap().instance_metadatas, 0); assert_ok!(Uniques::set_metadata(Origin::signed(1), 0, 42, bvec![42, 42], false)); assert_eq!(Balances::reserved_balance(&1), 10); @@ -119,19 +119,19 @@ fn lifecycle_should_work() { assert_eq!(Balances::reserved_balance(&1), 13); assert!(InstanceMetadataOf::::contains_key(0, 69)); - let w = Class::::get(0).unwrap().destroy_witness(); + let w = Collection::::get(0).unwrap().destroy_witness(); assert_eq!(w.instances, 2); assert_eq!(w.instance_metadatas, 2); assert_ok!(Uniques::destroy(Origin::signed(1), 0, w)); assert_eq!(Balances::reserved_balance(&1), 0); - assert!(!Class::::contains_key(0)); + assert!(!Collection::::contains_key(0)); assert!(!Asset::::contains_key(0, 42)); assert!(!Asset::::contains_key(0, 69)); - assert!(!ClassMetadataOf::::contains_key(0)); + assert!(!CollectionMetadataOf::::contains_key(0)); assert!(!InstanceMetadataOf::::contains_key(0, 42)); assert!(!InstanceMetadataOf::::contains_key(0, 69)); - assert_eq!(classes(), vec![]); + assert_eq!(collectiones(), vec![]); assert_eq!(assets(), 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,7 +154,7 @@ 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!(collectiones(), vec![(1, 0)]); assert_eq!(assets(), vec![(1, 0, 42)]); }); } @@ -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!(collectiones(), 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!(collectiones(), 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!(collectiones(), 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,61 +276,64 @@ 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 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 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)); }); } @@ -384,7 +387,7 @@ 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)); @@ -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])); @@ -476,7 +479,7 @@ fn force_asset_status_should_work() { 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); @@ -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)); @@ -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/frame/uniques/src/types.rs b/frame/uniques/src/types.rs index b5aee6912fec2..2cc27f2e78ae5 100644 --- a/frame/uniques/src/types.rs +++ b/frame/uniques/src/types.rs @@ -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 CollectionDetailsFor = + CollectionDetails<::AccountId, DepositBalanceOf>; pub(super) type InstanceDetailsFor = InstanceDetails<::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,16 +41,16 @@ 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 asset 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 instances of this collection. pub(super) free_holding: bool, - /// The total number of outstanding instances of this asset class. + /// The total number of outstanding instances of this asset collection. pub(super) instances: u32, - /// The total number of outstanding instance metadata of this asset class. + /// The total number of outstanding instance metadata of this asset collection. pub(super) instance_metadatas: u32, - /// The total number of attributes for this asset class. + /// The total number of attributes for this asset collection. pub(super) attributes: u32, /// Whether the asset is frozen for non-admin transfers. pub(super) is_frozen: bool, @@ -59,18 +59,18 @@ pub struct ClassDetails { /// 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 instances of this asset collection. #[codec(compact)] pub instances: u32, - /// The total number of outstanding instance metadata of this asset class. + /// The total number of outstanding instance metadata of this asset collection. #[codec(compact)] pub instance_metadatas: u32, #[codec(compact)] - /// The total number of attributes for this asset class. + /// The total number of attributes for this asset collection. pub attributes: u32, } -impl ClassDetails { +impl CollectionDetails { pub fn destroy_witness(&self) -> DestroyWitness { DestroyWitness { instances: self.instances, @@ -97,7 +97,7 @@ 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. diff --git a/frame/uniques/src/weights.rs b/frame/uniques/src/weights.rs index eb9067b7133a0..2f490724abcb8 100644 --- a/frame/uniques/src/weights.rs +++ b/frame/uniques/src/weights.rs @@ -55,8 +55,8 @@ 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; @@ -64,8 +64,8 @@ pub trait WeightInfo { 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; @@ -74,25 +74,25 @@ pub trait WeightInfo { /// Weights for pallet_uniques using the Substrate node and recommended hardware. pub struct SubstrateWeight(PhantomData); impl WeightInfo for SubstrateWeight { - // Storage: Uniques Class (r:1 w:1) - // Storage: Uniques ClassAccount (r:0 w:1) + // Storage: Uniques Collection (r:1 w:1) + // Storage: Uniques CollectionAccount (r:0 w:1) fn create() -> Weight { (24_063_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) + // Storage: Uniques Collection (r:1 w:1) + // Storage: Uniques CollectionAccount (r:0 w:1) fn force_create() -> Weight { (13_017_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 Collection (r:1 w:1) // Storage: Uniques Asset (r:1 w:0) - // Storage: Uniques ClassAccount (r:0 w:1) + // Storage: Uniques CollectionAccount (r:0 w:1) // Storage: Uniques Attribute (r:0 w:1000) - // Storage: Uniques ClassMetadataOf (r:0 w:1) + // Storage: Uniques CollectionMetadataOf (r:0 w:1) // Storage: Uniques InstanceMetadataOf (r:0 w:1000) // Storage: Uniques Account (r:0 w:20) fn destroy(n: u32, m: u32, a: u32, ) -> Weight { @@ -111,14 +111,14 @@ impl WeightInfo for SubstrateWeight { .saturating_add(T::DbWeight::get().writes((1 as Weight).saturating_mul(a as Weight))) } // Storage: Uniques Asset (r:1 w:1) - // Storage: Uniques Class (r:1 w:1) + // Storage: Uniques Collection (r:1 w:1) // Storage: Uniques Account (r:0 w:1) fn mint() -> Weight { (29_865_000 as Weight) .saturating_add(T::DbWeight::get().reads(2 as Weight)) .saturating_add(T::DbWeight::get().writes(3 as Weight)) } - // Storage: Uniques Class (r:1 w:1) + // Storage: Uniques Collection (r:1 w:1) // Storage: Uniques Asset (r:1 w:1) // Storage: Uniques Account (r:0 w:1) fn burn() -> Weight { @@ -126,7 +126,7 @@ impl WeightInfo for SubstrateWeight { .saturating_add(T::DbWeight::get().reads(2 as Weight)) .saturating_add(T::DbWeight::get().writes(3 as Weight)) } - // Storage: Uniques Class (r:1 w:0) + // Storage: Uniques Collection (r:1 w:0) // Storage: Uniques Asset (r:1 w:1) // Storage: Uniques Account (r:0 w:2) fn transfer() -> Weight { @@ -134,7 +134,7 @@ impl WeightInfo for SubstrateWeight { .saturating_add(T::DbWeight::get().reads(2 as Weight)) .saturating_add(T::DbWeight::get().writes(3 as Weight)) } - // Storage: Uniques Class (r:1 w:1) + // Storage: Uniques Collection (r:1 w:1) // Storage: Uniques Asset (r:100 w:100) fn redeposit(i: u32, ) -> Weight { (0 as Weight) @@ -146,53 +146,53 @@ impl WeightInfo for SubstrateWeight { .saturating_add(T::DbWeight::get().writes((1 as Weight).saturating_mul(i as Weight))) } // Storage: Uniques Asset (r:1 w:1) - // Storage: Uniques Class (r:1 w:0) + // Storage: Uniques Collection (r:1 w:0) fn freeze() -> Weight { (18_617_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) + // Storage: Uniques Collection (r:1 w:0) fn thaw() -> Weight { (18_618_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 { + // Storage: Uniques Collection (r:1 w:1) + fn freeze_collection() -> Weight { (13_570_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 { + // Storage: Uniques Collection (r:1 w:1) + fn thaw_collection() -> Weight { (13_937_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 Collection (r:1 w:1) // Storage: System Account (r:1 w:1) - // Storage: Uniques ClassAccount (r:0 w:2) + // Storage: Uniques CollectionAccount (r:0 w:2) fn transfer_ownership() -> Weight { (31_021_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) + // Storage: Uniques Collection (r:1 w:1) fn set_team() -> Weight { (14_739_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) + // Storage: Uniques Collection (r:1 w:1) + // Storage: Uniques CollectionAccount (r:0 w:1) fn force_asset_status() -> Weight { (16_826_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 Collection (r:1 w:1) // Storage: Uniques InstanceMetadataOf (r:1 w:0) // Storage: Uniques Attribute (r:1 w:1) fn set_attribute() -> Weight { @@ -200,7 +200,7 @@ impl WeightInfo for SubstrateWeight { .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 Collection (r:1 w:1) // Storage: Uniques InstanceMetadataOf (r:1 w:0) // Storage: Uniques Attribute (r:1 w:1) fn clear_attribute() -> Weight { @@ -208,49 +208,49 @@ impl WeightInfo for SubstrateWeight { .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 Collection (r:1 w:1) // Storage: Uniques InstanceMetadataOf (r:1 w:1) fn set_metadata() -> Weight { (28_575_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 Collection (r:1 w:1) // Storage: Uniques InstanceMetadataOf (r:1 w:1) fn clear_metadata() -> Weight { (28_730_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 { + // Storage: Uniques Collection (r:1 w:1) + // Storage: Uniques CollectionMetadataOf (r:1 w:1) + fn set_collection_metadata() -> Weight { (28_225_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 { + // Storage: Uniques Collection (r:1 w:0) + // Storage: Uniques CollectionMetadataOf (r:1 w:1) + fn clear_collection_metadata() -> Weight { (26_455_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 Collection (r:1 w:0) // Storage: Uniques Asset (r:1 w:1) fn approve_transfer() -> Weight { (19_587_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 Collection (r:1 w:0) // Storage: Uniques Asset (r:1 w:1) fn cancel_approval() -> Weight { (19_417_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 Collection (r:1 w:0) // Storage: Uniques Asset (r:1 w:1) fn set_accept_ownership() -> Weight { (19_417_000 as Weight) @@ -261,25 +261,25 @@ impl WeightInfo for SubstrateWeight { // For backwards compatibility and tests impl WeightInfo for () { - // Storage: Uniques Class (r:1 w:1) - // Storage: Uniques ClassAccount (r:0 w:1) + // Storage: Uniques Collection (r:1 w:1) + // Storage: Uniques CollectionAccount (r:0 w:1) fn create() -> Weight { (24_063_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) + // Storage: Uniques Collection (r:1 w:1) + // Storage: Uniques CollectionAccount (r:0 w:1) fn force_create() -> Weight { (13_017_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 Collection (r:1 w:1) // Storage: Uniques Asset (r:1 w:0) - // Storage: Uniques ClassAccount (r:0 w:1) + // Storage: Uniques CollectionAccount (r:0 w:1) // Storage: Uniques Attribute (r:0 w:1000) - // Storage: Uniques ClassMetadataOf (r:0 w:1) + // Storage: Uniques CollectionMetadataOf (r:0 w:1) // Storage: Uniques InstanceMetadataOf (r:0 w:1000) // Storage: Uniques Account (r:0 w:20) fn destroy(n: u32, m: u32, a: u32, ) -> Weight { @@ -298,14 +298,14 @@ impl WeightInfo for () { .saturating_add(RocksDbWeight::get().writes((1 as Weight).saturating_mul(a as Weight))) } // Storage: Uniques Asset (r:1 w:1) - // Storage: Uniques Class (r:1 w:1) + // Storage: Uniques Collection (r:1 w:1) // Storage: Uniques Account (r:0 w:1) fn mint() -> Weight { (29_865_000 as Weight) .saturating_add(RocksDbWeight::get().reads(2 as Weight)) .saturating_add(RocksDbWeight::get().writes(3 as Weight)) } - // Storage: Uniques Class (r:1 w:1) + // Storage: Uniques Collection (r:1 w:1) // Storage: Uniques Asset (r:1 w:1) // Storage: Uniques Account (r:0 w:1) fn burn() -> Weight { @@ -313,7 +313,7 @@ impl WeightInfo for () { .saturating_add(RocksDbWeight::get().reads(2 as Weight)) .saturating_add(RocksDbWeight::get().writes(3 as Weight)) } - // Storage: Uniques Class (r:1 w:0) + // Storage: Uniques Collection (r:1 w:0) // Storage: Uniques Asset (r:1 w:1) // Storage: Uniques Account (r:0 w:2) fn transfer() -> Weight { @@ -321,7 +321,7 @@ impl WeightInfo for () { .saturating_add(RocksDbWeight::get().reads(2 as Weight)) .saturating_add(RocksDbWeight::get().writes(3 as Weight)) } - // Storage: Uniques Class (r:1 w:1) + // Storage: Uniques Collection (r:1 w:1) // Storage: Uniques Asset (r:100 w:100) fn redeposit(i: u32, ) -> Weight { (0 as Weight) @@ -333,53 +333,53 @@ impl WeightInfo for () { .saturating_add(RocksDbWeight::get().writes((1 as Weight).saturating_mul(i as Weight))) } // Storage: Uniques Asset (r:1 w:1) - // Storage: Uniques Class (r:1 w:0) + // Storage: Uniques Collection (r:1 w:0) fn freeze() -> Weight { (18_617_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) + // Storage: Uniques Collection (r:1 w:0) fn thaw() -> Weight { (18_618_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 { + // Storage: Uniques Collection (r:1 w:1) + fn freeze_collection() -> Weight { (13_570_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 { + // Storage: Uniques Collection (r:1 w:1) + fn thaw_collection() -> Weight { (13_937_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 Collection (r:1 w:1) // Storage: System Account (r:1 w:1) - // Storage: Uniques ClassAccount (r:0 w:2) + // Storage: Uniques CollectionAccount (r:0 w:2) fn transfer_ownership() -> Weight { (31_021_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) + // Storage: Uniques Collection (r:1 w:1) fn set_team() -> Weight { (14_739_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) + // Storage: Uniques Collection (r:1 w:1) + // Storage: Uniques CollectionAccount (r:0 w:1) fn force_asset_status() -> Weight { (16_826_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 Collection (r:1 w:1) // Storage: Uniques InstanceMetadataOf (r:1 w:0) // Storage: Uniques Attribute (r:1 w:1) fn set_attribute() -> Weight { @@ -387,7 +387,7 @@ impl WeightInfo for () { .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 Collection (r:1 w:1) // Storage: Uniques InstanceMetadataOf (r:1 w:0) // Storage: Uniques Attribute (r:1 w:1) fn clear_attribute() -> Weight { @@ -395,49 +395,49 @@ impl WeightInfo for () { .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 Collection (r:1 w:1) // Storage: Uniques InstanceMetadataOf (r:1 w:1) fn set_metadata() -> Weight { (28_575_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 Collection (r:1 w:1) // Storage: Uniques InstanceMetadataOf (r:1 w:1) fn clear_metadata() -> Weight { (28_730_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 { + // Storage: Uniques Collection (r:1 w:1) + // Storage: Uniques CollectionMetadataOf (r:1 w:1) + fn set_collection_metadata() -> Weight { (28_225_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 { + // Storage: Uniques Collection (r:1 w:0) + // Storage: Uniques CollectionMetadataOf (r:1 w:1) + fn clear_collection_metadata() -> Weight { (26_455_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 Collection (r:1 w:0) // Storage: Uniques Asset (r:1 w:1) fn approve_transfer() -> Weight { (19_587_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 Collection (r:1 w:0) // Storage: Uniques Asset (r:1 w:1) fn cancel_approval() -> Weight { (19_417_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 Collection (r:1 w:0) // Storage: Uniques Asset (r:1 w:1) fn set_accept_ownership() -> Weight { (19_417_000 as Weight) From 8bd0d9d0df2fab701a307ec99100f2f5d0f25561 Mon Sep 17 00:00:00 2001 From: Jegor Sidorenko Date: Tue, 10 May 2022 18:01:20 +0200 Subject: [PATCH 02/16] Use "assets collection" instead of "asset collection" --- .../support/src/traits/tokens/nonfungible.rs | 2 +- .../support/src/traits/tokens/nonfungibles.rs | 8 +- frame/uniques/src/impl_nonfungibles.rs | 4 +- frame/uniques/src/lib.rs | 89 ++++++++++--------- frame/uniques/src/types.rs | 16 ++-- 5 files changed, 61 insertions(+), 58 deletions(-) diff --git a/frame/support/src/traits/tokens/nonfungible.rs b/frame/support/src/traits/tokens/nonfungible.rs index 300eec54317ab..5613bb203cc30 100644 --- a/frame/support/src/traits/tokens/nonfungible.rs +++ b/frame/support/src/traits/tokens/nonfungible.rs @@ -15,7 +15,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -//! Traits for dealing with a single non-fungible asset collection. +//! Traits for dealing with a single non-fungible assets collection. //! //! This assumes a single level namespace identified by `Inspect::InstanceId`, and could //! reasonably be implemented by pallets which wants to expose a single collection of NFT-like diff --git a/frame/support/src/traits/tokens/nonfungibles.rs b/frame/support/src/traits/tokens/nonfungibles.rs index 36e3f4b1342a2..70e8e43904dfe 100644 --- a/frame/support/src/traits/tokens/nonfungibles.rs +++ b/frame/support/src/traits/tokens/nonfungibles.rs @@ -37,7 +37,7 @@ pub trait Inspect { /// Type for identifying an asset instance. type InstanceId; - /// Type for identifying an asset collection (an identifier for an independent collection of + /// Type for identifying an assets collection (an identifier for an independent collection of /// asset instances). type CollectionId; @@ -46,7 +46,7 @@ pub trait Inspect { fn owner(collection: &Self::CollectionId, instance: &Self::InstanceId) -> Option; /// Returns the owner of the asset `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 an asset collection + /// make any sense, so users of this API should not be surprised to find an assets collection /// results in `None` here. fn collection_owner(_collection: &Self::CollectionId) -> Option { None @@ -105,8 +105,8 @@ pub trait Inspect { /// Interface for enumerating assets in existence or owned by a given account over many collections /// of NFTs. pub trait InspectEnumerable: Inspect { - /// Returns an iterator of the asset collectiones in existence. - fn collectiones() -> Box>; + /// Returns an iterator of the assets collections in existence. + fn collections() -> Box>; /// Returns an iterator of the instances of an asset `collection` in existence. fn instances(collection: &Self::CollectionId) -> Box>; diff --git a/frame/uniques/src/impl_nonfungibles.rs b/frame/uniques/src/impl_nonfungibles.rs index 272277b3f42c3..702999cacec34 100644 --- a/frame/uniques/src/impl_nonfungibles.rs +++ b/frame/uniques/src/impl_nonfungibles.rs @@ -156,10 +156,10 @@ impl, I: 'static> Transfer for Pallet { } impl, I: 'static> InspectEnumerable for Pallet { - /// Returns an iterator of the asset collectiones in existence. + /// Returns an iterator of the assets collections in existence. /// /// NOTE: iterating this list invokes a storage read per item. - fn collectiones() -> Box> { + fn collections() -> Box> { Box::new(CollectionMetadataOf::::iter_keys()) } diff --git a/frame/uniques/src/lib.rs b/frame/uniques/src/lib.rs index e9dba61c741db..7276bda99c1ea 100644 --- a/frame/uniques/src/lib.rs +++ b/frame/uniques/src/lib.rs @@ -92,7 +92,7 @@ pub mod pallet { /// Identifier for the collection of asset. type CollectionId: Member + Parameter + MaxEncodedLen + Copy; - /// The type used to identify a unique asset within an asset collection. + /// The type used to identify a unique asset within an assets collection. type InstanceId: Member + Parameter + MaxEncodedLen + Copy; /// The currency mechanism, used for paying for reserves. @@ -113,7 +113,7 @@ pub mod pallet { /// Locker trait to enable Locking mechanism downstream. type Locker: Locker; - /// The basic amount of funds that must be reserved for an asset collection. + /// The basic amount of funds that must be reserved for an assets collection. #[pallet::constant] type CollectionDeposit: Get>; @@ -155,7 +155,7 @@ pub mod pallet { } #[pallet::storage] - /// Details of an asset collection. + /// Details of an assets collection. pub(super) type Collection, I: 'static = ()> = StorageMap< _, Blake2_128Concat, @@ -208,7 +208,7 @@ pub mod pallet { >; #[pallet::storage] - /// Metadata of an asset collection. + /// Metadata of an assets collection. pub(super) type CollectionMetadataOf, I: 'static = ()> = StorageMap< _, Blake2_128Concat, @@ -230,7 +230,7 @@ pub mod pallet { >; #[pallet::storage] - /// Metadata of an asset collection. + /// Metadata of an assets collection. pub(super) type Attribute, I: 'static = ()> = StorageNMap< _, ( @@ -245,9 +245,9 @@ pub mod pallet { #[pallet::event] #[pallet::generate_deposit(pub(super) fn deposit_event)] pub enum Event, I: 'static = ()> { - /// An asset collection was created. + /// An assets collection was created. Created { collection: T::CollectionId, creator: T::AccountId, owner: T::AccountId }, - /// An asset collection was force-created. + /// An assets collection was force-created. ForceCreated { collection: T::CollectionId, owner: T::AccountId }, /// An asset `collection` was destroyed. Destroyed { collection: T::CollectionId }, @@ -297,13 +297,13 @@ pub mod pallet { }, /// An asset `collection` has had its attributes changed by the `Force` origin. AssetStatusChanged { collection: T::CollectionId }, - /// New metadata has been set for an asset collection. + /// New metadata has been set for an assets collection. CollectionMetadataSet { collection: T::CollectionId, data: BoundedVec, is_frozen: bool, }, - /// Metadata has been cleared for an asset collection. + /// Metadata has been cleared for an assets collection. CollectionMetadataCleared { collection: T::CollectionId }, /// New metadata has been set for an asset instance. MetadataSet { @@ -316,14 +316,14 @@ pub mod pallet { MetadataCleared { collection: T::CollectionId, instance: T::InstanceId }, /// Metadata has been cleared for an asset instance. Redeposited { collection: T::CollectionId, successful_instances: Vec }, - /// New attribute metadata has been set for an asset collection or instance. + /// New attribute metadata has been set for an assets collection or instance. AttributeSet { collection: T::CollectionId, maybe_instance: Option, key: BoundedVec, value: BoundedVec, }, - /// Attribute metadata has been cleared for an asset collection or instance. + /// Attribute metadata has been cleared for an assets collection or instance. AttributeCleared { collection: T::CollectionId, maybe_instance: Option, @@ -377,18 +377,18 @@ pub mod pallet { impl, I: 'static> Pallet { /// Issue a new collection of non-fungible assets from a public origin. /// - /// This new asset collection has no assets initially and its owner is the origin. + /// This new assets collection has no assets 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. /// /// Parameters: - /// - `collection`: The identifier of the new asset collection. This must not be currently + /// - `collection`: The identifier of the new assets collection. This must not be currently /// in use. /// - `admin`: The admin of this collection of assets. The admin is the initial address of /// each - /// member of the asset collection's admin team. + /// member of the assets collection's admin team. /// /// Emits `Created` event when successful. /// @@ -414,7 +414,7 @@ pub mod pallet { /// Issue a new collection of non-fungible assets from a privileged origin. /// - /// This new asset collection has no assets initially. + /// This new assets collection has no assets initially. /// /// The origin must conform to `ForceOrigin`. /// @@ -454,8 +454,8 @@ pub mod pallet { /// The origin must conform to `ForceOrigin` or must be `Signed` and the sender must be the /// owner of the asset `collection`. /// - /// - `collection`: The identifier of the asset collection to be destroyed. - /// - `witness`: Information on the instances minted in the asset collection. This must be + /// - `collection`: The identifier of the assets collection to be destroyed. + /// - `witness`: Information on the instances minted in the assets collection. This must be /// correct. /// /// Emits `Destroyed` event when successful. @@ -588,7 +588,8 @@ pub mod pallet { /// Origin must be Signed and the sender should be the Owner of the asset `collection`. /// /// - `collection`: The collection of the asset to be frozen. - /// - `instances`: The instances of the asset collection whose deposits will be reevaluated. + /// - `instances`: The instances of the assets collection whose deposits will be + /// reevaluated. /// /// NOTE: This exists as a best-effort function. Any asset instances which are unknown or /// in the case that the owner account does not have reservable funds to pay for a @@ -712,11 +713,11 @@ pub mod pallet { Ok(()) } - /// Disallow further unprivileged transfers for a whole asset collection. + /// Disallow further unprivileged transfers for a whole assets collection. /// /// Origin must be Signed and the sender should be the Freezer of the asset `collection`. /// - /// - `collection`: The asset collection to be frozen. + /// - `collection`: The assets collection to be frozen. /// /// Emits `CollectionFrozen`. /// @@ -739,7 +740,7 @@ pub mod pallet { }) } - /// Re-allow unprivileged transfers for a whole asset collection. + /// Re-allow unprivileged transfers for a whole assets collection. /// /// Origin must be Signed and the sender should be the Admin of the asset `collection`. /// @@ -766,12 +767,12 @@ pub mod pallet { }) } - /// Change the Owner of an asset collection. + /// Change the Owner of an assets collection. /// /// Origin must be Signed and the sender should be the Owner of the asset `collection`. /// - /// - `collection`: The asset collection whose owner should be changed. - /// - `owner`: The new Owner of this asset collection. They must have called + /// - `collection`: The assets collection whose owner should be changed. + /// - `owner`: The new Owner of this assets collection. They must have called /// `set_accept_ownership` with `collection` in order for this operation to succeed. /// /// Emits `OwnerChanged`. @@ -813,14 +814,14 @@ pub mod pallet { }) } - /// Change the Issuer, Admin and Freezer of an asset collection. + /// Change the Issuer, Admin and Freezer of an assets collection. /// /// Origin must be Signed and the sender should be the Owner of the asset `collection`. /// - /// - `collection`: The asset collection whose team should be changed. - /// - `issuer`: The new Issuer of this asset collection. - /// - `admin`: The new Admin of this asset collection. - /// - `freezer`: The new Freezer of this asset collection. + /// - `collection`: The assets collection whose team should be changed. + /// - `issuer`: The new Issuer of this assets collection. + /// - `admin`: The new Admin of this assets collection. + /// - `freezer`: The new Freezer of this assets collection. /// /// Emits `TeamChanged`. /// @@ -962,7 +963,7 @@ pub mod pallet { /// - `freezer`: The new Freezer of this asset. /// - `free_holding`: Whether a deposit is taken for holding an instance of this asset /// collection. - /// - `is_frozen`: Whether this asset collection is frozen except for permissioned/admin + /// - `is_frozen`: Whether this assets collection is frozen except for permissioned/admin /// instructions. /// /// Emits `AssetStatusChanged` with the identity of the asset. @@ -1000,7 +1001,7 @@ pub mod pallet { }) } - /// Set an attribute for an asset collection or instance. + /// Set an attribute for an assets collection or instance. /// /// Origin must be either `ForceOrigin` or Signed and the sender should be the Owner of the /// asset `collection`. @@ -1009,7 +1010,8 @@ pub mod pallet { /// `MetadataDepositBase + DepositPerByte * (key.len + value.len)` taking into /// account any already reserved funds. /// - /// - `collection`: The identifier of the asset collection whose instance's metadata to set. + /// - `collection`: The identifier of the assets collection whose instance's metadata to + /// set. /// - `maybe_instance`: The identifier of the asset instance whose metadata to set. /// - `key`: The key of the attribute. /// - `value`: The value to which to set the attribute. @@ -1066,14 +1068,14 @@ pub mod pallet { Ok(()) } - /// Clear an attribute for an asset collection or instance. + /// Clear an attribute for an assets collection or instance. /// /// Origin must be either `ForceOrigin` or Signed and the sender should be the Owner of the /// asset `collection`. /// - /// Any deposit is freed for the asset collection owner. + /// Any deposit is freed for the assets collection owner. /// - /// - `collection`: The identifier of the asset collection whose instance's metadata to + /// - `collection`: The identifier of the assets collection whose instance's metadata to /// clear. /// - `maybe_instance`: The identifier of the asset instance whose metadata to clear. /// - `key`: The key of the attribute. @@ -1124,7 +1126,8 @@ pub mod pallet { /// `MetadataDepositBase + DepositPerByte * data.len` taking into /// account any already reserved funds. /// - /// - `collection`: The identifier of the asset collection whose instance's metadata to set. + /// - `collection`: The identifier of the assets collection 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`. /// - `is_frozen`: Whether the metadata should be frozen against further changes. @@ -1186,9 +1189,9 @@ pub mod pallet { /// Origin must be either `ForceOrigin` or Signed and the sender should be the Owner of the /// asset `instance`. /// - /// Any deposit is freed for the asset collection owner. + /// Any deposit is freed for the assets collection owner. /// - /// - `collection`: The identifier of the asset collection whose instance's metadata to + /// - `collection`: The identifier of the assets collection whose instance's metadata to /// clear. /// - `instance`: The identifier of the asset instance whose metadata to clear. /// @@ -1228,7 +1231,7 @@ pub mod pallet { }) } - /// Set the metadata for an asset collection. + /// Set the metadata for an assets collection. /// /// Origin must be either `ForceOrigin` or `Signed` and the sender should be the Owner of /// the asset `collection`. @@ -1289,14 +1292,14 @@ pub mod pallet { }) } - /// Clear the metadata for an asset collection. + /// Clear the metadata for an assets collection. /// /// Origin must be either `ForceOrigin` or `Signed` and the sender should be the Owner of /// the asset `collection`. /// - /// Any deposit is freed for the asset collection owner. + /// Any deposit is freed for the assets collection owner. /// - /// - `collection`: The identifier of the asset collection whose metadata to clear. + /// - `collection`: The identifier of the assets collection whose metadata to clear. /// /// Emits `CollectionMetadataCleared`. /// @@ -1332,7 +1335,7 @@ pub mod pallet { /// Origin must be `Signed` and if `maybe_collection` is `Some`, then the signer must have a /// provider reference. /// - /// - `maybe_collection`: The identifier of the asset collection whose ownership the signer + /// - `maybe_collection`: The identifier of the assets collection whose ownership the signer /// is willing to accept, or if `None`, an indication that the signer is willing to accept /// no ownership transferal. /// diff --git a/frame/uniques/src/types.rs b/frame/uniques/src/types.rs index 2cc27f2e78ae5..52bbd52770fea 100644 --- a/frame/uniques/src/types.rs +++ b/frame/uniques/src/types.rs @@ -41,16 +41,16 @@ pub struct CollectionDetails { pub(super) admin: AccountId, /// Can freeze tokens. pub(super) freezer: AccountId, - /// The total balance deposited for the all storage associated with this asset collection. Used - /// by `destroy`. + /// The total balance deposited for the all storage associated with this assets collection. + /// Used by `destroy`. pub(super) total_deposit: DepositBalance, /// If `true`, then no deposit is needed to hold instances of this collection. pub(super) free_holding: bool, - /// The total number of outstanding instances of this asset collection. + /// The total number of outstanding instances of this assets collection. pub(super) instances: u32, - /// The total number of outstanding instance metadata of this asset collection. + /// The total number of outstanding instance metadata of this assets collection. pub(super) instance_metadatas: u32, - /// The total number of attributes for this asset collection. + /// The total number of attributes for this assets collection. pub(super) attributes: u32, /// Whether the asset is frozen for non-admin transfers. pub(super) is_frozen: bool, @@ -59,14 +59,14 @@ pub struct CollectionDetails { /// 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 collection. + /// The total number of outstanding instances of this assets collection. #[codec(compact)] pub instances: u32, - /// The total number of outstanding instance metadata of this asset collection. + /// The total number of outstanding instance metadata of this assets collection. #[codec(compact)] pub instance_metadatas: u32, #[codec(compact)] - /// The total number of attributes for this asset collection. + /// The total number of attributes for this assets collection. pub attributes: u32, } From dd81dc922ba826bf907850fb65d5459cede3b4a4 Mon Sep 17 00:00:00 2001 From: Jegor Sidorenko Date: Tue, 10 May 2022 18:36:31 +0200 Subject: [PATCH 03/16] Rename 'instance' to 'asset' --- frame/support/src/traits/tokens/misc.rs | 8 +- .../support/src/traits/tokens/nonfungible.rs | 103 +++--- .../support/src/traits/tokens/nonfungibles.rs | 70 ++-- frame/uniques/src/benchmarking.rs | 118 ++++--- frame/uniques/src/functions.rs | 71 ++-- frame/uniques/src/impl_nonfungibles.rs | 62 ++-- frame/uniques/src/lib.rs | 304 +++++++++--------- frame/uniques/src/mock.rs | 4 +- frame/uniques/src/tests.rs | 44 +-- frame/uniques/src/types.rs | 30 +- frame/uniques/src/weights.rs | 20 +- 11 files changed, 406 insertions(+), 428 deletions(-) diff --git a/frame/support/src/traits/tokens/misc.rs b/frame/support/src/traits/tokens/misc.rs index dd87fe36cd019..2d524371cead8 100644 --- a/frame/support/src/traits/tokens/misc.rs +++ b/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, asset: AssetId) -> 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, _asset: AssetId) -> bool { false } } diff --git a/frame/support/src/traits/tokens/nonfungible.rs b/frame/support/src/traits/tokens/nonfungible.rs index 5613bb203cc30..08b0c8408b2b2 100644 --- a/frame/support/src/traits/tokens/nonfungible.rs +++ b/frame/support/src/traits/tokens/nonfungible.rs @@ -17,7 +17,7 @@ //! Traits for dealing with a single non-fungible assets collection. //! -//! This assumes a single level namespace identified by `Inspect::InstanceId`, and could +//! This assumes a single level namespace identified by `Inspect::AssetId`, and could //! reasonably be implemented by pallets which wants to expose a single collection of NFT-like //! objects. //! @@ -30,34 +30,34 @@ 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 assets. pub trait Inspect { - /// Type for identifying an asset instance. - type InstanceId; + /// Type for identifying an asset. + type AssetId; - /// Returns the owner of asset `instance`, or `None` if the asset doesn't exist or has no + /// Returns the owner of asset `asset`, or `None` if the asset doesn't exist or has no /// owner. - fn owner(instance: &Self::InstanceId) -> Option; + fn owner(asset: &Self::AssetId) -> Option; - /// Returns the attribute value of `instance` corresponding to `key`. + /// Returns the attribute value of `asset` corresponding to `key`. /// /// By default this is `None`; no attributes are defined. - fn attribute(_instance: &Self::InstanceId, _key: &[u8]) -> Option> { + fn attribute(_asset: &Self::AssetId, _key: &[u8]) -> Option> { None } - /// Returns the strongly-typed attribute value of `instance` corresponding to `key`. + /// Returns the strongly-typed attribute value of `asset` 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(asset: &Self::AssetId, key: &K) -> Option { + key.using_encoded(|d| Self::attribute(asset, d)) .and_then(|v| V::decode(&mut &v[..]).ok()) } - /// Returns `true` if the asset `instance` may be transferred. + /// Returns `true` if the asset `asset` may be transferred. /// /// Default implementation is that all assets are transferable. - fn can_transfer(_instance: &Self::InstanceId) -> bool { + fn can_transfer(_asset: &Self::AssetId) -> bool { true } } @@ -65,56 +65,53 @@ pub trait Inspect { /// Interface for enumerating assets 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 `collection` in existence. - fn instances() -> Box>; + /// Returns an iterator of the assets of an asset `collection` in existence. + fn assets() -> Box>; - /// Returns an iterator of the asset instances of all collectiones owned by `who`. - fn owned(who: &AccountId) -> Box>; + /// Returns an iterator of the assets 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 /// attributes set on them. pub trait Mutate: Inspect { - /// Mint some asset `instance` to be owned by `who`. + /// Mint some asset `asset` 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(_asset: &Self::AssetId, _who: &AccountId) -> DispatchResult { Err(TokenError::Unsupported.into()) } - /// Burn some asset `instance`. + /// Burn some asset `asset`. /// /// By default, this is not a supported operation. - fn burn( - _instance: &Self::InstanceId, - _maybe_check_owner: Option<&AccountId>, - ) -> DispatchResult { + fn burn(_asset: &Self::AssetId, _maybe_check_owner: Option<&AccountId>) -> DispatchResult { Err(TokenError::Unsupported.into()) } - /// Set attribute `value` of asset `instance`'s `key`. + /// Set attribute `value` of asset `asset`'s `key`. /// /// By default, this is not a supported operation. - fn set_attribute(_instance: &Self::InstanceId, _key: &[u8], _value: &[u8]) -> DispatchResult { + fn set_attribute(_asset: &Self::AssetId, _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 `asset`'s `key`. /// /// By default this just attempts to use `set_attribute`. fn set_typed_attribute( - instance: &Self::InstanceId, + asset: &Self::AssetId, 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(asset, k, v))) } } /// Trait for providing a non-fungible set of assets which can only be transferred. pub trait Transfer: Inspect { - /// Transfer asset `instance` into `destination` account. - fn transfer(instance: &Self::InstanceId, destination: &AccountId) -> DispatchResult; + /// Transfer asset `asset` into `destination` account. + fn transfer(asset: &Self::AssetId, destination: &AccountId) -> DispatchResult; } /// Convert a `fungibles` trait implementation into a `fungible` trait implementation by identifying @@ -131,18 +128,18 @@ impl< AccountId, > Inspect for ItemOf { - type InstanceId = >::InstanceId; - fn owner(instance: &Self::InstanceId) -> Option { - >::owner(&A::get(), instance) + type AssetId = >::AssetId; + fn owner(asset: &Self::AssetId) -> Option { + >::owner(&A::get(), asset) } - fn attribute(instance: &Self::InstanceId, key: &[u8]) -> Option> { - >::attribute(&A::get(), instance, key) + fn attribute(asset: &Self::AssetId, key: &[u8]) -> Option> { + >::attribute(&A::get(), asset, key) } - fn typed_attribute(instance: &Self::InstanceId, key: &K) -> Option { - >::typed_attribute(&A::get(), instance, key) + fn typed_attribute(asset: &Self::AssetId, key: &K) -> Option { + >::typed_attribute(&A::get(), asset, key) } - fn can_transfer(instance: &Self::InstanceId) -> bool { - >::can_transfer(&A::get(), instance) + fn can_transfer(asset: &Self::AssetId) -> bool { + >::can_transfer(&A::get(), asset) } } @@ -152,10 +149,10 @@ impl< AccountId, > InspectEnumerable for ItemOf { - fn instances() -> Box> { - >::instances(&A::get()) + fn assets() -> Box> { + >::assets(&A::get()) } - fn owned(who: &AccountId) -> Box> { + fn owned(who: &AccountId) -> Box> { >::owned_in_collection(&A::get(), who) } } @@ -166,21 +163,21 @@ impl< AccountId, > Mutate for ItemOf { - fn mint_into(instance: &Self::InstanceId, who: &AccountId) -> DispatchResult { - >::mint_into(&A::get(), instance, who) + fn mint_into(asset: &Self::AssetId, who: &AccountId) -> DispatchResult { + >::mint_into(&A::get(), asset, who) } - fn burn(instance: &Self::InstanceId, maybe_check_owner: Option<&AccountId>) -> DispatchResult { - >::burn(&A::get(), instance, maybe_check_owner) + fn burn(asset: &Self::AssetId, maybe_check_owner: Option<&AccountId>) -> DispatchResult { + >::burn(&A::get(), asset, maybe_check_owner) } - fn set_attribute(instance: &Self::InstanceId, key: &[u8], value: &[u8]) -> DispatchResult { - >::set_attribute(&A::get(), instance, key, value) + fn set_attribute(asset: &Self::AssetId, key: &[u8], value: &[u8]) -> DispatchResult { + >::set_attribute(&A::get(), asset, key, value) } fn set_typed_attribute( - instance: &Self::InstanceId, + asset: &Self::AssetId, key: &K, value: &V, ) -> DispatchResult { - >::set_typed_attribute(&A::get(), instance, key, value) + >::set_typed_attribute(&A::get(), asset, key, value) } } @@ -190,7 +187,7 @@ impl< AccountId, > Transfer for ItemOf { - fn transfer(instance: &Self::InstanceId, destination: &AccountId) -> DispatchResult { - >::transfer(&A::get(), instance, destination) + fn transfer(asset: &Self::AssetId, destination: &AccountId) -> DispatchResult { + >::transfer(&A::get(), asset, destination) } } diff --git a/frame/support/src/traits/tokens/nonfungibles.rs b/frame/support/src/traits/tokens/nonfungibles.rs index 70e8e43904dfe..4b782d872048c 100644 --- a/frame/support/src/traits/tokens/nonfungibles.rs +++ b/frame/support/src/traits/tokens/nonfungibles.rs @@ -17,7 +17,7 @@ //! Traits for dealing with multiple collections of non-fungible assets. //! -//! This assumes a dual-level namespace identified by `Inspect::InstanceId`, and could +//! This assumes a dual-level namespace identified by `Inspect::AssetId`, and could //! reasonably be implemented by pallets which want to expose multiple independent collections of //! NFT-like objects. //! @@ -32,18 +32,18 @@ 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 assets. pub trait Inspect { - /// Type for identifying an asset instance. - type InstanceId; + /// Type for identifying an asset. + type AssetId; /// Type for identifying an assets collection (an identifier for an independent collection of - /// asset instances). + /// assets). type CollectionId; - /// Returns the owner of asset `instance` of `collection`, or `None` if the asset doesn't exist + /// Returns the owner of asset `asset` of `collection`, or `None` if the asset doesn't exist /// (or somehow has no owner). - fn owner(collection: &Self::CollectionId, instance: &Self::InstanceId) -> Option; + fn owner(collection: &Self::CollectionId, asset: &Self::AssetId) -> Option; /// Returns the owner of the asset `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 an assets collection @@ -52,27 +52,27 @@ pub trait Inspect { None } - /// Returns the attribute value of `instance` of `collection` corresponding to `key`. + /// Returns the attribute value of `asset` of `collection` corresponding to `key`. /// /// By default this is `None`; no attributes are defined. fn attribute( _collection: &Self::CollectionId, - _instance: &Self::InstanceId, + _asset: &Self::AssetId, _key: &[u8], ) -> Option> { None } - /// Returns the strongly-typed attribute value of `instance` of `collection` corresponding to + /// Returns the strongly-typed attribute value of `asset` of `collection` corresponding to /// `key`. /// /// By default this just attempts to use `attribute`. fn typed_attribute( collection: &Self::CollectionId, - instance: &Self::InstanceId, + asset: &Self::AssetId, key: &K, ) -> Option { - key.using_encoded(|d| Self::attribute(collection, instance, d)) + key.using_encoded(|d| Self::attribute(collection, asset, d)) .and_then(|v| V::decode(&mut &v[..]).ok()) } @@ -94,10 +94,10 @@ pub trait Inspect { .and_then(|v| V::decode(&mut &v[..]).ok()) } - /// Returns `true` if the asset `instance` of `collection` may be transferred. + /// Returns `true` if the asset `asset` of `collection` may be transferred. /// /// Default implementation is that all assets are transferable. - fn can_transfer(_collection: &Self::CollectionId, _instance: &Self::InstanceId) -> bool { + fn can_transfer(_collection: &Self::CollectionId, _asset: &Self::AssetId) -> bool { true } } @@ -108,20 +108,20 @@ pub trait InspectEnumerable: Inspect { /// Returns an iterator of the assets collections in existence. fn collections() -> Box>; - /// Returns an iterator of the instances of an asset `collection` in existence. - fn instances(collection: &Self::CollectionId) -> Box>; + /// Returns an iterator of the assets of an asset `collection` in existence. + fn assets(collection: &Self::CollectionId) -> Box>; - /// Returns an iterator of the asset instances of all collectiones owned by `who`. - fn owned(who: &AccountId) -> Box>; + /// Returns an iterator of the assets of all collections owned by `who`. + fn owned(who: &AccountId) -> Box>; - /// Returns an iterator of the asset instances of `collection` owned by `who`. + /// Returns an iterator of the assets of `collection` owned by `who`. fn owned_in_collection( collection: &Self::CollectionId, who: &AccountId, - ) -> Box>; + ) -> Box>; } -/// Trait for providing the ability to create collectiones of nonfungible assets. +/// Trait for providing the ability to create collections of nonfungible assets. pub trait Create: Inspect { /// Create a `collection` of nonfungible assets to be owned by `who` and managed by `admin`. fn create_collection( @@ -131,7 +131,7 @@ pub trait Create: Inspect { ) -> DispatchResult; } -/// Trait for providing the ability to destroy collectiones of nonfungible assets. +/// Trait for providing the ability to destroy collections of nonfungible assets. pub trait Destroy: Inspect { /// The witness data needed to destroy an asset. type DestroyWitness; @@ -156,55 +156,53 @@ pub trait Destroy: Inspect { ) -> Result; } -/// Trait for providing an interface for multiple collectiones of NFT-like assets which may be +/// Trait for providing an interface for multiple collections of NFT-like assets which may be /// minted, burned and/or have attributes set on them. pub trait Mutate: Inspect { - /// Mint some asset `instance` of `collection` to be owned by `who`. + /// Mint some asset `asset` of `collection` to be owned by `who`. /// /// By default, this is not a supported operation. fn mint_into( _collection: &Self::CollectionId, - _instance: &Self::InstanceId, + _asset: &Self::AssetId, _who: &AccountId, ) -> DispatchResult { Err(TokenError::Unsupported.into()) } - /// Burn some asset `instance` of `collection`. + /// Burn some asset `asset` of `collection`. /// /// By default, this is not a supported operation. fn burn( _collection: &Self::CollectionId, - _instance: &Self::InstanceId, + _asset: &Self::AssetId, _maybe_check_owner: Option<&AccountId>, ) -> DispatchResult { Err(TokenError::Unsupported.into()) } - /// Set attribute `value` of asset `instance` of `collection`'s `key`. + /// Set attribute `value` of asset `asset` of `collection`'s `key`. /// /// By default, this is not a supported operation. fn set_attribute( _collection: &Self::CollectionId, - _instance: &Self::InstanceId, + _asset: &Self::AssetId, _key: &[u8], _value: &[u8], ) -> DispatchResult { Err(TokenError::Unsupported.into()) } - /// Attempt to set the strongly-typed attribute `value` of `instance` of `collection`'s `key`. + /// Attempt to set the strongly-typed attribute `value` of `asset` of `collection`'s `key`. /// /// By default this just attempts to use `set_attribute`. fn set_typed_attribute( collection: &Self::CollectionId, - instance: &Self::InstanceId, + asset: &Self::AssetId, key: &K, value: &V, ) -> DispatchResult { - key.using_encoded(|k| { - value.using_encoded(|v| Self::set_attribute(collection, instance, k, v)) - }) + key.using_encoded(|k| value.using_encoded(|v| Self::set_attribute(collection, asset, k, v))) } /// Set attribute `value` of asset `collection`'s `key`. @@ -234,10 +232,10 @@ pub trait Mutate: Inspect { /// Trait for providing a non-fungible sets of assets which can only be transferred. pub trait Transfer: Inspect { - /// Transfer asset `instance` of `collection` into `destination` account. + /// Transfer asset `asset` of `collection` into `destination` account. fn transfer( collection: &Self::CollectionId, - instance: &Self::InstanceId, + asset: &Self::AssetId, destination: &AccountId, ) -> DispatchResult; } diff --git a/frame/uniques/src/benchmarking.rs b/frame/uniques/src/benchmarking.rs index f9770e38cb325..a0abf428b3fed 100644 --- a/frame/uniques/src/benchmarking.rs +++ b/frame/uniques/src/benchmarking.rs @@ -20,9 +20,7 @@ #![cfg(feature = "runtime-benchmarks")] use super::*; -use frame_benchmarking::{ - account, benchmarks_instance_pallet, whitelist_account, whitelisted_caller, -}; +use frame_benchmarking::{account, benchmarks_asset_pallet, whitelist_account, whitelisted_caller}; use frame_support::{ dispatch::UnfilteredDispatchable, traits::{EnsureOrigin, Get}, @@ -69,27 +67,27 @@ fn add_collection_metadata, I: 'static>( (caller, caller_lookup) } -fn mint_instance, I: 'static>( +fn mint_asset, I: 'static>( index: u16, -) -> (T::InstanceId, T::AccountId, ::Source) { +) -> (T::AssetId, 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 asset = T::Helper::asset(index); assert!(Uniques::::mint( SystemOrigin::Signed(caller.clone()).into(), T::Helper::collection(0), - instance, + asset, caller_lookup.clone(), ) .is_ok()); - (instance, caller, caller_lookup) + (asset, caller, caller_lookup) } -fn add_instance_metadata, I: 'static>( - instance: T::InstanceId, +fn add_asset_metadata, I: 'static>( + asset: T::AssetId, ) -> (T::AccountId, ::Source) { let caller = Collection::::get(T::Helper::collection(0)).unwrap().owner; if caller != whitelisted_caller() { @@ -99,7 +97,7 @@ fn add_instance_metadata, I: 'static>( assert!(Uniques::::set_metadata( SystemOrigin::Signed(caller.clone()).into(), T::Helper::collection(0), - instance, + asset, vec![0; T::StringLimit::get() as usize].try_into().unwrap(), false, ) @@ -107,8 +105,8 @@ fn add_instance_metadata, I: 'static>( (caller, caller_lookup) } -fn add_instance_attribute, I: 'static>( - instance: T::InstanceId, +fn add_asset_attribute, I: 'static>( + asset: T::AssetId, ) -> (BoundedVec, T::AccountId, ::Source) { let caller = Collection::::get(T::Helper::collection(0)).unwrap().owner; if caller != whitelisted_caller() { @@ -119,7 +117,7 @@ fn add_instance_attribute, I: 'static>( assert!(Uniques::::set_attribute( SystemOrigin::Signed(caller.clone()).into(), T::Helper::collection(0), - Some(instance), + Some(asset), key.clone(), vec![0; T::ValueLimit::get() as usize].try_into().unwrap(), ) @@ -135,7 +133,7 @@ fn assert_last_event, I: 'static>(generic_event: >:: assert_eq!(event, &system_event); } -benchmarks_instance_pallet! { +benchmarks_asset_pallet! { create { let collection = T::Helper::collection(0); let origin = T::CreateOrigin::successful_origin(&collection); @@ -165,13 +163,13 @@ benchmarks_instance_pallet! { let (collection, caller, caller_lookup) = create_collection::(); add_collection_metadata::(); for i in 0..n { - mint_instance::(i as u16); + mint_asset::(i as u16); } for i in 0..m { - add_instance_metadata::(T::Helper::instance(i as u16)); + add_asset_metadata::(T::Helper::asset(i as u16)); } for i in 0..a { - add_instance_attribute::(T::Helper::instance(i as u16)); + add_asset_attribute::(T::Helper::asset(i as u16)); } let witness = Collection::::get(collection).unwrap().destroy_witness(); }: _(SystemOrigin::Signed(caller), collection, witness) @@ -181,35 +179,35 @@ benchmarks_instance_pallet! { mint { let (collection, caller, caller_lookup) = create_collection::(); - let instance = T::Helper::instance(0); - }: _(SystemOrigin::Signed(caller.clone()), collection, instance, caller_lookup) + let asset = T::Helper::asset(0); + }: _(SystemOrigin::Signed(caller.clone()), collection, asset, caller_lookup) verify { - assert_last_event::(Event::Issued { collection, instance, owner: caller }.into()); + assert_last_event::(Event::Issued { collection, asset, owner: caller }.into()); } burn { let (collection, caller, caller_lookup) = create_collection::(); - let (instance, ..) = mint_instance::(0); - }: _(SystemOrigin::Signed(caller.clone()), collection, instance, Some(caller_lookup)) + let (asset, ..) = mint_asset::(0); + }: _(SystemOrigin::Signed(caller.clone()), collection, asset, Some(caller_lookup)) verify { - assert_last_event::(Event::Burned { collection, instance, owner: caller }.into()); + assert_last_event::(Event::Burned { collection, asset, owner: caller }.into()); } transfer { let (collection, caller, caller_lookup) = create_collection::(); - let (instance, ..) = mint_instance::(0); + let (asset, ..) = mint_asset::(0); let target: T::AccountId = account("target", 0, SEED); let target_lookup = T::Lookup::unlookup(target.clone()); - }: _(SystemOrigin::Signed(caller.clone()), collection, instance, target_lookup) + }: _(SystemOrigin::Signed(caller.clone()), collection, asset, target_lookup) verify { - assert_last_event::(Event::Transferred { collection, instance, from: caller, to: target }.into()); + assert_last_event::(Event::Transferred { collection, asset, from: caller, to: target }.into()); } redeposit { let i in 0 .. 5_000; let (collection, caller, caller_lookup) = create_collection::(); - let instances = (0..i).map(|x| mint_instance::(x as u16).0).collect::>(); + let assets = (0..i).map(|x| mint_asset::(x as u16).0).collect::>(); Uniques::::force_asset_status( SystemOrigin::Root.into(), collection, @@ -220,30 +218,30 @@ benchmarks_instance_pallet! { true, false, )?; - }: _(SystemOrigin::Signed(caller.clone()), collection, instances.clone()) + }: _(SystemOrigin::Signed(caller.clone()), collection, assets.clone()) verify { - assert_last_event::(Event::Redeposited { collection, successful_instances: instances }.into()); + assert_last_event::(Event::Redeposited { collection, successful_assets: assets }.into()); } freeze { let (collection, caller, caller_lookup) = create_collection::(); - let (instance, ..) = mint_instance::(0); - }: _(SystemOrigin::Signed(caller.clone()), T::Helper::collection(0), T::Helper::instance(0)) + let (asset, ..) = mint_asset::(0); + }: _(SystemOrigin::Signed(caller.clone()), T::Helper::collection(0), T::Helper::asset(0)) verify { - assert_last_event::(Event::Frozen { collection: T::Helper::collection(0), instance: T::Helper::instance(0) }.into()); + assert_last_event::(Event::Frozen { collection: T::Helper::collection(0), asset: T::Helper::asset(0) }.into()); } thaw { let (collection, caller, caller_lookup) = create_collection::(); - let (instance, ..) = mint_instance::(0); + let (asset, ..) = mint_asset::(0); Uniques::::freeze( SystemOrigin::Signed(caller.clone()).into(), collection, - instance, + asset, )?; - }: _(SystemOrigin::Signed(caller.clone()), collection, instance) + }: _(SystemOrigin::Signed(caller.clone()), collection, asset) verify { - assert_last_event::(Event::Thawed { collection, instance }.into()); + assert_last_event::(Event::Thawed { collection, asset }.into()); } freeze_collection { @@ -311,40 +309,40 @@ benchmarks_instance_pallet! { let value: BoundedVec<_, _> = vec![0u8; T::ValueLimit::get() as usize].try_into().unwrap(); let (collection, caller, _) = create_collection::(); - let (instance, ..) = mint_instance::(0); - add_instance_metadata::(instance); - }: _(SystemOrigin::Signed(caller), collection, Some(instance), key.clone(), value.clone()) + let (asset, ..) = mint_asset::(0); + add_asset_metadata::(asset); + }: _(SystemOrigin::Signed(caller), collection, Some(asset), key.clone(), value.clone()) verify { - assert_last_event::(Event::AttributeSet { collection, maybe_instance: Some(instance), key, value }.into()); + assert_last_event::(Event::AttributeSet { collection, maybe_asset: Some(asset), key, value }.into()); } clear_attribute { let (collection, caller, _) = create_collection::(); - let (instance, ..) = mint_instance::(0); - add_instance_metadata::(instance); - let (key, ..) = add_instance_attribute::(instance); - }: _(SystemOrigin::Signed(caller), collection, Some(instance), key.clone()) + let (asset, ..) = mint_asset::(0); + add_asset_metadata::(asset); + let (key, ..) = add_asset_attribute::(asset); + }: _(SystemOrigin::Signed(caller), collection, Some(asset), key.clone()) verify { - assert_last_event::(Event::AttributeCleared { collection, maybe_instance: Some(instance), key }.into()); + assert_last_event::(Event::AttributeCleared { collection, maybe_asset: Some(asset), key }.into()); } set_metadata { let data: BoundedVec<_, _> = vec![0u8; T::StringLimit::get() as usize].try_into().unwrap(); let (collection, caller, _) = create_collection::(); - let (instance, ..) = mint_instance::(0); - }: _(SystemOrigin::Signed(caller), collection, instance, data.clone(), false) + let (asset, ..) = mint_asset::(0); + }: _(SystemOrigin::Signed(caller), collection, asset, data.clone(), false) verify { - assert_last_event::(Event::MetadataSet { collection, instance, data, is_frozen: false }.into()); + assert_last_event::(Event::MetadataSet { collection, asset, data, is_frozen: false }.into()); } clear_metadata { let (collection, caller, _) = create_collection::(); - let (instance, ..) = mint_instance::(0); - add_instance_metadata::(instance); - }: _(SystemOrigin::Signed(caller), collection, instance) + let (asset, ..) = mint_asset::(0); + add_asset_metadata::(asset); + }: _(SystemOrigin::Signed(caller), collection, asset) verify { - assert_last_event::(Event::MetadataCleared { collection, instance }.into()); + assert_last_event::(Event::MetadataCleared { collection, asset }.into()); } set_collection_metadata { @@ -366,24 +364,24 @@ benchmarks_instance_pallet! { approve_transfer { let (collection, caller, _) = create_collection::(); - let (instance, ..) = mint_instance::(0); + let (asset, ..) = mint_asset::(0); let delegate: T::AccountId = account("delegate", 0, SEED); let delegate_lookup = T::Lookup::unlookup(delegate.clone()); - }: _(SystemOrigin::Signed(caller.clone()), collection, instance, delegate_lookup) + }: _(SystemOrigin::Signed(caller.clone()), collection, asset, delegate_lookup) verify { - assert_last_event::(Event::ApprovedTransfer { collection, instance, owner: caller, delegate }.into()); + assert_last_event::(Event::ApprovedTransfer { collection, asset, owner: caller, delegate }.into()); } cancel_approval { let (collection, caller, _) = create_collection::(); - let (instance, ..) = mint_instance::(0); + let (asset, ..) = mint_asset::(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, collection, instance, delegate_lookup.clone())?; - }: _(SystemOrigin::Signed(caller.clone()), collection, instance, Some(delegate_lookup)) + Uniques::::approve_transfer(origin, collection, asset, delegate_lookup.clone())?; + }: _(SystemOrigin::Signed(caller.clone()), collection, asset, Some(delegate_lookup)) verify { - assert_last_event::(Event::ApprovalCancelled { collection, instance, owner: caller, delegate }.into()); + assert_last_event::(Event::ApprovalCancelled { collection, asset, owner: caller, delegate }.into()); } set_accept_ownership { diff --git a/frame/uniques/src/functions.rs b/frame/uniques/src/functions.rs index eca72d6470b12..c73fcd5de18a5 100644 --- a/frame/uniques/src/functions.rs +++ b/frame/uniques/src/functions.rs @@ -24,32 +24,32 @@ use sp_runtime::{DispatchError, DispatchResult}; impl, I: 'static> Pallet { pub fn do_transfer( collection: T::CollectionId, - instance: T::InstanceId, + asset: T::AssetId, dest: T::AccountId, with_details: impl FnOnce( &CollectionDetailsFor, - &mut InstanceDetailsFor, + &mut AssetDetailsFor, ) -> DispatchResult, ) -> DispatchResult { let collection_details = Collection::::get(&collection).ok_or(Error::::UnknownCollection)?; ensure!(!collection_details.is_frozen, Error::::Frozen); - ensure!(!T::Locker::is_locked(collection, instance), Error::::Locked); + ensure!(!T::Locker::is_locked(collection, asset), Error::::Locked); let mut details = - Asset::::get(&collection, &instance).ok_or(Error::::UnknownCollection)?; + Asset::::get(&collection, &asset).ok_or(Error::::UnknownCollection)?; ensure!(!details.is_frozen, Error::::Frozen); with_details(&collection_details, &mut details)?; - Account::::remove((&details.owner, &collection, &instance)); - Account::::insert((&dest, &collection, &instance), ()); + Account::::remove((&details.owner, &collection, &asset)); + Account::::insert((&dest, &collection, &asset), ()); let origin = details.owner; details.owner = dest; - Asset::::insert(&collection, &instance, &details); + Asset::::insert(&collection, &asset, &details); Self::deposit_event(Event::Transferred { collection, - instance, + asset, from: origin, to: details.owner, }); @@ -77,8 +77,8 @@ impl, I: 'static> Pallet { freezer: admin, total_deposit: deposit, free_holding, - instances: 0, - instance_metadatas: 0, + assets: 0, + asset_metadatas: 0, attributes: 0, is_frozen: false, }, @@ -100,17 +100,17 @@ impl, I: 'static> Pallet { if let Some(check_owner) = maybe_check_owner { ensure!(collection_details.owner == check_owner, Error::::NoPermission); } - ensure!(collection_details.instances == witness.instances, Error::::BadWitness); + ensure!(collection_details.assets == witness.assets, Error::::BadWitness); ensure!( - collection_details.instance_metadatas == witness.instance_metadatas, + collection_details.asset_metadatas == witness.asset_metadatas, Error::::BadWitness ); ensure!(collection_details.attributes == witness.attributes, Error::::BadWitness); - for (instance, details) in Asset::::drain_prefix(&collection) { - Account::::remove((&details.owner, &collection, &instance)); + for (asset, details) in Asset::::drain_prefix(&collection) { + Account::::remove((&details.owner, &collection, &asset)); } - InstanceMetadataOf::::remove_prefix(&collection, None); + AssetMetadataOf::::remove_prefix(&collection, None); CollectionMetadataOf::::remove(&collection); Attribute::::remove_prefix((&collection,), None); CollectionAccount::::remove(&collection_details.owner, &collection); @@ -119,8 +119,8 @@ impl, I: 'static> Pallet { Self::deposit_event(Event::Destroyed { collection }); Ok(DestroyWitness { - instances: collection_details.instances, - instance_metadatas: collection_details.instance_metadatas, + assets: collection_details.assets, + asset_metadatas: collection_details.asset_metadatas, attributes: collection_details.attributes, }) }) @@ -128,11 +128,11 @@ impl, I: 'static> Pallet { pub fn do_mint( collection: T::CollectionId, - instance: T::InstanceId, + asset: T::AssetId, owner: T::AccountId, with_details: impl FnOnce(&CollectionDetailsFor) -> DispatchResult, ) -> DispatchResult { - ensure!(!Asset::::contains_key(collection, instance), Error::::AlreadyExists); + ensure!(!Asset::::contains_key(collection, asset), Error::::AlreadyExists); Collection::::try_mutate( &collection, @@ -142,58 +142,55 @@ impl, I: 'static> Pallet { with_details(collection_details)?; - let instances = - collection_details.instances.checked_add(1).ok_or(ArithmeticError::Overflow)?; - collection_details.instances = instances; + let assets = + collection_details.assets.checked_add(1).ok_or(ArithmeticError::Overflow)?; + collection_details.assets = assets; let deposit = match collection_details.free_holding { true => Zero::zero(), - false => T::InstanceDeposit::get(), + false => T::AssetDeposit::get(), }; T::Currency::reserve(&collection_details.owner, deposit)?; collection_details.total_deposit += deposit; let owner = owner.clone(); - Account::::insert((&owner, &collection, &instance), ()); - let details = InstanceDetails { owner, approved: None, is_frozen: false, deposit }; - Asset::::insert(&collection, &instance, details); + Account::::insert((&owner, &collection, &asset), ()); + let details = AssetDetails { owner, approved: None, is_frozen: false, deposit }; + Asset::::insert(&collection, &asset, details); Ok(()) }, )?; - Self::deposit_event(Event::Issued { collection, instance, owner }); + Self::deposit_event(Event::Issued { collection, asset, owner }); Ok(()) } pub fn do_burn( collection: T::CollectionId, - instance: T::InstanceId, - with_details: impl FnOnce( - &CollectionDetailsFor, - &InstanceDetailsFor, - ) -> DispatchResult, + asset: T::AssetId, + with_details: impl FnOnce(&CollectionDetailsFor, &AssetDetailsFor) -> DispatchResult, ) -> DispatchResult { let owner = Collection::::try_mutate( &collection, |maybe_collection_details| -> Result { let collection_details = maybe_collection_details.as_mut().ok_or(Error::::UnknownCollection)?; - let details = Asset::::get(&collection, &instance) + let details = Asset::::get(&collection, &asset) .ok_or(Error::::UnknownCollection)?; with_details(collection_details, &details)?; // Return the deposit. T::Currency::unreserve(&collection_details.owner, details.deposit); collection_details.total_deposit.saturating_reduce(details.deposit); - collection_details.instances.saturating_dec(); + collection_details.assets.saturating_dec(); Ok(details.owner) }, )?; - Asset::::remove(&collection, &instance); - Account::::remove((&owner, &collection, &instance)); + Asset::::remove(&collection, &asset); + Account::::remove((&owner, &collection, &asset)); - Self::deposit_event(Event::Burned { collection, instance, owner }); + Self::deposit_event(Event::Burned { collection, asset, owner }); Ok(()) } } diff --git a/frame/uniques/src/impl_nonfungibles.rs b/frame/uniques/src/impl_nonfungibles.rs index 702999cacec34..7f58a42e49706 100644 --- a/frame/uniques/src/impl_nonfungibles.rs +++ b/frame/uniques/src/impl_nonfungibles.rs @@ -26,60 +26,60 @@ use sp_runtime::{DispatchError, DispatchResult}; use sp_std::prelude::*; impl, I: 'static> Inspect<::AccountId> for Pallet { - type InstanceId = T::InstanceId; + type AssetId = T::AssetId; type CollectionId = T::CollectionId; fn owner( collection: &Self::CollectionId, - instance: &Self::InstanceId, + asset: &Self::AssetId, ) -> Option<::AccountId> { - Asset::::get(collection, instance).map(|a| a.owner) + Asset::::get(collection, asset).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 `collection` corresponding to `key`. + /// Returns the attribute value of `asset` of `collection` corresponding to `key`. /// - /// When `key` is empty, we return the instance metadata value. + /// When `key` is empty, we return the asset metadata value. /// /// By default this is `None`; no attributes are defined. fn attribute( collection: &Self::CollectionId, - instance: &Self::InstanceId, + asset: &Self::AssetId, key: &[u8], ) -> Option> { if key.is_empty() { - // We make the empty key map to the instance metadata value. - InstanceMetadataOf::::get(collection, instance).map(|m| m.data.into()) + // We make the empty key map to the asset metadata value. + AssetMetadataOf::::get(collection, asset).map(|m| m.data.into()) } else { let key = BoundedSlice::<_, _>::try_from(key).ok()?; - Attribute::::get((collection, Some(instance), key)).map(|a| a.0.into()) + Attribute::::get((collection, Some(asset), key)).map(|a| a.0.into()) } } - /// Returns the attribute value of `instance` of `collection` corresponding to `key`. + /// Returns the attribute value of `asset` of `collection` corresponding to `key`. /// - /// When `key` is empty, we return the instance metadata value. + /// When `key` is empty, we return the asset metadata value. /// /// By default this is `None`; no attributes are defined. fn collection_attribute(collection: &Self::CollectionId, key: &[u8]) -> Option> { if key.is_empty() { - // We make the empty key map to the instance metadata value. + // We make the empty key map to the asset metadata value. CollectionMetadataOf::::get(collection).map(|m| m.data.into()) } else { let key = BoundedSlice::<_, _>::try_from(key).ok()?; - Attribute::::get((collection, Option::::None, key)) + Attribute::::get((collection, Option::::None, key)) .map(|a| a.0.into()) } } - /// Returns `true` if the asset `instance` of `collection` may be transferred. + /// Returns `true` if the asset `asset` of `collection` may be transferred. /// /// Default implementation is that all assets are transferable. - fn can_transfer(collection: &Self::CollectionId, instance: &Self::InstanceId) -> bool { - match (Collection::::get(collection), Asset::::get(collection, instance)) { + fn can_transfer(collection: &Self::CollectionId, asset: &Self::AssetId) -> bool { + match (Collection::::get(collection), Asset::::get(collection, asset)) { (Some(cd), Some(id)) if !cd.is_frozen && !id.is_frozen => true, _ => false, } @@ -123,18 +123,18 @@ impl, I: 'static> Destroy<::AccountId> for Palle impl, I: 'static> Mutate<::AccountId> for Pallet { fn mint_into( collection: &Self::CollectionId, - instance: &Self::InstanceId, + asset: &Self::AssetId, who: &T::AccountId, ) -> DispatchResult { - Self::do_mint(*collection, *instance, who.clone(), |_| Ok(())) + Self::do_mint(*collection, *asset, who.clone(), |_| Ok(())) } fn burn( collection: &Self::CollectionId, - instance: &Self::InstanceId, + asset: &Self::AssetId, maybe_check_owner: Option<&T::AccountId>, ) -> DispatchResult { - Self::do_burn(*collection, *instance, |_, d| { + Self::do_burn(*collection, *asset, |_, d| { if let Some(check_owner) = maybe_check_owner { if &d.owner != check_owner { return Err(Error::::NoPermission.into()) @@ -148,44 +148,42 @@ impl, I: 'static> Mutate<::AccountId> for Pallet impl, I: 'static> Transfer for Pallet { fn transfer( collection: &Self::CollectionId, - instance: &Self::InstanceId, + asset: &Self::AssetId, destination: &T::AccountId, ) -> DispatchResult { - Self::do_transfer(*collection, *instance, destination.clone(), |_, _| Ok(())) + Self::do_transfer(*collection, *asset, destination.clone(), |_, _| Ok(())) } } impl, I: 'static> InspectEnumerable for Pallet { - /// Returns an iterator of the assets collections in existence. + /// Returns an iterator of the collections in existence. /// /// NOTE: iterating this list invokes a storage read per item. fn collections() -> Box> { Box::new(CollectionMetadataOf::::iter_keys()) } - /// Returns an iterator of the instances of an asset `collection` in existence. + /// Returns an iterator of the assets of an asset `collection` in existence. /// /// NOTE: iterating this list invokes a storage read per item. - fn instances(collection: &Self::CollectionId) -> Box> { - Box::new(InstanceMetadataOf::::iter_key_prefix(collection)) + fn assets(collection: &Self::CollectionId) -> Box> { + Box::new(AssetMetadataOf::::iter_key_prefix(collection)) } - /// Returns an iterator of the asset instances of all collectiones owned by `who`. + /// Returns an iterator of the assets 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 `collection` owned by `who`. + /// Returns an iterator of the assets of `collection` owned by `who`. /// /// NOTE: iterating this list invokes a storage read per item. fn owned_in_collection( collection: &Self::CollectionId, who: &T::AccountId, - ) -> Box> { + ) -> Box> { Box::new(Account::::iter_key_prefix((who, collection))) } } diff --git a/frame/uniques/src/lib.rs b/frame/uniques/src/lib.rs index 7276bda99c1ea..d339bfe7432b7 100644 --- a/frame/uniques/src/lib.rs +++ b/frame/uniques/src/lib.rs @@ -67,18 +67,16 @@ pub mod pallet { pub struct Pallet(_); #[cfg(feature = "runtime-benchmarks")] - pub trait BenchmarkHelper { + pub trait BenchmarkHelper { fn collection(i: u16) -> CollectionId; - fn instance(i: u16) -> InstanceId; + fn asset(i: u16) -> AssetId; } #[cfg(feature = "runtime-benchmarks")] - impl, InstanceId: From> BenchmarkHelper - for () - { + impl, AssetId: From> BenchmarkHelper for () { fn collection(i: u16) -> CollectionId { i.into() } - fn instance(i: u16) -> InstanceId { + fn asset(i: u16) -> AssetId { i.into() } } @@ -92,8 +90,8 @@ pub mod pallet { /// Identifier for the collection of asset. type CollectionId: Member + Parameter + MaxEncodedLen + Copy; - /// The type used to identify a unique asset within an assets collection. - type InstanceId: Member + Parameter + MaxEncodedLen + Copy; + /// The type used to identify a unique asset within a collection. + type AssetId: Member + Parameter + MaxEncodedLen + Copy; /// The currency mechanism, used for paying for reserves. type Currency: ReservableCurrency; @@ -111,15 +109,15 @@ pub mod pallet { >; /// Locker trait to enable Locking mechanism downstream. - type Locker: Locker; + type Locker: Locker; - /// The basic amount of funds that must be reserved for an assets collection. + /// The basic amount of funds that must be reserved for collection. #[pallet::constant] 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 asset. #[pallet::constant] - type InstanceDeposit: Get>; + type AssetDeposit: Get>; /// The basic amount of funds that must be reserved when adding metadata to your asset. #[pallet::constant] @@ -148,7 +146,7 @@ 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; @@ -176,14 +174,14 @@ pub mod pallet { ( NMapKey, // owner NMapKey, - NMapKey, + NMapKey, ), (), OptionQuery, >; #[pallet::storage] - /// The collectiones owned by any given account; set out this way so that collectiones owned by + /// 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< _, @@ -202,8 +200,8 @@ pub mod pallet { Blake2_128Concat, T::CollectionId, Blake2_128Concat, - T::InstanceId, - InstanceDetails>, + T::AssetId, + AssetDetails>, OptionQuery, >; @@ -218,14 +216,14 @@ pub mod pallet { >; #[pallet::storage] - /// Metadata of an asset instance. - pub(super) type InstanceMetadataOf, I: 'static = ()> = StorageDoubleMap< + /// Metadata of an asset. + pub(super) type AssetMetadataOf, I: 'static = ()> = StorageDoubleMap< _, Blake2_128Concat, T::CollectionId, Blake2_128Concat, - T::InstanceId, - InstanceMetadata, T::StringLimit>, + T::AssetId, + AssetMetadata, T::StringLimit>, OptionQuery, >; @@ -235,7 +233,7 @@ pub mod pallet { _, ( NMapKey, - NMapKey>, + NMapKey>, NMapKey>, ), (BoundedVec, DepositBalanceOf), @@ -251,21 +249,21 @@ pub mod pallet { ForceCreated { collection: T::CollectionId, owner: T::AccountId }, /// An asset `collection` was destroyed. Destroyed { collection: T::CollectionId }, - /// An asset `instance` was issued. - Issued { collection: T::CollectionId, instance: T::InstanceId, owner: T::AccountId }, - /// An asset `instance` was transferred. + /// An asset `asset` was issued. + Issued { collection: T::CollectionId, asset: T::AssetId, owner: T::AccountId }, + /// An asset `asset` was transferred. Transferred { collection: T::CollectionId, - instance: T::InstanceId, + asset: T::AssetId, from: T::AccountId, to: T::AccountId, }, - /// An asset `instance` was destroyed. - Burned { collection: T::CollectionId, instance: T::InstanceId, owner: T::AccountId }, - /// Some asset `instance` was frozen. - Frozen { collection: T::CollectionId, instance: T::InstanceId }, - /// Some asset `instance` was thawed. - Thawed { collection: T::CollectionId, instance: T::InstanceId }, + /// An asset `asset` was destroyed. + Burned { collection: T::CollectionId, asset: T::AssetId, owner: T::AccountId }, + /// Some asset `asset` was frozen. + Frozen { collection: T::CollectionId, asset: T::AssetId }, + /// Some asset `asset` was thawed. + Thawed { collection: T::CollectionId, asset: T::AssetId }, /// Some asset `collection` was frozen. CollectionFrozen { collection: T::CollectionId }, /// Some asset `collection` was thawed. @@ -279,19 +277,19 @@ pub mod pallet { admin: T::AccountId, freezer: T::AccountId, }, - /// An `instance` of an asset `collection` has been approved by the `owner` for transfer by + /// An `asset` of an asset `collection` has been approved by the `owner` for transfer by /// a `delegate`. ApprovedTransfer { collection: T::CollectionId, - instance: T::InstanceId, + asset: T::AssetId, owner: T::AccountId, delegate: T::AccountId, }, - /// An approval for a `delegate` account to transfer the `instance` of an asset + /// An approval for a `delegate` account to transfer the `asset` of an asset /// `collection` was cancelled by its `owner`. ApprovalCancelled { collection: T::CollectionId, - instance: T::InstanceId, + asset: T::AssetId, owner: T::AccountId, delegate: T::AccountId, }, @@ -305,28 +303,28 @@ pub mod pallet { }, /// Metadata has been cleared for an assets collection. CollectionMetadataCleared { collection: T::CollectionId }, - /// New metadata has been set for an asset instance. + /// New metadata has been set for an asset. MetadataSet { collection: T::CollectionId, - instance: T::InstanceId, + asset: T::AssetId, data: BoundedVec, is_frozen: bool, }, - /// Metadata has been cleared for an asset instance. - MetadataCleared { collection: T::CollectionId, instance: T::InstanceId }, - /// Metadata has been cleared for an asset instance. - Redeposited { collection: T::CollectionId, successful_instances: Vec }, - /// New attribute metadata has been set for an assets collection or instance. + /// Metadata has been cleared for an asset. + MetadataCleared { collection: T::CollectionId, asset: T::AssetId }, + /// Metadata has been cleared for an asset. + Redeposited { collection: T::CollectionId, successful_assets: Vec }, + /// New attribute metadata has been set for an assets collection or asset. AttributeSet { collection: T::CollectionId, - maybe_instance: Option, + maybe_asset: Option, key: BoundedVec, value: BoundedVec, }, - /// Attribute metadata has been cleared for an assets collection or instance. + /// Attribute metadata has been cleared for an assets collection or asset. AttributeCleared { collection: T::CollectionId, - maybe_instance: Option, + maybe_asset: Option, key: BoundedVec, }, /// Ownership acceptance has changed for an account. @@ -339,7 +337,7 @@ pub mod pallet { NoPermission, /// The given asset ID is unknown. UnknownCollection, - /// The asset instance ID has already been used for an asset. + /// The asset ID has already been used for an asset. AlreadyExists, /// The owner turned out to be different to what was expected. WrongOwner, @@ -347,7 +345,7 @@ pub mod pallet { BadWitness, /// The asset ID is already taken. InUse, - /// The asset instance or collection is frozen. + /// The asset or collection is frozen. Frozen, /// The delegate turned out to be different to what was expected. WrongDelegate, @@ -357,17 +355,17 @@ pub mod pallet { Unapproved, /// The named owner has not signed ownership of the collection is acceptable. Unaccepted, - /// The asset instance is locked. + /// The asset is locked. Locked, } impl, I: 'static> Pallet { - /// Get the owner of the asset instance, if the asset exists. - pub fn owner(collection: T::CollectionId, instance: T::InstanceId) -> Option { - Asset::::get(collection, instance).map(|i| i.owner) + /// Get the owner of the asset, if the asset exists. + pub fn owner(collection: T::CollectionId, asset: T::AssetId) -> Option { + Asset::::get(collection, asset).map(|i| i.owner) } - /// Get the owner of the asset instance, if the asset exists. + /// Get the owner of the asset, if the asset exists. pub fn collection_owner(collection: T::CollectionId) -> Option { Collection::::get(collection).map(|i| i.owner) } @@ -455,18 +453,18 @@ pub mod pallet { /// owner of the asset `collection`. /// /// - `collection`: The identifier of the assets collection to be destroyed. - /// - `witness`: Information on the instances minted in the assets collection. This must be + /// - `witness`: Information on the assets minted in the assets collection. This must be /// correct. /// /// Emits `Destroyed` event when successful. /// /// Weight: `O(n + m)` where: - /// - `n = witness.instances` - /// - `m = witness.instance_metadatas` + /// - `n = witness.assets` + /// - `m = witness.asset_metadatas` /// - `a = witness.attributes` #[pallet::weight(T::WeightInfo::destroy( - witness.instances, - witness.instance_metadatas, + witness.assets, + witness.asset_metadatas, witness.attributes, ))] pub fn destroy( @@ -481,19 +479,19 @@ pub mod pallet { let details = Self::do_destroy_collection(collection, witness, maybe_check_owner)?; Ok(Some(T::WeightInfo::destroy( - details.instances, - details.instance_metadatas, + details.assets, + details.asset_metadatas, details.attributes, )) .into()) } - /// Mint an asset instance of a particular collection. + /// Mint an asset of a particular collection. /// /// The origin must be Signed and the sender must be the Issuer of the asset `collection`. /// /// - `collection`: The collection of the asset to be minted. - /// - `instance`: The instance value of the asset to be minted. + /// - `asset`: The asset value of the asset to be minted. /// - `beneficiary`: The initial owner of the minted asset. /// /// Emits `Issued` event when successful. @@ -503,24 +501,24 @@ pub mod pallet { pub fn mint( origin: OriginFor, collection: T::CollectionId, - instance: T::InstanceId, + asset: T::AssetId, owner: ::Source, ) -> DispatchResult { let origin = ensure_signed(origin)?; let owner = T::Lookup::lookup(owner)?; - Self::do_mint(collection, instance, owner, |collection_details| { + Self::do_mint(collection, asset, owner, |collection_details| { ensure!(collection_details.issuer == origin, Error::::NoPermission); Ok(()) }) } - /// Destroy a single asset instance. + /// Destroy a single asset. /// /// Origin must be Signed and the sender should be the Admin of the asset `collection`. /// /// - `collection`: The collection of the asset to be burned. - /// - `instance`: The instance of the asset to be burned. + /// - `asset`: The asset of the asset to be burned. /// - `check_owner`: If `Some` then the operation will fail with `WrongOwner` unless the /// asset is owned by this value. /// @@ -532,13 +530,13 @@ pub mod pallet { pub fn burn( origin: OriginFor, collection: T::CollectionId, - instance: T::InstanceId, + asset: T::AssetId, check_owner: Option<::Source>, ) -> DispatchResult { let origin = ensure_signed(origin)?; let check_owner = check_owner.map(T::Lookup::lookup).transpose()?; - Self::do_burn(collection, instance, |collection_details, details| { + Self::do_burn(collection, asset, |collection_details, details| { let is_permitted = collection_details.admin == origin || details.owner == origin; ensure!(is_permitted, Error::::NoPermission); ensure!( @@ -553,12 +551,12 @@ pub mod pallet { /// /// Origin must be Signed and the signing account must be either: /// - the Admin of the asset `collection`; - /// - the Owner of the asset `instance`; - /// - the approved delegate for the asset `instance` (in this case, the approval is reset). + /// - the Owner of the asset `asset`; + /// - the approved delegate for the asset `asset` (in this case, the approval is reset). /// /// Arguments: /// - `collection`: The collection of the asset to be transferred. - /// - `instance`: The instance of the asset to be transferred. + /// - `asset`: The asset of the asset to be transferred. /// - `dest`: The account to receive ownership of the asset. /// /// Emits `Transferred`. @@ -568,13 +566,13 @@ pub mod pallet { pub fn transfer( origin: OriginFor, collection: T::CollectionId, - instance: T::InstanceId, + asset: T::AssetId, dest: ::Source, ) -> DispatchResult { let origin = ensure_signed(origin)?; let dest = T::Lookup::lookup(dest)?; - Self::do_transfer(collection, instance, dest, |collection_details, details| { + Self::do_transfer(collection, asset, 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); @@ -588,24 +586,23 @@ pub mod pallet { /// Origin must be Signed and the sender should be the Owner of the asset `collection`. /// /// - `collection`: The collection of the asset to be frozen. - /// - `instances`: The instances of the assets collection whose deposits will be - /// reevaluated. + /// - `assets`: The assets of the assets 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 assets 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 assets /// 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 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(assets.len())` + #[pallet::weight(T::WeightInfo::redeposit(assets.len() as u32))] pub fn redeposit( origin: OriginFor, collection: T::CollectionId, - instances: Vec, + assets: Vec, ) -> DispatchResult { let origin = ensure_signed(origin)?; @@ -614,12 +611,12 @@ pub mod pallet { ensure!(collection_details.owner == origin, Error::::NoPermission); let deposit = match collection_details.free_holding { true => Zero::zero(), - false => T::InstanceDeposit::get(), + false => T::AssetDeposit::get(), }; - let mut successful = Vec::with_capacity(instances.len()); - for instance in instances.into_iter() { - let mut details = match Asset::::get(&collection, &instance) { + let mut successful = Vec::with_capacity(assets.len()); + for asset in assets.into_iter() { + let mut details = match Asset::::get(&collection, &asset) { Some(x) => x, None => continue, }; @@ -638,25 +635,25 @@ pub mod pallet { collection_details.total_deposit.saturating_accrue(deposit); collection_details.total_deposit.saturating_reduce(old); details.deposit = deposit; - Asset::::insert(&collection, &instance, &details); - successful.push(instance); + Asset::::insert(&collection, &asset, &details); + successful.push(asset); } Collection::::insert(&collection, &collection_details); Self::deposit_event(Event::::Redeposited { collection, - successful_instances: successful, + successful_assets: successful, }); Ok(()) } - /// Disallow further unprivileged transfer of an asset instance. + /// Disallow further unprivileged transfer of an asset. /// /// Origin must be Signed and the sender should be the Freezer of the asset `collection`. /// /// - `collection`: The collection of the asset to be frozen. - /// - `instance`: The instance of the asset to be frozen. + /// - `asset`: The asset of the asset to be frozen. /// /// Emits `Frozen`. /// @@ -665,29 +662,29 @@ pub mod pallet { pub fn freeze( origin: OriginFor, collection: T::CollectionId, - instance: T::InstanceId, + asset: T::AssetId, ) -> DispatchResult { let origin = ensure_signed(origin)?; - let mut details = Asset::::get(&collection, &instance) - .ok_or(Error::::UnknownCollection)?; + let mut details = + Asset::::get(&collection, &asset).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(&collection, &instance, &details); + Asset::::insert(&collection, &asset, &details); - Self::deposit_event(Event::::Frozen { collection, instance }); + Self::deposit_event(Event::::Frozen { collection, asset }); Ok(()) } - /// Re-allow unprivileged transfer of an asset instance. + /// Re-allow unprivileged transfer of an asset. /// /// Origin must be Signed and the sender should be the Freezer of the asset `collection`. /// /// - `collection`: The collection of the asset to be thawed. - /// - `instance`: The instance of the asset to be thawed. + /// - `asset`: The asset of the asset to be thawed. /// /// Emits `Thawed`. /// @@ -696,20 +693,20 @@ pub mod pallet { pub fn thaw( origin: OriginFor, collection: T::CollectionId, - instance: T::InstanceId, + asset: T::AssetId, ) -> DispatchResult { let origin = ensure_signed(origin)?; - let mut details = Asset::::get(&collection, &instance) - .ok_or(Error::::UnknownCollection)?; + let mut details = + Asset::::get(&collection, &asset).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(&collection, &instance, &details); + Asset::::insert(&collection, &asset, &details); - Self::deposit_event(Event::::Thawed { collection, instance }); + Self::deposit_event(Event::::Thawed { collection, asset }); Ok(()) } @@ -852,12 +849,12 @@ pub mod pallet { }) } - /// Approve an instance to be transferred by a delegated third-party account. + /// Approve an asset 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 asset `asset`. /// /// - `collection`: The collection of the asset to be approved for delegated transfer. - /// - `instance`: The instance of the asset to be approved for delegated transfer. + /// - `asset`: The asset of the asset to be approved for delegated transfer. /// - `delegate`: The account to delegate permission to transfer the asset. /// /// Emits `ApprovedTransfer` on success. @@ -867,7 +864,7 @@ pub mod pallet { pub fn approve_transfer( origin: OriginFor, collection: T::CollectionId, - instance: T::InstanceId, + asset: T::AssetId, delegate: ::Source, ) -> DispatchResult { let maybe_check: Option = T::ForceOrigin::try_origin(origin) @@ -878,8 +875,8 @@ pub mod pallet { let collection_details = Collection::::get(&collection).ok_or(Error::::UnknownCollection)?; - let mut details = Asset::::get(&collection, &instance) - .ok_or(Error::::UnknownCollection)?; + let mut details = + Asset::::get(&collection, &asset).ok_or(Error::::UnknownCollection)?; if let Some(check) = maybe_check { let permitted = check == collection_details.admin || check == details.owner; @@ -887,12 +884,12 @@ pub mod pallet { } details.approved = Some(delegate); - Asset::::insert(&collection, &instance, &details); + Asset::::insert(&collection, &asset, &details); let delegate = details.approved.expect("set as Some above; qed"); Self::deposit_event(Event::ApprovedTransfer { collection, - instance, + asset, owner: details.owner, delegate, }); @@ -905,11 +902,11 @@ pub mod pallet { /// Origin must be either: /// - the `Force` origin; /// - `Signed` with the signer being the Admin of the asset `collection`; - /// - `Signed` with the signer being the Owner of the asset `instance`; + /// - `Signed` with the signer being the Owner of the asset `asset`; /// /// Arguments: /// - `collection`: The collection of the asset of whose approval will be cancelled. - /// - `instance`: The instance of the asset of whose approval will be cancelled. + /// - `asset`: The asset of the asset 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. /// @@ -920,7 +917,7 @@ pub mod pallet { pub fn cancel_approval( origin: OriginFor, collection: T::CollectionId, - instance: T::InstanceId, + asset: T::AssetId, maybe_check_delegate: Option<::Source>, ) -> DispatchResult { let maybe_check: Option = T::ForceOrigin::try_origin(origin) @@ -929,8 +926,8 @@ pub mod pallet { let collection_details = Collection::::get(&collection).ok_or(Error::::UnknownCollection)?; - let mut details = Asset::::get(&collection, &instance) - .ok_or(Error::::UnknownCollection)?; + let mut details = + Asset::::get(&collection, &asset).ok_or(Error::::UnknownCollection)?; if let Some(check) = maybe_check { let permitted = check == collection_details.admin || check == details.owner; ensure!(permitted, Error::::NoPermission); @@ -941,10 +938,10 @@ pub mod pallet { ensure!(check_delegate == old, Error::::WrongDelegate); } - Asset::::insert(&collection, &instance, &details); + Asset::::insert(&collection, &asset, &details); Self::deposit_event(Event::ApprovalCancelled { collection, - instance, + asset, owner: details.owner, delegate: old, }); @@ -961,7 +958,7 @@ pub mod pallet { /// - `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 + /// - `free_holding`: Whether a deposit is taken for holding an asset of this asset /// collection. /// - `is_frozen`: Whether this assets collection is frozen except for permissioned/admin /// instructions. @@ -1001,7 +998,7 @@ pub mod pallet { }) } - /// Set an attribute for an assets collection or instance. + /// Set an attribute for an assets collection or asset. /// /// Origin must be either `ForceOrigin` or Signed and the sender should be the Owner of the /// asset `collection`. @@ -1010,9 +1007,8 @@ pub mod pallet { /// `MetadataDepositBase + DepositPerByte * (key.len + value.len)` taking into /// account any already reserved funds. /// - /// - `collection`: The identifier of the assets collection whose instance's metadata to - /// set. - /// - `maybe_instance`: The identifier of the asset instance whose metadata to set. + /// - `collection`: The identifier of the assets collection whose asset's metadata to set. + /// - `maybe_asset`: The identifier of the asset whose metadata to set. /// - `key`: The key of the attribute. /// - `value`: The value to which to set the attribute. /// @@ -1023,7 +1019,7 @@ pub mod pallet { pub fn set_attribute( origin: OriginFor, collection: T::CollectionId, - maybe_instance: Option, + maybe_asset: Option, key: BoundedVec, value: BoundedVec, ) -> DispatchResult { @@ -1036,14 +1032,13 @@ pub mod pallet { if let Some(check_owner) = &maybe_check_owner { ensure!(check_owner == &collection_details.owner, Error::::NoPermission); } - let maybe_is_frozen = match maybe_instance { + let maybe_is_frozen = match maybe_asset { None => CollectionMetadataOf::::get(collection).map(|v| v.is_frozen), - Some(instance) => - InstanceMetadataOf::::get(collection, instance).map(|v| v.is_frozen), + Some(asset) => AssetMetadataOf::::get(collection, asset).map(|v| v.is_frozen), }; ensure!(!maybe_is_frozen.unwrap_or(false), Error::::Frozen); - let attribute = Attribute::::get((collection, maybe_instance, &key)); + let attribute = Attribute::::get((collection, maybe_asset, &key)); if attribute.is_none() { collection_details.attributes.saturating_inc(); } @@ -1062,22 +1057,21 @@ pub mod pallet { T::Currency::unreserve(&collection_details.owner, old_deposit - deposit); } - Attribute::::insert((&collection, maybe_instance, &key), (&value, deposit)); + Attribute::::insert((&collection, maybe_asset, &key), (&value, deposit)); Collection::::insert(collection, &collection_details); - Self::deposit_event(Event::AttributeSet { collection, maybe_instance, key, value }); + Self::deposit_event(Event::AttributeSet { collection, maybe_asset, key, value }); Ok(()) } - /// Clear an attribute for an assets collection or instance. + /// Clear an attribute for an assets collection or asset. /// /// Origin must be either `ForceOrigin` or Signed and the sender should be the Owner of the /// asset `collection`. /// /// Any deposit is freed for the assets collection owner. /// - /// - `collection`: The identifier of the assets collection whose instance's metadata to - /// clear. - /// - `maybe_instance`: The identifier of the asset instance whose metadata to clear. + /// - `collection`: The identifier of the assets collection whose asset's metadata to clear. + /// - `maybe_asset`: The identifier of the asset whose metadata to clear. /// - `key`: The key of the attribute. /// /// Emits `AttributeCleared`. @@ -1087,7 +1081,7 @@ pub mod pallet { pub fn clear_attribute( origin: OriginFor, collection: T::CollectionId, - maybe_instance: Option, + maybe_asset: Option, key: BoundedVec, ) -> DispatchResult { let maybe_check_owner = T::ForceOrigin::try_origin(origin) @@ -1099,25 +1093,23 @@ pub mod pallet { if let Some(check_owner) = &maybe_check_owner { ensure!(check_owner == &collection_details.owner, Error::::NoPermission); } - let maybe_is_frozen = match maybe_instance { + let maybe_is_frozen = match maybe_asset { None => CollectionMetadataOf::::get(collection).map(|v| v.is_frozen), - Some(instance) => - InstanceMetadataOf::::get(collection, instance).map(|v| v.is_frozen), + Some(asset) => AssetMetadataOf::::get(collection, asset).map(|v| v.is_frozen), }; ensure!(!maybe_is_frozen.unwrap_or(false), Error::::Frozen); - if let Some((_, deposit)) = Attribute::::take((collection, maybe_instance, &key)) - { + if let Some((_, deposit)) = Attribute::::take((collection, maybe_asset, &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_instance, key }); + Self::deposit_event(Event::AttributeCleared { collection, maybe_asset, key }); } Ok(()) } - /// Set the metadata for an asset instance. + /// Set the metadata for an asset. /// /// Origin must be either `ForceOrigin` or Signed and the sender should be the Owner of the /// asset `collection`. @@ -1126,9 +1118,8 @@ pub mod pallet { /// `MetadataDepositBase + DepositPerByte * data.len` taking into /// account any already reserved funds. /// - /// - `collection`: The identifier of the assets collection whose instance's metadata to - /// set. - /// - `instance`: The identifier of the asset instance whose metadata to set. + /// - `collection`: The identifier of the assets collection whose asset's metadata to set. + /// - `asset`: The identifier of the asset whose metadata to set. /// - `data`: The general information of this asset. Limited in length by `StringLimit`. /// - `is_frozen`: Whether the metadata should be frozen against further changes. /// @@ -1139,7 +1130,7 @@ pub mod pallet { pub fn set_metadata( origin: OriginFor, collection: T::CollectionId, - instance: T::InstanceId, + asset: T::AssetId, data: BoundedVec, is_frozen: bool, ) -> DispatchResult { @@ -1154,12 +1145,12 @@ pub mod pallet { ensure!(check_owner == &collection_details.owner, Error::::NoPermission); } - InstanceMetadataOf::::try_mutate_exists(collection, instance, |metadata| { + AssetMetadataOf::::try_mutate_exists(collection, asset, |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() { - collection_details.instance_metadatas.saturating_inc(); + collection_details.asset_metadatas.saturating_inc(); } let old_deposit = metadata.take().map_or(Zero::zero(), |m| m.deposit); collection_details.total_deposit.saturating_reduce(old_deposit); @@ -1176,24 +1167,23 @@ pub mod pallet { } collection_details.total_deposit.saturating_accrue(deposit); - *metadata = Some(InstanceMetadata { deposit, data: data.clone(), is_frozen }); + *metadata = Some(AssetMetadata { deposit, data: data.clone(), is_frozen }); Collection::::insert(&collection, &collection_details); - Self::deposit_event(Event::MetadataSet { collection, instance, data, is_frozen }); + Self::deposit_event(Event::MetadataSet { collection, asset, data, is_frozen }); Ok(()) }) } - /// Clear the metadata for an asset instance. + /// Clear the metadata for an asset. /// /// Origin must be either `ForceOrigin` or Signed and the sender should be the Owner of the - /// asset `instance`. + /// asset `asset`. /// /// Any deposit is freed for the assets collection owner. /// - /// - `collection`: The identifier of the assets collection whose instance's metadata to - /// clear. - /// - `instance`: The identifier of the asset instance whose metadata to clear. + /// - `collection`: The identifier of the assets collection whose asset's metadata to clear. + /// - `asset`: The identifier of the asset whose metadata to clear. /// /// Emits `MetadataCleared`. /// @@ -1202,7 +1192,7 @@ pub mod pallet { pub fn clear_metadata( origin: OriginFor, collection: T::CollectionId, - instance: T::InstanceId, + asset: T::AssetId, ) -> DispatchResult { let maybe_check_owner = T::ForceOrigin::try_origin(origin) .map(|_| None) @@ -1214,19 +1204,19 @@ pub mod pallet { ensure!(check_owner == &collection_details.owner, Error::::NoPermission); } - InstanceMetadataOf::::try_mutate_exists(collection, instance, |metadata| { + AssetMetadataOf::::try_mutate_exists(collection, asset, |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() { - collection_details.instance_metadatas.saturating_dec(); + collection_details.asset_metadatas.saturating_dec(); } let deposit = metadata.take().ok_or(Error::::UnknownCollection)?.deposit; T::Currency::unreserve(&collection_details.owner, deposit); collection_details.total_deposit.saturating_reduce(deposit); Collection::::insert(&collection, &collection_details); - Self::deposit_event(Event::MetadataCleared { collection, instance }); + Self::deposit_event(Event::MetadataCleared { collection, asset }); Ok(()) }) } diff --git a/frame/uniques/src/mock.rs b/frame/uniques/src/mock.rs index 38a347b41087f..8ff3aca77c486 100644 --- a/frame/uniques/src/mock.rs +++ b/frame/uniques/src/mock.rs @@ -87,13 +87,13 @@ impl pallet_balances::Config for Test { impl Config for Test { type Event = Event; type CollectionId = u32; - type InstanceId = u32; + type AssetId = u32; type Currency = Balances; type CreateOrigin = AsEnsureOriginWithArg>; type ForceOrigin = frame_system::EnsureRoot; type Locker = (); type CollectionDeposit = ConstU64<2>; - type InstanceDeposit = ConstU64<1>; + type AssetDeposit = ConstU64<1>; type MetadataDepositBase = ConstU64<1>; type AttributeDepositBase = ConstU64<1>; type DepositPerByte = ConstU64<1>; diff --git a/frame/uniques/src/tests.rs b/frame/uniques/src/tests.rs index 20963a58f3b79..cc8dc238e72d9 100644 --- a/frame/uniques/src/tests.rs +++ b/frame/uniques/src/tests.rs @@ -42,13 +42,13 @@ fn assets() -> Vec<(u64, u32, u32)> { .flatten() { let details = Collection::::get(collection).unwrap(); - let instances = Asset::::iter_prefix(collection).count() as u32; - assert_eq!(details.instances, instances); + let assets = Asset::::iter_prefix(collection).count() as u32; + assert_eq!(details.assets, assets); } r } -fn collectiones() -> Vec<(u64, u32)> { +fn collections() -> Vec<(u64, u32)> { let mut r: Vec<_> = CollectionAccount::::iter().map(|x| (x.0, x.1)).collect(); r.sort(); let mut s: Vec<_> = Collection::::iter().map(|x| (x.1.owner, x.0)).collect(); @@ -82,12 +82,12 @@ 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!(collectiones(), 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_ok!(Uniques::force_create(Origin::root(), 1, 2, true)); - assert_eq!(collectiones(), 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)]); }); @@ -99,7 +99,7 @@ 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!(collectiones(), vec![(1, 0)]); + 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!(CollectionMetadataOf::::contains_key(0)); @@ -109,19 +109,19 @@ fn lifecycle_should_work() { 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!(Collection::::get(0).unwrap().instances, 2); - assert_eq!(Collection::::get(0).unwrap().instance_metadatas, 0); + assert_eq!(Collection::::get(0).unwrap().assets, 2); + assert_eq!(Collection::::get(0).unwrap().asset_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!(AssetMetadataOf::::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!(AssetMetadataOf::::contains_key(0, 69)); let w = Collection::::get(0).unwrap().destroy_witness(); - assert_eq!(w.instances, 2); - assert_eq!(w.instance_metadatas, 2); + assert_eq!(w.assets, 2); + assert_eq!(w.asset_metadatas, 2); assert_ok!(Uniques::destroy(Origin::signed(1), 0, w)); assert_eq!(Balances::reserved_balance(&1), 0); @@ -129,9 +129,9 @@ fn lifecycle_should_work() { assert!(!Asset::::contains_key(0, 42)); assert!(!Asset::::contains_key(0, 69)); assert!(!CollectionMetadataOf::::contains_key(0)); - assert!(!InstanceMetadataOf::::contains_key(0, 42)); - assert!(!InstanceMetadataOf::::contains_key(0, 69)); - assert_eq!(collectiones(), vec![]); + assert!(!AssetMetadataOf::::contains_key(0, 42)); + assert!(!AssetMetadataOf::::contains_key(0, 69)); + assert_eq!(collections(), vec![]); assert_eq!(assets(), vec![]); }); } @@ -154,7 +154,7 @@ 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!(collectiones(), vec![(1, 0)]); + assert_eq!(collections(), vec![(1, 0)]); assert_eq!(assets(), vec![(1, 0, 42)]); }); } @@ -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!(collectiones(), 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!(collectiones(), 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); @@ -246,7 +246,7 @@ fn transfer_owner_should_work() { 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!(collectiones(), 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); @@ -338,7 +338,7 @@ fn set_collection_metadata_should_work() { } #[test] -fn set_instance_metadata_should_work() { +fn set_asset_metadata_should_work() { new_test_ext().execute_with(|| { Balances::make_free_balance_be(&1, 30); @@ -354,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!(AssetMetadataOf::::contains_key(0, 42)); // Force origin works, too. assert_ok!(Uniques::set_metadata(Origin::root(), 0, 42, bvec![0u8; 18], false)); @@ -390,7 +390,7 @@ fn set_instance_metadata_should_work() { Error::::UnknownCollection ); assert_ok!(Uniques::clear_metadata(Origin::signed(1), 0, 42)); - assert!(!InstanceMetadataOf::::contains_key(0, 42)); + assert!(!AssetMetadataOf::::contains_key(0, 42)); }); } diff --git a/frame/uniques/src/types.rs b/frame/uniques/src/types.rs index 52bbd52770fea..cf4d3d9852afc 100644 --- a/frame/uniques/src/types.rs +++ b/frame/uniques/src/types.rs @@ -28,8 +28,8 @@ pub(super) type DepositBalanceOf = <>::Currency as Currency<::AccountId>>::Balance; pub(super) type CollectionDetailsFor = CollectionDetails<::AccountId, DepositBalanceOf>; -pub(super) type InstanceDetailsFor = - InstanceDetails<::AccountId, DepositBalanceOf>; +pub(super) type AssetDetailsFor = + AssetDetails<::AccountId, DepositBalanceOf>; #[derive(Clone, Encode, Decode, Eq, PartialEq, RuntimeDebug, TypeInfo, MaxEncodedLen)] pub struct CollectionDetails { @@ -44,12 +44,12 @@ pub struct CollectionDetails { /// The total balance deposited for the all storage associated with this assets collection. /// Used by `destroy`. pub(super) total_deposit: DepositBalance, - /// If `true`, then no deposit is needed to hold instances of this collection. + /// If `true`, then no deposit is needed to hold assets of this collection. pub(super) free_holding: bool, - /// The total number of outstanding instances of this assets collection. - pub(super) instances: u32, - /// The total number of outstanding instance metadata of this assets collection. - pub(super) instance_metadatas: u32, + /// The total number of outstanding assets of this assets collection. + pub(super) assets: u32, + /// The total number of outstanding asset metadata of this assets collection. + pub(super) asset_metadatas: u32, /// The total number of attributes for this assets collection. pub(super) attributes: u32, /// Whether the asset is frozen for non-admin transfers. @@ -59,12 +59,12 @@ pub struct CollectionDetails { /// 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 assets collection. + /// The total number of outstanding assets of this assets collection. #[codec(compact)] - pub instances: u32, - /// The total number of outstanding instance metadata of this assets collection. + pub assets: u32, + /// The total number of outstanding asset metadata of this assets collection. #[codec(compact)] - pub instance_metadatas: u32, + pub asset_metadatas: u32, #[codec(compact)] /// The total number of attributes for this assets collection. pub attributes: u32, @@ -73,8 +73,8 @@ pub struct DestroyWitness { impl CollectionDetails { pub fn destroy_witness(&self) -> DestroyWitness { DestroyWitness { - instances: self.instances, - instance_metadatas: self.instance_metadatas, + assets: self.assets, + asset_metadatas: self.asset_metadatas, attributes: self.attributes, } } @@ -82,7 +82,7 @@ impl CollectionDetails { /// Information concerning the ownership of a single unique asset. #[derive(Clone, Encode, Decode, Eq, PartialEq, RuntimeDebug, Default, TypeInfo, MaxEncodedLen)] -pub struct InstanceDetails { +pub struct AssetDetails { /// The owner of this asset. pub(super) owner: AccountId, /// The approved transferrer of this asset, if one is set. @@ -113,7 +113,7 @@ pub struct CollectionMetadata> { #[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 AssetMetadata> { /// The balance deposited for this metadata. /// /// This pays for the data stored in this struct. diff --git a/frame/uniques/src/weights.rs b/frame/uniques/src/weights.rs index 2f490724abcb8..922f783e72932 100644 --- a/frame/uniques/src/weights.rs +++ b/frame/uniques/src/weights.rs @@ -93,7 +93,7 @@ impl WeightInfo for SubstrateWeight { // Storage: Uniques CollectionAccount (r:0 w:1) // Storage: Uniques Attribute (r:0 w:1000) // Storage: Uniques CollectionMetadataOf (r:0 w:1) - // Storage: Uniques InstanceMetadataOf (r:0 w:1000) + // Storage: Uniques AssetMetadataOf (r:0 w:1000) // Storage: Uniques Account (r:0 w:20) fn destroy(n: u32, m: u32, a: u32, ) -> Weight { (0 as Weight) @@ -193,7 +193,7 @@ impl WeightInfo for SubstrateWeight { .saturating_add(T::DbWeight::get().writes(2 as Weight)) } // Storage: Uniques Collection (r:1 w:1) - // Storage: Uniques InstanceMetadataOf (r:1 w:0) + // Storage: Uniques AssetMetadataOf (r:1 w:0) // Storage: Uniques Attribute (r:1 w:1) fn set_attribute() -> Weight { (37_010_000 as Weight) @@ -201,7 +201,7 @@ impl WeightInfo for SubstrateWeight { .saturating_add(T::DbWeight::get().writes(2 as Weight)) } // Storage: Uniques Collection (r:1 w:1) - // Storage: Uniques InstanceMetadataOf (r:1 w:0) + // Storage: Uniques AssetMetadataOf (r:1 w:0) // Storage: Uniques Attribute (r:1 w:1) fn clear_attribute() -> Weight { (34_432_000 as Weight) @@ -209,14 +209,14 @@ impl WeightInfo for SubstrateWeight { .saturating_add(T::DbWeight::get().writes(2 as Weight)) } // Storage: Uniques Collection (r:1 w:1) - // Storage: Uniques InstanceMetadataOf (r:1 w:1) + // Storage: Uniques AssetMetadataOf (r:1 w:1) fn set_metadata() -> Weight { (28_575_000 as Weight) .saturating_add(T::DbWeight::get().reads(2 as Weight)) .saturating_add(T::DbWeight::get().writes(2 as Weight)) } // Storage: Uniques Collection (r:1 w:1) - // Storage: Uniques InstanceMetadataOf (r:1 w:1) + // Storage: Uniques AssetMetadataOf (r:1 w:1) fn clear_metadata() -> Weight { (28_730_000 as Weight) .saturating_add(T::DbWeight::get().reads(2 as Weight)) @@ -280,7 +280,7 @@ impl WeightInfo for () { // Storage: Uniques CollectionAccount (r:0 w:1) // Storage: Uniques Attribute (r:0 w:1000) // Storage: Uniques CollectionMetadataOf (r:0 w:1) - // Storage: Uniques InstanceMetadataOf (r:0 w:1000) + // Storage: Uniques AssetMetadataOf (r:0 w:1000) // Storage: Uniques Account (r:0 w:20) fn destroy(n: u32, m: u32, a: u32, ) -> Weight { (0 as Weight) @@ -380,7 +380,7 @@ impl WeightInfo for () { .saturating_add(RocksDbWeight::get().writes(2 as Weight)) } // Storage: Uniques Collection (r:1 w:1) - // Storage: Uniques InstanceMetadataOf (r:1 w:0) + // Storage: Uniques AssetMetadataOf (r:1 w:0) // Storage: Uniques Attribute (r:1 w:1) fn set_attribute() -> Weight { (37_010_000 as Weight) @@ -388,7 +388,7 @@ impl WeightInfo for () { .saturating_add(RocksDbWeight::get().writes(2 as Weight)) } // Storage: Uniques Collection (r:1 w:1) - // Storage: Uniques InstanceMetadataOf (r:1 w:0) + // Storage: Uniques AssetMetadataOf (r:1 w:0) // Storage: Uniques Attribute (r:1 w:1) fn clear_attribute() -> Weight { (34_432_000 as Weight) @@ -396,14 +396,14 @@ impl WeightInfo for () { .saturating_add(RocksDbWeight::get().writes(2 as Weight)) } // Storage: Uniques Collection (r:1 w:1) - // Storage: Uniques InstanceMetadataOf (r:1 w:1) + // Storage: Uniques AssetMetadataOf (r:1 w:1) fn set_metadata() -> Weight { (28_575_000 as Weight) .saturating_add(RocksDbWeight::get().reads(2 as Weight)) .saturating_add(RocksDbWeight::get().writes(2 as Weight)) } // Storage: Uniques Collection (r:1 w:1) - // Storage: Uniques InstanceMetadataOf (r:1 w:1) + // Storage: Uniques AssetMetadataOf (r:1 w:1) fn clear_metadata() -> Weight { (28_730_000 as Weight) .saturating_add(RocksDbWeight::get().reads(2 as Weight)) From cd89fa642c74050d3079827cbc79bdfd09a99f0b Mon Sep 17 00:00:00 2001 From: Jegor Sidorenko Date: Tue, 10 May 2022 18:45:19 +0200 Subject: [PATCH 04/16] Change "asset `collection`" to "`collection`" --- .../support/src/traits/tokens/nonfungible.rs | 14 ++-- .../support/src/traits/tokens/nonfungibles.rs | 18 ++--- frame/uniques/src/impl_nonfungibles.rs | 4 +- frame/uniques/src/lib.rs | 66 +++++++++---------- 4 files changed, 51 insertions(+), 51 deletions(-) diff --git a/frame/support/src/traits/tokens/nonfungible.rs b/frame/support/src/traits/tokens/nonfungible.rs index 08b0c8408b2b2..ec213801cfdb7 100644 --- a/frame/support/src/traits/tokens/nonfungible.rs +++ b/frame/support/src/traits/tokens/nonfungible.rs @@ -35,7 +35,7 @@ pub trait Inspect { /// Type for identifying an asset. type AssetId; - /// Returns the owner of asset `asset`, or `None` if the asset doesn't exist or has no + /// Returns the owner of `asset`, or `None` if the asset doesn't exist or has no /// owner. fn owner(asset: &Self::AssetId) -> Option; @@ -54,7 +54,7 @@ pub trait Inspect { .and_then(|v| V::decode(&mut &v[..]).ok()) } - /// Returns `true` if the asset `asset` may be transferred. + /// Returns `true` if the `asset` may be transferred. /// /// Default implementation is that all assets are transferable. fn can_transfer(_asset: &Self::AssetId) -> bool { @@ -65,7 +65,7 @@ pub trait Inspect { /// Interface for enumerating assets in existence or owned by a given account over a collection /// of NFTs. pub trait InspectEnumerable: Inspect { - /// Returns an iterator of the assets of an asset `collection` in existence. + /// Returns an iterator of the assets within a `collection` in existence. fn assets() -> Box>; /// Returns an iterator of the assets of all collections owned by `who`. @@ -75,21 +75,21 @@ pub trait InspectEnumerable: Inspect { /// Trait for providing an interface for NFT-like assets which may be minted, burned and/or have /// attributes set on them. pub trait Mutate: Inspect { - /// Mint some asset `asset` to be owned by `who`. + /// Mint some `asset` to be owned by `who`. /// /// By default, this is not a supported operation. fn mint_into(_asset: &Self::AssetId, _who: &AccountId) -> DispatchResult { Err(TokenError::Unsupported.into()) } - /// Burn some asset `asset`. + /// Burn some `asset`. /// /// By default, this is not a supported operation. fn burn(_asset: &Self::AssetId, _maybe_check_owner: Option<&AccountId>) -> DispatchResult { Err(TokenError::Unsupported.into()) } - /// Set attribute `value` of asset `asset`'s `key`. + /// Set attribute `value` of `asset`'s `key`. /// /// By default, this is not a supported operation. fn set_attribute(_asset: &Self::AssetId, _key: &[u8], _value: &[u8]) -> DispatchResult { @@ -110,7 +110,7 @@ pub trait Mutate: Inspect { /// Trait for providing a non-fungible set of assets which can only be transferred. pub trait Transfer: Inspect { - /// Transfer asset `asset` into `destination` account. + /// Transfer `asset` into `destination` account. fn transfer(asset: &Self::AssetId, destination: &AccountId) -> DispatchResult; } diff --git a/frame/support/src/traits/tokens/nonfungibles.rs b/frame/support/src/traits/tokens/nonfungibles.rs index 4b782d872048c..7bf913953832a 100644 --- a/frame/support/src/traits/tokens/nonfungibles.rs +++ b/frame/support/src/traits/tokens/nonfungibles.rs @@ -41,11 +41,11 @@ pub trait Inspect { /// assets). type CollectionId; - /// Returns the owner of asset `asset` of `collection`, or `None` if the asset doesn't exist + /// Returns the owner of `asset` of `collection`, or `None` if the asset doesn't exist /// (or somehow has no owner). fn owner(collection: &Self::CollectionId, asset: &Self::AssetId) -> Option; - /// Returns the owner of the asset `collection`, if there is one. For many NFTs this may not + /// 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 an assets collection /// results in `None` here. fn collection_owner(_collection: &Self::CollectionId) -> Option { @@ -94,7 +94,7 @@ pub trait Inspect { .and_then(|v| V::decode(&mut &v[..]).ok()) } - /// Returns `true` if the asset `asset` of `collection` may be transferred. + /// Returns `true` if the `asset` of `collection` may be transferred. /// /// Default implementation is that all assets are transferable. fn can_transfer(_collection: &Self::CollectionId, _asset: &Self::AssetId) -> bool { @@ -108,7 +108,7 @@ pub trait InspectEnumerable: Inspect { /// Returns an iterator of the assets collections in existence. fn collections() -> Box>; - /// Returns an iterator of the assets of an asset `collection` in existence. + /// Returns an iterator of the assets of a `collection` in existence. fn assets(collection: &Self::CollectionId) -> Box>; /// Returns an iterator of the assets of all collections owned by `who`. @@ -159,7 +159,7 @@ pub trait Destroy: Inspect { /// Trait for providing an interface for multiple collections of NFT-like assets which may be /// minted, burned and/or have attributes set on them. pub trait Mutate: Inspect { - /// Mint some asset `asset` of `collection` to be owned by `who`. + /// Mint some `asset` of `collection` to be owned by `who`. /// /// By default, this is not a supported operation. fn mint_into( @@ -170,7 +170,7 @@ pub trait Mutate: Inspect { Err(TokenError::Unsupported.into()) } - /// Burn some asset `asset` of `collection`. + /// Burn some `asset` of `collection`. /// /// By default, this is not a supported operation. fn burn( @@ -181,7 +181,7 @@ pub trait Mutate: Inspect { Err(TokenError::Unsupported.into()) } - /// Set attribute `value` of asset `asset` of `collection`'s `key`. + /// Set attribute `value` of `asset` of `collection`'s `key`. /// /// By default, this is not a supported operation. fn set_attribute( @@ -205,7 +205,7 @@ pub trait Mutate: Inspect { key.using_encoded(|k| value.using_encoded(|v| Self::set_attribute(collection, asset, k, v))) } - /// Set attribute `value` of asset `collection`'s `key`. + /// Set attribute `value` of `collection`'s `key`. /// /// By default, this is not a supported operation. fn set_collection_attribute( @@ -232,7 +232,7 @@ pub trait Mutate: Inspect { /// Trait for providing a non-fungible sets of assets which can only be transferred. pub trait Transfer: Inspect { - /// Transfer asset `asset` of `collection` into `destination` account. + /// Transfer `asset` of `collection` into `destination` account. fn transfer( collection: &Self::CollectionId, asset: &Self::AssetId, diff --git a/frame/uniques/src/impl_nonfungibles.rs b/frame/uniques/src/impl_nonfungibles.rs index 7f58a42e49706..ff5088ca3088d 100644 --- a/frame/uniques/src/impl_nonfungibles.rs +++ b/frame/uniques/src/impl_nonfungibles.rs @@ -75,7 +75,7 @@ impl, I: 'static> Inspect<::AccountId> for Palle } } - /// Returns `true` if the asset `asset` of `collection` may be transferred. + /// Returns `true` if the `asset` of `collection` may be transferred. /// /// Default implementation is that all assets are transferable. fn can_transfer(collection: &Self::CollectionId, asset: &Self::AssetId) -> bool { @@ -163,7 +163,7 @@ impl, I: 'static> InspectEnumerable for Pallet Box::new(CollectionMetadataOf::::iter_keys()) } - /// Returns an iterator of the assets of an asset `collection` in existence. + /// Returns an iterator of the assets of a `collection` in existence. /// /// NOTE: iterating this list invokes a storage read per item. fn assets(collection: &Self::CollectionId) -> Box> { diff --git a/frame/uniques/src/lib.rs b/frame/uniques/src/lib.rs index d339bfe7432b7..6a1f675a11039 100644 --- a/frame/uniques/src/lib.rs +++ b/frame/uniques/src/lib.rs @@ -245,28 +245,28 @@ pub mod pallet { pub enum Event, I: 'static = ()> { /// An assets collection was created. Created { collection: T::CollectionId, creator: T::AccountId, owner: T::AccountId }, - /// An assets collection was force-created. + /// A `collection` was force-created. ForceCreated { collection: T::CollectionId, owner: T::AccountId }, - /// An asset `collection` was destroyed. + /// A `collection` was destroyed. Destroyed { collection: T::CollectionId }, - /// An asset `asset` was issued. + /// An `asset` was issued. Issued { collection: T::CollectionId, asset: T::AssetId, owner: T::AccountId }, - /// An asset `asset` was transferred. + /// An `asset` was transferred. Transferred { collection: T::CollectionId, asset: T::AssetId, from: T::AccountId, to: T::AccountId, }, - /// An asset `asset` was destroyed. + /// An `asset` was destroyed. Burned { collection: T::CollectionId, asset: T::AssetId, owner: T::AccountId }, - /// Some asset `asset` was frozen. + /// Some `asset` was frozen. Frozen { collection: T::CollectionId, asset: T::AssetId }, - /// Some asset `asset` was thawed. + /// Some `asset` was thawed. Thawed { collection: T::CollectionId, asset: T::AssetId }, - /// Some asset `collection` was frozen. + /// Some `collection` was frozen. CollectionFrozen { collection: T::CollectionId }, - /// Some asset `collection` was thawed. + /// Some `collection` was thawed. CollectionThawed { collection: T::CollectionId }, /// The owner changed. OwnerChanged { collection: T::CollectionId, new_owner: T::AccountId }, @@ -277,7 +277,7 @@ pub mod pallet { admin: T::AccountId, freezer: T::AccountId, }, - /// An `asset` of an asset `collection` has been approved by the `owner` for transfer by + /// An `asset` of a `collection` has been approved by the `owner` for transfer by /// a `delegate`. ApprovedTransfer { collection: T::CollectionId, @@ -293,7 +293,7 @@ pub mod pallet { owner: T::AccountId, delegate: T::AccountId, }, - /// An asset `collection` has had its attributes changed by the `Force` origin. + /// A `collection` has had its attributes changed by the `Force` origin. AssetStatusChanged { collection: T::CollectionId }, /// New metadata has been set for an assets collection. CollectionMetadataSet { @@ -450,7 +450,7 @@ pub mod pallet { /// Destroy a collection of fungible assets. /// /// The origin must conform to `ForceOrigin` or must be `Signed` and the sender must be the - /// owner of the asset `collection`. + /// owner of the `collection`. /// /// - `collection`: The identifier of the assets collection to be destroyed. /// - `witness`: Information on the assets minted in the assets collection. This must be @@ -488,7 +488,7 @@ pub mod pallet { /// Mint an asset of a particular collection. /// - /// The origin must be Signed and the sender must be the Issuer of the asset `collection`. + /// The origin must be Signed and the sender must be the Issuer of the `collection`. /// /// - `collection`: The collection of the asset to be minted. /// - `asset`: The asset value of the asset to be minted. @@ -515,7 +515,7 @@ pub mod pallet { /// Destroy a single asset. /// - /// Origin must be Signed and the sender should be the Admin of the asset `collection`. + /// Origin must be Signed and the sender should be the Admin of the `collection`. /// /// - `collection`: The collection of the asset to be burned. /// - `asset`: The asset of the asset to be burned. @@ -550,9 +550,9 @@ pub mod pallet { /// Move an asset from the sender account to another. /// /// Origin must be Signed and the signing account must be either: - /// - the Admin of the asset `collection`; - /// - the Owner of the asset `asset`; - /// - the approved delegate for the asset `asset` (in this case, the approval is reset). + /// - the Admin of the `collection`; + /// - the Owner of the `asset`; + /// - the approved delegate for the `asset` (in this case, the approval is reset). /// /// Arguments: /// - `collection`: The collection of the asset to be transferred. @@ -583,7 +583,7 @@ pub mod pallet { /// Reevaluate the deposits on some assets. /// - /// Origin must be Signed and the sender should be the Owner of the asset `collection`. + /// Origin must be Signed and the sender should be the Owner of the `collection`. /// /// - `collection`: The collection of the asset to be frozen. /// - `assets`: The assets of the assets collection whose deposits will be reevaluated. @@ -650,7 +650,7 @@ pub mod pallet { /// Disallow further unprivileged transfer of an asset. /// - /// Origin must be Signed and the sender should be the Freezer of the asset `collection`. + /// Origin must be Signed and the sender should be the Freezer of the `collection`. /// /// - `collection`: The collection of the asset to be frozen. /// - `asset`: The asset of the asset to be frozen. @@ -681,7 +681,7 @@ pub mod pallet { /// Re-allow unprivileged transfer of an asset. /// - /// Origin must be Signed and the sender should be the Freezer of the asset `collection`. + /// Origin must be Signed and the sender should be the Freezer of the `collection`. /// /// - `collection`: The collection of the asset to be thawed. /// - `asset`: The asset of the asset to be thawed. @@ -712,7 +712,7 @@ pub mod pallet { /// Disallow further unprivileged transfers for a whole assets collection. /// - /// Origin must be Signed and the sender should be the Freezer of the asset `collection`. + /// Origin must be Signed and the sender should be the Freezer of the `collection`. /// /// - `collection`: The assets collection to be frozen. /// @@ -739,7 +739,7 @@ pub mod pallet { /// Re-allow unprivileged transfers for a whole assets collection. /// - /// Origin must be Signed and the sender should be the Admin of the asset `collection`. + /// Origin must be Signed and the sender should be the Admin of the `collection`. /// /// - `collection`: The collection to be thawed. /// @@ -766,7 +766,7 @@ pub mod pallet { /// Change the Owner of an assets collection. /// - /// Origin must be Signed and the sender should be the Owner of the asset `collection`. + /// Origin must be Signed and the sender should be the Owner of the `collection`. /// /// - `collection`: The assets collection whose owner should be changed. /// - `owner`: The new Owner of this assets collection. They must have called @@ -813,7 +813,7 @@ pub mod pallet { /// Change the Issuer, Admin and Freezer of an assets collection. /// - /// Origin must be Signed and the sender should be the Owner of the asset `collection`. + /// Origin must be Signed and the sender should be the Owner of the `collection`. /// /// - `collection`: The assets collection whose team should be changed. /// - `issuer`: The new Issuer of this assets collection. @@ -851,7 +851,7 @@ pub mod pallet { /// Approve an asset to be transferred by a delegated third-party account. /// - /// Origin must be Signed and must be the owner of the asset `asset`. + /// Origin must be Signed and must be the owner of the `asset`. /// /// - `collection`: The collection of the asset to be approved for delegated transfer. /// - `asset`: The asset of the asset to be approved for delegated transfer. @@ -901,8 +901,8 @@ pub mod pallet { /// /// Origin must be either: /// - the `Force` origin; - /// - `Signed` with the signer being the Admin of the asset `collection`; - /// - `Signed` with the signer being the Owner of the asset `asset`; + /// - `Signed` with the signer being the Admin of the `collection`; + /// - `Signed` with the signer being the Owner of the `asset`; /// /// Arguments: /// - `collection`: The collection of the asset of whose approval will be cancelled. @@ -1001,7 +1001,7 @@ pub mod pallet { /// Set an attribute for an assets collection or asset. /// /// Origin must be either `ForceOrigin` or Signed and the sender should be the Owner of the - /// asset `collection`. + /// `collection`. /// /// If the origin is Signed, then funds of signer are reserved according to the formula: /// `MetadataDepositBase + DepositPerByte * (key.len + value.len)` taking into @@ -1066,7 +1066,7 @@ pub mod pallet { /// Clear an attribute for an assets collection or asset. /// /// Origin must be either `ForceOrigin` or Signed and the sender should be the Owner of the - /// asset `collection`. + /// `collection`. /// /// Any deposit is freed for the assets collection owner. /// @@ -1112,7 +1112,7 @@ pub mod pallet { /// Set the metadata for an asset. /// /// Origin must be either `ForceOrigin` or Signed and the sender should be the Owner of the - /// asset `collection`. + /// `collection`. /// /// If the origin is Signed, then funds of signer are reserved according to the formula: /// `MetadataDepositBase + DepositPerByte * data.len` taking into @@ -1178,7 +1178,7 @@ pub mod pallet { /// Clear the metadata for an asset. /// /// Origin must be either `ForceOrigin` or Signed and the sender should be the Owner of the - /// asset `asset`. + /// `asset`. /// /// Any deposit is freed for the assets collection owner. /// @@ -1224,7 +1224,7 @@ pub mod pallet { /// Set the metadata for an assets collection. /// /// Origin must be either `ForceOrigin` or `Signed` and the sender should be the Owner of - /// the asset `collection`. + /// the `collection`. /// /// If the origin is `Signed`, then funds of signer are reserved according to the formula: /// `MetadataDepositBase + DepositPerByte * data.len` taking into @@ -1285,7 +1285,7 @@ pub mod pallet { /// Clear the metadata for an assets collection. /// /// Origin must be either `ForceOrigin` or `Signed` and the sender should be the Owner of - /// the asset `collection`. + /// the `collection`. /// /// Any deposit is freed for the assets collection owner. /// From a0701e4e7f66c809b7d8381a6eac0c9893a6ae2b Mon Sep 17 00:00:00 2001 From: Jegor Sidorenko Date: Tue, 10 May 2022 18:50:17 +0200 Subject: [PATCH 05/16] A bit more clean up --- frame/uniques/src/lib.rs | 14 +++++++------- frame/uniques/src/types.rs | 14 +++++++------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/frame/uniques/src/lib.rs b/frame/uniques/src/lib.rs index 6a1f675a11039..f500aba01862a 100644 --- a/frame/uniques/src/lib.rs +++ b/frame/uniques/src/lib.rs @@ -243,7 +243,7 @@ pub mod pallet { #[pallet::event] #[pallet::generate_deposit(pub(super) fn deposit_event)] pub enum Event, I: 'static = ()> { - /// An assets collection was created. + /// 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 }, @@ -295,13 +295,13 @@ pub mod pallet { }, /// A `collection` has had its attributes changed by the `Force` origin. AssetStatusChanged { collection: T::CollectionId }, - /// New metadata has been set for an assets collection. + /// New metadata has been set for a `collection`. CollectionMetadataSet { collection: T::CollectionId, data: BoundedVec, is_frozen: bool, }, - /// Metadata has been cleared for an assets collection. + /// Metadata has been cleared for a `collection`. CollectionMetadataCleared { collection: T::CollectionId }, /// New metadata has been set for an asset. MetadataSet { @@ -314,14 +314,14 @@ pub mod pallet { MetadataCleared { collection: T::CollectionId, asset: T::AssetId }, /// Metadata has been cleared for an asset. Redeposited { collection: T::CollectionId, successful_assets: Vec }, - /// New attribute metadata has been set for an assets collection or asset. + /// New attribute metadata has been set for a `collection` or `asset`. AttributeSet { collection: T::CollectionId, maybe_asset: Option, key: BoundedVec, value: BoundedVec, }, - /// Attribute metadata has been cleared for an assets collection or asset. + /// Attribute metadata has been cleared for a `collection` or `asset`. AttributeCleared { collection: T::CollectionId, maybe_asset: Option, @@ -375,7 +375,7 @@ pub mod pallet { impl, I: 'static> Pallet { /// Issue a new collection of non-fungible assets from a public origin. /// - /// This new assets collection has no assets initially and its owner is the origin. + /// This new collection has no assets initially and its owner is the origin. /// /// The origin must be Signed and the sender must have sufficient funds free. /// @@ -412,7 +412,7 @@ pub mod pallet { /// Issue a new collection of non-fungible assets from a privileged origin. /// - /// This new assets collection has no assets initially. + /// This new collection has no assets initially. /// /// The origin must conform to `ForceOrigin`. /// diff --git a/frame/uniques/src/types.rs b/frame/uniques/src/types.rs index cf4d3d9852afc..61ffa08b4f725 100644 --- a/frame/uniques/src/types.rs +++ b/frame/uniques/src/types.rs @@ -41,16 +41,16 @@ pub struct CollectionDetails { pub(super) admin: AccountId, /// Can freeze tokens. pub(super) freezer: AccountId, - /// The total balance deposited for the all storage associated with this assets collection. + /// 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 assets of this collection. pub(super) free_holding: bool, - /// The total number of outstanding assets of this assets collection. + /// The total number of outstanding assets of this collection. pub(super) assets: u32, - /// The total number of outstanding asset metadata of this assets collection. + /// The total number of outstanding asset metadata of this collection. pub(super) asset_metadatas: u32, - /// The total number of attributes for this assets collection. + /// The total number of attributes for this collection. pub(super) attributes: u32, /// Whether the asset is frozen for non-admin transfers. pub(super) is_frozen: bool, @@ -59,14 +59,14 @@ pub struct CollectionDetails { /// Witness data for the destroy transactions. #[derive(Copy, Clone, Encode, Decode, Eq, PartialEq, RuntimeDebug, TypeInfo, MaxEncodedLen)] pub struct DestroyWitness { - /// The total number of outstanding assets of this assets collection. + /// The total number of outstanding assets of this collection. #[codec(compact)] pub assets: u32, - /// The total number of outstanding asset metadata of this assets collection. + /// The total number of outstanding asset metadata of this collection. #[codec(compact)] pub asset_metadatas: u32, #[codec(compact)] - /// The total number of attributes for this assets collection. + /// The total number of attributes for this collection. pub attributes: u32, } From 16565eace1ac185fed5b0f3c3260f953e38b2115 Mon Sep 17 00:00:00 2001 From: Jegor Sidorenko Date: Tue, 10 May 2022 19:24:02 +0200 Subject: [PATCH 06/16] Rename Asset to Item --- frame/support/src/traits/tokens/misc.rs | 8 +- .../support/src/traits/tokens/nonfungible.rs | 110 ++--- .../support/src/traits/tokens/nonfungibles.rs | 94 ++-- frame/uniques/src/benchmarking.rs | 126 ++--- frame/uniques/src/functions.rs | 68 +-- frame/uniques/src/impl_nonfungibles.rs | 63 ++- frame/uniques/src/lib.rs | 452 +++++++++--------- frame/uniques/src/mock.rs | 6 +- frame/uniques/src/tests.rs | 66 +-- frame/uniques/src/types.rs | 52 +- frame/uniques/src/weights.rs | 66 +-- 11 files changed, 555 insertions(+), 556 deletions(-) diff --git a/frame/support/src/traits/tokens/misc.rs b/frame/support/src/traits/tokens/misc.rs index 2d524371cead8..fbbef6c31822f 100644 --- a/frame/support/src/traits/tokens/misc.rs +++ b/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(collection: CollectionId, asset: AssetId) -> 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(_collection: CollectionId, _asset: AssetId) -> bool { + fn is_locked(_collection: CollectionId, _item: ItemId) -> bool { false } } diff --git a/frame/support/src/traits/tokens/nonfungible.rs b/frame/support/src/traits/tokens/nonfungible.rs index ec213801cfdb7..c23fabe5b54ff 100644 --- a/frame/support/src/traits/tokens/nonfungible.rs +++ b/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 assets collection. +//! Traits for dealing with a single non-fungible items collection. //! -//! This assumes a single level namespace identified by `Inspect::AssetId`, 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,88 +30,88 @@ 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 assets. +/// Trait for providing an interface to a read-only NFT-like set of items. pub trait Inspect { - /// Type for identifying an asset. - type AssetId; + /// Type for identifying an item. + type ItemId; - /// Returns the owner of `asset`, 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(asset: &Self::AssetId) -> Option; + fn owner(item: &Self::ItemId) -> Option; - /// Returns the attribute value of `asset` corresponding to `key`. + /// Returns the attribute value of `item` corresponding to `key`. /// /// By default this is `None`; no attributes are defined. - fn attribute(_asset: &Self::AssetId, _key: &[u8]) -> Option> { + fn attribute(_item: &Self::ItemId, _key: &[u8]) -> Option> { None } - /// Returns the strongly-typed attribute value of `asset` 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(asset: &Self::AssetId, key: &K) -> Option { - key.using_encoded(|d| Self::attribute(asset, 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` may be transferred. + /// Returns `true` if the `item` may be transferred. /// - /// Default implementation is that all assets are transferable. - fn can_transfer(_asset: &Self::AssetId) -> 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 assets within a `collection` in existence. - fn assets() -> Box>; + /// Returns an iterator of the items within a `collection` in existence. + fn items() -> Box>; - /// Returns an iterator of the assets of all collections 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` to be owned by `who`. + /// Mint some `item` to be owned by `who`. /// /// By default, this is not a supported operation. - fn mint_into(_asset: &Self::AssetId, _who: &AccountId) -> DispatchResult { + fn mint_into(_item: &Self::ItemId, _who: &AccountId) -> DispatchResult { Err(TokenError::Unsupported.into()) } - /// Burn some `asset`. + /// Burn some `item`. /// /// By default, this is not a supported operation. - fn burn(_asset: &Self::AssetId, _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`'s `key`. + /// Set attribute `value` of `item`'s `key`. /// /// By default, this is not a supported operation. - fn set_attribute(_asset: &Self::AssetId, _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 `asset`'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( - asset: &Self::AssetId, + item: &Self::ItemId, key: &K, value: &V, ) -> DispatchResult { - key.using_encoded(|k| value.using_encoded(|v| Self::set_attribute(asset, 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` into `destination` account. - fn transfer(asset: &Self::AssetId, 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 @@ -128,18 +128,18 @@ impl< AccountId, > Inspect for ItemOf { - type AssetId = >::AssetId; - fn owner(asset: &Self::AssetId) -> Option { - >::owner(&A::get(), asset) + type ItemId = >::ItemId; + fn owner(item: &Self::ItemId) -> Option { + >::owner(&A::get(), item) } - fn attribute(asset: &Self::AssetId, key: &[u8]) -> Option> { - >::attribute(&A::get(), asset, key) + fn attribute(item: &Self::ItemId, key: &[u8]) -> Option> { + >::attribute(&A::get(), item, key) } - fn typed_attribute(asset: &Self::AssetId, key: &K) -> Option { - >::typed_attribute(&A::get(), asset, key) + fn typed_attribute(item: &Self::ItemId, key: &K) -> Option { + >::typed_attribute(&A::get(), item, key) } - fn can_transfer(asset: &Self::AssetId) -> bool { - >::can_transfer(&A::get(), asset) + fn can_transfer(item: &Self::ItemId) -> bool { + >::can_transfer(&A::get(), item) } } @@ -149,10 +149,10 @@ impl< AccountId, > InspectEnumerable for ItemOf { - fn assets() -> Box> { - >::assets(&A::get()) + fn items() -> Box> { + >::items(&A::get()) } - fn owned(who: &AccountId) -> Box> { + fn owned(who: &AccountId) -> Box> { >::owned_in_collection(&A::get(), who) } } @@ -163,21 +163,21 @@ impl< AccountId, > Mutate for ItemOf { - fn mint_into(asset: &Self::AssetId, who: &AccountId) -> DispatchResult { - >::mint_into(&A::get(), asset, who) + fn mint_into(item: &Self::ItemId, who: &AccountId) -> DispatchResult { + >::mint_into(&A::get(), item, who) } - fn burn(asset: &Self::AssetId, maybe_check_owner: Option<&AccountId>) -> DispatchResult { - >::burn(&A::get(), asset, maybe_check_owner) + fn burn(item: &Self::ItemId, maybe_check_owner: Option<&AccountId>) -> DispatchResult { + >::burn(&A::get(), item, maybe_check_owner) } - fn set_attribute(asset: &Self::AssetId, key: &[u8], value: &[u8]) -> DispatchResult { - >::set_attribute(&A::get(), asset, key, value) + fn set_attribute(item: &Self::ItemId, key: &[u8], value: &[u8]) -> DispatchResult { + >::set_attribute(&A::get(), item, key, value) } fn set_typed_attribute( - asset: &Self::AssetId, + item: &Self::ItemId, key: &K, value: &V, ) -> DispatchResult { - >::set_typed_attribute(&A::get(), asset, key, value) + >::set_typed_attribute(&A::get(), item, key, value) } } @@ -187,7 +187,7 @@ impl< AccountId, > Transfer for ItemOf { - fn transfer(asset: &Self::AssetId, destination: &AccountId) -> DispatchResult { - >::transfer(&A::get(), asset, destination) + fn transfer(item: &Self::ItemId, destination: &AccountId) -> DispatchResult { + >::transfer(&A::get(), item, destination) } } diff --git a/frame/support/src/traits/tokens/nonfungibles.rs b/frame/support/src/traits/tokens/nonfungibles.rs index 7bf913953832a..5e9461469f851 100644 --- a/frame/support/src/traits/tokens/nonfungibles.rs +++ b/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::AssetId`, 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,47 +32,47 @@ 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 assets. +/// Trait for providing an interface to many read-only NFT-like sets of items. pub trait Inspect { - /// Type for identifying an asset. - type AssetId; + /// Type for identifying an item. + type ItemId; - /// Type for identifying an assets collection (an identifier for an independent collection of - /// assets). + /// Type for identifying an items collection (an identifier for an independent collection of + /// items). type CollectionId; - /// Returns the owner of `asset` of `collection`, or `None` if the asset doesn't exist + /// 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, asset: &Self::AssetId) -> Option; + fn owner(collection: &Self::CollectionId, item: &Self::ItemId) -> 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 an assets collection + /// make any sense, so users of this API should not be surprised to find an items collection /// results in `None` here. fn collection_owner(_collection: &Self::CollectionId) -> Option { None } - /// Returns the attribute value of `asset` of `collection` 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( _collection: &Self::CollectionId, - _asset: &Self::AssetId, + _item: &Self::ItemId, _key: &[u8], ) -> Option> { None } - /// Returns the strongly-typed attribute value of `asset` of `collection` corresponding to + /// Returns the strongly-typed attribute value of `item` of `collection` corresponding to /// `key`. /// /// By default this just attempts to use `attribute`. fn typed_attribute( collection: &Self::CollectionId, - asset: &Self::AssetId, + item: &Self::ItemId, key: &K, ) -> Option { - key.using_encoded(|d| Self::attribute(collection, asset, d)) + key.using_encoded(|d| Self::attribute(collection, item, d)) .and_then(|v| V::decode(&mut &v[..]).ok()) } @@ -94,36 +94,36 @@ pub trait Inspect { .and_then(|v| V::decode(&mut &v[..]).ok()) } - /// Returns `true` if the `asset` of `collection` may be transferred. + /// Returns `true` if the `item` of `collection` may be transferred. /// - /// Default implementation is that all assets are transferable. - fn can_transfer(_collection: &Self::CollectionId, _asset: &Self::AssetId) -> 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 assets collections in existence. + /// Returns an iterator of the items collections in existence. fn collections() -> Box>; - /// Returns an iterator of the assets of a `collection` in existence. - fn assets(collection: &Self::CollectionId) -> Box>; + /// Returns an iterator of the items of a `collection` in existence. + fn items(collection: &Self::CollectionId) -> Box>; - /// Returns an iterator of the assets of all collections 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 assets of `collection` owned by `who`. + /// 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 collections of nonfungible assets. +/// Trait for providing the ability to create collections of nonfungible items. pub trait Create: Inspect { - /// Create a `collection` of nonfungible assets to be owned by `who` and managed by `admin`. + /// Create a `collection` of nonfungible items to be owned by `who` and managed by `admin`. fn create_collection( collection: &Self::CollectionId, who: &AccountId, @@ -131,23 +131,23 @@ pub trait Create: Inspect { ) -> DispatchResult; } -/// Trait for providing the ability to destroy collections 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. + /// Provide the appropriate witness data needed to destroy an item. fn get_destroy_witness(collection: &Self::CollectionId) -> Option; - /// Destroy an existing fungible asset. + /// 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( collection: Self::CollectionId, @@ -156,53 +156,53 @@ pub trait Destroy: Inspect { ) -> Result; } -/// Trait for providing an interface for multiple collections of NFT-like assets which may be +/// 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` of `collection` 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( _collection: &Self::CollectionId, - _asset: &Self::AssetId, + _item: &Self::ItemId, _who: &AccountId, ) -> DispatchResult { Err(TokenError::Unsupported.into()) } - /// Burn some `asset` of `collection`. + /// Burn some `item` of `collection`. /// /// By default, this is not a supported operation. fn burn( _collection: &Self::CollectionId, - _asset: &Self::AssetId, + _item: &Self::ItemId, _maybe_check_owner: Option<&AccountId>, ) -> DispatchResult { Err(TokenError::Unsupported.into()) } - /// Set attribute `value` of `asset` of `collection`'s `key`. + /// Set attribute `value` of `item` of `collection`'s `key`. /// /// By default, this is not a supported operation. fn set_attribute( _collection: &Self::CollectionId, - _asset: &Self::AssetId, + _item: &Self::ItemId, _key: &[u8], _value: &[u8], ) -> DispatchResult { Err(TokenError::Unsupported.into()) } - /// Attempt to set the strongly-typed attribute `value` of `asset` of `collection`'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( collection: &Self::CollectionId, - asset: &Self::AssetId, + item: &Self::ItemId, key: &K, value: &V, ) -> DispatchResult { - key.using_encoded(|k| value.using_encoded(|v| Self::set_attribute(collection, asset, k, v))) + key.using_encoded(|k| value.using_encoded(|v| Self::set_attribute(collection, item, k, v))) } /// Set attribute `value` of `collection`'s `key`. @@ -230,12 +230,12 @@ pub trait Mutate: Inspect { } } -/// 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` of `collection` into `destination` account. + /// Transfer `item` of `collection` into `destination` account. fn transfer( collection: &Self::CollectionId, - asset: &Self::AssetId, + item: &Self::ItemId, destination: &AccountId, ) -> DispatchResult; } diff --git a/frame/uniques/src/benchmarking.rs b/frame/uniques/src/benchmarking.rs index a0abf428b3fed..34f2f8f336d09 100644 --- a/frame/uniques/src/benchmarking.rs +++ b/frame/uniques/src/benchmarking.rs @@ -15,12 +15,12 @@ // See the License for the specific language governing permissions and // limitations under the License. -//! Assets pallet benchmarking. +//! Items pallet benchmarking. #![cfg(feature = "runtime-benchmarks")] use super::*; -use frame_benchmarking::{account, benchmarks_asset_pallet, whitelist_account, whitelisted_caller}; +use frame_benchmarking::{account, benchmarks_item_pallet, whitelist_account, whitelisted_caller}; use frame_support::{ dispatch::UnfilteredDispatchable, traits::{EnsureOrigin, Get}, @@ -67,27 +67,27 @@ fn add_collection_metadata, I: 'static>( (caller, caller_lookup) } -fn mint_asset, I: 'static>( +fn mint_item, I: 'static>( index: u16, -) -> (T::AssetId, T::AccountId, ::Source) { +) -> (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 asset = T::Helper::asset(index); + let item = T::Helper::item(index); assert!(Uniques::::mint( SystemOrigin::Signed(caller.clone()).into(), T::Helper::collection(0), - asset, + item, caller_lookup.clone(), ) .is_ok()); - (asset, caller, caller_lookup) + (item, caller, caller_lookup) } -fn add_asset_metadata, I: 'static>( - asset: T::AssetId, +fn add_item_metadata, I: 'static>( + item: T::ItemId, ) -> (T::AccountId, ::Source) { let caller = Collection::::get(T::Helper::collection(0)).unwrap().owner; if caller != whitelisted_caller() { @@ -97,7 +97,7 @@ fn add_asset_metadata, I: 'static>( assert!(Uniques::::set_metadata( SystemOrigin::Signed(caller.clone()).into(), T::Helper::collection(0), - asset, + item, vec![0; T::StringLimit::get() as usize].try_into().unwrap(), false, ) @@ -105,8 +105,8 @@ fn add_asset_metadata, I: 'static>( (caller, caller_lookup) } -fn add_asset_attribute, I: 'static>( - asset: T::AssetId, +fn add_item_attribute, I: 'static>( + item: T::ItemId, ) -> (BoundedVec, T::AccountId, ::Source) { let caller = Collection::::get(T::Helper::collection(0)).unwrap().owner; if caller != whitelisted_caller() { @@ -117,7 +117,7 @@ fn add_asset_attribute, I: 'static>( assert!(Uniques::::set_attribute( SystemOrigin::Signed(caller.clone()).into(), T::Helper::collection(0), - Some(asset), + Some(item), key.clone(), vec![0; T::ValueLimit::get() as usize].try_into().unwrap(), ) @@ -133,7 +133,7 @@ fn assert_last_event, I: 'static>(generic_event: >:: assert_eq!(event, &system_event); } -benchmarks_asset_pallet! { +benchmarks_item_pallet! { create { let collection = T::Helper::collection(0); let origin = T::CreateOrigin::successful_origin(&collection); @@ -163,13 +163,13 @@ benchmarks_asset_pallet! { let (collection, caller, caller_lookup) = create_collection::(); add_collection_metadata::(); for i in 0..n { - mint_asset::(i as u16); + mint_item::(i as u16); } for i in 0..m { - add_asset_metadata::(T::Helper::asset(i as u16)); + add_item_metadata::(T::Helper::item(i as u16)); } for i in 0..a { - add_asset_attribute::(T::Helper::asset(i as u16)); + add_item_attribute::(T::Helper::item(i as u16)); } let witness = Collection::::get(collection).unwrap().destroy_witness(); }: _(SystemOrigin::Signed(caller), collection, witness) @@ -179,36 +179,36 @@ benchmarks_asset_pallet! { mint { let (collection, caller, caller_lookup) = create_collection::(); - let asset = T::Helper::asset(0); - }: _(SystemOrigin::Signed(caller.clone()), collection, asset, caller_lookup) + let item = T::Helper::item(0); + }: _(SystemOrigin::Signed(caller.clone()), collection, item, caller_lookup) verify { - assert_last_event::(Event::Issued { collection, asset, owner: caller }.into()); + assert_last_event::(Event::Issued { collection, item, owner: caller }.into()); } burn { let (collection, caller, caller_lookup) = create_collection::(); - let (asset, ..) = mint_asset::(0); - }: _(SystemOrigin::Signed(caller.clone()), collection, asset, Some(caller_lookup)) + let (item, ..) = mint_item::(0); + }: _(SystemOrigin::Signed(caller.clone()), collection, item, Some(caller_lookup)) verify { - assert_last_event::(Event::Burned { collection, asset, owner: caller }.into()); + assert_last_event::(Event::Burned { collection, item, owner: caller }.into()); } transfer { let (collection, caller, caller_lookup) = create_collection::(); - let (asset, ..) = mint_asset::(0); + 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()), collection, asset, target_lookup) + }: _(SystemOrigin::Signed(caller.clone()), collection, item, target_lookup) verify { - assert_last_event::(Event::Transferred { collection, asset, 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 (collection, caller, caller_lookup) = create_collection::(); - let assets = (0..i).map(|x| mint_asset::(x as u16).0).collect::>(); - Uniques::::force_asset_status( + let items = (0..i).map(|x| mint_item::(x as u16).0).collect::>(); + Uniques::::force_item_status( SystemOrigin::Root.into(), collection, caller_lookup.clone(), @@ -218,30 +218,30 @@ benchmarks_asset_pallet! { true, false, )?; - }: _(SystemOrigin::Signed(caller.clone()), collection, assets.clone()) + }: _(SystemOrigin::Signed(caller.clone()), collection, items.clone()) verify { - assert_last_event::(Event::Redeposited { collection, successful_assets: assets }.into()); + assert_last_event::(Event::Redeposited { collection, successful_items: items }.into()); } freeze { let (collection, caller, caller_lookup) = create_collection::(); - let (asset, ..) = mint_asset::(0); - }: _(SystemOrigin::Signed(caller.clone()), T::Helper::collection(0), T::Helper::asset(0)) + let (item, ..) = mint_item::(0); + }: _(SystemOrigin::Signed(caller.clone()), T::Helper::collection(0), T::Helper::item(0)) verify { - assert_last_event::(Event::Frozen { collection: T::Helper::collection(0), asset: T::Helper::asset(0) }.into()); + assert_last_event::(Event::Frozen { collection: T::Helper::collection(0), item: T::Helper::item(0) }.into()); } thaw { let (collection, caller, caller_lookup) = create_collection::(); - let (asset, ..) = mint_asset::(0); + let (item, ..) = mint_item::(0); Uniques::::freeze( SystemOrigin::Signed(caller.clone()).into(), collection, - asset, + item, )?; - }: _(SystemOrigin::Signed(caller.clone()), collection, asset) + }: _(SystemOrigin::Signed(caller.clone()), collection, item) verify { - assert_last_event::(Event::Thawed { collection, asset }.into()); + assert_last_event::(Event::Thawed { collection, item }.into()); } freeze_collection { @@ -287,10 +287,10 @@ benchmarks_asset_pallet! { }.into()); } - force_asset_status { + force_item_status { let (collection, caller, caller_lookup) = create_collection::(); let origin = T::ForceOrigin::successful_origin(); - let call = Call::::force_asset_status { + let call = Call::::force_item_status { collection, owner: caller_lookup.clone(), issuer: caller_lookup.clone(), @@ -301,7 +301,7 @@ benchmarks_asset_pallet! { }; }: { call.dispatch_bypass_filter(origin)? } verify { - assert_last_event::(Event::AssetStatusChanged { collection }.into()); + assert_last_event::(Event::ItemStatusChanged { collection }.into()); } set_attribute { @@ -309,40 +309,40 @@ benchmarks_asset_pallet! { let value: BoundedVec<_, _> = vec![0u8; T::ValueLimit::get() as usize].try_into().unwrap(); let (collection, caller, _) = create_collection::(); - let (asset, ..) = mint_asset::(0); - add_asset_metadata::(asset); - }: _(SystemOrigin::Signed(caller), collection, Some(asset), key.clone(), value.clone()) + 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 { collection, maybe_asset: Some(asset), key, value }.into()); + assert_last_event::(Event::AttributeSet { collection, maybe_item: Some(item), key, value }.into()); } clear_attribute { let (collection, caller, _) = create_collection::(); - let (asset, ..) = mint_asset::(0); - add_asset_metadata::(asset); - let (key, ..) = add_asset_attribute::(asset); - }: _(SystemOrigin::Signed(caller), collection, Some(asset), key.clone()) + 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 { collection, maybe_asset: Some(asset), 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 (collection, caller, _) = create_collection::(); - let (asset, ..) = mint_asset::(0); - }: _(SystemOrigin::Signed(caller), collection, asset, data.clone(), false) + let (item, ..) = mint_item::(0); + }: _(SystemOrigin::Signed(caller), collection, item, data.clone(), false) verify { - assert_last_event::(Event::MetadataSet { collection, asset, data, is_frozen: false }.into()); + assert_last_event::(Event::MetadataSet { collection, item, data, is_frozen: false }.into()); } clear_metadata { let (collection, caller, _) = create_collection::(); - let (asset, ..) = mint_asset::(0); - add_asset_metadata::(asset); - }: _(SystemOrigin::Signed(caller), collection, asset) + let (item, ..) = mint_item::(0); + add_item_metadata::(item); + }: _(SystemOrigin::Signed(caller), collection, item) verify { - assert_last_event::(Event::MetadataCleared { collection, asset }.into()); + assert_last_event::(Event::MetadataCleared { collection, item }.into()); } set_collection_metadata { @@ -364,24 +364,24 @@ benchmarks_asset_pallet! { approve_transfer { let (collection, caller, _) = create_collection::(); - let (asset, ..) = mint_asset::(0); + 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()), collection, asset, delegate_lookup) + }: _(SystemOrigin::Signed(caller.clone()), collection, item, delegate_lookup) verify { - assert_last_event::(Event::ApprovedTransfer { collection, asset, owner: caller, delegate }.into()); + assert_last_event::(Event::ApprovedTransfer { collection, item, owner: caller, delegate }.into()); } cancel_approval { let (collection, caller, _) = create_collection::(); - let (asset, ..) = mint_asset::(0); + 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, collection, asset, delegate_lookup.clone())?; - }: _(SystemOrigin::Signed(caller.clone()), collection, asset, 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 { collection, asset, owner: caller, delegate }.into()); + assert_last_event::(Event::ApprovalCancelled { collection, item, owner: caller, delegate }.into()); } set_accept_ownership { diff --git a/frame/uniques/src/functions.rs b/frame/uniques/src/functions.rs index c73fcd5de18a5..20e1410a8a849 100644 --- a/frame/uniques/src/functions.rs +++ b/frame/uniques/src/functions.rs @@ -24,32 +24,32 @@ use sp_runtime::{DispatchError, DispatchResult}; impl, I: 'static> Pallet { pub fn do_transfer( collection: T::CollectionId, - asset: T::AssetId, + item: T::ItemId, dest: T::AccountId, with_details: impl FnOnce( &CollectionDetailsFor, - &mut AssetDetailsFor, + &mut ItemDetailsFor, ) -> DispatchResult, ) -> DispatchResult { let collection_details = Collection::::get(&collection).ok_or(Error::::UnknownCollection)?; ensure!(!collection_details.is_frozen, Error::::Frozen); - ensure!(!T::Locker::is_locked(collection, asset), Error::::Locked); + ensure!(!T::Locker::is_locked(collection, item), Error::::Locked); let mut details = - Asset::::get(&collection, &asset).ok_or(Error::::UnknownCollection)?; + Item::::get(&collection, &item).ok_or(Error::::UnknownCollection)?; ensure!(!details.is_frozen, Error::::Frozen); with_details(&collection_details, &mut details)?; - Account::::remove((&details.owner, &collection, &asset)); - Account::::insert((&dest, &collection, &asset), ()); + Account::::remove((&details.owner, &collection, &item)); + Account::::insert((&dest, &collection, &item), ()); let origin = details.owner; details.owner = dest; - Asset::::insert(&collection, &asset, &details); + Item::::insert(&collection, &item, &details); Self::deposit_event(Event::Transferred { collection, - asset, + item, from: origin, to: details.owner, }); @@ -77,8 +77,8 @@ impl, I: 'static> Pallet { freezer: admin, total_deposit: deposit, free_holding, - assets: 0, - asset_metadatas: 0, + items: 0, + item_metadatas: 0, attributes: 0, is_frozen: false, }, @@ -100,17 +100,17 @@ impl, I: 'static> Pallet { if let Some(check_owner) = maybe_check_owner { ensure!(collection_details.owner == check_owner, Error::::NoPermission); } - ensure!(collection_details.assets == witness.assets, Error::::BadWitness); + ensure!(collection_details.items == witness.items, Error::::BadWitness); ensure!( - collection_details.asset_metadatas == witness.asset_metadatas, + collection_details.item_metadatas == witness.item_metadatas, Error::::BadWitness ); ensure!(collection_details.attributes == witness.attributes, Error::::BadWitness); - for (asset, details) in Asset::::drain_prefix(&collection) { - Account::::remove((&details.owner, &collection, &asset)); + for (item, details) in Item::::drain_prefix(&collection) { + Account::::remove((&details.owner, &collection, &item)); } - AssetMetadataOf::::remove_prefix(&collection, None); + ItemMetadataOf::::remove_prefix(&collection, None); CollectionMetadataOf::::remove(&collection); Attribute::::remove_prefix((&collection,), None); CollectionAccount::::remove(&collection_details.owner, &collection); @@ -119,8 +119,8 @@ impl, I: 'static> Pallet { Self::deposit_event(Event::Destroyed { collection }); Ok(DestroyWitness { - assets: collection_details.assets, - asset_metadatas: collection_details.asset_metadatas, + items: collection_details.items, + item_metadatas: collection_details.item_metadatas, attributes: collection_details.attributes, }) }) @@ -128,11 +128,11 @@ impl, I: 'static> Pallet { pub fn do_mint( collection: T::CollectionId, - asset: T::AssetId, + item: T::ItemId, owner: T::AccountId, with_details: impl FnOnce(&CollectionDetailsFor) -> DispatchResult, ) -> DispatchResult { - ensure!(!Asset::::contains_key(collection, asset), Error::::AlreadyExists); + ensure!(!Item::::contains_key(collection, item), Error::::AlreadyExists); Collection::::try_mutate( &collection, @@ -142,55 +142,55 @@ impl, I: 'static> Pallet { with_details(collection_details)?; - let assets = - collection_details.assets.checked_add(1).ok_or(ArithmeticError::Overflow)?; - collection_details.assets = assets; + let items = + collection_details.items.checked_add(1).ok_or(ArithmeticError::Overflow)?; + collection_details.items = items; let deposit = match collection_details.free_holding { true => Zero::zero(), - false => T::AssetDeposit::get(), + false => T::ItemDeposit::get(), }; T::Currency::reserve(&collection_details.owner, deposit)?; collection_details.total_deposit += deposit; let owner = owner.clone(); - Account::::insert((&owner, &collection, &asset), ()); - let details = AssetDetails { owner, approved: None, is_frozen: false, deposit }; - Asset::::insert(&collection, &asset, details); + 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 { collection, asset, owner }); + Self::deposit_event(Event::Issued { collection, item, owner }); Ok(()) } pub fn do_burn( collection: T::CollectionId, - asset: T::AssetId, - with_details: impl FnOnce(&CollectionDetailsFor, &AssetDetailsFor) -> DispatchResult, + item: T::ItemId, + with_details: impl FnOnce(&CollectionDetailsFor, &ItemDetailsFor) -> DispatchResult, ) -> DispatchResult { let owner = Collection::::try_mutate( &collection, |maybe_collection_details| -> Result { let collection_details = maybe_collection_details.as_mut().ok_or(Error::::UnknownCollection)?; - let details = Asset::::get(&collection, &asset) + let details = Item::::get(&collection, &item) .ok_or(Error::::UnknownCollection)?; with_details(collection_details, &details)?; // Return the deposit. T::Currency::unreserve(&collection_details.owner, details.deposit); collection_details.total_deposit.saturating_reduce(details.deposit); - collection_details.assets.saturating_dec(); + collection_details.items.saturating_dec(); Ok(details.owner) }, )?; - Asset::::remove(&collection, &asset); - Account::::remove((&owner, &collection, &asset)); + Item::::remove(&collection, &item); + Account::::remove((&owner, &collection, &item)); - Self::deposit_event(Event::Burned { collection, asset, owner }); + Self::deposit_event(Event::Burned { collection, item, owner }); Ok(()) } } diff --git a/frame/uniques/src/impl_nonfungibles.rs b/frame/uniques/src/impl_nonfungibles.rs index ff5088ca3088d..cead6f562ab58 100644 --- a/frame/uniques/src/impl_nonfungibles.rs +++ b/frame/uniques/src/impl_nonfungibles.rs @@ -26,60 +26,59 @@ use sp_runtime::{DispatchError, DispatchResult}; use sp_std::prelude::*; impl, I: 'static> Inspect<::AccountId> for Pallet { - type AssetId = T::AssetId; + type ItemId = T::ItemId; type CollectionId = T::CollectionId; fn owner( collection: &Self::CollectionId, - asset: &Self::AssetId, + item: &Self::ItemId, ) -> Option<::AccountId> { - Asset::::get(collection, asset).map(|a| a.owner) + Item::::get(collection, item).map(|a| a.owner) } fn collection_owner(collection: &Self::CollectionId) -> Option<::AccountId> { Collection::::get(collection).map(|a| a.owner) } - /// Returns the attribute value of `asset` of `collection` corresponding to `key`. + /// Returns the attribute value of `item` of `collection` corresponding to `key`. /// - /// When `key` is empty, we return the asset metadata value. + /// When `key` is empty, we return the item metadata value. /// /// By default this is `None`; no attributes are defined. fn attribute( collection: &Self::CollectionId, - asset: &Self::AssetId, + item: &Self::ItemId, key: &[u8], ) -> Option> { if key.is_empty() { - // We make the empty key map to the asset metadata value. - AssetMetadataOf::::get(collection, asset).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((collection, Some(asset), key)).map(|a| a.0.into()) + Attribute::::get((collection, Some(item), key)).map(|a| a.0.into()) } } - /// Returns the attribute value of `asset` of `collection` corresponding to `key`. + /// Returns the attribute value of `item` of `collection` corresponding to `key`. /// - /// When `key` is empty, we return the asset metadata value. + /// When `key` is empty, we return the item metadata value. /// /// By default this is `None`; no attributes are defined. fn collection_attribute(collection: &Self::CollectionId, key: &[u8]) -> Option> { if key.is_empty() { - // We make the empty key map to the asset metadata value. + // 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((collection, Option::::None, key)) - .map(|a| a.0.into()) + Attribute::::get((collection, Option::::None, key)).map(|a| a.0.into()) } } - /// Returns `true` if the `asset` of `collection` may be transferred. + /// Returns `true` if the `item` of `collection` may be transferred. /// - /// Default implementation is that all assets are transferable. - fn can_transfer(collection: &Self::CollectionId, asset: &Self::AssetId) -> bool { - match (Collection::::get(collection), Asset::::get(collection, asset)) { + /// 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, } @@ -87,7 +86,7 @@ impl, I: 'static> Inspect<::AccountId> for Palle } impl, I: 'static> Create<::AccountId> for Pallet { - /// Create a `collection` of nonfungible assets to be owned by `who` and managed by `admin`. + /// Create a `collection` of nonfungible items to be owned by `who` and managed by `admin`. fn create_collection( collection: &Self::CollectionId, who: &T::AccountId, @@ -123,18 +122,18 @@ impl, I: 'static> Destroy<::AccountId> for Palle impl, I: 'static> Mutate<::AccountId> for Pallet { fn mint_into( collection: &Self::CollectionId, - asset: &Self::AssetId, + item: &Self::ItemId, who: &T::AccountId, ) -> DispatchResult { - Self::do_mint(*collection, *asset, who.clone(), |_| Ok(())) + Self::do_mint(*collection, *item, who.clone(), |_| Ok(())) } fn burn( collection: &Self::CollectionId, - asset: &Self::AssetId, + item: &Self::ItemId, maybe_check_owner: Option<&T::AccountId>, ) -> DispatchResult { - Self::do_burn(*collection, *asset, |_, 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()) @@ -148,10 +147,10 @@ impl, I: 'static> Mutate<::AccountId> for Pallet impl, I: 'static> Transfer for Pallet { fn transfer( collection: &Self::CollectionId, - asset: &Self::AssetId, + item: &Self::ItemId, destination: &T::AccountId, ) -> DispatchResult { - Self::do_transfer(*collection, *asset, destination.clone(), |_, _| Ok(())) + Self::do_transfer(*collection, *item, destination.clone(), |_, _| Ok(())) } } @@ -163,27 +162,27 @@ impl, I: 'static> InspectEnumerable for Pallet Box::new(CollectionMetadataOf::::iter_keys()) } - /// Returns an iterator of the assets of a `collection` in existence. + /// Returns an iterator of the items of a `collection` in existence. /// /// NOTE: iterating this list invokes a storage read per item. - fn assets(collection: &Self::CollectionId) -> Box> { - Box::new(AssetMetadataOf::::iter_key_prefix(collection)) + fn items(collection: &Self::CollectionId) -> Box> { + Box::new(ItemMetadataOf::::iter_key_prefix(collection)) } - /// Returns an iterator of the assets of all collections 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 assets of `collection` 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_collection( collection: &Self::CollectionId, who: &T::AccountId, - ) -> Box> { + ) -> Box> { Box::new(Account::::iter_key_prefix((who, collection))) } } diff --git a/frame/uniques/src/lib.rs b/frame/uniques/src/lib.rs index f500aba01862a..c5cd845229860 100644 --- a/frame/uniques/src/lib.rs +++ b/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 { + pub trait BenchmarkHelper { fn collection(i: u16) -> CollectionId; - fn asset(i: u16) -> AssetId; + fn item(i: u16) -> ItemId; } #[cfg(feature = "runtime-benchmarks")] - impl, AssetId: From> BenchmarkHelper for () { + impl, ItemId: From> BenchmarkHelper for () { fn collection(i: u16) -> CollectionId { i.into() } - fn asset(i: u16) -> AssetId { + fn item(i: u16) -> ItemId { i.into() } } @@ -87,16 +87,16 @@ pub mod pallet { /// The overarching event type. type Event: From> + IsType<::Event>; - /// Identifier for the collection of asset. + /// Identifier for the collection of item. type CollectionId: Member + Parameter + MaxEncodedLen + Copy; - /// The type used to identify a unique asset within a collection. - type AssetId: 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; @@ -109,21 +109,21 @@ pub mod pallet { >; /// Locker trait to enable Locking mechanism downstream. - type Locker: Locker; + type Locker: Locker; /// The basic amount of funds that must be reserved for collection. #[pallet::constant] type CollectionDeposit: Get>; - /// The basic amount of funds that must be reserved for an asset. + /// The basic amount of funds that must be reserved for an item. #[pallet::constant] - type AssetDeposit: 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,14 +146,14 @@ 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 assets collection. + /// Details of an items collection. pub(super) type Collection, I: 'static = ()> = StorageMap< _, Blake2_128Concat, @@ -167,14 +167,14 @@ pub mod pallet { 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, ), (), OptionQuery, @@ -194,19 +194,19 @@ pub mod pallet { >; #[pallet::storage] - /// The assets in existence and their ownership details. - pub(super) type Asset, I: 'static = ()> = StorageDoubleMap< + /// The items in existence and their ownership details. + pub(super) type Item, I: 'static = ()> = StorageDoubleMap< _, Blake2_128Concat, T::CollectionId, Blake2_128Concat, - T::AssetId, - AssetDetails>, + T::ItemId, + ItemDetails>, OptionQuery, >; #[pallet::storage] - /// Metadata of an assets collection. + /// Metadata of an items collection. pub(super) type CollectionMetadataOf, I: 'static = ()> = StorageMap< _, Blake2_128Concat, @@ -216,24 +216,24 @@ pub mod pallet { >; #[pallet::storage] - /// Metadata of an asset. - pub(super) type AssetMetadataOf, I: 'static = ()> = StorageDoubleMap< + /// Metadata of an item. + pub(super) type ItemMetadataOf, I: 'static = ()> = StorageDoubleMap< _, Blake2_128Concat, T::CollectionId, Blake2_128Concat, - T::AssetId, - AssetMetadata, T::StringLimit>, + T::ItemId, + ItemMetadata, T::StringLimit>, OptionQuery, >; #[pallet::storage] - /// Metadata of an assets collection. + /// Metadata of an items collection. pub(super) type Attribute, I: 'static = ()> = StorageNMap< _, ( NMapKey, - NMapKey>, + NMapKey>, NMapKey>, ), (BoundedVec, DepositBalanceOf), @@ -249,21 +249,21 @@ pub mod pallet { ForceCreated { collection: T::CollectionId, owner: T::AccountId }, /// A `collection` was destroyed. Destroyed { collection: T::CollectionId }, - /// An `asset` was issued. - Issued { collection: T::CollectionId, asset: T::AssetId, owner: T::AccountId }, - /// An `asset` was transferred. + /// An `item` was issued. + Issued { collection: T::CollectionId, item: T::ItemId, owner: T::AccountId }, + /// An `item` was transferred. Transferred { collection: T::CollectionId, - asset: T::AssetId, + item: T::ItemId, from: T::AccountId, to: T::AccountId, }, - /// An `asset` was destroyed. - Burned { collection: T::CollectionId, asset: T::AssetId, owner: T::AccountId }, - /// Some `asset` was frozen. - Frozen { collection: T::CollectionId, asset: T::AssetId }, - /// Some `asset` was thawed. - Thawed { collection: T::CollectionId, asset: T::AssetId }, + /// 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. @@ -277,24 +277,24 @@ pub mod pallet { admin: T::AccountId, freezer: T::AccountId, }, - /// An `asset` of a `collection` has been approved by the `owner` for transfer by + /// An `item` of a `collection` has been approved by the `owner` for transfer by /// a `delegate`. ApprovedTransfer { collection: T::CollectionId, - asset: T::AssetId, + item: T::ItemId, owner: T::AccountId, delegate: T::AccountId, }, - /// An approval for a `delegate` account to transfer the `asset` of an asset + /// An approval for a `delegate` account to transfer the `item` of an item /// `collection` was cancelled by its `owner`. ApprovalCancelled { collection: T::CollectionId, - asset: T::AssetId, + item: T::ItemId, owner: T::AccountId, delegate: T::AccountId, }, /// A `collection` has had its attributes changed by the `Force` origin. - AssetStatusChanged { collection: T::CollectionId }, + ItemStatusChanged { collection: T::CollectionId }, /// New metadata has been set for a `collection`. CollectionMetadataSet { collection: T::CollectionId, @@ -303,28 +303,28 @@ pub mod pallet { }, /// Metadata has been cleared for a `collection`. CollectionMetadataCleared { collection: T::CollectionId }, - /// New metadata has been set for an asset. + /// New metadata has been set for an item. MetadataSet { collection: T::CollectionId, - asset: T::AssetId, + item: T::ItemId, data: BoundedVec, is_frozen: bool, }, - /// Metadata has been cleared for an asset. - MetadataCleared { collection: T::CollectionId, asset: T::AssetId }, - /// Metadata has been cleared for an asset. - Redeposited { collection: T::CollectionId, successful_assets: Vec }, - /// New attribute metadata has been set for a `collection` or `asset`. + /// 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 { collection: T::CollectionId, - maybe_asset: Option, + maybe_item: Option, key: BoundedVec, value: BoundedVec, }, - /// Attribute metadata has been cleared for a `collection` or `asset`. + /// Attribute metadata has been cleared for a `collection` or `item`. AttributeCleared { collection: T::CollectionId, - maybe_asset: Option, + maybe_item: Option, key: BoundedVec, }, /// Ownership acceptance has changed for an account. @@ -335,17 +335,17 @@ pub mod pallet { pub enum Error { /// The signing account has no permission to do the operation. NoPermission, - /// The given asset ID is unknown. + /// The given item ID is unknown. UnknownCollection, - /// The asset ID has already been used for an asset. + /// 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 or collection is frozen. + /// The item or collection is frozen. Frozen, /// The delegate turned out to be different to what was expected. WrongDelegate, @@ -355,17 +355,17 @@ pub mod pallet { Unapproved, /// The named owner has not signed ownership of the collection is acceptable. Unaccepted, - /// The asset is locked. + /// The item is locked. Locked, } impl, I: 'static> Pallet { - /// Get the owner of the asset, if the asset exists. - pub fn owner(collection: T::CollectionId, asset: T::AssetId) -> Option { - Asset::::get(collection, asset).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, if the asset exists. + /// 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) } @@ -373,20 +373,20 @@ pub mod pallet { #[pallet::call] impl, I: 'static> Pallet { - /// Issue a new collection of non-fungible assets from a public origin. + /// Issue a new collection of non-fungible items from a public origin. /// - /// This new collection 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: - /// - `collection`: The identifier of the new assets collection. This must not be currently + /// - `collection`: The identifier of the new items collection. This must not be currently /// in use. - /// - `admin`: The admin of this collection of assets. The admin is the initial address of + /// - `admin`: The admin of this collection of items. The admin is the initial address of /// each - /// member of the assets collection's admin team. + /// member of the items collection's admin team. /// /// Emits `Created` event when successful. /// @@ -410,18 +410,18 @@ pub mod pallet { ) } - /// Issue a new collection of non-fungible assets from a privileged origin. + /// Issue a new collection of non-fungible items from a privileged origin. /// - /// This new collection has no assets initially. + /// This new collection has no items initially. /// /// The origin must conform to `ForceOrigin`. /// /// Unlike `create`, no funds are reserved. /// - /// - `collection`: The identifier of the new asset. This must not be currently in use. - /// - `owner`: The owner of this collection of assets. The owner has full superuser + /// - `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 asset, but may later change and configure the permissions using + /// over this item, but may later change and configure the permissions using /// `transfer_ownership` and `set_team`. /// /// Emits `ForceCreated` event when successful. @@ -447,24 +447,24 @@ pub mod pallet { ) } - /// Destroy a collection 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 `collection`. /// - /// - `collection`: The identifier of the assets collection to be destroyed. - /// - `witness`: Information on the assets minted in the assets collection. This must be + /// - `collection`: The identifier of the items collection to be destroyed. + /// - `witness`: Information on the items minted in the items collection. This must be /// correct. /// /// Emits `Destroyed` event when successful. /// /// Weight: `O(n + m)` where: - /// - `n = witness.assets` - /// - `m = witness.asset_metadatas` + /// - `n = witness.items` + /// - `m = witness.item_metadatas` /// - `a = witness.attributes` #[pallet::weight(T::WeightInfo::destroy( - witness.assets, - witness.asset_metadatas, + witness.items, + witness.item_metadatas, witness.attributes, ))] pub fn destroy( @@ -479,20 +479,20 @@ pub mod pallet { let details = Self::do_destroy_collection(collection, witness, maybe_check_owner)?; Ok(Some(T::WeightInfo::destroy( - details.assets, - details.asset_metadatas, + details.items, + details.item_metadatas, details.attributes, )) .into()) } - /// Mint an asset of a particular collection. + /// Mint an item of a particular collection. /// /// The origin must be Signed and the sender must be the Issuer of the `collection`. /// - /// - `collection`: The collection of the asset to be minted. - /// - `asset`: The asset 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. /// @@ -501,26 +501,26 @@ pub mod pallet { pub fn mint( origin: OriginFor, collection: T::CollectionId, - asset: T::AssetId, + item: T::ItemId, owner: ::Source, ) -> DispatchResult { let origin = ensure_signed(origin)?; let owner = T::Lookup::lookup(owner)?; - Self::do_mint(collection, asset, owner, |collection_details| { + Self::do_mint(collection, item, owner, |collection_details| { ensure!(collection_details.issuer == origin, Error::::NoPermission); Ok(()) }) } - /// Destroy a single asset. + /// Destroy a single item. /// /// Origin must be Signed and the sender should be the Admin of the `collection`. /// - /// - `collection`: The collection of the asset to be burned. - /// - `asset`: The asset 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. /// @@ -530,13 +530,13 @@ pub mod pallet { pub fn burn( origin: OriginFor, collection: T::CollectionId, - asset: T::AssetId, + 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(collection, asset, |collection_details, details| { + Self::do_burn(collection, item, |collection_details, details| { let is_permitted = collection_details.admin == origin || details.owner == origin; ensure!(is_permitted, Error::::NoPermission); ensure!( @@ -547,17 +547,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 `collection`; - /// - the Owner of the `asset`; - /// - the approved delegate for the `asset` (in this case, the approval is reset). + /// - the Owner of the `item`; + /// - the approved delegate for the `item` (in this case, the approval is reset). /// /// Arguments: - /// - `collection`: The collection of the asset to be transferred. - /// - `asset`: The asset 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`. /// @@ -566,13 +566,13 @@ pub mod pallet { pub fn transfer( origin: OriginFor, collection: T::CollectionId, - asset: T::AssetId, + item: T::ItemId, dest: ::Source, ) -> DispatchResult { let origin = ensure_signed(origin)?; let dest = T::Lookup::lookup(dest)?; - Self::do_transfer(collection, asset, dest, |collection_details, details| { + 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); @@ -581,28 +581,28 @@ 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 `collection`. /// - /// - `collection`: The collection of the asset to be frozen. - /// - `assets`: The assets of the assets collection whose deposits will be reevaluated. + /// - `collection`: The collection of the item to be frozen. + /// - `items`: The items of the items collection whose deposits will be reevaluated. /// - /// NOTE: This exists as a best-effort function. Any assets 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 assets + /// 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 collection is unknown of the signer /// is not permitted to call it. /// - /// Weight: `O(assets.len())` - #[pallet::weight(T::WeightInfo::redeposit(assets.len() as u32))] + /// Weight: `O(items.len())` + #[pallet::weight(T::WeightInfo::redeposit(items.len() as u32))] pub fn redeposit( origin: OriginFor, collection: T::CollectionId, - assets: Vec, + items: Vec, ) -> DispatchResult { let origin = ensure_signed(origin)?; @@ -611,12 +611,12 @@ pub mod pallet { ensure!(collection_details.owner == origin, Error::::NoPermission); let deposit = match collection_details.free_holding { true => Zero::zero(), - false => T::AssetDeposit::get(), + false => T::ItemDeposit::get(), }; - let mut successful = Vec::with_capacity(assets.len()); - for asset in assets.into_iter() { - let mut details = match Asset::::get(&collection, &asset) { + 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, }; @@ -635,25 +635,25 @@ pub mod pallet { collection_details.total_deposit.saturating_accrue(deposit); collection_details.total_deposit.saturating_reduce(old); details.deposit = deposit; - Asset::::insert(&collection, &asset, &details); - successful.push(asset); + Item::::insert(&collection, &item, &details); + successful.push(item); } Collection::::insert(&collection, &collection_details); Self::deposit_event(Event::::Redeposited { collection, - successful_assets: successful, + successful_items: successful, }); Ok(()) } - /// Disallow further unprivileged transfer of an asset. + /// Disallow further unprivileged transfer of an item. /// /// Origin must be Signed and the sender should be the Freezer of the `collection`. /// - /// - `collection`: The collection of the asset to be frozen. - /// - `asset`: The asset 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`. /// @@ -662,29 +662,29 @@ pub mod pallet { pub fn freeze( origin: OriginFor, collection: T::CollectionId, - asset: T::AssetId, + item: T::ItemId, ) -> DispatchResult { let origin = ensure_signed(origin)?; let mut details = - Asset::::get(&collection, &asset).ok_or(Error::::UnknownCollection)?; + 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(&collection, &asset, &details); + Item::::insert(&collection, &item, &details); - Self::deposit_event(Event::::Frozen { collection, asset }); + Self::deposit_event(Event::::Frozen { collection, item }); Ok(()) } - /// Re-allow unprivileged transfer of an asset. + /// Re-allow unprivileged transfer of an item. /// /// Origin must be Signed and the sender should be the Freezer of the `collection`. /// - /// - `collection`: The collection of the asset to be thawed. - /// - `asset`: The asset 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`. /// @@ -693,28 +693,28 @@ pub mod pallet { pub fn thaw( origin: OriginFor, collection: T::CollectionId, - asset: T::AssetId, + item: T::ItemId, ) -> DispatchResult { let origin = ensure_signed(origin)?; let mut details = - Asset::::get(&collection, &asset).ok_or(Error::::UnknownCollection)?; + 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(&collection, &asset, &details); + Item::::insert(&collection, &item, &details); - Self::deposit_event(Event::::Thawed { collection, asset }); + Self::deposit_event(Event::::Thawed { collection, item }); Ok(()) } - /// Disallow further unprivileged transfers for a whole assets collection. + /// Disallow further unprivileged transfers for a whole items collection. /// /// Origin must be Signed and the sender should be the Freezer of the `collection`. /// - /// - `collection`: The assets collection to be frozen. + /// - `collection`: The items collection to be frozen. /// /// Emits `CollectionFrozen`. /// @@ -737,7 +737,7 @@ pub mod pallet { }) } - /// Re-allow unprivileged transfers for a whole assets collection. + /// Re-allow unprivileged transfers for a whole items collection. /// /// Origin must be Signed and the sender should be the Admin of the `collection`. /// @@ -764,12 +764,12 @@ pub mod pallet { }) } - /// Change the Owner of an assets collection. + /// Change the Owner of an items collection. /// /// Origin must be Signed and the sender should be the Owner of the `collection`. /// - /// - `collection`: The assets collection whose owner should be changed. - /// - `owner`: The new Owner of this assets collection. They must have called + /// - `collection`: The items collection whose owner should be changed. + /// - `owner`: The new Owner of this items collection. They must have called /// `set_accept_ownership` with `collection` in order for this operation to succeed. /// /// Emits `OwnerChanged`. @@ -811,14 +811,14 @@ pub mod pallet { }) } - /// Change the Issuer, Admin and Freezer of an assets collection. + /// Change the Issuer, Admin and Freezer of an items collection. /// /// Origin must be Signed and the sender should be the Owner of the `collection`. /// - /// - `collection`: The assets collection whose team should be changed. - /// - `issuer`: The new Issuer of this assets collection. - /// - `admin`: The new Admin of this assets collection. - /// - `freezer`: The new Freezer of this assets collection. + /// - `collection`: The items collection whose team should be changed. + /// - `issuer`: The new Issuer of this items collection. + /// - `admin`: The new Admin of this items collection. + /// - `freezer`: The new Freezer of this items collection. /// /// Emits `TeamChanged`. /// @@ -849,13 +849,13 @@ pub mod pallet { }) } - /// Approve an asset 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`. + /// Origin must be Signed and must be the owner of the `item`. /// - /// - `collection`: The collection of the asset to be approved for delegated transfer. - /// - `asset`: The asset 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. /// @@ -864,7 +864,7 @@ pub mod pallet { pub fn approve_transfer( origin: OriginFor, collection: T::CollectionId, - asset: T::AssetId, + item: T::ItemId, delegate: ::Source, ) -> DispatchResult { let maybe_check: Option = T::ForceOrigin::try_origin(origin) @@ -876,7 +876,7 @@ pub mod pallet { let collection_details = Collection::::get(&collection).ok_or(Error::::UnknownCollection)?; let mut details = - Asset::::get(&collection, &asset).ok_or(Error::::UnknownCollection)?; + Item::::get(&collection, &item).ok_or(Error::::UnknownCollection)?; if let Some(check) = maybe_check { let permitted = check == collection_details.admin || check == details.owner; @@ -884,12 +884,12 @@ pub mod pallet { } details.approved = Some(delegate); - Asset::::insert(&collection, &asset, &details); + Item::::insert(&collection, &item, &details); let delegate = details.approved.expect("set as Some above; qed"); Self::deposit_event(Event::ApprovedTransfer { collection, - asset, + item, owner: details.owner, delegate, }); @@ -897,16 +897,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 `collection`; - /// - `Signed` with the signer being the Owner of the `asset`; + /// - `Signed` with the signer being the Owner of the `item`; /// /// Arguments: - /// - `collection`: The collection of the asset of whose approval will be cancelled. - /// - `asset`: The asset 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. /// @@ -917,7 +917,7 @@ pub mod pallet { pub fn cancel_approval( origin: OriginFor, collection: T::CollectionId, - asset: T::AssetId, + item: T::ItemId, maybe_check_delegate: Option<::Source>, ) -> DispatchResult { let maybe_check: Option = T::ForceOrigin::try_origin(origin) @@ -927,7 +927,7 @@ pub mod pallet { let collection_details = Collection::::get(&collection).ok_or(Error::::UnknownCollection)?; let mut details = - Asset::::get(&collection, &asset).ok_or(Error::::UnknownCollection)?; + Item::::get(&collection, &item).ok_or(Error::::UnknownCollection)?; if let Some(check) = maybe_check { let permitted = check == collection_details.admin || check == details.owner; ensure!(permitted, Error::::NoPermission); @@ -938,10 +938,10 @@ pub mod pallet { ensure!(check_delegate == old, Error::::WrongDelegate); } - Asset::::insert(&collection, &asset, &details); + Item::::insert(&collection, &item, &details); Self::deposit_event(Event::ApprovalCancelled { collection, - asset, + item, owner: details.owner, delegate: old, }); @@ -949,25 +949,25 @@ pub mod pallet { Ok(()) } - /// Alter the attributes of a given asset. + /// Alter the attributes of a given item. /// /// Origin must be `ForceOrigin`. /// - /// - `collection`: 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 asset of this asset + /// - `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 item /// collection. - /// - `is_frozen`: Whether this assets collection is frozen except for permissioned/admin + /// - `is_frozen`: Whether this items 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, collection: T::CollectionId, owner: ::Source, @@ -979,26 +979,26 @@ pub mod pallet { ) -> DispatchResult { T::ForceOrigin::ensure_origin(origin)?; - Collection::::try_mutate(collection, |maybe_asset| { - let mut asset = maybe_asset.take().ok_or(Error::::UnknownCollection)?; - 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); + 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 { collection }); + Self::deposit_event(Event::ItemStatusChanged { collection }); Ok(()) }) } - /// Set an attribute for an assets collection or asset. + /// Set an attribute for an items collection or item. /// /// Origin must be either `ForceOrigin` or Signed and the sender should be the Owner of the /// `collection`. @@ -1007,8 +1007,8 @@ pub mod pallet { /// `MetadataDepositBase + DepositPerByte * (key.len + value.len)` taking into /// account any already reserved funds. /// - /// - `collection`: The identifier of the assets collection whose asset's metadata to set. - /// - `maybe_asset`: The identifier of the asset whose metadata to set. + /// - `collection`: The identifier of the items 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. /// @@ -1019,7 +1019,7 @@ pub mod pallet { pub fn set_attribute( origin: OriginFor, collection: T::CollectionId, - maybe_asset: Option, + maybe_item: Option, key: BoundedVec, value: BoundedVec, ) -> DispatchResult { @@ -1032,13 +1032,13 @@ pub mod pallet { if let Some(check_owner) = &maybe_check_owner { ensure!(check_owner == &collection_details.owner, Error::::NoPermission); } - let maybe_is_frozen = match maybe_asset { + let maybe_is_frozen = match maybe_item { None => CollectionMetadataOf::::get(collection).map(|v| v.is_frozen), - Some(asset) => AssetMetadataOf::::get(collection, asset).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((collection, maybe_asset, &key)); + let attribute = Attribute::::get((collection, maybe_item, &key)); if attribute.is_none() { collection_details.attributes.saturating_inc(); } @@ -1057,21 +1057,21 @@ pub mod pallet { T::Currency::unreserve(&collection_details.owner, old_deposit - deposit); } - Attribute::::insert((&collection, maybe_asset, &key), (&value, deposit)); + Attribute::::insert((&collection, maybe_item, &key), (&value, deposit)); Collection::::insert(collection, &collection_details); - Self::deposit_event(Event::AttributeSet { collection, maybe_asset, key, value }); + Self::deposit_event(Event::AttributeSet { collection, maybe_item, key, value }); Ok(()) } - /// Clear an attribute for an assets collection or asset. + /// Clear an attribute for an items collection or item. /// /// Origin must be either `ForceOrigin` or Signed and the sender should be the Owner of the /// `collection`. /// - /// Any deposit is freed for the assets collection owner. + /// Any deposit is freed for the items collection owner. /// - /// - `collection`: The identifier of the assets collection whose asset's metadata to clear. - /// - `maybe_asset`: The identifier of the asset whose metadata to clear. + /// - `collection`: The identifier of the items 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`. @@ -1081,7 +1081,7 @@ pub mod pallet { pub fn clear_attribute( origin: OriginFor, collection: T::CollectionId, - maybe_asset: Option, + maybe_item: Option, key: BoundedVec, ) -> DispatchResult { let maybe_check_owner = T::ForceOrigin::try_origin(origin) @@ -1093,23 +1093,23 @@ pub mod pallet { if let Some(check_owner) = &maybe_check_owner { ensure!(check_owner == &collection_details.owner, Error::::NoPermission); } - let maybe_is_frozen = match maybe_asset { + let maybe_is_frozen = match maybe_item { None => CollectionMetadataOf::::get(collection).map(|v| v.is_frozen), - Some(asset) => AssetMetadataOf::::get(collection, asset).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((collection, maybe_asset, &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_asset, key }); + Self::deposit_event(Event::AttributeCleared { collection, maybe_item, key }); } Ok(()) } - /// Set the metadata for an asset. + /// Set the metadata for an item. /// /// Origin must be either `ForceOrigin` or Signed and the sender should be the Owner of the /// `collection`. @@ -1118,9 +1118,9 @@ pub mod pallet { /// `MetadataDepositBase + DepositPerByte * data.len` taking into /// account any already reserved funds. /// - /// - `collection`: The identifier of the assets collection whose asset's metadata to set. - /// - `asset`: The identifier of the asset whose metadata to set. - /// - `data`: The general information of this asset. Limited in length by `StringLimit`. + /// - `collection`: The identifier of the items 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`. @@ -1130,7 +1130,7 @@ pub mod pallet { pub fn set_metadata( origin: OriginFor, collection: T::CollectionId, - asset: T::AssetId, + item: T::ItemId, data: BoundedVec, is_frozen: bool, ) -> DispatchResult { @@ -1145,12 +1145,12 @@ pub mod pallet { ensure!(check_owner == &collection_details.owner, Error::::NoPermission); } - AssetMetadataOf::::try_mutate_exists(collection, asset, |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() { - collection_details.asset_metadatas.saturating_inc(); + collection_details.item_metadatas.saturating_inc(); } let old_deposit = metadata.take().map_or(Zero::zero(), |m| m.deposit); collection_details.total_deposit.saturating_reduce(old_deposit); @@ -1167,23 +1167,23 @@ pub mod pallet { } collection_details.total_deposit.saturating_accrue(deposit); - *metadata = Some(AssetMetadata { deposit, data: data.clone(), is_frozen }); + *metadata = Some(ItemMetadata { deposit, data: data.clone(), is_frozen }); Collection::::insert(&collection, &collection_details); - Self::deposit_event(Event::MetadataSet { collection, asset, data, is_frozen }); + Self::deposit_event(Event::MetadataSet { collection, item, data, is_frozen }); Ok(()) }) } - /// Clear the metadata for an asset. + /// Clear the metadata for an item. /// /// Origin must be either `ForceOrigin` or Signed and the sender should be the Owner of the - /// `asset`. + /// `item`. /// - /// Any deposit is freed for the assets collection owner. + /// Any deposit is freed for the items collection owner. /// - /// - `collection`: The identifier of the assets collection whose asset's metadata to clear. - /// - `asset`: The identifier of the asset whose metadata to clear. + /// - `collection`: The identifier of the items collection whose item's metadata to clear. + /// - `item`: The identifier of the item whose metadata to clear. /// /// Emits `MetadataCleared`. /// @@ -1192,7 +1192,7 @@ pub mod pallet { pub fn clear_metadata( origin: OriginFor, collection: T::CollectionId, - asset: T::AssetId, + item: T::ItemId, ) -> DispatchResult { let maybe_check_owner = T::ForceOrigin::try_origin(origin) .map(|_| None) @@ -1204,24 +1204,24 @@ pub mod pallet { ensure!(check_owner == &collection_details.owner, Error::::NoPermission); } - AssetMetadataOf::::try_mutate_exists(collection, asset, |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() { - collection_details.asset_metadatas.saturating_dec(); + collection_details.item_metadatas.saturating_dec(); } let deposit = metadata.take().ok_or(Error::::UnknownCollection)?.deposit; T::Currency::unreserve(&collection_details.owner, deposit); collection_details.total_deposit.saturating_reduce(deposit); Collection::::insert(&collection, &collection_details); - Self::deposit_event(Event::MetadataCleared { collection, asset }); + Self::deposit_event(Event::MetadataCleared { collection, item }); Ok(()) }) } - /// Set the metadata for an assets collection. + /// Set the metadata for an items collection. /// /// Origin must be either `ForceOrigin` or `Signed` and the sender should be the Owner of /// the `collection`. @@ -1230,8 +1230,8 @@ pub mod pallet { /// `MetadataDepositBase + DepositPerByte * data.len` taking into /// account any already reserved funds. /// - /// - `collection`: 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 `CollectionMetadataSet`. @@ -1282,14 +1282,14 @@ pub mod pallet { }) } - /// Clear the metadata for an assets collection. + /// Clear the metadata for an items collection. /// /// Origin must be either `ForceOrigin` or `Signed` and the sender should be the Owner of /// the `collection`. /// - /// Any deposit is freed for the assets collection owner. + /// Any deposit is freed for the items collection owner. /// - /// - `collection`: The identifier of the assets collection whose metadata to clear. + /// - `collection`: The identifier of the items collection whose metadata to clear. /// /// Emits `CollectionMetadataCleared`. /// @@ -1325,7 +1325,7 @@ pub mod pallet { /// Origin must be `Signed` and if `maybe_collection` is `Some`, then the signer must have a /// provider reference. /// - /// - `maybe_collection`: The identifier of the assets collection whose ownership the signer + /// - `maybe_collection`: The identifier of the items collection whose ownership the signer /// is willing to accept, or if `None`, an indication that the signer is willing to accept /// no ownership transferal. /// diff --git a/frame/uniques/src/mock.rs b/frame/uniques/src/mock.rs index 8ff3aca77c486..6fb6102391fa0 100644 --- a/frame/uniques/src/mock.rs +++ b/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 Items pallet. use super::*; use crate as pallet_uniques; @@ -87,13 +87,13 @@ impl pallet_balances::Config for Test { impl Config for Test { type Event = Event; type CollectionId = u32; - type AssetId = u32; + type ItemId = u32; type Currency = Balances; type CreateOrigin = AsEnsureOriginWithArg>; type ForceOrigin = frame_system::EnsureRoot; type Locker = (); type CollectionDeposit = ConstU64<2>; - type AssetDeposit = ConstU64<1>; + type ItemDeposit = ConstU64<1>; type MetadataDepositBase = ConstU64<1>; type AttributeDepositBase = ConstU64<1>; type DepositPerByte = ConstU64<1>; diff --git a/frame/uniques/src/tests.rs b/frame/uniques/src/tests.rs index cc8dc238e72d9..6bd397eefa7ef 100644 --- a/frame/uniques/src/tests.rs +++ b/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 collection in Asset::::iter() + for collection in Item::::iter() .map(|x| x.0) .scan(None, |s, item| { if s.map_or(false, |last| last == item) { @@ -42,8 +42,8 @@ fn assets() -> Vec<(u64, u32, u32)> { .flatten() { let details = Collection::::get(collection).unwrap(); - let assets = Asset::::iter_prefix(collection).count() as u32; - assert_eq!(details.assets, assets); + let items = Item::::iter_prefix(collection).count() as u32; + assert_eq!(details.items, items); } r } @@ -74,7 +74,7 @@ fn attributes(collection: u32) -> Vec<(Option, Vec, Vec)> { #[test] fn basic_setup_works() { new_test_ext().execute_with(|| { - assert_eq!(assets(), vec![]); + assert_eq!(items(), vec![]); }); } @@ -84,12 +84,12 @@ fn basic_minting_should_work() { assert_ok!(Uniques::force_create(Origin::root(), 0, 1, true)); 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!(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)]); }); } @@ -108,31 +108,31 @@ fn lifecycle_should_work() { 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!(Collection::::get(0).unwrap().assets, 2); - assert_eq!(Collection::::get(0).unwrap().asset_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!(AssetMetadataOf::::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!(AssetMetadataOf::::contains_key(0, 69)); + assert!(ItemMetadataOf::::contains_key(0, 69)); let w = Collection::::get(0).unwrap().destroy_witness(); - assert_eq!(w.assets, 2); - assert_eq!(w.asset_metadatas, 2); + 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!(!Collection::::contains_key(0)); - assert!(!Asset::::contains_key(0, 42)); - assert!(!Asset::::contains_key(0, 69)); + assert!(!Item::::contains_key(0, 42)); + assert!(!Item::::contains_key(0, 69)); assert!(!CollectionMetadataOf::::contains_key(0)); - assert!(!AssetMetadataOf::::contains_key(0, 42)); - assert!(!AssetMetadataOf::::contains_key(0, 69)); + assert!(!ItemMetadataOf::::contains_key(0, 42)); + assert!(!ItemMetadataOf::::contains_key(0, 69)); assert_eq!(collections(), vec![]); - assert_eq!(assets(), vec![]); + assert_eq!(items(), vec![]); }); } @@ -155,7 +155,7 @@ fn mint_should_work() { assert_ok!(Uniques::mint(Origin::signed(1), 0, 42, 1)); assert_eq!(Uniques::owner(0, 42).unwrap(), 1); assert_eq!(collections(), vec![(1, 0)]); - assert_eq!(assets(), vec![(1, 0, 42)]); + 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)); @@ -278,13 +278,13 @@ fn set_team_should_work() { #[test] 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_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_collection_metadata(Origin::signed(2), 0, bvec![0u8; 20], false), Error::::NoPermission, @@ -338,14 +338,14 @@ fn set_collection_metadata_should_work() { } #[test] -fn set_asset_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, @@ -354,7 +354,7 @@ fn set_asset_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!(AssetMetadataOf::::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)); @@ -390,7 +390,7 @@ fn set_asset_metadata_should_work() { Error::::UnknownCollection ); assert_ok!(Uniques::clear_metadata(Origin::signed(1), 0, 42)); - assert!(!AssetMetadataOf::::contains_key(0, 42)); + assert!(!ItemMetadataOf::::contains_key(0, 42)); }); } @@ -472,7 +472,7 @@ 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); @@ -484,8 +484,8 @@ 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), 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)); @@ -539,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)); diff --git a/frame/uniques/src/types.rs b/frame/uniques/src/types.rs index 61ffa08b4f725..76817df2c39c6 100644 --- a/frame/uniques/src/types.rs +++ b/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 items pallet. use super::*; use frame_support::{ @@ -28,8 +28,8 @@ pub(super) type DepositBalanceOf = <>::Currency as Currency<::AccountId>>::Balance; pub(super) type CollectionDetailsFor = CollectionDetails<::AccountId, DepositBalanceOf>; -pub(super) type AssetDetailsFor = - AssetDetails<::AccountId, DepositBalanceOf>; +pub(super) type ItemDetailsFor = + ItemDetails<::AccountId, DepositBalanceOf>; #[derive(Clone, Encode, Decode, Eq, PartialEq, RuntimeDebug, TypeInfo, MaxEncodedLen)] pub struct CollectionDetails { @@ -44,27 +44,27 @@ pub struct CollectionDetails { /// 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 assets of this collection. + /// If `true`, then no deposit is needed to hold items of this collection. pub(super) free_holding: bool, - /// The total number of outstanding assets of this collection. - pub(super) assets: u32, - /// The total number of outstanding asset metadata of this collection. - pub(super) asset_metadatas: u32, + /// 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 item 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 assets of this collection. + /// The total number of outstanding items of this collection. #[codec(compact)] - pub assets: u32, - /// The total number of outstanding asset metadata of this collection. + pub items: u32, + /// The total number of outstanding item metadata of this collection. #[codec(compact)] - pub asset_metadatas: u32, + pub item_metadatas: u32, #[codec(compact)] /// The total number of attributes for this collection. pub attributes: u32, @@ -73,23 +73,23 @@ pub struct DestroyWitness { impl CollectionDetails { pub fn destroy_witness(&self) -> DestroyWitness { DestroyWitness { - assets: self.assets, - asset_metadatas: self.asset_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 AssetDetails { - /// 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, } @@ -102,26 +102,26 @@ pub struct CollectionMetadata> { /// /// 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, } #[derive(Clone, Encode, Decode, Eq, PartialEq, RuntimeDebug, Default, TypeInfo, MaxEncodedLen)] #[scale_info(skip_type_params(StringLimit))] #[codec(mel_bound(DepositBalance: MaxEncodedLen))] -pub struct AssetMetadata> { +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/frame/uniques/src/weights.rs b/frame/uniques/src/weights.rs index 922f783e72932..e418bac2bd315 100644 --- a/frame/uniques/src/weights.rs +++ b/frame/uniques/src/weights.rs @@ -59,7 +59,7 @@ pub trait WeightInfo { 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; @@ -89,11 +89,11 @@ impl WeightInfo for SubstrateWeight { .saturating_add(T::DbWeight::get().writes(2 as Weight)) } // Storage: Uniques Collection (r:1 w:1) - // Storage: Uniques Asset (r:1 w:0) + // Storage: Uniques Item (r:1 w:0) // Storage: Uniques CollectionAccount (r:0 w:1) // Storage: Uniques Attribute (r:0 w:1000) // Storage: Uniques CollectionMetadataOf (r:0 w:1) - // Storage: Uniques AssetMetadataOf (r:0 w:1000) + // Storage: Uniques ItemMetadataOf (r:0 w:1000) // Storage: Uniques Account (r:0 w:20) fn destroy(n: u32, m: u32, a: u32, ) -> Weight { (0 as Weight) @@ -110,7 +110,7 @@ impl WeightInfo for SubstrateWeight { .saturating_add(T::DbWeight::get().writes((1 as Weight).saturating_mul(m as Weight))) .saturating_add(T::DbWeight::get().writes((1 as Weight).saturating_mul(a as Weight))) } - // Storage: Uniques Asset (r:1 w:1) + // Storage: Uniques Item (r:1 w:1) // Storage: Uniques Collection (r:1 w:1) // Storage: Uniques Account (r:0 w:1) fn mint() -> Weight { @@ -119,7 +119,7 @@ impl WeightInfo for SubstrateWeight { .saturating_add(T::DbWeight::get().writes(3 as Weight)) } // Storage: Uniques Collection (r:1 w:1) - // Storage: Uniques Asset (r:1 w:1) + // Storage: Uniques Item (r:1 w:1) // Storage: Uniques Account (r:0 w:1) fn burn() -> Weight { (31_603_000 as Weight) @@ -127,7 +127,7 @@ impl WeightInfo for SubstrateWeight { .saturating_add(T::DbWeight::get().writes(3 as Weight)) } // Storage: Uniques Collection (r:1 w:0) - // Storage: Uniques Asset (r:1 w:1) + // Storage: Uniques Item (r:1 w:1) // Storage: Uniques Account (r:0 w:2) fn transfer() -> Weight { (23_331_000 as Weight) @@ -135,7 +135,7 @@ impl WeightInfo for SubstrateWeight { .saturating_add(T::DbWeight::get().writes(3 as Weight)) } // Storage: Uniques Collection (r:1 w:1) - // Storage: Uniques Asset (r:100 w:100) + // Storage: Uniques Item (r:100 w:100) fn redeposit(i: u32, ) -> Weight { (0 as Weight) // Standard Error: 12_000 @@ -145,14 +145,14 @@ impl WeightInfo for SubstrateWeight { .saturating_add(T::DbWeight::get().writes(1 as Weight)) .saturating_add(T::DbWeight::get().writes((1 as Weight).saturating_mul(i as Weight))) } - // Storage: Uniques Asset (r:1 w:1) + // Storage: Uniques Item (r:1 w:1) // Storage: Uniques Collection (r:1 w:0) fn freeze() -> Weight { (18_617_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 Item (r:1 w:1) // Storage: Uniques Collection (r:1 w:0) fn thaw() -> Weight { (18_618_000 as Weight) @@ -187,13 +187,13 @@ impl WeightInfo for SubstrateWeight { } // Storage: Uniques Collection (r:1 w:1) // Storage: Uniques CollectionAccount (r:0 w:1) - fn force_asset_status() -> Weight { + fn force_item_status() -> Weight { (16_826_000 as Weight) .saturating_add(T::DbWeight::get().reads(1 as Weight)) .saturating_add(T::DbWeight::get().writes(2 as Weight)) } // Storage: Uniques Collection (r:1 w:1) - // Storage: Uniques AssetMetadataOf (r:1 w:0) + // Storage: Uniques ItemMetadataOf (r:1 w:0) // Storage: Uniques Attribute (r:1 w:1) fn set_attribute() -> Weight { (37_010_000 as Weight) @@ -201,7 +201,7 @@ impl WeightInfo for SubstrateWeight { .saturating_add(T::DbWeight::get().writes(2 as Weight)) } // Storage: Uniques Collection (r:1 w:1) - // Storage: Uniques AssetMetadataOf (r:1 w:0) + // Storage: Uniques ItemMetadataOf (r:1 w:0) // Storage: Uniques Attribute (r:1 w:1) fn clear_attribute() -> Weight { (34_432_000 as Weight) @@ -209,14 +209,14 @@ impl WeightInfo for SubstrateWeight { .saturating_add(T::DbWeight::get().writes(2 as Weight)) } // Storage: Uniques Collection (r:1 w:1) - // Storage: Uniques AssetMetadataOf (r:1 w:1) + // Storage: Uniques ItemMetadataOf (r:1 w:1) fn set_metadata() -> Weight { (28_575_000 as Weight) .saturating_add(T::DbWeight::get().reads(2 as Weight)) .saturating_add(T::DbWeight::get().writes(2 as Weight)) } // Storage: Uniques Collection (r:1 w:1) - // Storage: Uniques AssetMetadataOf (r:1 w:1) + // Storage: Uniques ItemMetadataOf (r:1 w:1) fn clear_metadata() -> Weight { (28_730_000 as Weight) .saturating_add(T::DbWeight::get().reads(2 as Weight)) @@ -237,21 +237,21 @@ impl WeightInfo for SubstrateWeight { .saturating_add(T::DbWeight::get().writes(1 as Weight)) } // Storage: Uniques Collection (r:1 w:0) - // Storage: Uniques Asset (r:1 w:1) + // Storage: Uniques Item (r:1 w:1) fn approve_transfer() -> Weight { (19_587_000 as Weight) .saturating_add(T::DbWeight::get().reads(2 as Weight)) .saturating_add(T::DbWeight::get().writes(1 as Weight)) } // Storage: Uniques Collection (r:1 w:0) - // Storage: Uniques Asset (r:1 w:1) + // Storage: Uniques Item (r:1 w:1) fn cancel_approval() -> Weight { (19_417_000 as Weight) .saturating_add(T::DbWeight::get().reads(2 as Weight)) .saturating_add(T::DbWeight::get().writes(1 as Weight)) } // Storage: Uniques Collection (r:1 w:0) - // Storage: Uniques Asset (r:1 w:1) + // Storage: Uniques Item (r:1 w:1) fn set_accept_ownership() -> Weight { (19_417_000 as Weight) .saturating_add(T::DbWeight::get().reads(1 as Weight)) @@ -276,11 +276,11 @@ impl WeightInfo for () { .saturating_add(RocksDbWeight::get().writes(2 as Weight)) } // Storage: Uniques Collection (r:1 w:1) - // Storage: Uniques Asset (r:1 w:0) + // Storage: Uniques Item (r:1 w:0) // Storage: Uniques CollectionAccount (r:0 w:1) // Storage: Uniques Attribute (r:0 w:1000) // Storage: Uniques CollectionMetadataOf (r:0 w:1) - // Storage: Uniques AssetMetadataOf (r:0 w:1000) + // Storage: Uniques ItemMetadataOf (r:0 w:1000) // Storage: Uniques Account (r:0 w:20) fn destroy(n: u32, m: u32, a: u32, ) -> Weight { (0 as Weight) @@ -297,7 +297,7 @@ impl WeightInfo for () { .saturating_add(RocksDbWeight::get().writes((1 as Weight).saturating_mul(m as Weight))) .saturating_add(RocksDbWeight::get().writes((1 as Weight).saturating_mul(a as Weight))) } - // Storage: Uniques Asset (r:1 w:1) + // Storage: Uniques Item (r:1 w:1) // Storage: Uniques Collection (r:1 w:1) // Storage: Uniques Account (r:0 w:1) fn mint() -> Weight { @@ -306,7 +306,7 @@ impl WeightInfo for () { .saturating_add(RocksDbWeight::get().writes(3 as Weight)) } // Storage: Uniques Collection (r:1 w:1) - // Storage: Uniques Asset (r:1 w:1) + // Storage: Uniques Item (r:1 w:1) // Storage: Uniques Account (r:0 w:1) fn burn() -> Weight { (31_603_000 as Weight) @@ -314,7 +314,7 @@ impl WeightInfo for () { .saturating_add(RocksDbWeight::get().writes(3 as Weight)) } // Storage: Uniques Collection (r:1 w:0) - // Storage: Uniques Asset (r:1 w:1) + // Storage: Uniques Item (r:1 w:1) // Storage: Uniques Account (r:0 w:2) fn transfer() -> Weight { (23_331_000 as Weight) @@ -322,7 +322,7 @@ impl WeightInfo for () { .saturating_add(RocksDbWeight::get().writes(3 as Weight)) } // Storage: Uniques Collection (r:1 w:1) - // Storage: Uniques Asset (r:100 w:100) + // Storage: Uniques Item (r:100 w:100) fn redeposit(i: u32, ) -> Weight { (0 as Weight) // Standard Error: 12_000 @@ -332,14 +332,14 @@ impl WeightInfo for () { .saturating_add(RocksDbWeight::get().writes(1 as Weight)) .saturating_add(RocksDbWeight::get().writes((1 as Weight).saturating_mul(i as Weight))) } - // Storage: Uniques Asset (r:1 w:1) + // Storage: Uniques Item (r:1 w:1) // Storage: Uniques Collection (r:1 w:0) fn freeze() -> Weight { (18_617_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 Item (r:1 w:1) // Storage: Uniques Collection (r:1 w:0) fn thaw() -> Weight { (18_618_000 as Weight) @@ -374,13 +374,13 @@ impl WeightInfo for () { } // Storage: Uniques Collection (r:1 w:1) // Storage: Uniques CollectionAccount (r:0 w:1) - fn force_asset_status() -> Weight { + fn force_item_status() -> Weight { (16_826_000 as Weight) .saturating_add(RocksDbWeight::get().reads(1 as Weight)) .saturating_add(RocksDbWeight::get().writes(2 as Weight)) } // Storage: Uniques Collection (r:1 w:1) - // Storage: Uniques AssetMetadataOf (r:1 w:0) + // Storage: Uniques ItemMetadataOf (r:1 w:0) // Storage: Uniques Attribute (r:1 w:1) fn set_attribute() -> Weight { (37_010_000 as Weight) @@ -388,7 +388,7 @@ impl WeightInfo for () { .saturating_add(RocksDbWeight::get().writes(2 as Weight)) } // Storage: Uniques Collection (r:1 w:1) - // Storage: Uniques AssetMetadataOf (r:1 w:0) + // Storage: Uniques ItemMetadataOf (r:1 w:0) // Storage: Uniques Attribute (r:1 w:1) fn clear_attribute() -> Weight { (34_432_000 as Weight) @@ -396,14 +396,14 @@ impl WeightInfo for () { .saturating_add(RocksDbWeight::get().writes(2 as Weight)) } // Storage: Uniques Collection (r:1 w:1) - // Storage: Uniques AssetMetadataOf (r:1 w:1) + // Storage: Uniques ItemMetadataOf (r:1 w:1) fn set_metadata() -> Weight { (28_575_000 as Weight) .saturating_add(RocksDbWeight::get().reads(2 as Weight)) .saturating_add(RocksDbWeight::get().writes(2 as Weight)) } // Storage: Uniques Collection (r:1 w:1) - // Storage: Uniques AssetMetadataOf (r:1 w:1) + // Storage: Uniques ItemMetadataOf (r:1 w:1) fn clear_metadata() -> Weight { (28_730_000 as Weight) .saturating_add(RocksDbWeight::get().reads(2 as Weight)) @@ -424,21 +424,21 @@ impl WeightInfo for () { .saturating_add(RocksDbWeight::get().writes(1 as Weight)) } // Storage: Uniques Collection (r:1 w:0) - // Storage: Uniques Asset (r:1 w:1) + // Storage: Uniques Item (r:1 w:1) fn approve_transfer() -> Weight { (19_587_000 as Weight) .saturating_add(RocksDbWeight::get().reads(2 as Weight)) .saturating_add(RocksDbWeight::get().writes(1 as Weight)) } // Storage: Uniques Collection (r:1 w:0) - // Storage: Uniques Asset (r:1 w:1) + // Storage: Uniques Item (r:1 w:1) fn cancel_approval() -> Weight { (19_417_000 as Weight) .saturating_add(RocksDbWeight::get().reads(2 as Weight)) .saturating_add(RocksDbWeight::get().writes(1 as Weight)) } // Storage: Uniques Collection (r:1 w:0) - // Storage: Uniques Asset (r:1 w:1) + // Storage: Uniques Item (r:1 w:1) fn set_accept_ownership() -> Weight { (19_417_000 as Weight) .saturating_add(RocksDbWeight::get().reads(1 as Weight)) From 101fc98f6c82e5e7db11b091f2697572be4617b8 Mon Sep 17 00:00:00 2001 From: Jegor Sidorenko Date: Wed, 11 May 2022 13:12:58 +0200 Subject: [PATCH 07/16] Add a storage hack --- frame/uniques/src/lib.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/frame/uniques/src/lib.rs b/frame/uniques/src/lib.rs index c5cd845229860..d864825578a53 100644 --- a/frame/uniques/src/lib.rs +++ b/frame/uniques/src/lib.rs @@ -153,6 +153,7 @@ pub mod pallet { } #[pallet::storage] + #[pallet::storage_prefix = "Class"] /// Details of an items collection. pub(super) type Collection, I: 'static = ()> = StorageMap< _, @@ -181,6 +182,7 @@ pub mod pallet { >; #[pallet::storage] + #[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< @@ -194,6 +196,7 @@ pub mod pallet { >; #[pallet::storage] + #[pallet::storage_prefix = "Instance"] /// The items in existence and their ownership details. pub(super) type Item, I: 'static = ()> = StorageDoubleMap< _, @@ -206,6 +209,7 @@ pub mod pallet { >; #[pallet::storage] + #[pallet::storage_prefix = "ClassMetadataOf"] /// Metadata of an items collection. pub(super) type CollectionMetadataOf, I: 'static = ()> = StorageMap< _, @@ -216,6 +220,7 @@ pub mod pallet { >; #[pallet::storage] + #[pallet::storage_prefix = "InstanceMetadataOf"] /// Metadata of an item. pub(super) type ItemMetadataOf, I: 'static = ()> = StorageDoubleMap< _, From 22fba9fcfc5b909ce0e241f52aa3189d9d87f3a5 Mon Sep 17 00:00:00 2001 From: Jegor Sidorenko Date: Thu, 12 May 2022 18:21:16 +0200 Subject: [PATCH 08/16] Typos --- frame/uniques/src/benchmarking.rs | 2 +- frame/uniques/src/mock.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/frame/uniques/src/benchmarking.rs b/frame/uniques/src/benchmarking.rs index 34f2f8f336d09..211ccd8a8fbf6 100644 --- a/frame/uniques/src/benchmarking.rs +++ b/frame/uniques/src/benchmarking.rs @@ -15,7 +15,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -//! Items pallet benchmarking. +//! Uniques pallet benchmarking. #![cfg(feature = "runtime-benchmarks")] diff --git a/frame/uniques/src/mock.rs b/frame/uniques/src/mock.rs index 6fb6102391fa0..ff7b791de4950 100644 --- a/frame/uniques/src/mock.rs +++ b/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 Items pallet. +//! Test environment for Uniques pallet. use super::*; use crate as pallet_uniques; From bc1faf0971bf9ea309f78454471317913b2ba441 Mon Sep 17 00:00:00 2001 From: Shawn Tabrizi Date: Thu, 12 May 2022 12:23:38 -0400 Subject: [PATCH 09/16] fix compile --- frame/uniques/src/benchmarking.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/frame/uniques/src/benchmarking.rs b/frame/uniques/src/benchmarking.rs index 34f2f8f336d09..b11f2a675e211 100644 --- a/frame/uniques/src/benchmarking.rs +++ b/frame/uniques/src/benchmarking.rs @@ -20,7 +20,7 @@ #![cfg(feature = "runtime-benchmarks")] use super::*; -use frame_benchmarking::{account, benchmarks_item_pallet, whitelist_account, whitelisted_caller}; +use frame_benchmarking::{account, benchmarks_instance_pallet, whitelist_account, whitelisted_caller}; use frame_support::{ dispatch::UnfilteredDispatchable, traits::{EnsureOrigin, Get}, @@ -133,7 +133,7 @@ fn assert_last_event, I: 'static>(generic_event: >:: assert_eq!(event, &system_event); } -benchmarks_item_pallet! { +benchmarks_instance_pallet! { create { let collection = T::Helper::collection(0); let origin = T::CreateOrigin::successful_origin(&collection); From 22f1477ce74f27258a64abb061012212ee1ef3fe Mon Sep 17 00:00:00 2001 From: Shawn Tabrizi Date: Thu, 12 May 2022 12:28:43 -0400 Subject: [PATCH 10/16] fmt --- frame/uniques/src/benchmarking.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/frame/uniques/src/benchmarking.rs b/frame/uniques/src/benchmarking.rs index a8c728e352a52..cd66d03922141 100644 --- a/frame/uniques/src/benchmarking.rs +++ b/frame/uniques/src/benchmarking.rs @@ -20,7 +20,9 @@ #![cfg(feature = "runtime-benchmarks")] use super::*; -use frame_benchmarking::{account, benchmarks_instance_pallet, whitelist_account, whitelisted_caller}; +use frame_benchmarking::{ + account, benchmarks_instance_pallet, whitelist_account, whitelisted_caller, +}; use frame_support::{ dispatch::UnfilteredDispatchable, traits::{EnsureOrigin, Get}, From 82c83ec1e69f0eeafaf3b6836a2f87b5771e290a Mon Sep 17 00:00:00 2001 From: Jegor Sidorenko Date: Thu, 12 May 2022 18:59:52 +0200 Subject: [PATCH 11/16] Fix --- bin/node/runtime/src/lib.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/bin/node/runtime/src/lib.rs b/bin/node/runtime/src/lib.rs index fee288cb2b7f8..5373aaba3ed11 100644 --- a/bin/node/runtime/src/lib.rs +++ b/bin/node/runtime/src/lib.rs @@ -1395,12 +1395,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; From 33622193079da4f80b1823d2de141bf9fe7baac0 Mon Sep 17 00:00:00 2001 From: Parity Bot Date: Thu, 12 May 2022 17:28:22 +0000 Subject: [PATCH 12/16] cargo run --quiet --profile=production --features=runtime-benchmarks --manifest-path=bin/node/cli/Cargo.toml -- benchmark pallet --chain=dev --steps=50 --repeat=20 --pallet=pallet_uniques --extrinsic=* --execution=wasm --wasm-execution=compiled --heap-pages=4096 --output=./frame/uniques/src/weights.rs --template=./.maintain/frame-weight-template.hbs --- frame/uniques/src/weights.rs | 299 +++++++++++++++++------------------ 1 file changed, 148 insertions(+), 151 deletions(-) diff --git a/frame/uniques/src/weights.rs b/frame/uniques/src/weights.rs index e418bac2bd315..4607c989fb783 100644 --- a/frame/uniques/src/weights.rs +++ b/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)] @@ -74,35 +73,35 @@ pub trait WeightInfo { /// Weights for pallet_uniques using the Substrate node and recommended hardware. pub struct SubstrateWeight(PhantomData); impl WeightInfo for SubstrateWeight { - // Storage: Uniques Collection (r:1 w:1) - // Storage: Uniques CollectionAccount (r:0 w:1) + // Storage: Uniques Class (r:1 w:1) + // Storage: Uniques ClassAccount (r:0 w:1) fn create() -> Weight { - (24_063_000 as Weight) + (23_737_000 as Weight) .saturating_add(T::DbWeight::get().reads(1 as Weight)) .saturating_add(T::DbWeight::get().writes(2 as Weight)) } - // Storage: Uniques Collection (r:1 w:1) - // Storage: Uniques CollectionAccount (r:0 w:1) + // Storage: Uniques Class (r:1 w:1) + // Storage: Uniques ClassAccount (r:0 w:1) fn force_create() -> Weight { - (13_017_000 as Weight) + (13_334_000 as Weight) .saturating_add(T::DbWeight::get().reads(1 as Weight)) .saturating_add(T::DbWeight::get().writes(2 as Weight)) } - // Storage: Uniques Collection (r:1 w:1) - // Storage: Uniques Item (r:1 w:0) - // Storage: Uniques CollectionAccount (r:0 w:1) + // Storage: Uniques Class (r:1 w:1) + // Storage: Uniques Instance (r:1 w:0) + // Storage: Uniques ClassAccount (r:0 w:1) // Storage: Uniques Attribute (r:0 w:1000) - // Storage: Uniques CollectionMetadataOf (r:0 w:1) - // Storage: Uniques ItemMetadataOf (r:0 w:1000) + // Storage: Uniques ClassMetadataOf (r:0 w:1) + // Storage: Uniques InstanceMetadataOf (r:0 w:1000) // 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)) + .saturating_add((9_463_000 as Weight).saturating_mul(n as Weight)) // Standard Error: 14_000 - .saturating_add((854_000 as Weight).saturating_mul(m as Weight)) + .saturating_add((928_000 as Weight).saturating_mul(m as Weight)) // Standard Error: 14_000 - .saturating_add((758_000 as Weight).saturating_mul(a as Weight)) + .saturating_add((835_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)) @@ -110,150 +109,149 @@ impl WeightInfo for SubstrateWeight { .saturating_add(T::DbWeight::get().writes((1 as Weight).saturating_mul(m as Weight))) .saturating_add(T::DbWeight::get().writes((1 as Weight).saturating_mul(a as Weight))) } - // Storage: Uniques Item (r:1 w:1) - // Storage: Uniques Collection (r:1 w:1) + // Storage: Uniques Instance (r:1 w:1) + // Storage: Uniques Class (r:1 w:1) // Storage: Uniques Account (r:0 w:1) fn mint() -> Weight { - (29_865_000 as Weight) + (29_845_000 as Weight) .saturating_add(T::DbWeight::get().reads(2 as Weight)) .saturating_add(T::DbWeight::get().writes(3 as Weight)) } - // Storage: Uniques Collection (r:1 w:1) - // Storage: Uniques Item (r:1 w:1) + // Storage: Uniques Class (r:1 w:1) + // Storage: Uniques Instance (r:1 w:1) // Storage: Uniques Account (r:0 w:1) fn burn() -> Weight { - (31_603_000 as Weight) + (31_662_000 as Weight) .saturating_add(T::DbWeight::get().reads(2 as Weight)) .saturating_add(T::DbWeight::get().writes(3 as Weight)) } - // Storage: Uniques Collection (r:1 w:0) - // Storage: Uniques Item (r:1 w:1) + // Storage: Uniques Class (r:1 w:0) + // Storage: Uniques Instance (r:1 w:1) // Storage: Uniques Account (r:0 w:2) fn transfer() -> Weight { - (23_331_000 as Weight) + (23_542_000 as Weight) .saturating_add(T::DbWeight::get().reads(2 as Weight)) .saturating_add(T::DbWeight::get().writes(3 as Weight)) } - // Storage: Uniques Collection (r:1 w:1) - // Storage: Uniques Item (r:100 w:100) + // Storage: Uniques Class (r:1 w:1) + // Storage: Uniques Instance (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: 11_000 + .saturating_add((11_719_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)) .saturating_add(T::DbWeight::get().writes((1 as Weight).saturating_mul(i as Weight))) } - // Storage: Uniques Item (r:1 w:1) - // Storage: Uniques Collection (r:1 w:0) + // Storage: Uniques Instance (r:1 w:1) + // Storage: Uniques Class (r:1 w:0) fn freeze() -> Weight { - (18_617_000 as Weight) + (18_276_000 as Weight) .saturating_add(T::DbWeight::get().reads(2 as Weight)) .saturating_add(T::DbWeight::get().writes(1 as Weight)) } - // Storage: Uniques Item (r:1 w:1) - // Storage: Uniques Collection (r:1 w:0) + // Storage: Uniques Instance (r:1 w:1) + // Storage: Uniques Class (r:1 w:0) fn thaw() -> Weight { - (18_618_000 as Weight) + (18_266_000 as Weight) .saturating_add(T::DbWeight::get().reads(2 as Weight)) .saturating_add(T::DbWeight::get().writes(1 as Weight)) } - // Storage: Uniques Collection (r:1 w:1) + // Storage: Uniques Class (r:1 w:1) fn freeze_collection() -> Weight { - (13_570_000 as Weight) + (13_749_000 as Weight) .saturating_add(T::DbWeight::get().reads(1 as Weight)) .saturating_add(T::DbWeight::get().writes(1 as Weight)) } - // Storage: Uniques Collection (r:1 w:1) + // Storage: Uniques Class (r:1 w:1) fn thaw_collection() -> Weight { - (13_937_000 as Weight) + (13_657_000 as Weight) .saturating_add(T::DbWeight::get().reads(1 as Weight)) .saturating_add(T::DbWeight::get().writes(1 as Weight)) } - // Storage: Uniques Collection (r:1 w:1) - // Storage: System Account (r:1 w:1) - // Storage: Uniques CollectionAccount (r:0 w:2) + // Storage: Uniques OwnershipAcceptance (r:1 w:1) + // Storage: Uniques Class (r:1 w:1) + // Storage: Uniques ClassAccount (r:0 w:2) fn transfer_ownership() -> Weight { - (31_021_000 as Weight) + (20_770_000 as Weight) .saturating_add(T::DbWeight::get().reads(2 as Weight)) .saturating_add(T::DbWeight::get().writes(4 as Weight)) } - // Storage: Uniques Collection (r:1 w:1) + // Storage: Uniques Class (r:1 w:1) fn set_team() -> Weight { - (14_739_000 as Weight) + (14_296_000 as Weight) .saturating_add(T::DbWeight::get().reads(1 as Weight)) .saturating_add(T::DbWeight::get().writes(1 as Weight)) } - // Storage: Uniques Collection (r:1 w:1) - // Storage: Uniques CollectionAccount (r:0 w:1) + // Storage: Uniques Class (r:1 w:1) + // Storage: Uniques ClassAccount (r:0 w:1) fn force_item_status() -> Weight { - (16_826_000 as Weight) + (16_398_000 as Weight) .saturating_add(T::DbWeight::get().reads(1 as Weight)) .saturating_add(T::DbWeight::get().writes(2 as Weight)) } - // Storage: Uniques Collection (r:1 w:1) - // Storage: Uniques ItemMetadataOf (r:1 w:0) + // Storage: Uniques Class (r:1 w:1) + // Storage: Uniques InstanceMetadataOf (r:1 w:0) // Storage: Uniques Attribute (r:1 w:1) fn set_attribute() -> Weight { - (37_010_000 as Weight) + (37_119_000 as Weight) .saturating_add(T::DbWeight::get().reads(3 as Weight)) .saturating_add(T::DbWeight::get().writes(2 as Weight)) } - // Storage: Uniques Collection (r:1 w:1) - // Storage: Uniques ItemMetadataOf (r:1 w:0) + // Storage: Uniques Class (r:1 w:1) + // Storage: Uniques InstanceMetadataOf (r:1 w:0) // Storage: Uniques Attribute (r:1 w:1) fn clear_attribute() -> Weight { - (34_432_000 as Weight) + (35_518_000 as Weight) .saturating_add(T::DbWeight::get().reads(3 as Weight)) .saturating_add(T::DbWeight::get().writes(2 as Weight)) } - // Storage: Uniques Collection (r:1 w:1) - // Storage: Uniques ItemMetadataOf (r:1 w:1) + // Storage: Uniques Class (r:1 w:1) + // Storage: Uniques InstanceMetadataOf (r:1 w:1) fn set_metadata() -> Weight { - (28_575_000 as Weight) + (29_044_000 as Weight) .saturating_add(T::DbWeight::get().reads(2 as Weight)) .saturating_add(T::DbWeight::get().writes(2 as Weight)) } - // Storage: Uniques Collection (r:1 w:1) - // Storage: Uniques ItemMetadataOf (r:1 w:1) + // Storage: Uniques Class (r:1 w:1) + // Storage: Uniques InstanceMetadataOf (r:1 w:1) fn clear_metadata() -> Weight { - (28_730_000 as Weight) + (29_257_000 as Weight) .saturating_add(T::DbWeight::get().reads(2 as Weight)) .saturating_add(T::DbWeight::get().writes(2 as Weight)) } - // Storage: Uniques Collection (r:1 w:1) - // Storage: Uniques CollectionMetadataOf (r:1 w:1) + // Storage: Uniques Class (r:1 w:1) + // Storage: Uniques ClassMetadataOf (r:1 w:1) fn set_collection_metadata() -> Weight { - (28_225_000 as Weight) + (27_864_000 as Weight) .saturating_add(T::DbWeight::get().reads(2 as Weight)) .saturating_add(T::DbWeight::get().writes(2 as Weight)) } - // Storage: Uniques Collection (r:1 w:0) - // Storage: Uniques CollectionMetadataOf (r:1 w:1) + // Storage: Uniques Class (r:1 w:0) + // Storage: Uniques ClassMetadataOf (r:1 w:1) fn clear_collection_metadata() -> Weight { - (26_455_000 as Weight) + (26_678_000 as Weight) .saturating_add(T::DbWeight::get().reads(2 as Weight)) .saturating_add(T::DbWeight::get().writes(1 as Weight)) } - // Storage: Uniques Collection (r:1 w:0) - // Storage: Uniques Item (r:1 w:1) + // Storage: Uniques Class (r:1 w:0) + // Storage: Uniques Instance (r:1 w:1) fn approve_transfer() -> Weight { - (19_587_000 as Weight) + (19_240_000 as Weight) .saturating_add(T::DbWeight::get().reads(2 as Weight)) .saturating_add(T::DbWeight::get().writes(1 as Weight)) } - // Storage: Uniques Collection (r:1 w:0) - // Storage: Uniques Item (r:1 w:1) + // Storage: Uniques Class (r:1 w:0) + // Storage: Uniques Instance (r:1 w:1) fn cancel_approval() -> Weight { - (19_417_000 as Weight) + (19_080_000 as Weight) .saturating_add(T::DbWeight::get().reads(2 as Weight)) .saturating_add(T::DbWeight::get().writes(1 as Weight)) } - // Storage: Uniques Collection (r:1 w:0) - // Storage: Uniques Item (r:1 w:1) + // Storage: Uniques OwnershipAcceptance (r:1 w:1) fn set_accept_ownership() -> Weight { - (19_417_000 as Weight) + (16_588_000 as Weight) .saturating_add(T::DbWeight::get().reads(1 as Weight)) .saturating_add(T::DbWeight::get().writes(1 as Weight)) } @@ -261,35 +259,35 @@ impl WeightInfo for SubstrateWeight { // For backwards compatibility and tests impl WeightInfo for () { - // Storage: Uniques Collection (r:1 w:1) - // Storage: Uniques CollectionAccount (r:0 w:1) + // Storage: Uniques Class (r:1 w:1) + // Storage: Uniques ClassAccount (r:0 w:1) fn create() -> Weight { - (24_063_000 as Weight) + (23_737_000 as Weight) .saturating_add(RocksDbWeight::get().reads(1 as Weight)) .saturating_add(RocksDbWeight::get().writes(2 as Weight)) } - // Storage: Uniques Collection (r:1 w:1) - // Storage: Uniques CollectionAccount (r:0 w:1) + // Storage: Uniques Class (r:1 w:1) + // Storage: Uniques ClassAccount (r:0 w:1) fn force_create() -> Weight { - (13_017_000 as Weight) + (13_334_000 as Weight) .saturating_add(RocksDbWeight::get().reads(1 as Weight)) .saturating_add(RocksDbWeight::get().writes(2 as Weight)) } - // Storage: Uniques Collection (r:1 w:1) - // Storage: Uniques Item (r:1 w:0) - // Storage: Uniques CollectionAccount (r:0 w:1) + // Storage: Uniques Class (r:1 w:1) + // Storage: Uniques Instance (r:1 w:0) + // Storage: Uniques ClassAccount (r:0 w:1) // Storage: Uniques Attribute (r:0 w:1000) - // Storage: Uniques CollectionMetadataOf (r:0 w:1) - // Storage: Uniques ItemMetadataOf (r:0 w:1000) + // Storage: Uniques ClassMetadataOf (r:0 w:1) + // Storage: Uniques InstanceMetadataOf (r:0 w:1000) // 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)) + .saturating_add((9_463_000 as Weight).saturating_mul(n as Weight)) // Standard Error: 14_000 - .saturating_add((854_000 as Weight).saturating_mul(m as Weight)) + .saturating_add((928_000 as Weight).saturating_mul(m as Weight)) // Standard Error: 14_000 - .saturating_add((758_000 as Weight).saturating_mul(a as Weight)) + .saturating_add((835_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)) @@ -297,150 +295,149 @@ impl WeightInfo for () { .saturating_add(RocksDbWeight::get().writes((1 as Weight).saturating_mul(m as Weight))) .saturating_add(RocksDbWeight::get().writes((1 as Weight).saturating_mul(a as Weight))) } - // Storage: Uniques Item (r:1 w:1) - // Storage: Uniques Collection (r:1 w:1) + // Storage: Uniques Instance (r:1 w:1) + // Storage: Uniques Class (r:1 w:1) // Storage: Uniques Account (r:0 w:1) fn mint() -> Weight { - (29_865_000 as Weight) + (29_845_000 as Weight) .saturating_add(RocksDbWeight::get().reads(2 as Weight)) .saturating_add(RocksDbWeight::get().writes(3 as Weight)) } - // Storage: Uniques Collection (r:1 w:1) - // Storage: Uniques Item (r:1 w:1) + // Storage: Uniques Class (r:1 w:1) + // Storage: Uniques Instance (r:1 w:1) // Storage: Uniques Account (r:0 w:1) fn burn() -> Weight { - (31_603_000 as Weight) + (31_662_000 as Weight) .saturating_add(RocksDbWeight::get().reads(2 as Weight)) .saturating_add(RocksDbWeight::get().writes(3 as Weight)) } - // Storage: Uniques Collection (r:1 w:0) - // Storage: Uniques Item (r:1 w:1) + // Storage: Uniques Class (r:1 w:0) + // Storage: Uniques Instance (r:1 w:1) // Storage: Uniques Account (r:0 w:2) fn transfer() -> Weight { - (23_331_000 as Weight) + (23_542_000 as Weight) .saturating_add(RocksDbWeight::get().reads(2 as Weight)) .saturating_add(RocksDbWeight::get().writes(3 as Weight)) } - // Storage: Uniques Collection (r:1 w:1) - // Storage: Uniques Item (r:100 w:100) + // Storage: Uniques Class (r:1 w:1) + // Storage: Uniques Instance (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: 11_000 + .saturating_add((11_719_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)) .saturating_add(RocksDbWeight::get().writes((1 as Weight).saturating_mul(i as Weight))) } - // Storage: Uniques Item (r:1 w:1) - // Storage: Uniques Collection (r:1 w:0) + // Storage: Uniques Instance (r:1 w:1) + // Storage: Uniques Class (r:1 w:0) fn freeze() -> Weight { - (18_617_000 as Weight) + (18_276_000 as Weight) .saturating_add(RocksDbWeight::get().reads(2 as Weight)) .saturating_add(RocksDbWeight::get().writes(1 as Weight)) } - // Storage: Uniques Item (r:1 w:1) - // Storage: Uniques Collection (r:1 w:0) + // Storage: Uniques Instance (r:1 w:1) + // Storage: Uniques Class (r:1 w:0) fn thaw() -> Weight { - (18_618_000 as Weight) + (18_266_000 as Weight) .saturating_add(RocksDbWeight::get().reads(2 as Weight)) .saturating_add(RocksDbWeight::get().writes(1 as Weight)) } - // Storage: Uniques Collection (r:1 w:1) + // Storage: Uniques Class (r:1 w:1) fn freeze_collection() -> Weight { - (13_570_000 as Weight) + (13_749_000 as Weight) .saturating_add(RocksDbWeight::get().reads(1 as Weight)) .saturating_add(RocksDbWeight::get().writes(1 as Weight)) } - // Storage: Uniques Collection (r:1 w:1) + // Storage: Uniques Class (r:1 w:1) fn thaw_collection() -> Weight { - (13_937_000 as Weight) + (13_657_000 as Weight) .saturating_add(RocksDbWeight::get().reads(1 as Weight)) .saturating_add(RocksDbWeight::get().writes(1 as Weight)) } - // Storage: Uniques Collection (r:1 w:1) - // Storage: System Account (r:1 w:1) - // Storage: Uniques CollectionAccount (r:0 w:2) + // Storage: Uniques OwnershipAcceptance (r:1 w:1) + // Storage: Uniques Class (r:1 w:1) + // Storage: Uniques ClassAccount (r:0 w:2) fn transfer_ownership() -> Weight { - (31_021_000 as Weight) + (20_770_000 as Weight) .saturating_add(RocksDbWeight::get().reads(2 as Weight)) .saturating_add(RocksDbWeight::get().writes(4 as Weight)) } - // Storage: Uniques Collection (r:1 w:1) + // Storage: Uniques Class (r:1 w:1) fn set_team() -> Weight { - (14_739_000 as Weight) + (14_296_000 as Weight) .saturating_add(RocksDbWeight::get().reads(1 as Weight)) .saturating_add(RocksDbWeight::get().writes(1 as Weight)) } - // Storage: Uniques Collection (r:1 w:1) - // Storage: Uniques CollectionAccount (r:0 w:1) + // Storage: Uniques Class (r:1 w:1) + // Storage: Uniques ClassAccount (r:0 w:1) fn force_item_status() -> Weight { - (16_826_000 as Weight) + (16_398_000 as Weight) .saturating_add(RocksDbWeight::get().reads(1 as Weight)) .saturating_add(RocksDbWeight::get().writes(2 as Weight)) } - // Storage: Uniques Collection (r:1 w:1) - // Storage: Uniques ItemMetadataOf (r:1 w:0) + // Storage: Uniques Class (r:1 w:1) + // Storage: Uniques InstanceMetadataOf (r:1 w:0) // Storage: Uniques Attribute (r:1 w:1) fn set_attribute() -> Weight { - (37_010_000 as Weight) + (37_119_000 as Weight) .saturating_add(RocksDbWeight::get().reads(3 as Weight)) .saturating_add(RocksDbWeight::get().writes(2 as Weight)) } - // Storage: Uniques Collection (r:1 w:1) - // Storage: Uniques ItemMetadataOf (r:1 w:0) + // Storage: Uniques Class (r:1 w:1) + // Storage: Uniques InstanceMetadataOf (r:1 w:0) // Storage: Uniques Attribute (r:1 w:1) fn clear_attribute() -> Weight { - (34_432_000 as Weight) + (35_518_000 as Weight) .saturating_add(RocksDbWeight::get().reads(3 as Weight)) .saturating_add(RocksDbWeight::get().writes(2 as Weight)) } - // Storage: Uniques Collection (r:1 w:1) - // Storage: Uniques ItemMetadataOf (r:1 w:1) + // Storage: Uniques Class (r:1 w:1) + // Storage: Uniques InstanceMetadataOf (r:1 w:1) fn set_metadata() -> Weight { - (28_575_000 as Weight) + (29_044_000 as Weight) .saturating_add(RocksDbWeight::get().reads(2 as Weight)) .saturating_add(RocksDbWeight::get().writes(2 as Weight)) } - // Storage: Uniques Collection (r:1 w:1) - // Storage: Uniques ItemMetadataOf (r:1 w:1) + // Storage: Uniques Class (r:1 w:1) + // Storage: Uniques InstanceMetadataOf (r:1 w:1) fn clear_metadata() -> Weight { - (28_730_000 as Weight) + (29_257_000 as Weight) .saturating_add(RocksDbWeight::get().reads(2 as Weight)) .saturating_add(RocksDbWeight::get().writes(2 as Weight)) } - // Storage: Uniques Collection (r:1 w:1) - // Storage: Uniques CollectionMetadataOf (r:1 w:1) + // Storage: Uniques Class (r:1 w:1) + // Storage: Uniques ClassMetadataOf (r:1 w:1) fn set_collection_metadata() -> Weight { - (28_225_000 as Weight) + (27_864_000 as Weight) .saturating_add(RocksDbWeight::get().reads(2 as Weight)) .saturating_add(RocksDbWeight::get().writes(2 as Weight)) } - // Storage: Uniques Collection (r:1 w:0) - // Storage: Uniques CollectionMetadataOf (r:1 w:1) + // Storage: Uniques Class (r:1 w:0) + // Storage: Uniques ClassMetadataOf (r:1 w:1) fn clear_collection_metadata() -> Weight { - (26_455_000 as Weight) + (26_678_000 as Weight) .saturating_add(RocksDbWeight::get().reads(2 as Weight)) .saturating_add(RocksDbWeight::get().writes(1 as Weight)) } - // Storage: Uniques Collection (r:1 w:0) - // Storage: Uniques Item (r:1 w:1) + // Storage: Uniques Class (r:1 w:0) + // Storage: Uniques Instance (r:1 w:1) fn approve_transfer() -> Weight { - (19_587_000 as Weight) + (19_240_000 as Weight) .saturating_add(RocksDbWeight::get().reads(2 as Weight)) .saturating_add(RocksDbWeight::get().writes(1 as Weight)) } - // Storage: Uniques Collection (r:1 w:0) - // Storage: Uniques Item (r:1 w:1) + // Storage: Uniques Class (r:1 w:0) + // Storage: Uniques Instance (r:1 w:1) fn cancel_approval() -> Weight { - (19_417_000 as Weight) + (19_080_000 as Weight) .saturating_add(RocksDbWeight::get().reads(2 as Weight)) .saturating_add(RocksDbWeight::get().writes(1 as Weight)) } - // Storage: Uniques Collection (r:1 w:0) - // Storage: Uniques Item (r:1 w:1) + // Storage: Uniques OwnershipAcceptance (r:1 w:1) fn set_accept_ownership() -> Weight { - (19_417_000 as Weight) + (16_588_000 as Weight) .saturating_add(RocksDbWeight::get().reads(1 as Weight)) .saturating_add(RocksDbWeight::get().writes(1 as Weight)) } From ac2ecc8e2c18ea70ca8f57e69d98953ad8df18f2 Mon Sep 17 00:00:00 2001 From: Shawn Tabrizi Date: Thu, 12 May 2022 15:48:14 -0400 Subject: [PATCH 13/16] Update frame/uniques/src/lib.rs --- frame/uniques/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frame/uniques/src/lib.rs b/frame/uniques/src/lib.rs index d864825578a53..4ff0e548c78f2 100644 --- a/frame/uniques/src/lib.rs +++ b/frame/uniques/src/lib.rs @@ -196,7 +196,7 @@ pub mod pallet { >; #[pallet::storage] - #[pallet::storage_prefix = "Instance"] + #[pallet::storage_prefix = "Asset"] /// The items in existence and their ownership details. pub(super) type Item, I: 'static = ()> = StorageDoubleMap< _, From fd801a7ef89cc90a1cff6f6adc16bee792239ef1 Mon Sep 17 00:00:00 2001 From: Parity Bot Date: Thu, 12 May 2022 20:14:41 +0000 Subject: [PATCH 14/16] cargo run --quiet --profile=production --features=runtime-benchmarks --manifest-path=bin/node/cli/Cargo.toml -- benchmark pallet --chain=dev --steps=50 --repeat=20 --pallet=pallet_uniques --extrinsic=* --execution=wasm --wasm-execution=compiled --heap-pages=4096 --output=./frame/uniques/src/weights.rs --template=./.maintain/frame-weight-template.hbs --- frame/uniques/src/weights.rs | 152 +++++++++++++++++------------------ 1 file changed, 76 insertions(+), 76 deletions(-) diff --git a/frame/uniques/src/weights.rs b/frame/uniques/src/weights.rs index 4607c989fb783..9b0cbda423ace 100644 --- a/frame/uniques/src/weights.rs +++ b/frame/uniques/src/weights.rs @@ -76,19 +76,19 @@ impl WeightInfo for SubstrateWeight { // Storage: Uniques Class (r:1 w:1) // Storage: Uniques ClassAccount (r:0 w:1) fn create() -> Weight { - (23_737_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_334_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)) } // Storage: Uniques Class (r:1 w:1) - // Storage: Uniques Instance (r:1 w:0) + // Storage: Uniques Asset (r:1 w:0) // Storage: Uniques ClassAccount (r:0 w:1) // Storage: Uniques Attribute (r:0 w:1000) // Storage: Uniques ClassMetadataOf (r:0 w:1) @@ -96,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_463_000 as Weight).saturating_mul(n as Weight)) - // Standard Error: 14_000 - .saturating_add((928_000 as Weight).saturating_mul(m as Weight)) - // Standard Error: 14_000 - .saturating_add((835_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)) @@ -109,64 +109,64 @@ impl WeightInfo for SubstrateWeight { .saturating_add(T::DbWeight::get().writes((1 as Weight).saturating_mul(m as Weight))) .saturating_add(T::DbWeight::get().writes((1 as Weight).saturating_mul(a as Weight))) } - // Storage: Uniques Instance (r:1 w:1) + // Storage: Uniques Asset (r:1 w:1) // Storage: Uniques Class (r:1 w:1) // Storage: Uniques Account (r:0 w:1) fn mint() -> Weight { - (29_845_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)) } // Storage: Uniques Class (r:1 w:1) - // Storage: Uniques Instance (r:1 w:1) + // Storage: Uniques Asset (r:1 w:1) // Storage: Uniques Account (r:0 w:1) fn burn() -> Weight { - (31_662_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)) } // Storage: Uniques Class (r:1 w:0) - // Storage: Uniques Instance (r:1 w:1) + // Storage: Uniques Asset (r:1 w:1) // Storage: Uniques Account (r:0 w:2) fn transfer() -> Weight { - (23_542_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)) } // Storage: Uniques Class (r:1 w:1) - // Storage: Uniques Instance (r:100 w:100) + // Storage: Uniques Asset (r:100 w:100) fn redeposit(i: u32, ) -> Weight { (0 as Weight) - // Standard Error: 11_000 - .saturating_add((11_719_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)) .saturating_add(T::DbWeight::get().writes((1 as Weight).saturating_mul(i as Weight))) } - // Storage: Uniques Instance (r:1 w:1) + // Storage: Uniques Asset (r:1 w:1) // Storage: Uniques Class (r:1 w:0) fn freeze() -> Weight { - (18_276_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 Instance (r:1 w:1) + // Storage: Uniques Asset (r:1 w:1) // Storage: Uniques Class (r:1 w:0) fn thaw() -> Weight { - (18_266_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_collection() -> Weight { - (13_749_000 as 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_collection() -> Weight { - (13_657_000 as Weight) + (13_636_000 as Weight) .saturating_add(T::DbWeight::get().reads(1 as Weight)) .saturating_add(T::DbWeight::get().writes(1 as Weight)) } @@ -174,20 +174,20 @@ impl WeightInfo for SubstrateWeight { // Storage: Uniques Class (r:1 w:1) // Storage: Uniques ClassAccount (r:0 w:2) fn transfer_ownership() -> Weight { - (20_770_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_296_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_item_status() -> Weight { - (16_398_000 as Weight) + (16_355_000 as Weight) .saturating_add(T::DbWeight::get().reads(1 as Weight)) .saturating_add(T::DbWeight::get().writes(2 as Weight)) } @@ -195,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_119_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)) } @@ -203,55 +203,55 @@ impl WeightInfo for SubstrateWeight { // Storage: Uniques InstanceMetadataOf (r:1 w:0) // Storage: Uniques Attribute (r:1 w:1) fn clear_attribute() -> Weight { - (35_518_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 { - (29_044_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 { - (29_257_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_collection_metadata() -> Weight { - (27_864_000 as 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_collection_metadata() -> Weight { - (26_678_000 as 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 Instance (r:1 w:1) + // Storage: Uniques Asset (r:1 w:1) fn approve_transfer() -> Weight { - (19_240_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 Instance (r:1 w:1) + // Storage: Uniques Asset (r:1 w:1) fn cancel_approval() -> Weight { - (19_080_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 OwnershipAcceptance (r:1 w:1) fn set_accept_ownership() -> Weight { - (16_588_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)) } @@ -262,19 +262,19 @@ impl WeightInfo for () { // Storage: Uniques Class (r:1 w:1) // Storage: Uniques ClassAccount (r:0 w:1) fn create() -> Weight { - (23_737_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_334_000 as Weight) + (13_572_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 Instance (r:1 w:0) + // Storage: Uniques Asset (r:1 w:0) // Storage: Uniques ClassAccount (r:0 w:1) // Storage: Uniques Attribute (r:0 w:1000) // Storage: Uniques ClassMetadataOf (r:0 w:1) @@ -282,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_463_000 as Weight).saturating_mul(n as Weight)) - // Standard Error: 14_000 - .saturating_add((928_000 as Weight).saturating_mul(m as Weight)) - // Standard Error: 14_000 - .saturating_add((835_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)) @@ -295,64 +295,64 @@ impl WeightInfo for () { .saturating_add(RocksDbWeight::get().writes((1 as Weight).saturating_mul(m as Weight))) .saturating_add(RocksDbWeight::get().writes((1 as Weight).saturating_mul(a as Weight))) } - // Storage: Uniques Instance (r:1 w:1) + // Storage: Uniques Asset (r:1 w:1) // Storage: Uniques Class (r:1 w:1) // Storage: Uniques Account (r:0 w:1) fn mint() -> Weight { - (29_845_000 as Weight) + (29_884_000 as Weight) .saturating_add(RocksDbWeight::get().reads(2 as Weight)) .saturating_add(RocksDbWeight::get().writes(3 as Weight)) } // Storage: Uniques Class (r:1 w:1) - // Storage: Uniques Instance (r:1 w:1) + // Storage: Uniques Asset (r:1 w:1) // Storage: Uniques Account (r:0 w:1) fn burn() -> Weight { - (31_662_000 as Weight) + (31_384_000 as Weight) .saturating_add(RocksDbWeight::get().reads(2 as Weight)) .saturating_add(RocksDbWeight::get().writes(3 as Weight)) } // Storage: Uniques Class (r:1 w:0) - // Storage: Uniques Instance (r:1 w:1) + // Storage: Uniques Asset (r:1 w:1) // Storage: Uniques Account (r:0 w:2) fn transfer() -> Weight { - (23_542_000 as Weight) + (23_254_000 as Weight) .saturating_add(RocksDbWeight::get().reads(2 as Weight)) .saturating_add(RocksDbWeight::get().writes(3 as Weight)) } // Storage: Uniques Class (r:1 w:1) - // Storage: Uniques Instance (r:100 w:100) + // Storage: Uniques Asset (r:100 w:100) fn redeposit(i: u32, ) -> Weight { (0 as Weight) - // Standard Error: 11_000 - .saturating_add((11_719_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)) .saturating_add(RocksDbWeight::get().writes((1 as Weight).saturating_mul(i as Weight))) } - // Storage: Uniques Instance (r:1 w:1) + // Storage: Uniques Asset (r:1 w:1) // Storage: Uniques Class (r:1 w:0) fn freeze() -> Weight { - (18_276_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 Instance (r:1 w:1) + // Storage: Uniques Asset (r:1 w:1) // Storage: Uniques Class (r:1 w:0) fn thaw() -> Weight { - (18_266_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_collection() -> Weight { - (13_749_000 as 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_collection() -> Weight { - (13_657_000 as Weight) + (13_636_000 as Weight) .saturating_add(RocksDbWeight::get().reads(1 as Weight)) .saturating_add(RocksDbWeight::get().writes(1 as Weight)) } @@ -360,20 +360,20 @@ impl WeightInfo for () { // Storage: Uniques Class (r:1 w:1) // Storage: Uniques ClassAccount (r:0 w:2) fn transfer_ownership() -> Weight { - (20_770_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_296_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_item_status() -> Weight { - (16_398_000 as Weight) + (16_355_000 as Weight) .saturating_add(RocksDbWeight::get().reads(1 as Weight)) .saturating_add(RocksDbWeight::get().writes(2 as Weight)) } @@ -381,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_119_000 as Weight) + (37_035_000 as Weight) .saturating_add(RocksDbWeight::get().reads(3 as Weight)) .saturating_add(RocksDbWeight::get().writes(2 as Weight)) } @@ -389,55 +389,55 @@ impl WeightInfo for () { // Storage: Uniques InstanceMetadataOf (r:1 w:0) // Storage: Uniques Attribute (r:1 w:1) fn clear_attribute() -> Weight { - (35_518_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 { - (29_044_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 { - (29_257_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_collection_metadata() -> Weight { - (27_864_000 as 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_collection_metadata() -> Weight { - (26_678_000 as 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 Instance (r:1 w:1) + // Storage: Uniques Asset (r:1 w:1) fn approve_transfer() -> Weight { - (19_240_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 Instance (r:1 w:1) + // Storage: Uniques Asset (r:1 w:1) fn cancel_approval() -> Weight { - (19_080_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 OwnershipAcceptance (r:1 w:1) fn set_accept_ownership() -> Weight { - (16_588_000 as Weight) + (16_675_000 as Weight) .saturating_add(RocksDbWeight::get().reads(1 as Weight)) .saturating_add(RocksDbWeight::get().writes(1 as Weight)) } From afaac18f5c84f7fa460619c8b0512d0b5490d627 Mon Sep 17 00:00:00 2001 From: Jegor Sidorenko Date: Fri, 13 May 2022 14:48:07 +0200 Subject: [PATCH 15/16] Change 'items collection' to 'collection' --- .../support/src/traits/tokens/nonfungible.rs | 2 +- .../support/src/traits/tokens/nonfungibles.rs | 6 +- frame/uniques/src/lib.rs | 79 +++++++++---------- frame/uniques/src/types.rs | 6 +- 4 files changed, 45 insertions(+), 48 deletions(-) diff --git a/frame/support/src/traits/tokens/nonfungible.rs b/frame/support/src/traits/tokens/nonfungible.rs index c23fabe5b54ff..fe0d2e729930e 100644 --- a/frame/support/src/traits/tokens/nonfungible.rs +++ b/frame/support/src/traits/tokens/nonfungible.rs @@ -15,7 +15,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -//! Traits for dealing with a single non-fungible items collection. +//! Traits for dealing with a single non-fungible collection of items. //! //! 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 diff --git a/frame/support/src/traits/tokens/nonfungibles.rs b/frame/support/src/traits/tokens/nonfungibles.rs index 5e9461469f851..d043a87ce7c10 100644 --- a/frame/support/src/traits/tokens/nonfungibles.rs +++ b/frame/support/src/traits/tokens/nonfungibles.rs @@ -37,7 +37,7 @@ pub trait Inspect { /// Type for identifying an item. type ItemId; - /// Type for identifying an items collection (an identifier for an independent collection of + /// Type for identifying a collection (an identifier for an independent collection of /// items). type CollectionId; @@ -46,7 +46,7 @@ pub trait Inspect { fn owner(collection: &Self::CollectionId, item: &Self::ItemId) -> 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 an items collection + /// 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 @@ -105,7 +105,7 @@ pub trait Inspect { /// 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 items collections in existence. + /// Returns an iterator of the collections in existence. fn collections() -> Box>; /// Returns an iterator of the items of a `collection` in existence. diff --git a/frame/uniques/src/lib.rs b/frame/uniques/src/lib.rs index 4ff0e548c78f2..0a8cf201415a1 100644 --- a/frame/uniques/src/lib.rs +++ b/frame/uniques/src/lib.rs @@ -154,7 +154,7 @@ pub mod pallet { #[pallet::storage] #[pallet::storage_prefix = "Class"] - /// Details of an items collection. + /// Details of a collection. pub(super) type Collection, I: 'static = ()> = StorageMap< _, Blake2_128Concat, @@ -210,7 +210,7 @@ pub mod pallet { #[pallet::storage] #[pallet::storage_prefix = "ClassMetadataOf"] - /// Metadata of an items collection. + /// Metadata of a collection. pub(super) type CollectionMetadataOf, I: 'static = ()> = StorageMap< _, Blake2_128Concat, @@ -233,7 +233,7 @@ pub mod pallet { >; #[pallet::storage] - /// Metadata of an items collection. + /// Attributes of a collection. pub(super) type Attribute, I: 'static = ()> = StorageNMap< _, ( @@ -387,11 +387,9 @@ pub mod pallet { /// `ItemDeposit` funds of sender are reserved. /// /// Parameters: - /// - `collection`: The identifier of the new items collection. This must not be currently - /// in use. - /// - `admin`: The admin of this collection of items. The admin is the initial address of - /// each - /// member of the items collection'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. /// @@ -457,8 +455,8 @@ pub mod pallet { /// The origin must conform to `ForceOrigin` or must be `Signed` and the sender must be the /// owner of the `collection`. /// - /// - `collection`: The identifier of the items collection to be destroyed. - /// - `witness`: Information on the items minted in the items collection. 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. @@ -590,8 +588,8 @@ pub mod pallet { /// /// Origin must be Signed and the sender should be the Owner of the `collection`. /// - /// - `collection`: The collection of the item to be frozen. - /// - `items`: The items of the items collection 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 items which are unknown or /// in the case that the owner account does not have reservable funds to pay for a @@ -715,11 +713,11 @@ pub mod pallet { Ok(()) } - /// Disallow further unprivileged transfers for a whole items collection. + /// Disallow further unprivileged transfers for a whole collection. /// /// Origin must be Signed and the sender should be the Freezer of the `collection`. /// - /// - `collection`: The items collection to be frozen. + /// - `collection`: The collection to be frozen. /// /// Emits `CollectionFrozen`. /// @@ -742,7 +740,7 @@ pub mod pallet { }) } - /// Re-allow unprivileged transfers for a whole items collection. + /// Re-allow unprivileged transfers for a whole collection. /// /// Origin must be Signed and the sender should be the Admin of the `collection`. /// @@ -769,12 +767,12 @@ pub mod pallet { }) } - /// Change the Owner of an items collection. + /// Change the Owner of a collection. /// /// Origin must be Signed and the sender should be the Owner of the `collection`. /// - /// - `collection`: The items collection whose owner should be changed. - /// - `owner`: The new Owner of this items collection. They must have called + /// - `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`. @@ -816,14 +814,14 @@ pub mod pallet { }) } - /// Change the Issuer, Admin and Freezer of an items collection. + /// Change the Issuer, Admin and Freezer of a collection. /// /// Origin must be Signed and the sender should be the Owner of the `collection`. /// - /// - `collection`: The items collection whose team should be changed. - /// - `issuer`: The new Issuer of this items collection. - /// - `admin`: The new Admin of this items collection. - /// - `freezer`: The new Freezer of this items collection. + /// - `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`. /// @@ -963,9 +961,8 @@ pub mod pallet { /// - `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 item - /// collection. - /// - `is_frozen`: Whether this items collection is frozen except for permissioned/admin + /// - `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 `ItemStatusChanged` with the identity of the item. @@ -1003,7 +1000,7 @@ pub mod pallet { }) } - /// Set an attribute for an items collection or item. + /// Set an attribute for a collection or item. /// /// Origin must be either `ForceOrigin` or Signed and the sender should be the Owner of the /// `collection`. @@ -1012,7 +1009,7 @@ pub mod pallet { /// `MetadataDepositBase + DepositPerByte * (key.len + value.len)` taking into /// account any already reserved funds. /// - /// - `collection`: The identifier of the items collection whose item's 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. @@ -1068,14 +1065,14 @@ pub mod pallet { Ok(()) } - /// Clear an attribute for an items collection or item. + /// Clear an attribute for a collection or item. /// /// Origin must be either `ForceOrigin` or Signed and the sender should be the Owner of the /// `collection`. /// - /// Any deposit is freed for the items collection owner. + /// Any deposit is freed for the collection's owner. /// - /// - `collection`: The identifier of the items collection whose item's 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. /// @@ -1123,7 +1120,7 @@ pub mod pallet { /// `MetadataDepositBase + DepositPerByte * data.len` taking into /// account any already reserved funds. /// - /// - `collection`: The identifier of the items collection whose item's metadata to set. + /// - `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. @@ -1185,9 +1182,9 @@ pub mod pallet { /// Origin must be either `ForceOrigin` or Signed and the sender should be the Owner of the /// `item`. /// - /// Any deposit is freed for the items collection owner. + /// Any deposit is freed for the collection's owner. /// - /// - `collection`: The identifier of the items collection whose item's 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`. @@ -1226,7 +1223,7 @@ pub mod pallet { }) } - /// Set the metadata for an items collection. + /// Set the metadata for a collection. /// /// Origin must be either `ForceOrigin` or `Signed` and the sender should be the Owner of /// the `collection`. @@ -1287,14 +1284,14 @@ pub mod pallet { }) } - /// Clear the metadata for an items collection. + /// Clear the metadata for a collection. /// /// Origin must be either `ForceOrigin` or `Signed` and the sender should be the Owner of /// the `collection`. /// - /// Any deposit is freed for the items collection owner. + /// Any deposit is freed for the collection's owner. /// - /// - `collection`: The identifier of the items collection whose metadata to clear. + /// - `collection`: The identifier of the collection whose metadata to clear. /// /// Emits `CollectionMetadataCleared`. /// @@ -1330,9 +1327,9 @@ pub mod pallet { /// Origin must be `Signed` and if `maybe_collection` is `Some`, then the signer must have a /// provider reference. /// - /// - `maybe_collection`: The identifier of the items collection whose ownership the signer - /// is willing to accept, or if `None`, an indication that the signer is willing to accept - /// no ownership transferal. + /// - `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())] diff --git a/frame/uniques/src/types.rs b/frame/uniques/src/types.rs index 76817df2c39c6..ec87fd04b07df 100644 --- a/frame/uniques/src/types.rs +++ b/frame/uniques/src/types.rs @@ -102,11 +102,11 @@ pub struct CollectionMetadata> { /// /// This pays for the data stored in this struct. pub(super) deposit: DepositBalance, - /// 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 + /// 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 item 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, } From 4f544a16525c7cc166768191a0b17ded08fcf726 Mon Sep 17 00:00:00 2001 From: Jegor Sidorenko Date: Mon, 16 May 2022 11:56:20 +0200 Subject: [PATCH 16/16] Apply suggestions --- frame/uniques/src/types.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/frame/uniques/src/types.rs b/frame/uniques/src/types.rs index ec87fd04b07df..d7706fd7e3a58 100644 --- a/frame/uniques/src/types.rs +++ b/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 items pallet. +//! Various basic types for use in the Uniques pallet. use super::*; use frame_support::{ @@ -52,7 +52,7 @@ pub struct CollectionDetails { pub(super) item_metadatas: u32, /// The total number of attributes for this collection. pub(super) attributes: u32, - /// Whether the item is frozen for non-admin transfers. + /// Whether the collection is frozen for non-admin transfers. pub(super) is_frozen: bool, } @@ -62,7 +62,7 @@ pub struct DestroyWitness { /// The total number of outstanding items of this collection. #[codec(compact)] pub items: u32, - /// The total number of outstanding item metadata of this collection. + /// The total number of items in this collection that have outstanding item metadata. #[codec(compact)] pub item_metadatas: u32, #[codec(compact)]