Use 'Items' and 'Collections' in uniques pallet (#11389)

* Rename class to collection

* Use "assets collection" instead of "asset collection"

* Rename 'instance' to 'asset'

* Change "asset `collection`" to "`collection`"

* A bit more clean up

* Rename Asset to Item

* Add a storage hack

* Typos

* fix compile

* fmt

* Fix

* 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

* Update frame/uniques/src/lib.rs

* 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

* Change 'items collection' to 'collection'

* Apply suggestions

Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com>
Co-authored-by: Parity Bot <admin@parity.io>
This commit is contained in:
Jegor Sidorenko
2022-05-16 15:38:12 +02:00
committed by GitHub
parent 359849b169
commit ed7d1e7ac0
13 changed files with 1114 additions and 1076 deletions
+4 -4
View File
@@ -1414,12 +1414,12 @@ parameter_types! {
impl pallet_uniques::Config for Runtime { impl pallet_uniques::Config for Runtime {
type Event = Event; type Event = Event;
type ClassId = u32; type CollectionId = u32;
type InstanceId = u32; type ItemId = u32;
type Currency = Balances; type Currency = Balances;
type ForceOrigin = frame_system::EnsureRoot<AccountId>; type ForceOrigin = frame_system::EnsureRoot<AccountId>;
type ClassDeposit = ClassDeposit; type CollectionDeposit = ClassDeposit;
type InstanceDeposit = InstanceDeposit; type ItemDeposit = InstanceDeposit;
type MetadataDepositBase = MetadataDepositBase; type MetadataDepositBase = MetadataDepositBase;
type AttributeDepositBase = MetadataDepositBase; type AttributeDepositBase = MetadataDepositBase;
type DepositPerByte = MetadataDepositPerByte; type DepositPerByte = MetadataDepositPerByte;
@@ -182,16 +182,16 @@ pub trait BalanceConversion<InBalance, AssetId, OutBalance> {
/// Trait to handle asset locking mechanism to ensure interactions with the asset can be implemented /// Trait to handle asset locking mechanism to ensure interactions with the asset can be implemented
/// downstream to extend logic of Uniques current functionality. /// downstream to extend logic of Uniques current functionality.
pub trait Locker<ClassId, InstanceId> { pub trait Locker<CollectionId, ItemId> {
/// Check if the asset should be locked and prevent interactions with the asset from executing. /// Check if the asset should be locked and prevent interactions with the asset from executing.
fn is_locked(class: ClassId, instance: InstanceId) -> bool; fn is_locked(collection: CollectionId, item: ItemId) -> bool;
} }
impl<ClassId, InstanceId> Locker<ClassId, InstanceId> for () { impl<CollectionId, ItemId> Locker<CollectionId, ItemId> for () {
// Default will be false if not implemented downstream. // Default will be false if not implemented downstream.
// Note: The logic check in this function must be constant time and consistent for benchmarks // Note: The logic check in this function must be constant time and consistent for benchmarks
// to work. // to work.
fn is_locked(_class: ClassId, _instance: InstanceId) -> bool { fn is_locked(_collection: CollectionId, _item: ItemId) -> bool {
false false
} }
} }
@@ -15,9 +15,9 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
//! Traits for dealing with a single non-fungible asset class. //! Traits for dealing with a single non-fungible collection of items.
//! //!
//! This assumes a single level namespace identified by `Inspect::InstanceId`, and could //! This assumes a single level namespace identified by `Inspect::ItemId`, and could
//! reasonably be implemented by pallets which wants to expose a single collection of NFT-like //! reasonably be implemented by pallets which wants to expose a single collection of NFT-like
//! objects. //! objects.
//! //!
@@ -30,167 +30,164 @@ use codec::{Decode, Encode};
use sp_runtime::TokenError; use sp_runtime::TokenError;
use sp_std::prelude::*; use sp_std::prelude::*;
/// Trait for providing an interface to a read-only NFT-like set of asset instances. /// Trait for providing an interface to a read-only NFT-like set of items.
pub trait Inspect<AccountId> { pub trait Inspect<AccountId> {
/// Type for identifying an asset instance. /// Type for identifying an item.
type InstanceId; type ItemId;
/// Returns the owner of asset `instance`, or `None` if the asset doesn't exist or has no /// Returns the owner of `item`, or `None` if the item doesn't exist or has no
/// owner. /// owner.
fn owner(instance: &Self::InstanceId) -> Option<AccountId>; fn owner(item: &Self::ItemId) -> Option<AccountId>;
/// Returns the attribute value of `instance` corresponding to `key`. /// Returns the attribute value of `item` corresponding to `key`.
/// ///
/// By default this is `None`; no attributes are defined. /// By default this is `None`; no attributes are defined.
fn attribute(_instance: &Self::InstanceId, _key: &[u8]) -> Option<Vec<u8>> { fn attribute(_item: &Self::ItemId, _key: &[u8]) -> Option<Vec<u8>> {
None None
} }
/// Returns the strongly-typed attribute value of `instance` corresponding to `key`. /// Returns the strongly-typed attribute value of `item` corresponding to `key`.
/// ///
/// By default this just attempts to use `attribute`. /// By default this just attempts to use `attribute`.
fn typed_attribute<K: Encode, V: Decode>(instance: &Self::InstanceId, key: &K) -> Option<V> { fn typed_attribute<K: Encode, V: Decode>(item: &Self::ItemId, key: &K) -> Option<V> {
key.using_encoded(|d| Self::attribute(instance, d)) key.using_encoded(|d| Self::attribute(item, d))
.and_then(|v| V::decode(&mut &v[..]).ok()) .and_then(|v| V::decode(&mut &v[..]).ok())
} }
/// Returns `true` if the asset `instance` may be transferred. /// Returns `true` if the `item` may be transferred.
/// ///
/// Default implementation is that all assets are transferable. /// Default implementation is that all items are transferable.
fn can_transfer(_instance: &Self::InstanceId) -> bool { fn can_transfer(_item: &Self::ItemId) -> bool {
true 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. /// of NFTs.
pub trait InspectEnumerable<AccountId>: Inspect<AccountId> { pub trait InspectEnumerable<AccountId>: Inspect<AccountId> {
/// Returns an iterator of the instances of an asset `class` in existence. /// Returns an iterator of the items within a `collection` in existence.
fn instances() -> Box<dyn Iterator<Item = Self::InstanceId>>; fn items() -> Box<dyn Iterator<Item = Self::ItemId>>;
/// Returns an iterator of the asset instances of all classes owned by `who`. /// Returns an iterator of the items of all collections owned by `who`.
fn owned(who: &AccountId) -> Box<dyn Iterator<Item = Self::InstanceId>>; fn owned(who: &AccountId) -> Box<dyn Iterator<Item = Self::ItemId>>;
} }
/// 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. /// attributes set on them.
pub trait Mutate<AccountId>: Inspect<AccountId> { pub trait Mutate<AccountId>: Inspect<AccountId> {
/// Mint some asset `instance` to be owned by `who`. /// Mint some `item` to be owned by `who`.
/// ///
/// By default, this is not a supported operation. /// By default, this is not a supported operation.
fn mint_into(_instance: &Self::InstanceId, _who: &AccountId) -> DispatchResult { fn mint_into(_item: &Self::ItemId, _who: &AccountId) -> DispatchResult {
Err(TokenError::Unsupported.into()) Err(TokenError::Unsupported.into())
} }
/// Burn some asset `instance`. /// Burn some `item`.
/// ///
/// By default, this is not a supported operation. /// By default, this is not a supported operation.
fn burn( fn burn(_item: &Self::ItemId, _maybe_check_owner: Option<&AccountId>) -> DispatchResult {
_instance: &Self::InstanceId,
_maybe_check_owner: Option<&AccountId>,
) -> DispatchResult {
Err(TokenError::Unsupported.into()) Err(TokenError::Unsupported.into())
} }
/// Set attribute `value` of asset `instance`'s `key`. /// Set attribute `value` of `item`'s `key`.
/// ///
/// By default, this is not a supported operation. /// By default, this is not a supported operation.
fn set_attribute(_instance: &Self::InstanceId, _key: &[u8], _value: &[u8]) -> DispatchResult { fn set_attribute(_item: &Self::ItemId, _key: &[u8], _value: &[u8]) -> DispatchResult {
Err(TokenError::Unsupported.into()) Err(TokenError::Unsupported.into())
} }
/// Attempt to set the strongly-typed attribute `value` of `instance`'s `key`. /// Attempt to set the strongly-typed attribute `value` of `item`'s `key`.
/// ///
/// By default this just attempts to use `set_attribute`. /// By default this just attempts to use `set_attribute`.
fn set_typed_attribute<K: Encode, V: Encode>( fn set_typed_attribute<K: Encode, V: Encode>(
instance: &Self::InstanceId, item: &Self::ItemId,
key: &K, key: &K,
value: &V, value: &V,
) -> DispatchResult { ) -> DispatchResult {
key.using_encoded(|k| value.using_encoded(|v| Self::set_attribute(instance, k, v))) key.using_encoded(|k| value.using_encoded(|v| Self::set_attribute(item, k, v)))
} }
} }
/// Trait for providing a non-fungible set of assets which can only be transferred. /// Trait for providing a non-fungible set of items which can only be transferred.
pub trait Transfer<AccountId>: Inspect<AccountId> { pub trait Transfer<AccountId>: Inspect<AccountId> {
/// Transfer asset `instance` into `destination` account. /// Transfer `item` into `destination` account.
fn transfer(instance: &Self::InstanceId, destination: &AccountId) -> DispatchResult; fn transfer(item: &Self::ItemId, destination: &AccountId) -> DispatchResult;
} }
/// Convert a `fungibles` trait implementation into a `fungible` trait implementation by identifying /// Convert a `fungibles` trait implementation into a `fungible` trait implementation by identifying
/// a single item. /// a single item.
pub struct ItemOf< pub struct ItemOf<
F: nonfungibles::Inspect<AccountId>, F: nonfungibles::Inspect<AccountId>,
A: Get<<F as nonfungibles::Inspect<AccountId>>::ClassId>, A: Get<<F as nonfungibles::Inspect<AccountId>>::CollectionId>,
AccountId, AccountId,
>(sp_std::marker::PhantomData<(F, A, AccountId)>); >(sp_std::marker::PhantomData<(F, A, AccountId)>);
impl< impl<
F: nonfungibles::Inspect<AccountId>, F: nonfungibles::Inspect<AccountId>,
A: Get<<F as nonfungibles::Inspect<AccountId>>::ClassId>, A: Get<<F as nonfungibles::Inspect<AccountId>>::CollectionId>,
AccountId, AccountId,
> Inspect<AccountId> for ItemOf<F, A, AccountId> > Inspect<AccountId> for ItemOf<F, A, AccountId>
{ {
type InstanceId = <F as nonfungibles::Inspect<AccountId>>::InstanceId; type ItemId = <F as nonfungibles::Inspect<AccountId>>::ItemId;
fn owner(instance: &Self::InstanceId) -> Option<AccountId> { fn owner(item: &Self::ItemId) -> Option<AccountId> {
<F as nonfungibles::Inspect<AccountId>>::owner(&A::get(), instance) <F as nonfungibles::Inspect<AccountId>>::owner(&A::get(), item)
} }
fn attribute(instance: &Self::InstanceId, key: &[u8]) -> Option<Vec<u8>> { fn attribute(item: &Self::ItemId, key: &[u8]) -> Option<Vec<u8>> {
<F as nonfungibles::Inspect<AccountId>>::attribute(&A::get(), instance, key) <F as nonfungibles::Inspect<AccountId>>::attribute(&A::get(), item, key)
} }
fn typed_attribute<K: Encode, V: Decode>(instance: &Self::InstanceId, key: &K) -> Option<V> { fn typed_attribute<K: Encode, V: Decode>(item: &Self::ItemId, key: &K) -> Option<V> {
<F as nonfungibles::Inspect<AccountId>>::typed_attribute(&A::get(), instance, key) <F as nonfungibles::Inspect<AccountId>>::typed_attribute(&A::get(), item, key)
} }
fn can_transfer(instance: &Self::InstanceId) -> bool { fn can_transfer(item: &Self::ItemId) -> bool {
<F as nonfungibles::Inspect<AccountId>>::can_transfer(&A::get(), instance) <F as nonfungibles::Inspect<AccountId>>::can_transfer(&A::get(), item)
} }
} }
impl< impl<
F: nonfungibles::InspectEnumerable<AccountId>, F: nonfungibles::InspectEnumerable<AccountId>,
A: Get<<F as nonfungibles::Inspect<AccountId>>::ClassId>, A: Get<<F as nonfungibles::Inspect<AccountId>>::CollectionId>,
AccountId, AccountId,
> InspectEnumerable<AccountId> for ItemOf<F, A, AccountId> > InspectEnumerable<AccountId> for ItemOf<F, A, AccountId>
{ {
fn instances() -> Box<dyn Iterator<Item = Self::InstanceId>> { fn items() -> Box<dyn Iterator<Item = Self::ItemId>> {
<F as nonfungibles::InspectEnumerable<AccountId>>::instances(&A::get()) <F as nonfungibles::InspectEnumerable<AccountId>>::items(&A::get())
} }
fn owned(who: &AccountId) -> Box<dyn Iterator<Item = Self::InstanceId>> { fn owned(who: &AccountId) -> Box<dyn Iterator<Item = Self::ItemId>> {
<F as nonfungibles::InspectEnumerable<AccountId>>::owned_in_class(&A::get(), who) <F as nonfungibles::InspectEnumerable<AccountId>>::owned_in_collection(&A::get(), who)
} }
} }
impl< impl<
F: nonfungibles::Mutate<AccountId>, F: nonfungibles::Mutate<AccountId>,
A: Get<<F as nonfungibles::Inspect<AccountId>>::ClassId>, A: Get<<F as nonfungibles::Inspect<AccountId>>::CollectionId>,
AccountId, AccountId,
> Mutate<AccountId> for ItemOf<F, A, AccountId> > Mutate<AccountId> for ItemOf<F, A, AccountId>
{ {
fn mint_into(instance: &Self::InstanceId, who: &AccountId) -> DispatchResult { fn mint_into(item: &Self::ItemId, who: &AccountId) -> DispatchResult {
<F as nonfungibles::Mutate<AccountId>>::mint_into(&A::get(), instance, who) <F as nonfungibles::Mutate<AccountId>>::mint_into(&A::get(), item, who)
} }
fn burn(instance: &Self::InstanceId, maybe_check_owner: Option<&AccountId>) -> DispatchResult { fn burn(item: &Self::ItemId, maybe_check_owner: Option<&AccountId>) -> DispatchResult {
<F as nonfungibles::Mutate<AccountId>>::burn(&A::get(), instance, maybe_check_owner) <F as nonfungibles::Mutate<AccountId>>::burn(&A::get(), item, maybe_check_owner)
} }
fn set_attribute(instance: &Self::InstanceId, key: &[u8], value: &[u8]) -> DispatchResult { fn set_attribute(item: &Self::ItemId, key: &[u8], value: &[u8]) -> DispatchResult {
<F as nonfungibles::Mutate<AccountId>>::set_attribute(&A::get(), instance, key, value) <F as nonfungibles::Mutate<AccountId>>::set_attribute(&A::get(), item, key, value)
} }
fn set_typed_attribute<K: Encode, V: Encode>( fn set_typed_attribute<K: Encode, V: Encode>(
instance: &Self::InstanceId, item: &Self::ItemId,
key: &K, key: &K,
value: &V, value: &V,
) -> DispatchResult { ) -> DispatchResult {
<F as nonfungibles::Mutate<AccountId>>::set_typed_attribute(&A::get(), instance, key, value) <F as nonfungibles::Mutate<AccountId>>::set_typed_attribute(&A::get(), item, key, value)
} }
} }
impl< impl<
F: nonfungibles::Transfer<AccountId>, F: nonfungibles::Transfer<AccountId>,
A: Get<<F as nonfungibles::Inspect<AccountId>>::ClassId>, A: Get<<F as nonfungibles::Inspect<AccountId>>::CollectionId>,
AccountId, AccountId,
> Transfer<AccountId> for ItemOf<F, A, AccountId> > Transfer<AccountId> for ItemOf<F, A, AccountId>
{ {
fn transfer(instance: &Self::InstanceId, destination: &AccountId) -> DispatchResult { fn transfer(item: &Self::ItemId, destination: &AccountId) -> DispatchResult {
<F as nonfungibles::Transfer<AccountId>>::transfer(&A::get(), instance, destination) <F as nonfungibles::Transfer<AccountId>>::transfer(&A::get(), item, destination)
} }
} }
@@ -15,9 +15,9 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
//! Traits for dealing with multiple collections of non-fungible assets. //! Traits for dealing with multiple collections of non-fungible items.
//! //!
//! This assumes a dual-level namespace identified by `Inspect::InstanceId`, and could //! This assumes a dual-level namespace identified by `Inspect::ItemId`, and could
//! reasonably be implemented by pallets which want to expose multiple independent collections of //! reasonably be implemented by pallets which want to expose multiple independent collections of
//! NFT-like objects. //! NFT-like objects.
//! //!
@@ -32,196 +32,210 @@ use codec::{Decode, Encode};
use sp_runtime::TokenError; use sp_runtime::TokenError;
use sp_std::prelude::*; use sp_std::prelude::*;
/// Trait for providing an interface to many read-only NFT-like sets of asset instances. /// Trait for providing an interface to many read-only NFT-like sets of items.
pub trait Inspect<AccountId> { pub trait Inspect<AccountId> {
/// Type for identifying an asset instance. /// Type for identifying an item.
type InstanceId; type ItemId;
/// Type for identifying an asset class (an identifier for an independent collection of asset /// Type for identifying a collection (an identifier for an independent collection of
/// instances). /// items).
type ClassId; type CollectionId;
/// Returns the owner of asset `instance` of `class`, or `None` if the asset doesn't exist (or /// Returns the owner of `item` of `collection`, or `None` if the item doesn't exist
/// somehow has no owner). /// (or somehow has no owner).
fn owner(class: &Self::ClassId, instance: &Self::InstanceId) -> Option<AccountId>; fn owner(collection: &Self::CollectionId, item: &Self::ItemId) -> Option<AccountId>;
/// Returns the owner of the asset `class`, if there is one. For many NFTs this may not make /// Returns the owner of the `collection`, if there is one. For many NFTs this may not
/// any sense, so users of this API should not be surprised to find an asset class results in /// make any sense, so users of this API should not be surprised to find a collection
/// `None` here. /// results in `None` here.
fn class_owner(_class: &Self::ClassId) -> Option<AccountId> { fn collection_owner(_collection: &Self::CollectionId) -> Option<AccountId> {
None None
} }
/// Returns the attribute value of `instance` of `class` corresponding to `key`. /// Returns the attribute value of `item` of `collection` corresponding to `key`.
/// ///
/// By default this is `None`; no attributes are defined. /// By default this is `None`; no attributes are defined.
fn attribute( fn attribute(
_class: &Self::ClassId, _collection: &Self::CollectionId,
_instance: &Self::InstanceId, _item: &Self::ItemId,
_key: &[u8], _key: &[u8],
) -> Option<Vec<u8>> { ) -> Option<Vec<u8>> {
None None
} }
/// Returns the strongly-typed attribute value of `instance` of `class` corresponding to `key`. /// Returns the strongly-typed attribute value of `item` of `collection` corresponding to
/// `key`.
/// ///
/// By default this just attempts to use `attribute`. /// By default this just attempts to use `attribute`.
fn typed_attribute<K: Encode, V: Decode>( fn typed_attribute<K: Encode, V: Decode>(
class: &Self::ClassId, collection: &Self::CollectionId,
instance: &Self::InstanceId, item: &Self::ItemId,
key: &K, key: &K,
) -> Option<V> { ) -> Option<V> {
key.using_encoded(|d| Self::attribute(class, instance, d)) key.using_encoded(|d| Self::attribute(collection, item, d))
.and_then(|v| V::decode(&mut &v[..]).ok()) .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. /// By default this is `None`; no attributes are defined.
fn class_attribute(_class: &Self::ClassId, _key: &[u8]) -> Option<Vec<u8>> { fn collection_attribute(_collection: &Self::CollectionId, _key: &[u8]) -> Option<Vec<u8>> {
None 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`. /// By default this just attempts to use `collection_attribute`.
fn typed_class_attribute<K: Encode, V: Decode>(class: &Self::ClassId, key: &K) -> Option<V> { fn typed_collection_attribute<K: Encode, V: Decode>(
key.using_encoded(|d| Self::class_attribute(class, d)) collection: &Self::CollectionId,
key: &K,
) -> Option<V> {
key.using_encoded(|d| Self::collection_attribute(collection, d))
.and_then(|v| V::decode(&mut &v[..]).ok()) .and_then(|v| V::decode(&mut &v[..]).ok())
} }
/// Returns `true` if the asset `instance` of `class` may be transferred. /// Returns `true` if the `item` of `collection` may be transferred.
/// ///
/// Default implementation is that all assets are transferable. /// Default implementation is that all items are transferable.
fn can_transfer(_class: &Self::ClassId, _instance: &Self::InstanceId) -> bool { fn can_transfer(_collection: &Self::CollectionId, _item: &Self::ItemId) -> bool {
true 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. /// of NFTs.
pub trait InspectEnumerable<AccountId>: Inspect<AccountId> { pub trait InspectEnumerable<AccountId>: Inspect<AccountId> {
/// Returns an iterator of the asset classes in existence. /// Returns an iterator of the collections in existence.
fn classes() -> Box<dyn Iterator<Item = Self::ClassId>>; fn collections() -> Box<dyn Iterator<Item = Self::CollectionId>>;
/// Returns an iterator of the instances of an asset `class` in existence. /// Returns an iterator of the items of a `collection` in existence.
fn instances(class: &Self::ClassId) -> Box<dyn Iterator<Item = Self::InstanceId>>; fn items(collection: &Self::CollectionId) -> Box<dyn Iterator<Item = Self::ItemId>>;
/// Returns an iterator of the asset instances of all classes owned by `who`. /// Returns an iterator of the items of all collections owned by `who`.
fn owned(who: &AccountId) -> Box<dyn Iterator<Item = (Self::ClassId, Self::InstanceId)>>; fn owned(who: &AccountId) -> Box<dyn Iterator<Item = (Self::CollectionId, Self::ItemId)>>;
/// Returns an iterator of the asset instances of `class` owned by `who`. /// Returns an iterator of the items of `collection` owned by `who`.
fn owned_in_class( fn owned_in_collection(
class: &Self::ClassId, collection: &Self::CollectionId,
who: &AccountId, who: &AccountId,
) -> Box<dyn Iterator<Item = Self::InstanceId>>; ) -> Box<dyn Iterator<Item = Self::ItemId>>;
} }
/// Trait for providing the ability to create classes of nonfungible assets. /// Trait for providing the ability to create collections of nonfungible items.
pub trait Create<AccountId>: Inspect<AccountId> { pub trait Create<AccountId>: Inspect<AccountId> {
/// Create a `class` 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_class(class: &Self::ClassId, who: &AccountId, admin: &AccountId) -> DispatchResult; fn create_collection(
collection: &Self::CollectionId,
who: &AccountId,
admin: &AccountId,
) -> DispatchResult;
} }
/// Trait for providing the ability to destroy classes of nonfungible assets. /// Trait for providing the ability to destroy collections of nonfungible items.
pub trait Destroy<AccountId>: Inspect<AccountId> { pub trait Destroy<AccountId>: Inspect<AccountId> {
/// The witness data needed to destroy an asset. /// The witness data needed to destroy an item.
type DestroyWitness; 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(class: &Self::ClassId) -> Option<Self::DestroyWitness>; fn get_destroy_witness(collection: &Self::CollectionId) -> Option<Self::DestroyWitness>;
/// Destroy an existing fungible asset. /// Destroy an existing fungible item.
/// * `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 /// * `witness`: Any witness data that needs to be provided to complete the operation
/// successfully. /// successfully.
/// * `maybe_check_owner`: An optional account id that can be used to authorize the destroy /// * `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 /// 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. /// This may be different than the witness data provided, and can be used to refund weight.
fn destroy( fn destroy(
class: Self::ClassId, collection: Self::CollectionId,
witness: Self::DestroyWitness, witness: Self::DestroyWitness,
maybe_check_owner: Option<AccountId>, maybe_check_owner: Option<AccountId>,
) -> Result<Self::DestroyWitness, DispatchError>; ) -> Result<Self::DestroyWitness, DispatchError>;
} }
/// Trait for providing an interface for multiple classes of NFT-like assets which may be minted, /// Trait for providing an interface for multiple collections of NFT-like items which may be
/// burned and/or have attributes set on them. /// minted, burned and/or have attributes set on them.
pub trait Mutate<AccountId>: Inspect<AccountId> { pub trait Mutate<AccountId>: Inspect<AccountId> {
/// Mint some asset `instance` of `class` to be owned by `who`. /// Mint some `item` of `collection` to be owned by `who`.
/// ///
/// By default, this is not a supported operation. /// By default, this is not a supported operation.
fn mint_into( fn mint_into(
_class: &Self::ClassId, _collection: &Self::CollectionId,
_instance: &Self::InstanceId, _item: &Self::ItemId,
_who: &AccountId, _who: &AccountId,
) -> DispatchResult { ) -> DispatchResult {
Err(TokenError::Unsupported.into()) Err(TokenError::Unsupported.into())
} }
/// Burn some asset `instance` of `class`. /// Burn some `item` of `collection`.
/// ///
/// By default, this is not a supported operation. /// By default, this is not a supported operation.
fn burn( fn burn(
_class: &Self::ClassId, _collection: &Self::CollectionId,
_instance: &Self::InstanceId, _item: &Self::ItemId,
_maybe_check_owner: Option<&AccountId>, _maybe_check_owner: Option<&AccountId>,
) -> DispatchResult { ) -> DispatchResult {
Err(TokenError::Unsupported.into()) Err(TokenError::Unsupported.into())
} }
/// Set attribute `value` of asset `instance` of `class`'s `key`. /// Set attribute `value` of `item` of `collection`'s `key`.
/// ///
/// By default, this is not a supported operation. /// By default, this is not a supported operation.
fn set_attribute( fn set_attribute(
_class: &Self::ClassId, _collection: &Self::CollectionId,
_instance: &Self::InstanceId, _item: &Self::ItemId,
_key: &[u8], _key: &[u8],
_value: &[u8], _value: &[u8],
) -> DispatchResult { ) -> DispatchResult {
Err(TokenError::Unsupported.into()) Err(TokenError::Unsupported.into())
} }
/// Attempt to set the strongly-typed attribute `value` of `instance` of `class`'s `key`. /// Attempt to set the strongly-typed attribute `value` of `item` of `collection`'s `key`.
/// ///
/// By default this just attempts to use `set_attribute`. /// By default this just attempts to use `set_attribute`.
fn set_typed_attribute<K: Encode, V: Encode>( fn set_typed_attribute<K: Encode, V: Encode>(
class: &Self::ClassId, collection: &Self::CollectionId,
instance: &Self::InstanceId, item: &Self::ItemId,
key: &K, key: &K,
value: &V, value: &V,
) -> DispatchResult { ) -> DispatchResult {
key.using_encoded(|k| value.using_encoded(|v| Self::set_attribute(class, instance, k, v))) key.using_encoded(|k| value.using_encoded(|v| Self::set_attribute(collection, item, k, v)))
} }
/// Set attribute `value` of asset `class`'s `key`. /// Set attribute `value` of `collection`'s `key`.
/// ///
/// By default, this is not a supported operation. /// 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()) 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`. /// By default this just attempts to use `set_attribute`.
fn set_typed_class_attribute<K: Encode, V: Encode>( fn set_typed_collection_attribute<K: Encode, V: Encode>(
class: &Self::ClassId, collection: &Self::CollectionId,
key: &K, key: &K,
value: &V, value: &V,
) -> DispatchResult { ) -> DispatchResult {
key.using_encoded(|k| value.using_encoded(|v| Self::set_class_attribute(class, k, v))) key.using_encoded(|k| {
value.using_encoded(|v| Self::set_collection_attribute(collection, k, v))
})
} }
} }
/// Trait for providing a non-fungible sets of assets which can only be transferred. /// Trait for providing a non-fungible sets of items which can only be transferred.
pub trait Transfer<AccountId>: Inspect<AccountId> { pub trait Transfer<AccountId>: Inspect<AccountId> {
/// Transfer asset `instance` of `class` into `destination` account. /// Transfer `item` of `collection` into `destination` account.
fn transfer( fn transfer(
class: &Self::ClassId, collection: &Self::CollectionId,
instance: &Self::InstanceId, item: &Self::ItemId,
destination: &AccountId, destination: &AccountId,
) -> DispatchResult; ) -> DispatchResult;
} }
+132 -132
View File
@@ -15,7 +15,7 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
//! Assets pallet benchmarking. //! Uniques pallet benchmarking.
#![cfg(feature = "runtime-benchmarks")] #![cfg(feature = "runtime-benchmarks")]
@@ -36,32 +36,32 @@ use crate::Pallet as Uniques;
const SEED: u32 = 0; const SEED: u32 = 0;
fn create_class<T: Config<I>, I: 'static>( fn create_collection<T: Config<I>, I: 'static>(
) -> (T::ClassId, T::AccountId, <T::Lookup as StaticLookup>::Source) { ) -> (T::CollectionId, T::AccountId, <T::Lookup as StaticLookup>::Source) {
let caller: T::AccountId = whitelisted_caller(); let caller: T::AccountId = whitelisted_caller();
let caller_lookup = T::Lookup::unlookup(caller.clone()); 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::<T, I>::max_value()); T::Currency::make_free_balance_be(&caller, DepositBalanceOf::<T, I>::max_value());
assert!(Uniques::<T, I>::force_create( assert!(Uniques::<T, I>::force_create(
SystemOrigin::Root.into(), SystemOrigin::Root.into(),
class, collection,
caller_lookup.clone(), caller_lookup.clone(),
false, false,
) )
.is_ok()); .is_ok());
(class, caller, caller_lookup) (collection, caller, caller_lookup)
} }
fn add_class_metadata<T: Config<I>, I: 'static>( fn add_collection_metadata<T: Config<I>, I: 'static>(
) -> (T::AccountId, <T::Lookup as StaticLookup>::Source) { ) -> (T::AccountId, <T::Lookup as StaticLookup>::Source) {
let caller = Class::<T, I>::get(T::Helper::class(0)).unwrap().owner; let caller = Collection::<T, I>::get(T::Helper::collection(0)).unwrap().owner;
if caller != whitelisted_caller() { if caller != whitelisted_caller() {
whitelist_account!(caller); whitelist_account!(caller);
} }
let caller_lookup = T::Lookup::unlookup(caller.clone()); let caller_lookup = T::Lookup::unlookup(caller.clone());
assert!(Uniques::<T, I>::set_class_metadata( assert!(Uniques::<T, I>::set_collection_metadata(
SystemOrigin::Signed(caller.clone()).into(), SystemOrigin::Signed(caller.clone()).into(),
T::Helper::class(0), T::Helper::collection(0),
vec![0; T::StringLimit::get() as usize].try_into().unwrap(), vec![0; T::StringLimit::get() as usize].try_into().unwrap(),
false, false,
) )
@@ -69,37 +69,37 @@ fn add_class_metadata<T: Config<I>, I: 'static>(
(caller, caller_lookup) (caller, caller_lookup)
} }
fn mint_instance<T: Config<I>, I: 'static>( fn mint_item<T: Config<I>, I: 'static>(
index: u16, index: u16,
) -> (T::InstanceId, T::AccountId, <T::Lookup as StaticLookup>::Source) { ) -> (T::ItemId, T::AccountId, <T::Lookup as StaticLookup>::Source) {
let caller = Class::<T, I>::get(T::Helper::class(0)).unwrap().admin; let caller = Collection::<T, I>::get(T::Helper::collection(0)).unwrap().admin;
if caller != whitelisted_caller() { if caller != whitelisted_caller() {
whitelist_account!(caller); whitelist_account!(caller);
} }
let caller_lookup = T::Lookup::unlookup(caller.clone()); let caller_lookup = T::Lookup::unlookup(caller.clone());
let instance = T::Helper::instance(index); let item = T::Helper::item(index);
assert!(Uniques::<T, I>::mint( assert!(Uniques::<T, I>::mint(
SystemOrigin::Signed(caller.clone()).into(), SystemOrigin::Signed(caller.clone()).into(),
T::Helper::class(0), T::Helper::collection(0),
instance, item,
caller_lookup.clone(), caller_lookup.clone(),
) )
.is_ok()); .is_ok());
(instance, caller, caller_lookup) (item, caller, caller_lookup)
} }
fn add_instance_metadata<T: Config<I>, I: 'static>( fn add_item_metadata<T: Config<I>, I: 'static>(
instance: T::InstanceId, item: T::ItemId,
) -> (T::AccountId, <T::Lookup as StaticLookup>::Source) { ) -> (T::AccountId, <T::Lookup as StaticLookup>::Source) {
let caller = Class::<T, I>::get(T::Helper::class(0)).unwrap().owner; let caller = Collection::<T, I>::get(T::Helper::collection(0)).unwrap().owner;
if caller != whitelisted_caller() { if caller != whitelisted_caller() {
whitelist_account!(caller); whitelist_account!(caller);
} }
let caller_lookup = T::Lookup::unlookup(caller.clone()); let caller_lookup = T::Lookup::unlookup(caller.clone());
assert!(Uniques::<T, I>::set_metadata( assert!(Uniques::<T, I>::set_metadata(
SystemOrigin::Signed(caller.clone()).into(), SystemOrigin::Signed(caller.clone()).into(),
T::Helper::class(0), T::Helper::collection(0),
instance, item,
vec![0; T::StringLimit::get() as usize].try_into().unwrap(), vec![0; T::StringLimit::get() as usize].try_into().unwrap(),
false, false,
) )
@@ -107,10 +107,10 @@ fn add_instance_metadata<T: Config<I>, I: 'static>(
(caller, caller_lookup) (caller, caller_lookup)
} }
fn add_instance_attribute<T: Config<I>, I: 'static>( fn add_item_attribute<T: Config<I>, I: 'static>(
instance: T::InstanceId, item: T::ItemId,
) -> (BoundedVec<u8, T::KeyLimit>, T::AccountId, <T::Lookup as StaticLookup>::Source) { ) -> (BoundedVec<u8, T::KeyLimit>, T::AccountId, <T::Lookup as StaticLookup>::Source) {
let caller = Class::<T, I>::get(T::Helper::class(0)).unwrap().owner; let caller = Collection::<T, I>::get(T::Helper::collection(0)).unwrap().owner;
if caller != whitelisted_caller() { if caller != whitelisted_caller() {
whitelist_account!(caller); whitelist_account!(caller);
} }
@@ -118,8 +118,8 @@ fn add_instance_attribute<T: Config<I>, I: 'static>(
let key: BoundedVec<_, _> = vec![0; T::KeyLimit::get() as usize].try_into().unwrap(); let key: BoundedVec<_, _> = vec![0; T::KeyLimit::get() as usize].try_into().unwrap();
assert!(Uniques::<T, I>::set_attribute( assert!(Uniques::<T, I>::set_attribute(
SystemOrigin::Signed(caller.clone()).into(), SystemOrigin::Signed(caller.clone()).into(),
T::Helper::class(0), T::Helper::collection(0),
Some(instance), Some(item),
key.clone(), key.clone(),
vec![0; T::ValueLimit::get() as usize].try_into().unwrap(), vec![0; T::ValueLimit::get() as usize].try_into().unwrap(),
) )
@@ -137,24 +137,24 @@ fn assert_last_event<T: Config<I>, I: 'static>(generic_event: <T as Config<I>>::
benchmarks_instance_pallet! { benchmarks_instance_pallet! {
create { create {
let class = T::Helper::class(0); let collection = T::Helper::collection(0);
let origin = T::CreateOrigin::successful_origin(&class); let origin = T::CreateOrigin::successful_origin(&collection);
let caller = T::CreateOrigin::ensure_origin(origin.clone(), &class).unwrap(); let caller = T::CreateOrigin::ensure_origin(origin.clone(), &collection).unwrap();
whitelist_account!(caller); whitelist_account!(caller);
let admin = T::Lookup::unlookup(caller.clone()); let admin = T::Lookup::unlookup(caller.clone());
T::Currency::make_free_balance_be(&caller, DepositBalanceOf::<T, I>::max_value()); T::Currency::make_free_balance_be(&caller, DepositBalanceOf::<T, I>::max_value());
let call = Call::<T, I>::create { class, admin }; let call = Call::<T, I>::create { collection, admin };
}: { call.dispatch_bypass_filter(origin)? } }: { call.dispatch_bypass_filter(origin)? }
verify { verify {
assert_last_event::<T, I>(Event::Created { class: T::Helper::class(0), creator: caller.clone(), owner: caller }.into()); assert_last_event::<T, I>(Event::Created { collection: T::Helper::collection(0), creator: caller.clone(), owner: caller }.into());
} }
force_create { force_create {
let caller: T::AccountId = whitelisted_caller(); let caller: T::AccountId = whitelisted_caller();
let caller_lookup = T::Lookup::unlookup(caller.clone()); 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 { verify {
assert_last_event::<T, I>(Event::ForceCreated { class: T::Helper::class(0), owner: caller }.into()); assert_last_event::<T, I>(Event::ForceCreated { collection: T::Helper::collection(0), owner: caller }.into());
} }
destroy { destroy {
@@ -162,57 +162,57 @@ benchmarks_instance_pallet! {
let m in 0 .. 1_000; let m in 0 .. 1_000;
let a in 0 .. 1_000; let a in 0 .. 1_000;
let (class, caller, caller_lookup) = create_class::<T, I>(); let (collection, caller, caller_lookup) = create_collection::<T, I>();
add_class_metadata::<T, I>(); add_collection_metadata::<T, I>();
for i in 0..n { for i in 0..n {
mint_instance::<T, I>(i as u16); mint_item::<T, I>(i as u16);
} }
for i in 0..m { for i in 0..m {
add_instance_metadata::<T, I>(T::Helper::instance(i as u16)); add_item_metadata::<T, I>(T::Helper::item(i as u16));
} }
for i in 0..a { for i in 0..a {
add_instance_attribute::<T, I>(T::Helper::instance(i as u16)); add_item_attribute::<T, I>(T::Helper::item(i as u16));
} }
let witness = Class::<T, I>::get(class).unwrap().destroy_witness(); let witness = Collection::<T, I>::get(collection).unwrap().destroy_witness();
}: _(SystemOrigin::Signed(caller), class, witness) }: _(SystemOrigin::Signed(caller), collection, witness)
verify { verify {
assert_last_event::<T, I>(Event::Destroyed { class }.into()); assert_last_event::<T, I>(Event::Destroyed { collection }.into());
} }
mint { mint {
let (class, caller, caller_lookup) = create_class::<T, I>(); let (collection, caller, caller_lookup) = create_collection::<T, I>();
let instance = T::Helper::instance(0); let item = T::Helper::item(0);
}: _(SystemOrigin::Signed(caller.clone()), class, instance, caller_lookup) }: _(SystemOrigin::Signed(caller.clone()), collection, item, caller_lookup)
verify { verify {
assert_last_event::<T, I>(Event::Issued { class, instance, owner: caller }.into()); assert_last_event::<T, I>(Event::Issued { collection, item, owner: caller }.into());
} }
burn { burn {
let (class, caller, caller_lookup) = create_class::<T, I>(); let (collection, caller, caller_lookup) = create_collection::<T, I>();
let (instance, ..) = mint_instance::<T, I>(0); let (item, ..) = mint_item::<T, I>(0);
}: _(SystemOrigin::Signed(caller.clone()), class, instance, Some(caller_lookup)) }: _(SystemOrigin::Signed(caller.clone()), collection, item, Some(caller_lookup))
verify { verify {
assert_last_event::<T, I>(Event::Burned { class, instance, owner: caller }.into()); assert_last_event::<T, I>(Event::Burned { collection, item, owner: caller }.into());
} }
transfer { transfer {
let (class, caller, caller_lookup) = create_class::<T, I>(); let (collection, caller, caller_lookup) = create_collection::<T, I>();
let (instance, ..) = mint_instance::<T, I>(0); let (item, ..) = mint_item::<T, I>(0);
let target: T::AccountId = account("target", 0, SEED); let target: T::AccountId = account("target", 0, SEED);
let target_lookup = T::Lookup::unlookup(target.clone()); let target_lookup = T::Lookup::unlookup(target.clone());
}: _(SystemOrigin::Signed(caller.clone()), class, instance, target_lookup) }: _(SystemOrigin::Signed(caller.clone()), collection, item, target_lookup)
verify { verify {
assert_last_event::<T, I>(Event::Transferred { class, instance, from: caller, to: target }.into()); assert_last_event::<T, I>(Event::Transferred { collection, item, from: caller, to: target }.into());
} }
redeposit { redeposit {
let i in 0 .. 5_000; let i in 0 .. 5_000;
let (class, caller, caller_lookup) = create_class::<T, I>(); let (collection, caller, caller_lookup) = create_collection::<T, I>();
let instances = (0..i).map(|x| mint_instance::<T, I>(x as u16).0).collect::<Vec<_>>(); let items = (0..i).map(|x| mint_item::<T, I>(x as u16).0).collect::<Vec<_>>();
Uniques::<T, I>::force_asset_status( Uniques::<T, I>::force_item_status(
SystemOrigin::Root.into(), SystemOrigin::Root.into(),
class, collection,
caller_lookup.clone(), caller_lookup.clone(),
caller_lookup.clone(), caller_lookup.clone(),
caller_lookup.clone(), caller_lookup.clone(),
@@ -220,80 +220,80 @@ benchmarks_instance_pallet! {
true, true,
false, false,
)?; )?;
}: _(SystemOrigin::Signed(caller.clone()), class, instances.clone()) }: _(SystemOrigin::Signed(caller.clone()), collection, items.clone())
verify { verify {
assert_last_event::<T, I>(Event::Redeposited { class, successful_instances: instances }.into()); assert_last_event::<T, I>(Event::Redeposited { collection, successful_items: items }.into());
} }
freeze { freeze {
let (class, caller, caller_lookup) = create_class::<T, I>(); let (collection, caller, caller_lookup) = create_collection::<T, I>();
let (instance, ..) = mint_instance::<T, I>(0); let (item, ..) = mint_item::<T, I>(0);
}: _(SystemOrigin::Signed(caller.clone()), T::Helper::class(0), T::Helper::instance(0)) }: _(SystemOrigin::Signed(caller.clone()), T::Helper::collection(0), T::Helper::item(0))
verify { verify {
assert_last_event::<T, I>(Event::Frozen { class: T::Helper::class(0), instance: T::Helper::instance(0) }.into()); assert_last_event::<T, I>(Event::Frozen { collection: T::Helper::collection(0), item: T::Helper::item(0) }.into());
} }
thaw { thaw {
let (class, caller, caller_lookup) = create_class::<T, I>(); let (collection, caller, caller_lookup) = create_collection::<T, I>();
let (instance, ..) = mint_instance::<T, I>(0); let (item, ..) = mint_item::<T, I>(0);
Uniques::<T, I>::freeze( Uniques::<T, I>::freeze(
SystemOrigin::Signed(caller.clone()).into(), SystemOrigin::Signed(caller.clone()).into(),
class, collection,
instance, item,
)?; )?;
}: _(SystemOrigin::Signed(caller.clone()), class, instance) }: _(SystemOrigin::Signed(caller.clone()), collection, item)
verify { verify {
assert_last_event::<T, I>(Event::Thawed { class, instance }.into()); assert_last_event::<T, I>(Event::Thawed { collection, item }.into());
} }
freeze_class { freeze_collection {
let (class, caller, caller_lookup) = create_class::<T, I>(); let (collection, caller, caller_lookup) = create_collection::<T, I>();
}: _(SystemOrigin::Signed(caller.clone()), class) }: _(SystemOrigin::Signed(caller.clone()), collection)
verify { verify {
assert_last_event::<T, I>(Event::ClassFrozen { class }.into()); assert_last_event::<T, I>(Event::CollectionFrozen { collection }.into());
} }
thaw_class { thaw_collection {
let (class, caller, caller_lookup) = create_class::<T, I>(); let (collection, caller, caller_lookup) = create_collection::<T, I>();
let origin = SystemOrigin::Signed(caller.clone()).into(); let origin = SystemOrigin::Signed(caller.clone()).into();
Uniques::<T, I>::freeze_class(origin, class)?; Uniques::<T, I>::freeze_collection(origin, collection)?;
}: _(SystemOrigin::Signed(caller.clone()), class) }: _(SystemOrigin::Signed(caller.clone()), collection)
verify { verify {
assert_last_event::<T, I>(Event::ClassThawed { class }.into()); assert_last_event::<T, I>(Event::CollectionThawed { collection }.into());
} }
transfer_ownership { transfer_ownership {
let (class, caller, _) = create_class::<T, I>(); let (collection, caller, _) = create_collection::<T, I>();
let target: T::AccountId = account("target", 0, SEED); let target: T::AccountId = account("target", 0, SEED);
let target_lookup = T::Lookup::unlookup(target.clone()); let target_lookup = T::Lookup::unlookup(target.clone());
T::Currency::make_free_balance_be(&target, T::Currency::minimum_balance()); T::Currency::make_free_balance_be(&target, T::Currency::minimum_balance());
let origin = SystemOrigin::Signed(target.clone()).into(); let origin = SystemOrigin::Signed(target.clone()).into();
Uniques::<T, I>::set_accept_ownership(origin, Some(class))?; Uniques::<T, I>::set_accept_ownership(origin, Some(collection))?;
}: _(SystemOrigin::Signed(caller), class, target_lookup) }: _(SystemOrigin::Signed(caller), collection, target_lookup)
verify { verify {
assert_last_event::<T, I>(Event::OwnerChanged { class, new_owner: target }.into()); assert_last_event::<T, I>(Event::OwnerChanged { collection, new_owner: target }.into());
} }
set_team { set_team {
let (class, caller, _) = create_class::<T, I>(); let (collection, caller, _) = create_collection::<T, I>();
let target0 = T::Lookup::unlookup(account("target", 0, SEED)); let target0 = T::Lookup::unlookup(account("target", 0, SEED));
let target1 = T::Lookup::unlookup(account("target", 1, SEED)); let target1 = T::Lookup::unlookup(account("target", 1, SEED));
let target2 = T::Lookup::unlookup(account("target", 2, 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 { verify {
assert_last_event::<T, I>(Event::TeamChanged{ assert_last_event::<T, I>(Event::TeamChanged{
class, collection,
issuer: account("target", 0, SEED), issuer: account("target", 0, SEED),
admin: account("target", 1, SEED), admin: account("target", 1, SEED),
freezer: account("target", 2, SEED), freezer: account("target", 2, SEED),
}.into()); }.into());
} }
force_asset_status { force_item_status {
let (class, caller, caller_lookup) = create_class::<T, I>(); let (collection, caller, caller_lookup) = create_collection::<T, I>();
let origin = T::ForceOrigin::successful_origin(); let origin = T::ForceOrigin::successful_origin();
let call = Call::<T, I>::force_asset_status { let call = Call::<T, I>::force_item_status {
class, collection,
owner: caller_lookup.clone(), owner: caller_lookup.clone(),
issuer: caller_lookup.clone(), issuer: caller_lookup.clone(),
admin: caller_lookup.clone(), admin: caller_lookup.clone(),
@@ -303,98 +303,98 @@ benchmarks_instance_pallet! {
}; };
}: { call.dispatch_bypass_filter(origin)? } }: { call.dispatch_bypass_filter(origin)? }
verify { verify {
assert_last_event::<T, I>(Event::AssetStatusChanged { class }.into()); assert_last_event::<T, I>(Event::ItemStatusChanged { collection }.into());
} }
set_attribute { set_attribute {
let key: BoundedVec<_, _> = vec![0u8; T::KeyLimit::get() as usize].try_into().unwrap(); 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 value: BoundedVec<_, _> = vec![0u8; T::ValueLimit::get() as usize].try_into().unwrap();
let (class, caller, _) = create_class::<T, I>(); let (collection, caller, _) = create_collection::<T, I>();
let (instance, ..) = mint_instance::<T, I>(0); let (item, ..) = mint_item::<T, I>(0);
add_instance_metadata::<T, I>(instance); add_item_metadata::<T, I>(item);
}: _(SystemOrigin::Signed(caller), class, Some(instance), key.clone(), value.clone()) }: _(SystemOrigin::Signed(caller), collection, Some(item), key.clone(), value.clone())
verify { verify {
assert_last_event::<T, I>(Event::AttributeSet { class, maybe_instance: Some(instance), key, value }.into()); assert_last_event::<T, I>(Event::AttributeSet { collection, maybe_item: Some(item), key, value }.into());
} }
clear_attribute { clear_attribute {
let (class, caller, _) = create_class::<T, I>(); let (collection, caller, _) = create_collection::<T, I>();
let (instance, ..) = mint_instance::<T, I>(0); let (item, ..) = mint_item::<T, I>(0);
add_instance_metadata::<T, I>(instance); add_item_metadata::<T, I>(item);
let (key, ..) = add_instance_attribute::<T, I>(instance); let (key, ..) = add_item_attribute::<T, I>(item);
}: _(SystemOrigin::Signed(caller), class, Some(instance), key.clone()) }: _(SystemOrigin::Signed(caller), collection, Some(item), key.clone())
verify { verify {
assert_last_event::<T, I>(Event::AttributeCleared { class, maybe_instance: Some(instance), key }.into()); assert_last_event::<T, I>(Event::AttributeCleared { collection, maybe_item: Some(item), key }.into());
} }
set_metadata { set_metadata {
let data: BoundedVec<_, _> = vec![0u8; T::StringLimit::get() as usize].try_into().unwrap(); let data: BoundedVec<_, _> = vec![0u8; T::StringLimit::get() as usize].try_into().unwrap();
let (class, caller, _) = create_class::<T, I>(); let (collection, caller, _) = create_collection::<T, I>();
let (instance, ..) = mint_instance::<T, I>(0); let (item, ..) = mint_item::<T, I>(0);
}: _(SystemOrigin::Signed(caller), class, instance, data.clone(), false) }: _(SystemOrigin::Signed(caller), collection, item, data.clone(), false)
verify { verify {
assert_last_event::<T, I>(Event::MetadataSet { class, instance, data, is_frozen: false }.into()); assert_last_event::<T, I>(Event::MetadataSet { collection, item, data, is_frozen: false }.into());
} }
clear_metadata { clear_metadata {
let (class, caller, _) = create_class::<T, I>(); let (collection, caller, _) = create_collection::<T, I>();
let (instance, ..) = mint_instance::<T, I>(0); let (item, ..) = mint_item::<T, I>(0);
add_instance_metadata::<T, I>(instance); add_item_metadata::<T, I>(item);
}: _(SystemOrigin::Signed(caller), class, instance) }: _(SystemOrigin::Signed(caller), collection, item)
verify { verify {
assert_last_event::<T, I>(Event::MetadataCleared { class, instance }.into()); assert_last_event::<T, I>(Event::MetadataCleared { collection, item }.into());
} }
set_class_metadata { set_collection_metadata {
let data: BoundedVec<_, _> = vec![0u8; T::StringLimit::get() as usize].try_into().unwrap(); let data: BoundedVec<_, _> = vec![0u8; T::StringLimit::get() as usize].try_into().unwrap();
let (class, caller, _) = create_class::<T, I>(); let (collection, caller, _) = create_collection::<T, I>();
}: _(SystemOrigin::Signed(caller), class, data.clone(), false) }: _(SystemOrigin::Signed(caller), collection, data.clone(), false)
verify { verify {
assert_last_event::<T, I>(Event::ClassMetadataSet { class, data, is_frozen: false }.into()); assert_last_event::<T, I>(Event::CollectionMetadataSet { collection, data, is_frozen: false }.into());
} }
clear_class_metadata { clear_collection_metadata {
let (class, caller, _) = create_class::<T, I>(); let (collection, caller, _) = create_collection::<T, I>();
add_class_metadata::<T, I>(); add_collection_metadata::<T, I>();
}: _(SystemOrigin::Signed(caller), class) }: _(SystemOrigin::Signed(caller), collection)
verify { verify {
assert_last_event::<T, I>(Event::ClassMetadataCleared { class }.into()); assert_last_event::<T, I>(Event::CollectionMetadataCleared { collection }.into());
} }
approve_transfer { approve_transfer {
let (class, caller, _) = create_class::<T, I>(); let (collection, caller, _) = create_collection::<T, I>();
let (instance, ..) = mint_instance::<T, I>(0); let (item, ..) = mint_item::<T, I>(0);
let delegate: T::AccountId = account("delegate", 0, SEED); let delegate: T::AccountId = account("delegate", 0, SEED);
let delegate_lookup = T::Lookup::unlookup(delegate.clone()); let delegate_lookup = T::Lookup::unlookup(delegate.clone());
}: _(SystemOrigin::Signed(caller.clone()), class, instance, delegate_lookup) }: _(SystemOrigin::Signed(caller.clone()), collection, item, delegate_lookup)
verify { verify {
assert_last_event::<T, I>(Event::ApprovedTransfer { class, instance, owner: caller, delegate }.into()); assert_last_event::<T, I>(Event::ApprovedTransfer { collection, item, owner: caller, delegate }.into());
} }
cancel_approval { cancel_approval {
let (class, caller, _) = create_class::<T, I>(); let (collection, caller, _) = create_collection::<T, I>();
let (instance, ..) = mint_instance::<T, I>(0); let (item, ..) = mint_item::<T, I>(0);
let delegate: T::AccountId = account("delegate", 0, SEED); let delegate: T::AccountId = account("delegate", 0, SEED);
let delegate_lookup = T::Lookup::unlookup(delegate.clone()); let delegate_lookup = T::Lookup::unlookup(delegate.clone());
let origin = SystemOrigin::Signed(caller.clone()).into(); let origin = SystemOrigin::Signed(caller.clone()).into();
Uniques::<T, I>::approve_transfer(origin, class, instance, delegate_lookup.clone())?; Uniques::<T, I>::approve_transfer(origin, collection, item, delegate_lookup.clone())?;
}: _(SystemOrigin::Signed(caller.clone()), class, instance, Some(delegate_lookup)) }: _(SystemOrigin::Signed(caller.clone()), collection, item, Some(delegate_lookup))
verify { verify {
assert_last_event::<T, I>(Event::ApprovalCancelled { class, instance, owner: caller, delegate }.into()); assert_last_event::<T, I>(Event::ApprovalCancelled { collection, item, owner: caller, delegate }.into());
} }
set_accept_ownership { set_accept_ownership {
let caller: T::AccountId = whitelisted_caller(); let caller: T::AccountId = whitelisted_caller();
T::Currency::make_free_balance_be(&caller, DepositBalanceOf::<T, I>::max_value()); T::Currency::make_free_balance_be(&caller, DepositBalanceOf::<T, I>::max_value());
let class = T::Helper::class(0); let collection = T::Helper::collection(0);
}: _(SystemOrigin::Signed(caller.clone()), Some(class)) }: _(SystemOrigin::Signed(caller.clone()), Some(collection))
verify { verify {
assert_last_event::<T, I>(Event::OwnershipAcceptanceChanged { assert_last_event::<T, I>(Event::OwnershipAcceptanceChanged {
who: caller, who: caller,
maybe_class: Some(class), maybe_collection: Some(collection),
}.into()); }.into());
} }
+88 -82
View File
@@ -23,168 +23,174 @@ use sp_runtime::{DispatchError, DispatchResult};
impl<T: Config<I>, I: 'static> Pallet<T, I> { impl<T: Config<I>, I: 'static> Pallet<T, I> {
pub fn do_transfer( pub fn do_transfer(
class: T::ClassId, collection: T::CollectionId,
instance: T::InstanceId, item: T::ItemId,
dest: T::AccountId, dest: T::AccountId,
with_details: impl FnOnce( with_details: impl FnOnce(
&ClassDetailsFor<T, I>, &CollectionDetailsFor<T, I>,
&mut InstanceDetailsFor<T, I>, &mut ItemDetailsFor<T, I>,
) -> DispatchResult, ) -> DispatchResult,
) -> DispatchResult { ) -> DispatchResult {
let class_details = Class::<T, I>::get(&class).ok_or(Error::<T, I>::UnknownClass)?; let collection_details =
ensure!(!class_details.is_frozen, Error::<T, I>::Frozen); Collection::<T, I>::get(&collection).ok_or(Error::<T, I>::UnknownCollection)?;
ensure!(!T::Locker::is_locked(class, instance), Error::<T, I>::Locked); ensure!(!collection_details.is_frozen, Error::<T, I>::Frozen);
ensure!(!T::Locker::is_locked(collection, item), Error::<T, I>::Locked);
let mut details = let mut details =
Asset::<T, I>::get(&class, &instance).ok_or(Error::<T, I>::UnknownClass)?; Item::<T, I>::get(&collection, &item).ok_or(Error::<T, I>::UnknownCollection)?;
ensure!(!details.is_frozen, Error::<T, I>::Frozen); ensure!(!details.is_frozen, Error::<T, I>::Frozen);
with_details(&class_details, &mut details)?; with_details(&collection_details, &mut details)?;
Account::<T, I>::remove((&details.owner, &class, &instance)); Account::<T, I>::remove((&details.owner, &collection, &item));
Account::<T, I>::insert((&dest, &class, &instance), ()); Account::<T, I>::insert((&dest, &collection, &item), ());
let origin = details.owner; let origin = details.owner;
details.owner = dest; details.owner = dest;
Asset::<T, I>::insert(&class, &instance, &details); Item::<T, I>::insert(&collection, &item, &details);
Self::deposit_event(Event::Transferred { Self::deposit_event(Event::Transferred {
class, collection,
instance, item,
from: origin, from: origin,
to: details.owner, to: details.owner,
}); });
Ok(()) Ok(())
} }
pub fn do_create_class( pub fn do_create_collection(
class: T::ClassId, collection: T::CollectionId,
owner: T::AccountId, owner: T::AccountId,
admin: T::AccountId, admin: T::AccountId,
deposit: DepositBalanceOf<T, I>, deposit: DepositBalanceOf<T, I>,
free_holding: bool, free_holding: bool,
event: Event<T, I>, event: Event<T, I>,
) -> DispatchResult { ) -> DispatchResult {
ensure!(!Class::<T, I>::contains_key(class), Error::<T, I>::InUse); ensure!(!Collection::<T, I>::contains_key(collection), Error::<T, I>::InUse);
T::Currency::reserve(&owner, deposit)?; T::Currency::reserve(&owner, deposit)?;
Class::<T, I>::insert( Collection::<T, I>::insert(
class, collection,
ClassDetails { CollectionDetails {
owner: owner.clone(), owner: owner.clone(),
issuer: admin.clone(), issuer: admin.clone(),
admin: admin.clone(), admin: admin.clone(),
freezer: admin, freezer: admin,
total_deposit: deposit, total_deposit: deposit,
free_holding, free_holding,
instances: 0, items: 0,
instance_metadatas: 0, item_metadatas: 0,
attributes: 0, attributes: 0,
is_frozen: false, is_frozen: false,
}, },
); );
ClassAccount::<T, I>::insert(&owner, &class, ()); CollectionAccount::<T, I>::insert(&owner, &collection, ());
Self::deposit_event(event); Self::deposit_event(event);
Ok(()) Ok(())
} }
pub fn do_destroy_class( pub fn do_destroy_collection(
class: T::ClassId, collection: T::CollectionId,
witness: DestroyWitness, witness: DestroyWitness,
maybe_check_owner: Option<T::AccountId>, maybe_check_owner: Option<T::AccountId>,
) -> Result<DestroyWitness, DispatchError> { ) -> Result<DestroyWitness, DispatchError> {
Class::<T, I>::try_mutate_exists(class, |maybe_details| { Collection::<T, I>::try_mutate_exists(collection, |maybe_details| {
let class_details = maybe_details.take().ok_or(Error::<T, I>::UnknownClass)?; let collection_details =
maybe_details.take().ok_or(Error::<T, I>::UnknownCollection)?;
if let Some(check_owner) = maybe_check_owner { if let Some(check_owner) = maybe_check_owner {
ensure!(class_details.owner == check_owner, Error::<T, I>::NoPermission); ensure!(collection_details.owner == check_owner, Error::<T, I>::NoPermission);
} }
ensure!(class_details.instances == witness.instances, Error::<T, I>::BadWitness); ensure!(collection_details.items == witness.items, Error::<T, I>::BadWitness);
ensure!( ensure!(
class_details.instance_metadatas == witness.instance_metadatas, collection_details.item_metadatas == witness.item_metadatas,
Error::<T, I>::BadWitness Error::<T, I>::BadWitness
); );
ensure!(class_details.attributes == witness.attributes, Error::<T, I>::BadWitness); ensure!(collection_details.attributes == witness.attributes, Error::<T, I>::BadWitness);
for (instance, details) in Asset::<T, I>::drain_prefix(&class) { for (item, details) in Item::<T, I>::drain_prefix(&collection) {
Account::<T, I>::remove((&details.owner, &class, &instance)); Account::<T, I>::remove((&details.owner, &collection, &item));
} }
InstanceMetadataOf::<T, I>::remove_prefix(&class, None); ItemMetadataOf::<T, I>::remove_prefix(&collection, None);
ClassMetadataOf::<T, I>::remove(&class); CollectionMetadataOf::<T, I>::remove(&collection);
Attribute::<T, I>::remove_prefix((&class,), None); Attribute::<T, I>::remove_prefix((&collection,), None);
ClassAccount::<T, I>::remove(&class_details.owner, &class); CollectionAccount::<T, I>::remove(&collection_details.owner, &collection);
T::Currency::unreserve(&class_details.owner, class_details.total_deposit); T::Currency::unreserve(&collection_details.owner, collection_details.total_deposit);
Self::deposit_event(Event::Destroyed { class }); Self::deposit_event(Event::Destroyed { collection });
Ok(DestroyWitness { Ok(DestroyWitness {
instances: class_details.instances, items: collection_details.items,
instance_metadatas: class_details.instance_metadatas, item_metadatas: collection_details.item_metadatas,
attributes: class_details.attributes, attributes: collection_details.attributes,
}) })
}) })
} }
pub fn do_mint( pub fn do_mint(
class: T::ClassId, collection: T::CollectionId,
instance: T::InstanceId, item: T::ItemId,
owner: T::AccountId, owner: T::AccountId,
with_details: impl FnOnce(&ClassDetailsFor<T, I>) -> DispatchResult, with_details: impl FnOnce(&CollectionDetailsFor<T, I>) -> DispatchResult,
) -> DispatchResult { ) -> DispatchResult {
ensure!(!Asset::<T, I>::contains_key(class, instance), Error::<T, I>::AlreadyExists); ensure!(!Item::<T, I>::contains_key(collection, item), Error::<T, I>::AlreadyExists);
Class::<T, I>::try_mutate(&class, |maybe_class_details| -> DispatchResult { Collection::<T, I>::try_mutate(
let class_details = maybe_class_details.as_mut().ok_or(Error::<T, I>::UnknownClass)?; &collection,
|maybe_collection_details| -> DispatchResult {
let collection_details =
maybe_collection_details.as_mut().ok_or(Error::<T, I>::UnknownCollection)?;
with_details(class_details)?; with_details(collection_details)?;
let instances = let items =
class_details.instances.checked_add(1).ok_or(ArithmeticError::Overflow)?; collection_details.items.checked_add(1).ok_or(ArithmeticError::Overflow)?;
class_details.instances = instances; collection_details.items = items;
let deposit = match class_details.free_holding { let deposit = match collection_details.free_holding {
true => Zero::zero(), true => Zero::zero(),
false => T::InstanceDeposit::get(), false => T::ItemDeposit::get(),
}; };
T::Currency::reserve(&class_details.owner, deposit)?; T::Currency::reserve(&collection_details.owner, deposit)?;
class_details.total_deposit += deposit; collection_details.total_deposit += deposit;
let owner = owner.clone(); let owner = owner.clone();
Account::<T, I>::insert((&owner, &class, &instance), ()); Account::<T, I>::insert((&owner, &collection, &item), ());
let details = InstanceDetails { owner, approved: None, is_frozen: false, deposit }; let details = ItemDetails { owner, approved: None, is_frozen: false, deposit };
Asset::<T, I>::insert(&class, &instance, details); Item::<T, I>::insert(&collection, &item, details);
Ok(()) Ok(())
})?; },
)?;
Self::deposit_event(Event::Issued { class, instance, owner }); Self::deposit_event(Event::Issued { collection, item, owner });
Ok(()) Ok(())
} }
pub fn do_burn( pub fn do_burn(
class: T::ClassId, collection: T::CollectionId,
instance: T::InstanceId, item: T::ItemId,
with_details: impl FnOnce(&ClassDetailsFor<T, I>, &InstanceDetailsFor<T, I>) -> DispatchResult, with_details: impl FnOnce(&CollectionDetailsFor<T, I>, &ItemDetailsFor<T, I>) -> DispatchResult,
) -> DispatchResult { ) -> DispatchResult {
let owner = Class::<T, I>::try_mutate( let owner = Collection::<T, I>::try_mutate(
&class, &collection,
|maybe_class_details| -> Result<T::AccountId, DispatchError> { |maybe_collection_details| -> Result<T::AccountId, DispatchError> {
let class_details = let collection_details =
maybe_class_details.as_mut().ok_or(Error::<T, I>::UnknownClass)?; maybe_collection_details.as_mut().ok_or(Error::<T, I>::UnknownCollection)?;
let details = let details = Item::<T, I>::get(&collection, &item)
Asset::<T, I>::get(&class, &instance).ok_or(Error::<T, I>::UnknownClass)?; .ok_or(Error::<T, I>::UnknownCollection)?;
with_details(class_details, &details)?; with_details(collection_details, &details)?;
// Return the deposit. // Return the deposit.
T::Currency::unreserve(&class_details.owner, details.deposit); T::Currency::unreserve(&collection_details.owner, details.deposit);
class_details.total_deposit.saturating_reduce(details.deposit); collection_details.total_deposit.saturating_reduce(details.deposit);
class_details.instances.saturating_dec(); collection_details.items.saturating_dec();
Ok(details.owner) Ok(details.owner)
}, },
)?; )?;
Asset::<T, I>::remove(&class, &instance); Item::<T, I>::remove(&collection, &item);
Account::<T, I>::remove((&owner, &class, &instance)); Account::<T, I>::remove((&owner, &collection, &item));
Self::deposit_event(Event::Burned { class, instance, owner }); Self::deposit_event(Event::Burned { collection, item, owner });
Ok(()) Ok(())
} }
} }
@@ -26,59 +26,59 @@ use sp_runtime::{DispatchError, DispatchResult};
use sp_std::prelude::*; use sp_std::prelude::*;
impl<T: Config<I>, I: 'static> Inspect<<T as SystemConfig>::AccountId> for Pallet<T, I> { impl<T: Config<I>, I: 'static> Inspect<<T as SystemConfig>::AccountId> for Pallet<T, I> {
type InstanceId = T::InstanceId; type ItemId = T::ItemId;
type ClassId = T::ClassId; type CollectionId = T::CollectionId;
fn owner( fn owner(
class: &Self::ClassId, collection: &Self::CollectionId,
instance: &Self::InstanceId, item: &Self::ItemId,
) -> Option<<T as SystemConfig>::AccountId> { ) -> Option<<T as SystemConfig>::AccountId> {
Asset::<T, I>::get(class, instance).map(|a| a.owner) Item::<T, I>::get(collection, item).map(|a| a.owner)
} }
fn class_owner(class: &Self::ClassId) -> Option<<T as SystemConfig>::AccountId> { fn collection_owner(collection: &Self::CollectionId) -> Option<<T as SystemConfig>::AccountId> {
Class::<T, I>::get(class).map(|a| a.owner) Collection::<T, I>::get(collection).map(|a| a.owner)
} }
/// Returns the attribute value of `instance` of `class` corresponding to `key`. /// Returns the attribute value of `item` of `collection` corresponding to `key`.
/// ///
/// When `key` is empty, we return the instance metadata value. /// When `key` is empty, we return the item metadata value.
/// ///
/// By default this is `None`; no attributes are defined. /// By default this is `None`; no attributes are defined.
fn attribute( fn attribute(
class: &Self::ClassId, collection: &Self::CollectionId,
instance: &Self::InstanceId, item: &Self::ItemId,
key: &[u8], key: &[u8],
) -> Option<Vec<u8>> { ) -> Option<Vec<u8>> {
if key.is_empty() { if key.is_empty() {
// We make the empty key map to the instance metadata value. // We make the empty key map to the item metadata value.
InstanceMetadataOf::<T, I>::get(class, instance).map(|m| m.data.into()) ItemMetadataOf::<T, I>::get(collection, item).map(|m| m.data.into())
} else { } else {
let key = BoundedSlice::<_, _>::try_from(key).ok()?; let key = BoundedSlice::<_, _>::try_from(key).ok()?;
Attribute::<T, I>::get((class, Some(instance), key)).map(|a| a.0.into()) Attribute::<T, I>::get((collection, Some(item), key)).map(|a| a.0.into())
} }
} }
/// Returns the attribute value of `instance` of `class` corresponding to `key`. /// Returns the attribute value of `item` of `collection` corresponding to `key`.
/// ///
/// When `key` is empty, we return the instance metadata value. /// When `key` is empty, we return the item metadata value.
/// ///
/// By default this is `None`; no attributes are defined. /// By default this is `None`; no attributes are defined.
fn class_attribute(class: &Self::ClassId, key: &[u8]) -> Option<Vec<u8>> { fn collection_attribute(collection: &Self::CollectionId, key: &[u8]) -> Option<Vec<u8>> {
if key.is_empty() { if key.is_empty() {
// We make the empty key map to the instance metadata value. // We make the empty key map to the item metadata value.
ClassMetadataOf::<T, I>::get(class).map(|m| m.data.into()) CollectionMetadataOf::<T, I>::get(collection).map(|m| m.data.into())
} else { } else {
let key = BoundedSlice::<_, _>::try_from(key).ok()?; let key = BoundedSlice::<_, _>::try_from(key).ok()?;
Attribute::<T, I>::get((class, Option::<T::InstanceId>::None, key)).map(|a| a.0.into()) Attribute::<T, I>::get((collection, Option::<T::ItemId>::None, key)).map(|a| a.0.into())
} }
} }
/// Returns `true` if the asset `instance` of `class` may be transferred. /// Returns `true` if the `item` of `collection` may be transferred.
/// ///
/// Default implementation is that all assets are transferable. /// Default implementation is that all items are transferable.
fn can_transfer(class: &Self::ClassId, instance: &Self::InstanceId) -> bool { fn can_transfer(collection: &Self::CollectionId, item: &Self::ItemId) -> bool {
match (Class::<T, I>::get(class), Asset::<T, I>::get(class, instance)) { match (Collection::<T, I>::get(collection), Item::<T, I>::get(collection, item)) {
(Some(cd), Some(id)) if !cd.is_frozen && !id.is_frozen => true, (Some(cd), Some(id)) if !cd.is_frozen && !id.is_frozen => true,
_ => false, _ => false,
} }
@@ -86,19 +86,19 @@ impl<T: Config<I>, I: 'static> Inspect<<T as SystemConfig>::AccountId> for Palle
} }
impl<T: Config<I>, I: 'static> Create<<T as SystemConfig>::AccountId> for Pallet<T, I> { impl<T: Config<I>, I: 'static> Create<<T as SystemConfig>::AccountId> for Pallet<T, I> {
/// Create a `class` 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_class( fn create_collection(
class: &Self::ClassId, collection: &Self::CollectionId,
who: &T::AccountId, who: &T::AccountId,
admin: &T::AccountId, admin: &T::AccountId,
) -> DispatchResult { ) -> DispatchResult {
Self::do_create_class( Self::do_create_collection(
*class, *collection,
who.clone(), who.clone(),
admin.clone(), admin.clone(),
T::ClassDeposit::get(), T::CollectionDeposit::get(),
false, false,
Event::Created { class: *class, creator: who.clone(), owner: admin.clone() }, Event::Created { collection: *collection, creator: who.clone(), owner: admin.clone() },
) )
} }
} }
@@ -106,34 +106,34 @@ impl<T: Config<I>, I: 'static> Create<<T as SystemConfig>::AccountId> for Pallet
impl<T: Config<I>, I: 'static> Destroy<<T as SystemConfig>::AccountId> for Pallet<T, I> { impl<T: Config<I>, I: 'static> Destroy<<T as SystemConfig>::AccountId> for Pallet<T, I> {
type DestroyWitness = DestroyWitness; type DestroyWitness = DestroyWitness;
fn get_destroy_witness(class: &Self::ClassId) -> Option<DestroyWitness> { fn get_destroy_witness(collection: &Self::CollectionId) -> Option<DestroyWitness> {
Class::<T, I>::get(class).map(|a| a.destroy_witness()) Collection::<T, I>::get(collection).map(|a| a.destroy_witness())
} }
fn destroy( fn destroy(
class: Self::ClassId, collection: Self::CollectionId,
witness: Self::DestroyWitness, witness: Self::DestroyWitness,
maybe_check_owner: Option<T::AccountId>, maybe_check_owner: Option<T::AccountId>,
) -> Result<Self::DestroyWitness, DispatchError> { ) -> Result<Self::DestroyWitness, DispatchError> {
Self::do_destroy_class(class, witness, maybe_check_owner) Self::do_destroy_collection(collection, witness, maybe_check_owner)
} }
} }
impl<T: Config<I>, I: 'static> Mutate<<T as SystemConfig>::AccountId> for Pallet<T, I> { impl<T: Config<I>, I: 'static> Mutate<<T as SystemConfig>::AccountId> for Pallet<T, I> {
fn mint_into( fn mint_into(
class: &Self::ClassId, collection: &Self::CollectionId,
instance: &Self::InstanceId, item: &Self::ItemId,
who: &T::AccountId, who: &T::AccountId,
) -> DispatchResult { ) -> DispatchResult {
Self::do_mint(*class, *instance, who.clone(), |_| Ok(())) Self::do_mint(*collection, *item, who.clone(), |_| Ok(()))
} }
fn burn( fn burn(
class: &Self::ClassId, collection: &Self::CollectionId,
instance: &Self::InstanceId, item: &Self::ItemId,
maybe_check_owner: Option<&T::AccountId>, maybe_check_owner: Option<&T::AccountId>,
) -> DispatchResult { ) -> DispatchResult {
Self::do_burn(*class, *instance, |_, d| { Self::do_burn(*collection, *item, |_, d| {
if let Some(check_owner) = maybe_check_owner { if let Some(check_owner) = maybe_check_owner {
if &d.owner != check_owner { if &d.owner != check_owner {
return Err(Error::<T, I>::NoPermission.into()) return Err(Error::<T, I>::NoPermission.into())
@@ -146,43 +146,43 @@ impl<T: Config<I>, I: 'static> Mutate<<T as SystemConfig>::AccountId> for Pallet
impl<T: Config<I>, I: 'static> Transfer<T::AccountId> for Pallet<T, I> { impl<T: Config<I>, I: 'static> Transfer<T::AccountId> for Pallet<T, I> {
fn transfer( fn transfer(
class: &Self::ClassId, collection: &Self::CollectionId,
instance: &Self::InstanceId, item: &Self::ItemId,
destination: &T::AccountId, destination: &T::AccountId,
) -> DispatchResult { ) -> DispatchResult {
Self::do_transfer(*class, *instance, destination.clone(), |_, _| Ok(())) Self::do_transfer(*collection, *item, destination.clone(), |_, _| Ok(()))
} }
} }
impl<T: Config<I>, I: 'static> InspectEnumerable<T::AccountId> for Pallet<T, I> { impl<T: Config<I>, I: 'static> InspectEnumerable<T::AccountId> for Pallet<T, I> {
/// Returns an iterator of the asset classes in existence. /// Returns an iterator of the collections in existence.
/// ///
/// NOTE: iterating this list invokes a storage read per item. /// NOTE: iterating this list invokes a storage read per item.
fn classes() -> Box<dyn Iterator<Item = Self::ClassId>> { fn collections() -> Box<dyn Iterator<Item = Self::CollectionId>> {
Box::new(ClassMetadataOf::<T, I>::iter_keys()) Box::new(CollectionMetadataOf::<T, I>::iter_keys())
} }
/// Returns an iterator of the instances of an asset `class` in existence. /// Returns an iterator of the items of a `collection` in existence.
/// ///
/// NOTE: iterating this list invokes a storage read per item. /// NOTE: iterating this list invokes a storage read per item.
fn instances(class: &Self::ClassId) -> Box<dyn Iterator<Item = Self::InstanceId>> { fn items(collection: &Self::CollectionId) -> Box<dyn Iterator<Item = Self::ItemId>> {
Box::new(InstanceMetadataOf::<T, I>::iter_key_prefix(class)) Box::new(ItemMetadataOf::<T, I>::iter_key_prefix(collection))
} }
/// Returns an iterator of the asset instances of all classes owned by `who`. /// Returns an iterator of the items of all collections owned by `who`.
/// ///
/// NOTE: iterating this list invokes a storage read per item. /// NOTE: iterating this list invokes a storage read per item.
fn owned(who: &T::AccountId) -> Box<dyn Iterator<Item = (Self::ClassId, Self::InstanceId)>> { fn owned(who: &T::AccountId) -> Box<dyn Iterator<Item = (Self::CollectionId, Self::ItemId)>> {
Box::new(Account::<T, I>::iter_key_prefix((who,))) Box::new(Account::<T, I>::iter_key_prefix((who,)))
} }
/// Returns an iterator of the asset instances of `class` owned by `who`. /// Returns an iterator of the items of `collection` owned by `who`.
/// ///
/// NOTE: iterating this list invokes a storage read per item. /// NOTE: iterating this list invokes a storage read per item.
fn owned_in_class( fn owned_in_collection(
class: &Self::ClassId, collection: &Self::CollectionId,
who: &T::AccountId, who: &T::AccountId,
) -> Box<dyn Iterator<Item = Self::InstanceId>> { ) -> Box<dyn Iterator<Item = Self::ItemId>> {
Box::new(Account::<T, I>::iter_key_prefix((who, class))) Box::new(Account::<T, I>::iter_key_prefix((who, collection)))
} }
} }
File diff suppressed because it is too large Load Diff
+2 -2
View File
@@ -34,8 +34,8 @@ pub fn migrate_to_v1<T: Config<I>, I: 'static, P: GetStorageVersion + PalletInfo
if on_chain_storage_version < 1 { if on_chain_storage_version < 1 {
let mut count = 0; let mut count = 0;
for (class, detail) in Class::<T, I>::iter() { for (collection, detail) in Collection::<T, I>::iter() {
ClassAccount::<T, I>::insert(&detail.owner, &class, ()); CollectionAccount::<T, I>::insert(&detail.owner, &collection, ());
count += 1; count += 1;
} }
StorageVersion::new(1).put::<P>(); StorageVersion::new(1).put::<P>();
+5 -5
View File
@@ -15,7 +15,7 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
//! Test environment for Assets pallet. //! Test environment for Uniques pallet.
use super::*; use super::*;
use crate as pallet_uniques; use crate as pallet_uniques;
@@ -86,14 +86,14 @@ impl pallet_balances::Config for Test {
impl Config for Test { impl Config for Test {
type Event = Event; type Event = Event;
type ClassId = u32; type CollectionId = u32;
type InstanceId = u32; type ItemId = u32;
type Currency = Balances; type Currency = Balances;
type CreateOrigin = AsEnsureOriginWithArg<frame_system::EnsureSigned<u64>>; type CreateOrigin = AsEnsureOriginWithArg<frame_system::EnsureSigned<u64>>;
type ForceOrigin = frame_system::EnsureRoot<u64>; type ForceOrigin = frame_system::EnsureRoot<u64>;
type Locker = (); type Locker = ();
type ClassDeposit = ConstU64<2>; type CollectionDeposit = ConstU64<2>;
type InstanceDeposit = ConstU64<1>; type ItemDeposit = ConstU64<1>;
type MetadataDepositBase = ConstU64<1>; type MetadataDepositBase = ConstU64<1>;
type AttributeDepositBase = ConstU64<1>; type AttributeDepositBase = ConstU64<1>;
type DepositPerByte = ConstU64<1>; type DepositPerByte = ConstU64<1>;
+94 -88
View File
@@ -23,13 +23,13 @@ use frame_support::{assert_noop, assert_ok, traits::Currency};
use pallet_balances::Error as BalancesError; use pallet_balances::Error as BalancesError;
use sp_std::prelude::*; use sp_std::prelude::*;
fn assets() -> Vec<(u64, u32, u32)> { fn items() -> Vec<(u64, u32, u32)> {
let mut r: Vec<_> = Account::<Test>::iter().map(|x| x.0).collect(); let mut r: Vec<_> = Account::<Test>::iter().map(|x| x.0).collect();
r.sort(); r.sort();
let mut s: Vec<_> = Asset::<Test>::iter().map(|x| (x.2.owner, x.0, x.1)).collect(); let mut s: Vec<_> = Item::<Test>::iter().map(|x| (x.2.owner, x.0, x.1)).collect();
s.sort(); s.sort();
assert_eq!(r, s); assert_eq!(r, s);
for class in Asset::<Test>::iter() for collection in Item::<Test>::iter()
.map(|x| x.0) .map(|x| x.0)
.scan(None, |s, item| { .scan(None, |s, item| {
if s.map_or(false, |last| last == item) { if s.map_or(false, |last| last == item) {
@@ -41,17 +41,17 @@ fn assets() -> Vec<(u64, u32, u32)> {
}) })
.flatten() .flatten()
{ {
let details = Class::<Test>::get(class).unwrap(); let details = Collection::<Test>::get(collection).unwrap();
let instances = Asset::<Test>::iter_prefix(class).count() as u32; let items = Item::<Test>::iter_prefix(collection).count() as u32;
assert_eq!(details.instances, instances); assert_eq!(details.items, items);
} }
r r
} }
fn classes() -> Vec<(u64, u32)> { fn collections() -> Vec<(u64, u32)> {
let mut r: Vec<_> = ClassAccount::<Test>::iter().map(|x| (x.0, x.1)).collect(); let mut r: Vec<_> = CollectionAccount::<Test>::iter().map(|x| (x.0, x.1)).collect();
r.sort(); r.sort();
let mut s: Vec<_> = Class::<Test>::iter().map(|x| (x.1.owner, x.0)).collect(); let mut s: Vec<_> = Collection::<Test>::iter().map(|x| (x.1.owner, x.0)).collect();
s.sort(); s.sort();
assert_eq!(r, s); assert_eq!(r, s);
r r
@@ -63,8 +63,8 @@ macro_rules! bvec {
} }
} }
fn attributes(class: u32) -> Vec<(Option<u32>, Vec<u8>, Vec<u8>)> { fn attributes(collection: u32) -> Vec<(Option<u32>, Vec<u8>, Vec<u8>)> {
let mut s: Vec<_> = Attribute::<Test>::iter_prefix((class,)) let mut s: Vec<_> = Attribute::<Test>::iter_prefix((collection,))
.map(|(k, v)| (k.0, k.1.into(), v.0.into())) .map(|(k, v)| (k.0, k.1.into(), v.0.into()))
.collect(); .collect();
s.sort(); s.sort();
@@ -74,7 +74,7 @@ fn attributes(class: u32) -> Vec<(Option<u32>, Vec<u8>, Vec<u8>)> {
#[test] #[test]
fn basic_setup_works() { fn basic_setup_works() {
new_test_ext().execute_with(|| { new_test_ext().execute_with(|| {
assert_eq!(assets(), vec![]); assert_eq!(items(), vec![]);
}); });
} }
@@ -82,14 +82,14 @@ fn basic_setup_works() {
fn basic_minting_should_work() { fn basic_minting_should_work() {
new_test_ext().execute_with(|| { new_test_ext().execute_with(|| {
assert_ok!(Uniques::force_create(Origin::root(), 0, 1, true)); assert_ok!(Uniques::force_create(Origin::root(), 0, 1, true));
assert_eq!(classes(), vec![(1, 0)]); assert_eq!(collections(), vec![(1, 0)]);
assert_ok!(Uniques::mint(Origin::signed(1), 0, 42, 1)); assert_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_ok!(Uniques::force_create(Origin::root(), 1, 2, true));
assert_eq!(classes(), vec![(1, 0), (2, 1)]); assert_eq!(collections(), vec![(1, 0), (2, 1)]);
assert_ok!(Uniques::mint(Origin::signed(2), 1, 69, 1)); assert_ok!(Uniques::mint(Origin::signed(2), 1, 69, 1));
assert_eq!(assets(), vec![(1, 0, 42), (1, 1, 69)]); assert_eq!(items(), vec![(1, 0, 42), (1, 1, 69)]);
}); });
} }
@@ -99,40 +99,40 @@ fn lifecycle_should_work() {
Balances::make_free_balance_be(&1, 100); Balances::make_free_balance_be(&1, 100);
assert_ok!(Uniques::create(Origin::signed(1), 0, 1)); assert_ok!(Uniques::create(Origin::signed(1), 0, 1));
assert_eq!(Balances::reserved_balance(&1), 2); assert_eq!(Balances::reserved_balance(&1), 2);
assert_eq!(classes(), vec![(1, 0)]); assert_eq!(collections(), vec![(1, 0)]);
assert_ok!(Uniques::set_class_metadata(Origin::signed(1), 0, bvec![0, 0], false)); assert_ok!(Uniques::set_collection_metadata(Origin::signed(1), 0, bvec![0, 0], false));
assert_eq!(Balances::reserved_balance(&1), 5); assert_eq!(Balances::reserved_balance(&1), 5);
assert!(ClassMetadataOf::<Test>::contains_key(0)); assert!(CollectionMetadataOf::<Test>::contains_key(0));
assert_ok!(Uniques::mint(Origin::signed(1), 0, 42, 10)); assert_ok!(Uniques::mint(Origin::signed(1), 0, 42, 10));
assert_eq!(Balances::reserved_balance(&1), 6); assert_eq!(Balances::reserved_balance(&1), 6);
assert_ok!(Uniques::mint(Origin::signed(1), 0, 69, 20)); assert_ok!(Uniques::mint(Origin::signed(1), 0, 69, 20));
assert_eq!(Balances::reserved_balance(&1), 7); assert_eq!(Balances::reserved_balance(&1), 7);
assert_eq!(assets(), vec![(10, 0, 42), (20, 0, 69)]); assert_eq!(items(), vec![(10, 0, 42), (20, 0, 69)]);
assert_eq!(Class::<Test>::get(0).unwrap().instances, 2); assert_eq!(Collection::<Test>::get(0).unwrap().items, 2);
assert_eq!(Class::<Test>::get(0).unwrap().instance_metadatas, 0); assert_eq!(Collection::<Test>::get(0).unwrap().item_metadatas, 0);
assert_ok!(Uniques::set_metadata(Origin::signed(1), 0, 42, bvec![42, 42], false)); assert_ok!(Uniques::set_metadata(Origin::signed(1), 0, 42, bvec![42, 42], false));
assert_eq!(Balances::reserved_balance(&1), 10); assert_eq!(Balances::reserved_balance(&1), 10);
assert!(InstanceMetadataOf::<Test>::contains_key(0, 42)); assert!(ItemMetadataOf::<Test>::contains_key(0, 42));
assert_ok!(Uniques::set_metadata(Origin::signed(1), 0, 69, bvec![69, 69], false)); assert_ok!(Uniques::set_metadata(Origin::signed(1), 0, 69, bvec![69, 69], false));
assert_eq!(Balances::reserved_balance(&1), 13); assert_eq!(Balances::reserved_balance(&1), 13);
assert!(InstanceMetadataOf::<Test>::contains_key(0, 69)); assert!(ItemMetadataOf::<Test>::contains_key(0, 69));
let w = Class::<Test>::get(0).unwrap().destroy_witness(); let w = Collection::<Test>::get(0).unwrap().destroy_witness();
assert_eq!(w.instances, 2); assert_eq!(w.items, 2);
assert_eq!(w.instance_metadatas, 2); assert_eq!(w.item_metadatas, 2);
assert_ok!(Uniques::destroy(Origin::signed(1), 0, w)); assert_ok!(Uniques::destroy(Origin::signed(1), 0, w));
assert_eq!(Balances::reserved_balance(&1), 0); assert_eq!(Balances::reserved_balance(&1), 0);
assert!(!Class::<Test>::contains_key(0)); assert!(!Collection::<Test>::contains_key(0));
assert!(!Asset::<Test>::contains_key(0, 42)); assert!(!Item::<Test>::contains_key(0, 42));
assert!(!Asset::<Test>::contains_key(0, 69)); assert!(!Item::<Test>::contains_key(0, 69));
assert!(!ClassMetadataOf::<Test>::contains_key(0)); assert!(!CollectionMetadataOf::<Test>::contains_key(0));
assert!(!InstanceMetadataOf::<Test>::contains_key(0, 42)); assert!(!ItemMetadataOf::<Test>::contains_key(0, 42));
assert!(!InstanceMetadataOf::<Test>::contains_key(0, 69)); assert!(!ItemMetadataOf::<Test>::contains_key(0, 69));
assert_eq!(classes(), vec![]); assert_eq!(collections(), vec![]);
assert_eq!(assets(), vec![]); assert_eq!(items(), vec![]);
}); });
} }
@@ -142,7 +142,7 @@ fn destroy_with_bad_witness_should_not_work() {
Balances::make_free_balance_be(&1, 100); Balances::make_free_balance_be(&1, 100);
assert_ok!(Uniques::create(Origin::signed(1), 0, 1)); assert_ok!(Uniques::create(Origin::signed(1), 0, 1));
let w = Class::<Test>::get(0).unwrap().destroy_witness(); let w = Collection::<Test>::get(0).unwrap().destroy_witness();
assert_ok!(Uniques::mint(Origin::signed(1), 0, 42, 1)); assert_ok!(Uniques::mint(Origin::signed(1), 0, 42, 1));
assert_noop!(Uniques::destroy(Origin::signed(1), 0, w), Error::<Test>::BadWitness); assert_noop!(Uniques::destroy(Origin::signed(1), 0, w), Error::<Test>::BadWitness);
}); });
@@ -154,8 +154,8 @@ fn mint_should_work() {
assert_ok!(Uniques::force_create(Origin::root(), 0, 1, true)); assert_ok!(Uniques::force_create(Origin::root(), 0, 1, true));
assert_ok!(Uniques::mint(Origin::signed(1), 0, 42, 1)); assert_ok!(Uniques::mint(Origin::signed(1), 0, 42, 1));
assert_eq!(Uniques::owner(0, 42).unwrap(), 1); assert_eq!(Uniques::owner(0, 42).unwrap(), 1);
assert_eq!(classes(), vec![(1, 0)]); 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::mint(Origin::signed(1), 0, 42, 2));
assert_ok!(Uniques::transfer(Origin::signed(2), 0, 42, 3)); 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::<Test>::NoPermission); assert_noop!(Uniques::transfer(Origin::signed(2), 0, 42, 4), Error::<Test>::NoPermission);
assert_ok!(Uniques::approve_transfer(Origin::signed(3), 0, 42, 2)); assert_ok!(Uniques::approve_transfer(Origin::signed(3), 0, 42, 2));
@@ -183,10 +183,10 @@ fn freezing_should_work() {
assert_noop!(Uniques::transfer(Origin::signed(1), 0, 42, 2), Error::<Test>::Frozen); assert_noop!(Uniques::transfer(Origin::signed(1), 0, 42, 2), Error::<Test>::Frozen);
assert_ok!(Uniques::thaw(Origin::signed(1), 0, 42)); 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::<Test>::Frozen); assert_noop!(Uniques::transfer(Origin::signed(1), 0, 42, 2), Error::<Test>::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)); 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::<Test>::NoPermission); assert_noop!(Uniques::thaw(Origin::signed(2), 0, 42), Error::<Test>::NoPermission);
assert_noop!(Uniques::mint(Origin::signed(2), 0, 69, 2), Error::<Test>::NoPermission); assert_noop!(Uniques::mint(Origin::signed(2), 0, 69, 2), Error::<Test>::NoPermission);
assert_noop!(Uniques::burn(Origin::signed(2), 0, 42, None), Error::<Test>::NoPermission); assert_noop!(Uniques::burn(Origin::signed(2), 0, 42, None), Error::<Test>::NoPermission);
let w = Class::<Test>::get(0).unwrap().destroy_witness(); let w = Collection::<Test>::get(0).unwrap().destroy_witness();
assert_noop!(Uniques::destroy(Origin::signed(2), 0, w), Error::<Test>::NoPermission); assert_noop!(Uniques::destroy(Origin::signed(2), 0, w), Error::<Test>::NoPermission);
}); });
} }
@@ -220,7 +220,7 @@ fn transfer_owner_should_work() {
Balances::make_free_balance_be(&2, 100); Balances::make_free_balance_be(&2, 100);
Balances::make_free_balance_be(&3, 100); Balances::make_free_balance_be(&3, 100);
assert_ok!(Uniques::create(Origin::signed(1), 0, 1)); assert_ok!(Uniques::create(Origin::signed(1), 0, 1));
assert_eq!(classes(), vec![(1, 0)]); assert_eq!(collections(), vec![(1, 0)]);
assert_noop!( assert_noop!(
Uniques::transfer_ownership(Origin::signed(1), 0, 2), Uniques::transfer_ownership(Origin::signed(1), 0, 2),
Error::<Test>::Unaccepted Error::<Test>::Unaccepted
@@ -228,7 +228,7 @@ fn transfer_owner_should_work() {
assert_ok!(Uniques::set_accept_ownership(Origin::signed(2), Some(0))); assert_ok!(Uniques::set_accept_ownership(Origin::signed(2), Some(0)));
assert_ok!(Uniques::transfer_ownership(Origin::signed(1), 0, 2)); assert_ok!(Uniques::transfer_ownership(Origin::signed(1), 0, 2));
assert_eq!(classes(), vec![(2, 0)]); assert_eq!(collections(), vec![(2, 0)]);
assert_eq!(Balances::total_balance(&1), 98); assert_eq!(Balances::total_balance(&1), 98);
assert_eq!(Balances::total_balance(&2), 102); assert_eq!(Balances::total_balance(&2), 102);
assert_eq!(Balances::reserved_balance(&1), 0); 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. // 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::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_metadata(Origin::signed(2), 0, 42, bvec![0u8; 20], false));
assert_ok!(Uniques::set_accept_ownership(Origin::signed(3), Some(0))); assert_ok!(Uniques::set_accept_ownership(Origin::signed(3), Some(0)));
assert_ok!(Uniques::transfer_ownership(Origin::signed(2), 0, 3)); assert_ok!(Uniques::transfer_ownership(Origin::signed(2), 0, 3));
assert_eq!(classes(), vec![(3, 0)]); assert_eq!(collections(), vec![(3, 0)]);
assert_eq!(Balances::total_balance(&2), 57); assert_eq!(Balances::total_balance(&2), 57);
assert_eq!(Balances::total_balance(&3), 145); assert_eq!(Balances::total_balance(&3), 145);
assert_eq!(Balances::reserved_balance(&2), 0); assert_eq!(Balances::reserved_balance(&2), 0);
@@ -276,73 +276,76 @@ fn set_team_should_work() {
} }
#[test] #[test]
fn set_class_metadata_should_work() { fn set_collection_metadata_should_work() {
new_test_ext().execute_with(|| { new_test_ext().execute_with(|| {
// Cannot add metadata to unknown asset // Cannot add metadata to unknown item
assert_noop!( assert_noop!(
Uniques::set_class_metadata(Origin::signed(1), 0, bvec![0u8; 20], false), Uniques::set_collection_metadata(Origin::signed(1), 0, bvec![0u8; 20], false),
Error::<Test>::UnknownClass, Error::<Test>::UnknownCollection,
); );
assert_ok!(Uniques::force_create(Origin::root(), 0, 1, false)); assert_ok!(Uniques::force_create(Origin::root(), 0, 1, false));
// Cannot add metadata to unowned asset // Cannot add metadata to unowned item
assert_noop!( 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::<Test>::NoPermission, Error::<Test>::NoPermission,
); );
// Successfully add metadata and take deposit // Successfully add metadata and take deposit
Balances::make_free_balance_be(&1, 30); 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_eq!(Balances::free_balance(&1), 9);
assert!(ClassMetadataOf::<Test>::contains_key(0)); assert!(CollectionMetadataOf::<Test>::contains_key(0));
// Force origin works, too. // 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 // 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_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); assert_eq!(Balances::free_balance(&1), 4);
// Cannot over-reserve // Cannot over-reserve
assert_noop!( 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::<Test, _>::InsufficientBalance, BalancesError::<Test, _>::InsufficientBalance,
); );
// Can't set or clear metadata once frozen // 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!( 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::<Test, _>::Frozen, Error::<Test, _>::Frozen,
); );
assert_noop!(Uniques::clear_class_metadata(Origin::signed(1), 0), Error::<Test>::Frozen); assert_noop!(
Uniques::clear_collection_metadata(Origin::signed(1), 0),
Error::<Test>::Frozen
);
// Clear Metadata // 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!( assert_noop!(
Uniques::clear_class_metadata(Origin::signed(2), 0), Uniques::clear_collection_metadata(Origin::signed(2), 0),
Error::<Test>::NoPermission Error::<Test>::NoPermission
); );
assert_noop!( assert_noop!(
Uniques::clear_class_metadata(Origin::signed(1), 1), Uniques::clear_collection_metadata(Origin::signed(1), 1),
Error::<Test>::UnknownClass Error::<Test>::UnknownCollection
); );
assert_ok!(Uniques::clear_class_metadata(Origin::signed(1), 0)); assert_ok!(Uniques::clear_collection_metadata(Origin::signed(1), 0));
assert!(!ClassMetadataOf::<Test>::contains_key(0)); assert!(!CollectionMetadataOf::<Test>::contains_key(0));
}); });
} }
#[test] #[test]
fn set_instance_metadata_should_work() { fn set_item_metadata_should_work() {
new_test_ext().execute_with(|| { new_test_ext().execute_with(|| {
Balances::make_free_balance_be(&1, 30); 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::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, 42, 1));
// Cannot add metadata to unowned asset // Cannot add metadata to unowned item
assert_noop!( assert_noop!(
Uniques::set_metadata(Origin::signed(2), 0, 42, bvec![0u8; 20], false), Uniques::set_metadata(Origin::signed(2), 0, 42, bvec![0u8; 20], false),
Error::<Test>::NoPermission, Error::<Test>::NoPermission,
@@ -351,7 +354,7 @@ fn set_instance_metadata_should_work() {
// Successfully add metadata and take deposit // Successfully add metadata and take deposit
assert_ok!(Uniques::set_metadata(Origin::signed(1), 0, 42, bvec![0u8; 20], false)); assert_ok!(Uniques::set_metadata(Origin::signed(1), 0, 42, bvec![0u8; 20], false));
assert_eq!(Balances::free_balance(&1), 8); assert_eq!(Balances::free_balance(&1), 8);
assert!(InstanceMetadataOf::<Test>::contains_key(0, 42)); assert!(ItemMetadataOf::<Test>::contains_key(0, 42));
// Force origin works, too. // Force origin works, too.
assert_ok!(Uniques::set_metadata(Origin::root(), 0, 42, bvec![0u8; 18], false)); assert_ok!(Uniques::set_metadata(Origin::root(), 0, 42, bvec![0u8; 18], false));
@@ -384,10 +387,10 @@ fn set_instance_metadata_should_work() {
); );
assert_noop!( assert_noop!(
Uniques::clear_metadata(Origin::signed(1), 1, 42), Uniques::clear_metadata(Origin::signed(1), 1, 42),
Error::<Test>::UnknownClass Error::<Test>::UnknownCollection
); );
assert_ok!(Uniques::clear_metadata(Origin::signed(1), 0, 42)); assert_ok!(Uniques::clear_metadata(Origin::signed(1), 0, 42));
assert!(!InstanceMetadataOf::<Test>::contains_key(0, 42)); assert!(!ItemMetadataOf::<Test>::contains_key(0, 42));
}); });
} }
@@ -429,7 +432,7 @@ fn set_attribute_should_work() {
); );
assert_eq!(Balances::reserved_balance(1), 15); assert_eq!(Balances::reserved_balance(1), 15);
let w = Class::<Test>::get(0).unwrap().destroy_witness(); let w = Collection::<Test>::get(0).unwrap().destroy_witness();
assert_ok!(Uniques::destroy(Origin::signed(1), 0, w)); assert_ok!(Uniques::destroy(Origin::signed(1), 0, w));
assert_eq!(attributes(0), vec![]); assert_eq!(attributes(0), vec![]);
assert_eq!(Balances::reserved_balance(1), 0); 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_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::<Test>::Frozen; let e = Error::<Test>::Frozen;
assert_noop!(Uniques::set_attribute(Origin::signed(1), 0, None, bvec![0], bvec![0]), e); 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])); assert_ok!(Uniques::set_attribute(Origin::signed(1), 0, Some(0), bvec![0], bvec![1]));
@@ -469,20 +472,20 @@ fn set_attribute_should_respect_freeze() {
} }
#[test] #[test]
fn force_asset_status_should_work() { fn force_item_status_should_work() {
new_test_ext().execute_with(|| { new_test_ext().execute_with(|| {
Balances::make_free_balance_be(&1, 100); Balances::make_free_balance_be(&1, 100);
assert_ok!(Uniques::force_create(Origin::root(), 0, 1, false)); 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, 42, 1));
assert_ok!(Uniques::mint(Origin::signed(1), 0, 69, 2)); 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, 42, bvec![0; 20], false));
assert_ok!(Uniques::set_metadata(Origin::signed(1), 0, 69, 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); assert_eq!(Balances::reserved_balance(1), 65);
// force asset status to be free holding // force item status to be free holding
assert_ok!(Uniques::force_asset_status(Origin::root(), 0, 1, 1, 1, 1, true, false)); 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, 142, 1));
assert_ok!(Uniques::mint(Origin::signed(1), 0, 169, 2)); assert_ok!(Uniques::mint(Origin::signed(1), 0, 169, 2));
assert_ok!(Uniques::set_metadata(Origin::signed(1), 0, 142, bvec![0; 20], false)); assert_ok!(Uniques::set_metadata(Origin::signed(1), 0, 142, bvec![0; 20], false));
@@ -498,7 +501,7 @@ fn force_asset_status_should_work() {
assert_ok!(Uniques::set_metadata(Origin::signed(1), 0, 69, bvec![0; 20], false)); assert_ok!(Uniques::set_metadata(Origin::signed(1), 0, 69, bvec![0; 20], false));
assert_eq!(Balances::reserved_balance(1), 21); 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); 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::force_create(Origin::root(), 0, 1, false));
assert_ok!(Uniques::set_team(Origin::signed(1), 0, 2, 3, 4)); assert_ok!(Uniques::set_team(Origin::signed(1), 0, 2, 3, 4));
assert_noop!(Uniques::burn(Origin::signed(5), 0, 42, Some(5)), Error::<Test>::UnknownClass); assert_noop!(
Uniques::burn(Origin::signed(5), 0, 42, Some(5)),
Error::<Test>::UnknownCollection
);
assert_ok!(Uniques::mint(Origin::signed(2), 0, 42, 5)); assert_ok!(Uniques::mint(Origin::signed(2), 0, 42, 5));
assert_ok!(Uniques::mint(Origin::signed(2), 0, 69, 5)); assert_ok!(Uniques::mint(Origin::signed(2), 0, 69, 5));
@@ -533,7 +539,7 @@ fn approval_lifecycle_works() {
assert_ok!(Uniques::approve_transfer(Origin::signed(2), 0, 42, 3)); assert_ok!(Uniques::approve_transfer(Origin::signed(2), 0, 42, 3));
assert_ok!(Uniques::transfer(Origin::signed(3), 0, 42, 4)); assert_ok!(Uniques::transfer(Origin::signed(3), 0, 42, 4));
assert_noop!(Uniques::transfer(Origin::signed(3), 0, 42, 3), Error::<Test>::NoPermission); assert_noop!(Uniques::transfer(Origin::signed(3), 0, 42, 3), Error::<Test>::NoPermission);
assert!(Asset::<Test>::get(0, 42).unwrap().approved.is_none()); assert!(Item::<Test>::get(0, 42).unwrap().approved.is_none());
assert_ok!(Uniques::approve_transfer(Origin::signed(4), 0, 42, 2)); assert_ok!(Uniques::approve_transfer(Origin::signed(4), 0, 42, 2));
assert_ok!(Uniques::transfer(Origin::signed(2), 0, 42, 2)); assert_ok!(Uniques::transfer(Origin::signed(2), 0, 42, 2));
@@ -549,11 +555,11 @@ fn cancel_approval_works() {
assert_ok!(Uniques::approve_transfer(Origin::signed(2), 0, 42, 3)); assert_ok!(Uniques::approve_transfer(Origin::signed(2), 0, 42, 3));
assert_noop!( assert_noop!(
Uniques::cancel_approval(Origin::signed(2), 1, 42, None), Uniques::cancel_approval(Origin::signed(2), 1, 42, None),
Error::<Test>::UnknownClass Error::<Test>::UnknownCollection
); );
assert_noop!( assert_noop!(
Uniques::cancel_approval(Origin::signed(2), 0, 43, None), Uniques::cancel_approval(Origin::signed(2), 0, 43, None),
Error::<Test>::UnknownClass Error::<Test>::UnknownCollection
); );
assert_noop!( assert_noop!(
Uniques::cancel_approval(Origin::signed(3), 0, 42, None), 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_ok!(Uniques::approve_transfer(Origin::signed(2), 0, 42, 3));
assert_noop!( assert_noop!(
Uniques::cancel_approval(Origin::signed(1), 1, 42, None), Uniques::cancel_approval(Origin::signed(1), 1, 42, None),
Error::<Test>::UnknownClass Error::<Test>::UnknownCollection
); );
assert_noop!( assert_noop!(
Uniques::cancel_approval(Origin::signed(1), 0, 43, None), Uniques::cancel_approval(Origin::signed(1), 0, 43, None),
Error::<Test>::UnknownClass Error::<Test>::UnknownCollection
); );
assert_noop!( assert_noop!(
Uniques::cancel_approval(Origin::signed(1), 0, 42, Some(4)), 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_ok!(Uniques::approve_transfer(Origin::signed(2), 0, 42, 3));
assert_noop!( assert_noop!(
Uniques::cancel_approval(Origin::root(), 1, 42, None), Uniques::cancel_approval(Origin::root(), 1, 42, None),
Error::<Test>::UnknownClass Error::<Test>::UnknownCollection
); );
assert_noop!( assert_noop!(
Uniques::cancel_approval(Origin::root(), 0, 43, None), Uniques::cancel_approval(Origin::root(), 0, 43, None),
Error::<Test>::UnknownClass Error::<Test>::UnknownCollection
); );
assert_noop!( assert_noop!(
Uniques::cancel_approval(Origin::root(), 0, 42, Some(4)), Uniques::cancel_approval(Origin::root(), 0, 42, Some(4)),
+36 -36
View File
@@ -15,7 +15,7 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
//! Various basic types for use in the assets pallet. //! Various basic types for use in the Uniques pallet.
use super::*; use super::*;
use frame_support::{ use frame_support::{
@@ -26,13 +26,13 @@ use scale_info::TypeInfo;
pub(super) type DepositBalanceOf<T, I = ()> = pub(super) type DepositBalanceOf<T, I = ()> =
<<T as Config<I>>::Currency as Currency<<T as SystemConfig>::AccountId>>::Balance; <<T as Config<I>>::Currency as Currency<<T as SystemConfig>::AccountId>>::Balance;
pub(super) type ClassDetailsFor<T, I> = pub(super) type CollectionDetailsFor<T, I> =
ClassDetails<<T as SystemConfig>::AccountId, DepositBalanceOf<T, I>>; CollectionDetails<<T as SystemConfig>::AccountId, DepositBalanceOf<T, I>>;
pub(super) type InstanceDetailsFor<T, I> = pub(super) type ItemDetailsFor<T, I> =
InstanceDetails<<T as SystemConfig>::AccountId, DepositBalanceOf<T, I>>; ItemDetails<<T as SystemConfig>::AccountId, DepositBalanceOf<T, I>>;
#[derive(Clone, Encode, Decode, Eq, PartialEq, RuntimeDebug, TypeInfo, MaxEncodedLen)] #[derive(Clone, Encode, Decode, Eq, PartialEq, RuntimeDebug, TypeInfo, MaxEncodedLen)]
pub struct ClassDetails<AccountId, DepositBalance> { pub struct CollectionDetails<AccountId, DepositBalance> {
/// Can change `owner`, `issuer`, `freezer` and `admin` accounts. /// Can change `owner`, `issuer`, `freezer` and `admin` accounts.
pub(super) owner: AccountId, pub(super) owner: AccountId,
/// Can mint tokens. /// Can mint tokens.
@@ -41,55 +41,55 @@ pub struct ClassDetails<AccountId, DepositBalance> {
pub(super) admin: AccountId, pub(super) admin: AccountId,
/// Can freeze tokens. /// Can freeze tokens.
pub(super) freezer: AccountId, pub(super) freezer: AccountId,
/// The total balance deposited for the all storage associated with this asset class. Used by /// The total balance deposited for the all storage associated with this collection.
/// `destroy`. /// Used by `destroy`.
pub(super) total_deposit: DepositBalance, pub(super) total_deposit: DepositBalance,
/// If `true`, then no deposit is needed to hold instances of this class. /// If `true`, then no deposit is needed to hold items of this collection.
pub(super) free_holding: bool, pub(super) free_holding: bool,
/// The total number of outstanding instances of this asset class. /// The total number of outstanding items of this collection.
pub(super) instances: u32, pub(super) items: u32,
/// The total number of outstanding instance metadata of this asset class. /// The total number of outstanding item metadata of this collection.
pub(super) instance_metadatas: u32, pub(super) item_metadatas: u32,
/// The total number of attributes for this asset class. /// The total number of attributes for this collection.
pub(super) attributes: u32, pub(super) attributes: u32,
/// Whether the asset is frozen for non-admin transfers. /// Whether the collection is frozen for non-admin transfers.
pub(super) is_frozen: bool, pub(super) is_frozen: bool,
} }
/// Witness data for the destroy transactions. /// Witness data for the destroy transactions.
#[derive(Copy, Clone, Encode, Decode, Eq, PartialEq, RuntimeDebug, TypeInfo, MaxEncodedLen)] #[derive(Copy, Clone, Encode, Decode, Eq, PartialEq, RuntimeDebug, TypeInfo, MaxEncodedLen)]
pub struct DestroyWitness { pub struct DestroyWitness {
/// The total number of outstanding instances of this asset class. /// The total number of outstanding items of this collection.
#[codec(compact)] #[codec(compact)]
pub instances: u32, pub items: u32,
/// The total number of outstanding instance metadata of this asset class. /// The total number of items in this collection that have outstanding item metadata.
#[codec(compact)] #[codec(compact)]
pub instance_metadatas: u32, pub item_metadatas: u32,
#[codec(compact)] #[codec(compact)]
/// The total number of attributes for this asset class. /// The total number of attributes for this collection.
pub attributes: u32, pub attributes: u32,
} }
impl<AccountId, DepositBalance> ClassDetails<AccountId, DepositBalance> { impl<AccountId, DepositBalance> CollectionDetails<AccountId, DepositBalance> {
pub fn destroy_witness(&self) -> DestroyWitness { pub fn destroy_witness(&self) -> DestroyWitness {
DestroyWitness { DestroyWitness {
instances: self.instances, items: self.items,
instance_metadatas: self.instance_metadatas, item_metadatas: self.item_metadatas,
attributes: self.attributes, 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)] #[derive(Clone, Encode, Decode, Eq, PartialEq, RuntimeDebug, Default, TypeInfo, MaxEncodedLen)]
pub struct InstanceDetails<AccountId, DepositBalance> { pub struct ItemDetails<AccountId, DepositBalance> {
/// The owner of this asset. /// The owner of this item.
pub(super) owner: AccountId, 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<AccountId>, pub(super) approved: Option<AccountId>,
/// Whether the asset can be transferred or not. /// Whether the item can be transferred or not.
pub(super) is_frozen: bool, 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. /// this as zero.
pub(super) deposit: DepositBalance, pub(super) deposit: DepositBalance,
} }
@@ -97,31 +97,31 @@ pub struct InstanceDetails<AccountId, DepositBalance> {
#[derive(Clone, Encode, Decode, Eq, PartialEq, RuntimeDebug, Default, TypeInfo, MaxEncodedLen)] #[derive(Clone, Encode, Decode, Eq, PartialEq, RuntimeDebug, Default, TypeInfo, MaxEncodedLen)]
#[scale_info(skip_type_params(StringLimit))] #[scale_info(skip_type_params(StringLimit))]
#[codec(mel_bound(DepositBalance: MaxEncodedLen))] #[codec(mel_bound(DepositBalance: MaxEncodedLen))]
pub struct ClassMetadata<DepositBalance, StringLimit: Get<u32>> { pub struct CollectionMetadata<DepositBalance, StringLimit: Get<u32>> {
/// The balance deposited for this metadata. /// The balance deposited for this metadata.
/// ///
/// This pays for the data stored in this struct. /// This pays for the data stored in this struct.
pub(super) deposit: DepositBalance, pub(super) deposit: DepositBalance,
/// General information concerning this asset. Limited in length by `StringLimit`. This will /// General information concerning this collection. Limited in length by `StringLimit`. This
/// generally be either a JSON dump or the hash of some JSON which can be found on a /// 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. /// hash-addressable global publication system such as IPFS.
pub(super) data: BoundedVec<u8, StringLimit>, pub(super) data: BoundedVec<u8, StringLimit>,
/// Whether the asset metadata may be changed by a non Force origin. /// Whether the collection's metadata may be changed by a non Force origin.
pub(super) is_frozen: bool, pub(super) is_frozen: bool,
} }
#[derive(Clone, Encode, Decode, Eq, PartialEq, RuntimeDebug, Default, TypeInfo, MaxEncodedLen)] #[derive(Clone, Encode, Decode, Eq, PartialEq, RuntimeDebug, Default, TypeInfo, MaxEncodedLen)]
#[scale_info(skip_type_params(StringLimit))] #[scale_info(skip_type_params(StringLimit))]
#[codec(mel_bound(DepositBalance: MaxEncodedLen))] #[codec(mel_bound(DepositBalance: MaxEncodedLen))]
pub struct InstanceMetadata<DepositBalance, StringLimit: Get<u32>> { pub struct ItemMetadata<DepositBalance, StringLimit: Get<u32>> {
/// The balance deposited for this metadata. /// The balance deposited for this metadata.
/// ///
/// This pays for the data stored in this struct. /// This pays for the data stored in this struct.
pub(super) deposit: DepositBalance, 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 /// 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. /// hash-addressable global publication system such as IPFS.
pub(super) data: BoundedVec<u8, StringLimit>, pub(super) data: BoundedVec<u8, StringLimit>,
/// 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, pub(super) is_frozen: bool,
} }
+81 -84
View File
@@ -18,12 +18,13 @@
//! Autogenerated weights for pallet_uniques //! Autogenerated weights for pallet_uniques
//! //!
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev //! 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 //! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB CACHE: 1024
// Executed Command: // Executed Command:
// ./target/production/substrate // target/production/substrate
// benchmark // benchmark
// pallet
// --chain=dev // --chain=dev
// --steps=50 // --steps=50
// --repeat=20 // --repeat=20
@@ -33,9 +34,7 @@
// --wasm-execution=compiled // --wasm-execution=compiled
// --heap-pages=4096 // --heap-pages=4096
// --output=./frame/uniques/src/weights.rs // --output=./frame/uniques/src/weights.rs
// --template=.maintain/frame-weight-template.hbs // --template=./.maintain/frame-weight-template.hbs
// --header=HEADER-APACHE2
// --raw
#![cfg_attr(rustfmt, rustfmt_skip)] #![cfg_attr(rustfmt, rustfmt_skip)]
#![allow(unused_parens)] #![allow(unused_parens)]
@@ -55,17 +54,17 @@ pub trait WeightInfo {
fn redeposit(i: u32, ) -> Weight; fn redeposit(i: u32, ) -> Weight;
fn freeze() -> Weight; fn freeze() -> Weight;
fn thaw() -> Weight; fn thaw() -> Weight;
fn freeze_class() -> Weight; fn freeze_collection() -> Weight;
fn thaw_class() -> Weight; fn thaw_collection() -> Weight;
fn transfer_ownership() -> Weight; fn transfer_ownership() -> Weight;
fn set_team() -> Weight; fn set_team() -> Weight;
fn force_asset_status() -> Weight; fn force_item_status() -> Weight;
fn set_attribute() -> Weight; fn set_attribute() -> Weight;
fn clear_attribute() -> Weight; fn clear_attribute() -> Weight;
fn set_metadata() -> Weight; fn set_metadata() -> Weight;
fn clear_metadata() -> Weight; fn clear_metadata() -> Weight;
fn set_class_metadata() -> Weight; fn set_collection_metadata() -> Weight;
fn clear_class_metadata() -> Weight; fn clear_collection_metadata() -> Weight;
fn approve_transfer() -> Weight; fn approve_transfer() -> Weight;
fn cancel_approval() -> Weight; fn cancel_approval() -> Weight;
fn set_accept_ownership() -> Weight; fn set_accept_ownership() -> Weight;
@@ -77,14 +76,14 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
// Storage: Uniques Class (r:1 w:1) // Storage: Uniques Class (r:1 w:1)
// Storage: Uniques ClassAccount (r:0 w:1) // Storage: Uniques ClassAccount (r:0 w:1)
fn create() -> Weight { fn create() -> Weight {
(24_063_000 as Weight) (24_319_000 as Weight)
.saturating_add(T::DbWeight::get().reads(1 as Weight)) .saturating_add(T::DbWeight::get().reads(1 as Weight))
.saturating_add(T::DbWeight::get().writes(2 as Weight)) .saturating_add(T::DbWeight::get().writes(2 as Weight))
} }
// Storage: Uniques Class (r:1 w:1) // Storage: Uniques Class (r:1 w:1)
// Storage: Uniques ClassAccount (r:0 w:1) // Storage: Uniques ClassAccount (r:0 w:1)
fn force_create() -> Weight { fn force_create() -> Weight {
(13_017_000 as Weight) (13_572_000 as Weight)
.saturating_add(T::DbWeight::get().reads(1 as Weight)) .saturating_add(T::DbWeight::get().reads(1 as Weight))
.saturating_add(T::DbWeight::get().writes(2 as Weight)) .saturating_add(T::DbWeight::get().writes(2 as Weight))
} }
@@ -97,12 +96,12 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
// Storage: Uniques Account (r:0 w:20) // Storage: Uniques Account (r:0 w:20)
fn destroy(n: u32, m: u32, a: u32, ) -> Weight { fn destroy(n: u32, m: u32, a: u32, ) -> Weight {
(0 as Weight) (0 as Weight)
// Standard Error: 14_000 // Standard Error: 15_000
.saturating_add((9_248_000 as Weight).saturating_mul(n as Weight)) .saturating_add((9_433_000 as Weight).saturating_mul(n as Weight))
// Standard Error: 14_000 // Standard Error: 15_000
.saturating_add((854_000 as Weight).saturating_mul(m as Weight)) .saturating_add((980_000 as Weight).saturating_mul(m as Weight))
// Standard Error: 14_000 // Standard Error: 15_000
.saturating_add((758_000 as Weight).saturating_mul(a as Weight)) .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(2 as Weight))
.saturating_add(T::DbWeight::get().reads((1 as Weight).saturating_mul(n 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)) .saturating_add(T::DbWeight::get().writes(3 as Weight))
@@ -114,7 +113,7 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
// Storage: Uniques Class (r:1 w:1) // Storage: Uniques Class (r:1 w:1)
// Storage: Uniques Account (r:0 w:1) // Storage: Uniques Account (r:0 w:1)
fn mint() -> Weight { fn mint() -> Weight {
(29_865_000 as Weight) (29_884_000 as Weight)
.saturating_add(T::DbWeight::get().reads(2 as Weight)) .saturating_add(T::DbWeight::get().reads(2 as Weight))
.saturating_add(T::DbWeight::get().writes(3 as Weight)) .saturating_add(T::DbWeight::get().writes(3 as Weight))
} }
@@ -122,7 +121,7 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
// Storage: Uniques Asset (r:1 w:1) // Storage: Uniques Asset (r:1 w:1)
// Storage: Uniques Account (r:0 w:1) // Storage: Uniques Account (r:0 w:1)
fn burn() -> Weight { fn burn() -> Weight {
(31_603_000 as Weight) (31_384_000 as Weight)
.saturating_add(T::DbWeight::get().reads(2 as Weight)) .saturating_add(T::DbWeight::get().reads(2 as Weight))
.saturating_add(T::DbWeight::get().writes(3 as Weight)) .saturating_add(T::DbWeight::get().writes(3 as Weight))
} }
@@ -130,7 +129,7 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
// Storage: Uniques Asset (r:1 w:1) // Storage: Uniques Asset (r:1 w:1)
// Storage: Uniques Account (r:0 w:2) // Storage: Uniques Account (r:0 w:2)
fn transfer() -> Weight { fn transfer() -> Weight {
(23_331_000 as Weight) (23_254_000 as Weight)
.saturating_add(T::DbWeight::get().reads(2 as Weight)) .saturating_add(T::DbWeight::get().reads(2 as Weight))
.saturating_add(T::DbWeight::get().writes(3 as Weight)) .saturating_add(T::DbWeight::get().writes(3 as Weight))
} }
@@ -138,8 +137,8 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
// Storage: Uniques Asset (r:100 w:100) // Storage: Uniques Asset (r:100 w:100)
fn redeposit(i: u32, ) -> Weight { fn redeposit(i: u32, ) -> Weight {
(0 as Weight) (0 as Weight)
// Standard Error: 12_000 // Standard Error: 13_000
.saturating_add((11_527_000 as Weight).saturating_mul(i as Weight)) .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_add(T::DbWeight::get().reads((1 as Weight).saturating_mul(i 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))
@@ -148,47 +147,47 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
// Storage: Uniques Asset (r:1 w:1) // Storage: Uniques Asset (r:1 w:1)
// Storage: Uniques Class (r:1 w:0) // Storage: Uniques Class (r:1 w:0)
fn freeze() -> Weight { fn freeze() -> Weight {
(18_617_000 as Weight) (17_807_000 as Weight)
.saturating_add(T::DbWeight::get().reads(2 as Weight)) .saturating_add(T::DbWeight::get().reads(2 as Weight))
.saturating_add(T::DbWeight::get().writes(1 as Weight)) .saturating_add(T::DbWeight::get().writes(1 as Weight))
} }
// Storage: Uniques Asset (r:1 w:1) // Storage: Uniques Asset (r:1 w:1)
// Storage: Uniques Class (r:1 w:0) // Storage: Uniques Class (r:1 w:0)
fn thaw() -> Weight { fn thaw() -> Weight {
(18_618_000 as Weight) (17_904_000 as Weight)
.saturating_add(T::DbWeight::get().reads(2 as Weight)) .saturating_add(T::DbWeight::get().reads(2 as Weight))
.saturating_add(T::DbWeight::get().writes(1 as Weight)) .saturating_add(T::DbWeight::get().writes(1 as Weight))
} }
// Storage: Uniques Class (r:1 w:1) // Storage: Uniques Class (r:1 w:1)
fn freeze_class() -> Weight { fn freeze_collection() -> Weight {
(13_570_000 as Weight) (13_828_000 as Weight)
.saturating_add(T::DbWeight::get().reads(1 as Weight)) .saturating_add(T::DbWeight::get().reads(1 as Weight))
.saturating_add(T::DbWeight::get().writes(1 as Weight)) .saturating_add(T::DbWeight::get().writes(1 as Weight))
} }
// Storage: Uniques Class (r:1 w:1) // Storage: Uniques Class (r:1 w:1)
fn thaw_class() -> Weight { fn thaw_collection() -> Weight {
(13_937_000 as Weight) (13_636_000 as Weight)
.saturating_add(T::DbWeight::get().reads(1 as Weight)) .saturating_add(T::DbWeight::get().reads(1 as Weight))
.saturating_add(T::DbWeight::get().writes(1 as Weight)) .saturating_add(T::DbWeight::get().writes(1 as Weight))
} }
// Storage: Uniques OwnershipAcceptance (r:1 w:1)
// Storage: Uniques Class (r:1 w:1) // Storage: Uniques Class (r:1 w:1)
// Storage: System Account (r:1 w:1)
// Storage: Uniques ClassAccount (r:0 w:2) // Storage: Uniques ClassAccount (r:0 w:2)
fn transfer_ownership() -> Weight { fn transfer_ownership() -> Weight {
(31_021_000 as Weight) (20_897_000 as Weight)
.saturating_add(T::DbWeight::get().reads(2 as Weight)) .saturating_add(T::DbWeight::get().reads(2 as Weight))
.saturating_add(T::DbWeight::get().writes(4 as Weight)) .saturating_add(T::DbWeight::get().writes(4 as Weight))
} }
// Storage: Uniques Class (r:1 w:1) // Storage: Uniques Class (r:1 w:1)
fn set_team() -> Weight { fn set_team() -> Weight {
(14_739_000 as Weight) (14_340_000 as Weight)
.saturating_add(T::DbWeight::get().reads(1 as Weight)) .saturating_add(T::DbWeight::get().reads(1 as Weight))
.saturating_add(T::DbWeight::get().writes(1 as Weight)) .saturating_add(T::DbWeight::get().writes(1 as Weight))
} }
// Storage: Uniques Class (r:1 w:1) // Storage: Uniques Class (r:1 w:1)
// Storage: Uniques ClassAccount (r:0 w:1) // Storage: Uniques ClassAccount (r:0 w:1)
fn force_asset_status() -> Weight { fn force_item_status() -> Weight {
(16_826_000 as Weight) (16_355_000 as Weight)
.saturating_add(T::DbWeight::get().reads(1 as Weight)) .saturating_add(T::DbWeight::get().reads(1 as Weight))
.saturating_add(T::DbWeight::get().writes(2 as Weight)) .saturating_add(T::DbWeight::get().writes(2 as Weight))
} }
@@ -196,7 +195,7 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
// Storage: Uniques InstanceMetadataOf (r:1 w:0) // Storage: Uniques InstanceMetadataOf (r:1 w:0)
// Storage: Uniques Attribute (r:1 w:1) // Storage: Uniques Attribute (r:1 w:1)
fn set_attribute() -> Weight { fn set_attribute() -> Weight {
(37_010_000 as Weight) (37_035_000 as Weight)
.saturating_add(T::DbWeight::get().reads(3 as Weight)) .saturating_add(T::DbWeight::get().reads(3 as Weight))
.saturating_add(T::DbWeight::get().writes(2 as Weight)) .saturating_add(T::DbWeight::get().writes(2 as Weight))
} }
@@ -204,56 +203,55 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
// Storage: Uniques InstanceMetadataOf (r:1 w:0) // Storage: Uniques InstanceMetadataOf (r:1 w:0)
// Storage: Uniques Attribute (r:1 w:1) // Storage: Uniques Attribute (r:1 w:1)
fn clear_attribute() -> Weight { fn clear_attribute() -> Weight {
(34_432_000 as Weight) (34_957_000 as Weight)
.saturating_add(T::DbWeight::get().reads(3 as Weight)) .saturating_add(T::DbWeight::get().reads(3 as Weight))
.saturating_add(T::DbWeight::get().writes(2 as Weight)) .saturating_add(T::DbWeight::get().writes(2 as Weight))
} }
// Storage: Uniques Class (r:1 w:1) // Storage: Uniques Class (r:1 w:1)
// Storage: Uniques InstanceMetadataOf (r:1 w:1) // Storage: Uniques InstanceMetadataOf (r:1 w:1)
fn set_metadata() -> Weight { fn set_metadata() -> Weight {
(28_575_000 as Weight) (28_337_000 as Weight)
.saturating_add(T::DbWeight::get().reads(2 as Weight)) .saturating_add(T::DbWeight::get().reads(2 as Weight))
.saturating_add(T::DbWeight::get().writes(2 as Weight)) .saturating_add(T::DbWeight::get().writes(2 as Weight))
} }
// Storage: Uniques Class (r:1 w:1) // Storage: Uniques Class (r:1 w:1)
// Storage: Uniques InstanceMetadataOf (r:1 w:1) // Storage: Uniques InstanceMetadataOf (r:1 w:1)
fn clear_metadata() -> Weight { fn clear_metadata() -> Weight {
(28_730_000 as Weight) (29_166_000 as Weight)
.saturating_add(T::DbWeight::get().reads(2 as Weight)) .saturating_add(T::DbWeight::get().reads(2 as Weight))
.saturating_add(T::DbWeight::get().writes(2 as Weight)) .saturating_add(T::DbWeight::get().writes(2 as Weight))
} }
// Storage: Uniques Class (r:1 w:1) // Storage: Uniques Class (r:1 w:1)
// Storage: Uniques ClassMetadataOf (r:1 w:1) // Storage: Uniques ClassMetadataOf (r:1 w:1)
fn set_class_metadata() -> Weight { fn set_collection_metadata() -> Weight {
(28_225_000 as Weight) (28_246_000 as Weight)
.saturating_add(T::DbWeight::get().reads(2 as Weight)) .saturating_add(T::DbWeight::get().reads(2 as Weight))
.saturating_add(T::DbWeight::get().writes(2 as Weight)) .saturating_add(T::DbWeight::get().writes(2 as Weight))
} }
// Storage: Uniques Class (r:1 w:0) // Storage: Uniques Class (r:1 w:0)
// Storage: Uniques ClassMetadataOf (r:1 w:1) // Storage: Uniques ClassMetadataOf (r:1 w:1)
fn clear_class_metadata() -> Weight { fn clear_collection_metadata() -> Weight {
(26_455_000 as Weight) (26_637_000 as Weight)
.saturating_add(T::DbWeight::get().reads(2 as Weight)) .saturating_add(T::DbWeight::get().reads(2 as Weight))
.saturating_add(T::DbWeight::get().writes(1 as Weight)) .saturating_add(T::DbWeight::get().writes(1 as Weight))
} }
// Storage: Uniques Class (r:1 w:0) // Storage: Uniques Class (r:1 w:0)
// Storage: Uniques Asset (r:1 w:1) // Storage: Uniques Asset (r:1 w:1)
fn approve_transfer() -> Weight { fn approve_transfer() -> Weight {
(19_587_000 as Weight) (18_938_000 as Weight)
.saturating_add(T::DbWeight::get().reads(2 as Weight)) .saturating_add(T::DbWeight::get().reads(2 as Weight))
.saturating_add(T::DbWeight::get().writes(1 as Weight)) .saturating_add(T::DbWeight::get().writes(1 as Weight))
} }
// Storage: Uniques Class (r:1 w:0) // Storage: Uniques Class (r:1 w:0)
// Storage: Uniques Asset (r:1 w:1) // Storage: Uniques Asset (r:1 w:1)
fn cancel_approval() -> Weight { fn cancel_approval() -> Weight {
(19_417_000 as Weight) (18_465_000 as Weight)
.saturating_add(T::DbWeight::get().reads(2 as Weight)) .saturating_add(T::DbWeight::get().reads(2 as Weight))
.saturating_add(T::DbWeight::get().writes(1 as Weight)) .saturating_add(T::DbWeight::get().writes(1 as Weight))
} }
// Storage: Uniques Class (r:1 w:0) // Storage: Uniques OwnershipAcceptance (r:1 w:1)
// Storage: Uniques Asset (r:1 w:1)
fn set_accept_ownership() -> Weight { fn set_accept_ownership() -> Weight {
(19_417_000 as Weight) (16_675_000 as Weight)
.saturating_add(T::DbWeight::get().reads(1 as Weight)) .saturating_add(T::DbWeight::get().reads(1 as Weight))
.saturating_add(T::DbWeight::get().writes(1 as Weight)) .saturating_add(T::DbWeight::get().writes(1 as Weight))
} }
@@ -264,14 +262,14 @@ impl WeightInfo for () {
// Storage: Uniques Class (r:1 w:1) // Storage: Uniques Class (r:1 w:1)
// Storage: Uniques ClassAccount (r:0 w:1) // Storage: Uniques ClassAccount (r:0 w:1)
fn create() -> Weight { fn create() -> Weight {
(24_063_000 as Weight) (24_319_000 as Weight)
.saturating_add(RocksDbWeight::get().reads(1 as Weight)) .saturating_add(RocksDbWeight::get().reads(1 as Weight))
.saturating_add(RocksDbWeight::get().writes(2 as Weight)) .saturating_add(RocksDbWeight::get().writes(2 as Weight))
} }
// Storage: Uniques Class (r:1 w:1) // Storage: Uniques Class (r:1 w:1)
// Storage: Uniques ClassAccount (r:0 w:1) // Storage: Uniques ClassAccount (r:0 w:1)
fn force_create() -> Weight { fn force_create() -> Weight {
(13_017_000 as Weight) (13_572_000 as Weight)
.saturating_add(RocksDbWeight::get().reads(1 as Weight)) .saturating_add(RocksDbWeight::get().reads(1 as Weight))
.saturating_add(RocksDbWeight::get().writes(2 as Weight)) .saturating_add(RocksDbWeight::get().writes(2 as Weight))
} }
@@ -284,12 +282,12 @@ impl WeightInfo for () {
// Storage: Uniques Account (r:0 w:20) // Storage: Uniques Account (r:0 w:20)
fn destroy(n: u32, m: u32, a: u32, ) -> Weight { fn destroy(n: u32, m: u32, a: u32, ) -> Weight {
(0 as Weight) (0 as Weight)
// Standard Error: 14_000 // Standard Error: 15_000
.saturating_add((9_248_000 as Weight).saturating_mul(n as Weight)) .saturating_add((9_433_000 as Weight).saturating_mul(n as Weight))
// Standard Error: 14_000 // Standard Error: 15_000
.saturating_add((854_000 as Weight).saturating_mul(m as Weight)) .saturating_add((980_000 as Weight).saturating_mul(m as Weight))
// Standard Error: 14_000 // Standard Error: 15_000
.saturating_add((758_000 as Weight).saturating_mul(a as Weight)) .saturating_add((852_000 as Weight).saturating_mul(a as Weight))
.saturating_add(RocksDbWeight::get().reads(2 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().reads((1 as Weight).saturating_mul(n as Weight)))
.saturating_add(RocksDbWeight::get().writes(3 as Weight)) .saturating_add(RocksDbWeight::get().writes(3 as Weight))
@@ -301,7 +299,7 @@ impl WeightInfo for () {
// Storage: Uniques Class (r:1 w:1) // Storage: Uniques Class (r:1 w:1)
// Storage: Uniques Account (r:0 w:1) // Storage: Uniques Account (r:0 w:1)
fn mint() -> Weight { fn mint() -> Weight {
(29_865_000 as Weight) (29_884_000 as Weight)
.saturating_add(RocksDbWeight::get().reads(2 as Weight)) .saturating_add(RocksDbWeight::get().reads(2 as Weight))
.saturating_add(RocksDbWeight::get().writes(3 as Weight)) .saturating_add(RocksDbWeight::get().writes(3 as Weight))
} }
@@ -309,7 +307,7 @@ impl WeightInfo for () {
// Storage: Uniques Asset (r:1 w:1) // Storage: Uniques Asset (r:1 w:1)
// Storage: Uniques Account (r:0 w:1) // Storage: Uniques Account (r:0 w:1)
fn burn() -> Weight { fn burn() -> Weight {
(31_603_000 as Weight) (31_384_000 as Weight)
.saturating_add(RocksDbWeight::get().reads(2 as Weight)) .saturating_add(RocksDbWeight::get().reads(2 as Weight))
.saturating_add(RocksDbWeight::get().writes(3 as Weight)) .saturating_add(RocksDbWeight::get().writes(3 as Weight))
} }
@@ -317,7 +315,7 @@ impl WeightInfo for () {
// Storage: Uniques Asset (r:1 w:1) // Storage: Uniques Asset (r:1 w:1)
// Storage: Uniques Account (r:0 w:2) // Storage: Uniques Account (r:0 w:2)
fn transfer() -> Weight { fn transfer() -> Weight {
(23_331_000 as Weight) (23_254_000 as Weight)
.saturating_add(RocksDbWeight::get().reads(2 as Weight)) .saturating_add(RocksDbWeight::get().reads(2 as Weight))
.saturating_add(RocksDbWeight::get().writes(3 as Weight)) .saturating_add(RocksDbWeight::get().writes(3 as Weight))
} }
@@ -325,8 +323,8 @@ impl WeightInfo for () {
// Storage: Uniques Asset (r:100 w:100) // Storage: Uniques Asset (r:100 w:100)
fn redeposit(i: u32, ) -> Weight { fn redeposit(i: u32, ) -> Weight {
(0 as Weight) (0 as Weight)
// Standard Error: 12_000 // Standard Error: 13_000
.saturating_add((11_527_000 as Weight).saturating_mul(i as Weight)) .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_add(RocksDbWeight::get().reads((1 as Weight).saturating_mul(i 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))
@@ -335,47 +333,47 @@ impl WeightInfo for () {
// Storage: Uniques Asset (r:1 w:1) // Storage: Uniques Asset (r:1 w:1)
// Storage: Uniques Class (r:1 w:0) // Storage: Uniques Class (r:1 w:0)
fn freeze() -> Weight { fn freeze() -> Weight {
(18_617_000 as Weight) (17_807_000 as Weight)
.saturating_add(RocksDbWeight::get().reads(2 as Weight)) .saturating_add(RocksDbWeight::get().reads(2 as Weight))
.saturating_add(RocksDbWeight::get().writes(1 as Weight)) .saturating_add(RocksDbWeight::get().writes(1 as Weight))
} }
// Storage: Uniques Asset (r:1 w:1) // Storage: Uniques Asset (r:1 w:1)
// Storage: Uniques Class (r:1 w:0) // Storage: Uniques Class (r:1 w:0)
fn thaw() -> Weight { fn thaw() -> Weight {
(18_618_000 as Weight) (17_904_000 as Weight)
.saturating_add(RocksDbWeight::get().reads(2 as Weight)) .saturating_add(RocksDbWeight::get().reads(2 as Weight))
.saturating_add(RocksDbWeight::get().writes(1 as Weight)) .saturating_add(RocksDbWeight::get().writes(1 as Weight))
} }
// Storage: Uniques Class (r:1 w:1) // Storage: Uniques Class (r:1 w:1)
fn freeze_class() -> Weight { fn freeze_collection() -> Weight {
(13_570_000 as Weight) (13_828_000 as Weight)
.saturating_add(RocksDbWeight::get().reads(1 as Weight)) .saturating_add(RocksDbWeight::get().reads(1 as Weight))
.saturating_add(RocksDbWeight::get().writes(1 as Weight)) .saturating_add(RocksDbWeight::get().writes(1 as Weight))
} }
// Storage: Uniques Class (r:1 w:1) // Storage: Uniques Class (r:1 w:1)
fn thaw_class() -> Weight { fn thaw_collection() -> Weight {
(13_937_000 as Weight) (13_636_000 as Weight)
.saturating_add(RocksDbWeight::get().reads(1 as Weight)) .saturating_add(RocksDbWeight::get().reads(1 as Weight))
.saturating_add(RocksDbWeight::get().writes(1 as Weight)) .saturating_add(RocksDbWeight::get().writes(1 as Weight))
} }
// Storage: Uniques OwnershipAcceptance (r:1 w:1)
// Storage: Uniques Class (r:1 w:1) // Storage: Uniques Class (r:1 w:1)
// Storage: System Account (r:1 w:1)
// Storage: Uniques ClassAccount (r:0 w:2) // Storage: Uniques ClassAccount (r:0 w:2)
fn transfer_ownership() -> Weight { fn transfer_ownership() -> Weight {
(31_021_000 as Weight) (20_897_000 as Weight)
.saturating_add(RocksDbWeight::get().reads(2 as Weight)) .saturating_add(RocksDbWeight::get().reads(2 as Weight))
.saturating_add(RocksDbWeight::get().writes(4 as Weight)) .saturating_add(RocksDbWeight::get().writes(4 as Weight))
} }
// Storage: Uniques Class (r:1 w:1) // Storage: Uniques Class (r:1 w:1)
fn set_team() -> Weight { fn set_team() -> Weight {
(14_739_000 as Weight) (14_340_000 as Weight)
.saturating_add(RocksDbWeight::get().reads(1 as Weight)) .saturating_add(RocksDbWeight::get().reads(1 as Weight))
.saturating_add(RocksDbWeight::get().writes(1 as Weight)) .saturating_add(RocksDbWeight::get().writes(1 as Weight))
} }
// Storage: Uniques Class (r:1 w:1) // Storage: Uniques Class (r:1 w:1)
// Storage: Uniques ClassAccount (r:0 w:1) // Storage: Uniques ClassAccount (r:0 w:1)
fn force_asset_status() -> Weight { fn force_item_status() -> Weight {
(16_826_000 as Weight) (16_355_000 as Weight)
.saturating_add(RocksDbWeight::get().reads(1 as Weight)) .saturating_add(RocksDbWeight::get().reads(1 as Weight))
.saturating_add(RocksDbWeight::get().writes(2 as Weight)) .saturating_add(RocksDbWeight::get().writes(2 as Weight))
} }
@@ -383,7 +381,7 @@ impl WeightInfo for () {
// Storage: Uniques InstanceMetadataOf (r:1 w:0) // Storage: Uniques InstanceMetadataOf (r:1 w:0)
// Storage: Uniques Attribute (r:1 w:1) // Storage: Uniques Attribute (r:1 w:1)
fn set_attribute() -> Weight { fn set_attribute() -> Weight {
(37_010_000 as Weight) (37_035_000 as Weight)
.saturating_add(RocksDbWeight::get().reads(3 as Weight)) .saturating_add(RocksDbWeight::get().reads(3 as Weight))
.saturating_add(RocksDbWeight::get().writes(2 as Weight)) .saturating_add(RocksDbWeight::get().writes(2 as Weight))
} }
@@ -391,56 +389,55 @@ impl WeightInfo for () {
// Storage: Uniques InstanceMetadataOf (r:1 w:0) // Storage: Uniques InstanceMetadataOf (r:1 w:0)
// Storage: Uniques Attribute (r:1 w:1) // Storage: Uniques Attribute (r:1 w:1)
fn clear_attribute() -> Weight { fn clear_attribute() -> Weight {
(34_432_000 as Weight) (34_957_000 as Weight)
.saturating_add(RocksDbWeight::get().reads(3 as Weight)) .saturating_add(RocksDbWeight::get().reads(3 as Weight))
.saturating_add(RocksDbWeight::get().writes(2 as Weight)) .saturating_add(RocksDbWeight::get().writes(2 as Weight))
} }
// Storage: Uniques Class (r:1 w:1) // Storage: Uniques Class (r:1 w:1)
// Storage: Uniques InstanceMetadataOf (r:1 w:1) // Storage: Uniques InstanceMetadataOf (r:1 w:1)
fn set_metadata() -> Weight { fn set_metadata() -> Weight {
(28_575_000 as Weight) (28_337_000 as Weight)
.saturating_add(RocksDbWeight::get().reads(2 as Weight)) .saturating_add(RocksDbWeight::get().reads(2 as Weight))
.saturating_add(RocksDbWeight::get().writes(2 as Weight)) .saturating_add(RocksDbWeight::get().writes(2 as Weight))
} }
// Storage: Uniques Class (r:1 w:1) // Storage: Uniques Class (r:1 w:1)
// Storage: Uniques InstanceMetadataOf (r:1 w:1) // Storage: Uniques InstanceMetadataOf (r:1 w:1)
fn clear_metadata() -> Weight { fn clear_metadata() -> Weight {
(28_730_000 as Weight) (29_166_000 as Weight)
.saturating_add(RocksDbWeight::get().reads(2 as Weight)) .saturating_add(RocksDbWeight::get().reads(2 as Weight))
.saturating_add(RocksDbWeight::get().writes(2 as Weight)) .saturating_add(RocksDbWeight::get().writes(2 as Weight))
} }
// Storage: Uniques Class (r:1 w:1) // Storage: Uniques Class (r:1 w:1)
// Storage: Uniques ClassMetadataOf (r:1 w:1) // Storage: Uniques ClassMetadataOf (r:1 w:1)
fn set_class_metadata() -> Weight { fn set_collection_metadata() -> Weight {
(28_225_000 as Weight) (28_246_000 as Weight)
.saturating_add(RocksDbWeight::get().reads(2 as Weight)) .saturating_add(RocksDbWeight::get().reads(2 as Weight))
.saturating_add(RocksDbWeight::get().writes(2 as Weight)) .saturating_add(RocksDbWeight::get().writes(2 as Weight))
} }
// Storage: Uniques Class (r:1 w:0) // Storage: Uniques Class (r:1 w:0)
// Storage: Uniques ClassMetadataOf (r:1 w:1) // Storage: Uniques ClassMetadataOf (r:1 w:1)
fn clear_class_metadata() -> Weight { fn clear_collection_metadata() -> Weight {
(26_455_000 as Weight) (26_637_000 as Weight)
.saturating_add(RocksDbWeight::get().reads(2 as Weight)) .saturating_add(RocksDbWeight::get().reads(2 as Weight))
.saturating_add(RocksDbWeight::get().writes(1 as Weight)) .saturating_add(RocksDbWeight::get().writes(1 as Weight))
} }
// Storage: Uniques Class (r:1 w:0) // Storage: Uniques Class (r:1 w:0)
// Storage: Uniques Asset (r:1 w:1) // Storage: Uniques Asset (r:1 w:1)
fn approve_transfer() -> Weight { fn approve_transfer() -> Weight {
(19_587_000 as Weight) (18_938_000 as Weight)
.saturating_add(RocksDbWeight::get().reads(2 as Weight)) .saturating_add(RocksDbWeight::get().reads(2 as Weight))
.saturating_add(RocksDbWeight::get().writes(1 as Weight)) .saturating_add(RocksDbWeight::get().writes(1 as Weight))
} }
// Storage: Uniques Class (r:1 w:0) // Storage: Uniques Class (r:1 w:0)
// Storage: Uniques Asset (r:1 w:1) // Storage: Uniques Asset (r:1 w:1)
fn cancel_approval() -> Weight { fn cancel_approval() -> Weight {
(19_417_000 as Weight) (18_465_000 as Weight)
.saturating_add(RocksDbWeight::get().reads(2 as Weight)) .saturating_add(RocksDbWeight::get().reads(2 as Weight))
.saturating_add(RocksDbWeight::get().writes(1 as Weight)) .saturating_add(RocksDbWeight::get().writes(1 as Weight))
} }
// Storage: Uniques Class (r:1 w:0) // Storage: Uniques OwnershipAcceptance (r:1 w:1)
// Storage: Uniques Asset (r:1 w:1)
fn set_accept_ownership() -> Weight { fn set_accept_ownership() -> Weight {
(19_417_000 as Weight) (16_675_000 as Weight)
.saturating_add(RocksDbWeight::get().reads(1 as Weight)) .saturating_add(RocksDbWeight::get().reads(1 as Weight))
.saturating_add(RocksDbWeight::get().writes(1 as Weight)) .saturating_add(RocksDbWeight::get().writes(1 as Weight))
} }