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
@@ -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
/// 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.
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.
// Note: The logic check in this function must be constant time and consistent for benchmarks
// to work.
fn is_locked(_class: ClassId, _instance: InstanceId) -> bool {
fn is_locked(_collection: CollectionId, _item: ItemId) -> bool {
false
}
}
@@ -15,9 +15,9 @@
// See the License for the specific language governing permissions and
// limitations under the License.
//! Traits for dealing with a single non-fungible asset class.
//! Traits for dealing with a single non-fungible collection of items.
//!
//! This assumes a single level namespace identified by `Inspect::InstanceId`, and could
//! This assumes a single level namespace identified by `Inspect::ItemId`, and could
//! reasonably be implemented by pallets which wants to expose a single collection of NFT-like
//! objects.
//!
@@ -30,167 +30,164 @@ use codec::{Decode, Encode};
use sp_runtime::TokenError;
use sp_std::prelude::*;
/// Trait for providing an interface to a read-only NFT-like set of asset instances.
/// Trait for providing an interface to a read-only NFT-like set of items.
pub trait Inspect<AccountId> {
/// Type for identifying an asset instance.
type InstanceId;
/// Type for identifying an item.
type ItemId;
/// Returns the owner of asset `instance`, or `None` if the asset doesn't exist or has no
/// Returns the owner of `item`, or `None` if the item doesn't exist or has no
/// owner.
fn owner(instance: &Self::InstanceId) -> Option<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.
fn attribute(_instance: &Self::InstanceId, _key: &[u8]) -> Option<Vec<u8>> {
fn attribute(_item: &Self::ItemId, _key: &[u8]) -> Option<Vec<u8>> {
None
}
/// Returns the strongly-typed attribute value of `instance` corresponding to `key`.
/// Returns the strongly-typed attribute value of `item` corresponding to `key`.
///
/// By default this just attempts to use `attribute`.
fn typed_attribute<K: Encode, V: Decode>(instance: &Self::InstanceId, key: &K) -> Option<V> {
key.using_encoded(|d| Self::attribute(instance, d))
fn typed_attribute<K: Encode, V: Decode>(item: &Self::ItemId, key: &K) -> Option<V> {
key.using_encoded(|d| Self::attribute(item, d))
.and_then(|v| V::decode(&mut &v[..]).ok())
}
/// Returns `true` if the asset `instance` may be transferred.
/// Returns `true` if the `item` may be transferred.
///
/// Default implementation is that all assets are transferable.
fn can_transfer(_instance: &Self::InstanceId) -> bool {
/// Default implementation is that all items are transferable.
fn can_transfer(_item: &Self::ItemId) -> bool {
true
}
}
/// Interface for enumerating assets in existence or owned by a given account over a collection
/// Interface for enumerating items in existence or owned by a given account over a collection
/// of NFTs.
pub trait InspectEnumerable<AccountId>: Inspect<AccountId> {
/// Returns an iterator of the instances of an asset `class` in existence.
fn instances() -> Box<dyn Iterator<Item = Self::InstanceId>>;
/// Returns an iterator of the items within a `collection` in existence.
fn items() -> Box<dyn Iterator<Item = Self::ItemId>>;
/// Returns an iterator of the asset instances of all classes owned by `who`.
fn owned(who: &AccountId) -> Box<dyn Iterator<Item = Self::InstanceId>>;
/// Returns an iterator of the items of all collections owned by `who`.
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.
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.
fn mint_into(_instance: &Self::InstanceId, _who: &AccountId) -> DispatchResult {
fn mint_into(_item: &Self::ItemId, _who: &AccountId) -> DispatchResult {
Err(TokenError::Unsupported.into())
}
/// Burn some asset `instance`.
/// Burn some `item`.
///
/// By default, this is not a supported operation.
fn burn(
_instance: &Self::InstanceId,
_maybe_check_owner: Option<&AccountId>,
) -> DispatchResult {
fn burn(_item: &Self::ItemId, _maybe_check_owner: Option<&AccountId>) -> DispatchResult {
Err(TokenError::Unsupported.into())
}
/// Set attribute `value` of asset `instance`'s `key`.
/// Set attribute `value` of `item`'s `key`.
///
/// By default, this is not a supported operation.
fn set_attribute(_instance: &Self::InstanceId, _key: &[u8], _value: &[u8]) -> DispatchResult {
fn set_attribute(_item: &Self::ItemId, _key: &[u8], _value: &[u8]) -> DispatchResult {
Err(TokenError::Unsupported.into())
}
/// Attempt to set the strongly-typed attribute `value` of `instance`'s `key`.
/// Attempt to set the strongly-typed attribute `value` of `item`'s `key`.
///
/// By default this just attempts to use `set_attribute`.
fn set_typed_attribute<K: Encode, V: Encode>(
instance: &Self::InstanceId,
item: &Self::ItemId,
key: &K,
value: &V,
) -> DispatchResult {
key.using_encoded(|k| value.using_encoded(|v| Self::set_attribute(instance, k, v)))
key.using_encoded(|k| value.using_encoded(|v| Self::set_attribute(item, k, v)))
}
}
/// Trait for providing a non-fungible set of assets which can only be transferred.
/// Trait for providing a non-fungible set of items which can only be transferred.
pub trait Transfer<AccountId>: Inspect<AccountId> {
/// Transfer asset `instance` into `destination` account.
fn transfer(instance: &Self::InstanceId, destination: &AccountId) -> DispatchResult;
/// Transfer `item` into `destination` account.
fn transfer(item: &Self::ItemId, destination: &AccountId) -> DispatchResult;
}
/// Convert a `fungibles` trait implementation into a `fungible` trait implementation by identifying
/// a single item.
pub struct ItemOf<
F: nonfungibles::Inspect<AccountId>,
A: Get<<F as nonfungibles::Inspect<AccountId>>::ClassId>,
A: Get<<F as nonfungibles::Inspect<AccountId>>::CollectionId>,
AccountId,
>(sp_std::marker::PhantomData<(F, A, AccountId)>);
impl<
F: nonfungibles::Inspect<AccountId>,
A: Get<<F as nonfungibles::Inspect<AccountId>>::ClassId>,
A: Get<<F as nonfungibles::Inspect<AccountId>>::CollectionId>,
AccountId,
> Inspect<AccountId> for ItemOf<F, A, AccountId>
{
type InstanceId = <F as nonfungibles::Inspect<AccountId>>::InstanceId;
fn owner(instance: &Self::InstanceId) -> Option<AccountId> {
<F as nonfungibles::Inspect<AccountId>>::owner(&A::get(), instance)
type ItemId = <F as nonfungibles::Inspect<AccountId>>::ItemId;
fn owner(item: &Self::ItemId) -> Option<AccountId> {
<F as nonfungibles::Inspect<AccountId>>::owner(&A::get(), item)
}
fn attribute(instance: &Self::InstanceId, key: &[u8]) -> Option<Vec<u8>> {
<F as nonfungibles::Inspect<AccountId>>::attribute(&A::get(), instance, key)
fn attribute(item: &Self::ItemId, key: &[u8]) -> Option<Vec<u8>> {
<F as nonfungibles::Inspect<AccountId>>::attribute(&A::get(), item, key)
}
fn typed_attribute<K: Encode, V: Decode>(instance: &Self::InstanceId, key: &K) -> Option<V> {
<F as nonfungibles::Inspect<AccountId>>::typed_attribute(&A::get(), instance, key)
fn typed_attribute<K: Encode, V: Decode>(item: &Self::ItemId, key: &K) -> Option<V> {
<F as nonfungibles::Inspect<AccountId>>::typed_attribute(&A::get(), item, key)
}
fn can_transfer(instance: &Self::InstanceId) -> bool {
<F as nonfungibles::Inspect<AccountId>>::can_transfer(&A::get(), instance)
fn can_transfer(item: &Self::ItemId) -> bool {
<F as nonfungibles::Inspect<AccountId>>::can_transfer(&A::get(), item)
}
}
impl<
F: nonfungibles::InspectEnumerable<AccountId>,
A: Get<<F as nonfungibles::Inspect<AccountId>>::ClassId>,
A: Get<<F as nonfungibles::Inspect<AccountId>>::CollectionId>,
AccountId,
> InspectEnumerable<AccountId> for ItemOf<F, A, AccountId>
{
fn instances() -> Box<dyn Iterator<Item = Self::InstanceId>> {
<F as nonfungibles::InspectEnumerable<AccountId>>::instances(&A::get())
fn items() -> Box<dyn Iterator<Item = Self::ItemId>> {
<F as nonfungibles::InspectEnumerable<AccountId>>::items(&A::get())
}
fn owned(who: &AccountId) -> Box<dyn Iterator<Item = Self::InstanceId>> {
<F as nonfungibles::InspectEnumerable<AccountId>>::owned_in_class(&A::get(), who)
fn owned(who: &AccountId) -> Box<dyn Iterator<Item = Self::ItemId>> {
<F as nonfungibles::InspectEnumerable<AccountId>>::owned_in_collection(&A::get(), who)
}
}
impl<
F: nonfungibles::Mutate<AccountId>,
A: Get<<F as nonfungibles::Inspect<AccountId>>::ClassId>,
A: Get<<F as nonfungibles::Inspect<AccountId>>::CollectionId>,
AccountId,
> Mutate<AccountId> for ItemOf<F, A, AccountId>
{
fn mint_into(instance: &Self::InstanceId, who: &AccountId) -> DispatchResult {
<F as nonfungibles::Mutate<AccountId>>::mint_into(&A::get(), instance, who)
fn mint_into(item: &Self::ItemId, who: &AccountId) -> DispatchResult {
<F as nonfungibles::Mutate<AccountId>>::mint_into(&A::get(), item, who)
}
fn burn(instance: &Self::InstanceId, maybe_check_owner: Option<&AccountId>) -> DispatchResult {
<F as nonfungibles::Mutate<AccountId>>::burn(&A::get(), instance, maybe_check_owner)
fn burn(item: &Self::ItemId, maybe_check_owner: Option<&AccountId>) -> DispatchResult {
<F as nonfungibles::Mutate<AccountId>>::burn(&A::get(), item, maybe_check_owner)
}
fn set_attribute(instance: &Self::InstanceId, key: &[u8], value: &[u8]) -> DispatchResult {
<F as nonfungibles::Mutate<AccountId>>::set_attribute(&A::get(), instance, key, value)
fn set_attribute(item: &Self::ItemId, key: &[u8], value: &[u8]) -> DispatchResult {
<F as nonfungibles::Mutate<AccountId>>::set_attribute(&A::get(), item, key, value)
}
fn set_typed_attribute<K: Encode, V: Encode>(
instance: &Self::InstanceId,
item: &Self::ItemId,
key: &K,
value: &V,
) -> 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<
F: nonfungibles::Transfer<AccountId>,
A: Get<<F as nonfungibles::Inspect<AccountId>>::ClassId>,
A: Get<<F as nonfungibles::Inspect<AccountId>>::CollectionId>,
AccountId,
> Transfer<AccountId> for ItemOf<F, A, AccountId>
{
fn transfer(instance: &Self::InstanceId, destination: &AccountId) -> DispatchResult {
<F as nonfungibles::Transfer<AccountId>>::transfer(&A::get(), instance, destination)
fn transfer(item: &Self::ItemId, destination: &AccountId) -> DispatchResult {
<F as nonfungibles::Transfer<AccountId>>::transfer(&A::get(), item, destination)
}
}
@@ -15,9 +15,9 @@
// See the License for the specific language governing permissions and
// limitations under the License.
//! Traits for dealing with multiple collections of non-fungible assets.
//! Traits for dealing with multiple collections of non-fungible items.
//!
//! This assumes a dual-level namespace identified by `Inspect::InstanceId`, and could
//! This assumes a dual-level namespace identified by `Inspect::ItemId`, and could
//! reasonably be implemented by pallets which want to expose multiple independent collections of
//! NFT-like objects.
//!
@@ -32,196 +32,210 @@ use codec::{Decode, Encode};
use sp_runtime::TokenError;
use sp_std::prelude::*;
/// Trait for providing an interface to many read-only NFT-like sets of asset instances.
/// Trait for providing an interface to many read-only NFT-like sets of items.
pub trait Inspect<AccountId> {
/// Type for identifying an asset instance.
type InstanceId;
/// Type for identifying an item.
type ItemId;
/// Type for identifying an asset class (an identifier for an independent collection of asset
/// instances).
type ClassId;
/// Type for identifying a collection (an identifier for an independent collection of
/// items).
type CollectionId;
/// Returns the owner of asset `instance` of `class`, or `None` if the asset doesn't exist (or
/// somehow has no owner).
fn owner(class: &Self::ClassId, instance: &Self::InstanceId) -> Option<AccountId>;
/// Returns the owner of `item` of `collection`, or `None` if the item doesn't exist
/// (or somehow has no owner).
fn owner(collection: &Self::CollectionId, item: &Self::ItemId) -> Option<AccountId>;
/// Returns the owner of the asset `class`, if there is one. For many NFTs this may not make
/// any sense, so users of this API should not be surprised to find an asset class results in
/// `None` here.
fn class_owner(_class: &Self::ClassId) -> Option<AccountId> {
/// Returns the owner of the `collection`, if there is one. For many NFTs this may not
/// make any sense, so users of this API should not be surprised to find a collection
/// results in `None` here.
fn collection_owner(_collection: &Self::CollectionId) -> Option<AccountId> {
None
}
/// Returns the attribute value of `instance` of `class` corresponding to `key`.
/// Returns the attribute value of `item` of `collection` corresponding to `key`.
///
/// By default this is `None`; no attributes are defined.
fn attribute(
_class: &Self::ClassId,
_instance: &Self::InstanceId,
_collection: &Self::CollectionId,
_item: &Self::ItemId,
_key: &[u8],
) -> Option<Vec<u8>> {
None
}
/// Returns the strongly-typed attribute value of `instance` of `class` corresponding to `key`.
/// Returns the strongly-typed attribute value of `item` of `collection` corresponding to
/// `key`.
///
/// By default this just attempts to use `attribute`.
fn typed_attribute<K: Encode, V: Decode>(
class: &Self::ClassId,
instance: &Self::InstanceId,
collection: &Self::CollectionId,
item: &Self::ItemId,
key: &K,
) -> 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())
}
/// Returns the attribute value of `class` corresponding to `key`.
/// Returns the attribute value of `collection` corresponding to `key`.
///
/// By default this is `None`; no attributes are defined.
fn class_attribute(_class: &Self::ClassId, _key: &[u8]) -> Option<Vec<u8>> {
fn collection_attribute(_collection: &Self::CollectionId, _key: &[u8]) -> Option<Vec<u8>> {
None
}
/// Returns the strongly-typed attribute value of `class` corresponding to `key`.
/// Returns the strongly-typed attribute value of `collection` corresponding to `key`.
///
/// By default this just attempts to use `class_attribute`.
fn typed_class_attribute<K: Encode, V: Decode>(class: &Self::ClassId, key: &K) -> Option<V> {
key.using_encoded(|d| Self::class_attribute(class, d))
/// By default this just attempts to use `collection_attribute`.
fn typed_collection_attribute<K: Encode, V: Decode>(
collection: &Self::CollectionId,
key: &K,
) -> Option<V> {
key.using_encoded(|d| Self::collection_attribute(collection, d))
.and_then(|v| V::decode(&mut &v[..]).ok())
}
/// Returns `true` if the asset `instance` of `class` may be transferred.
/// Returns `true` if the `item` of `collection` may be transferred.
///
/// Default implementation is that all assets are transferable.
fn can_transfer(_class: &Self::ClassId, _instance: &Self::InstanceId) -> bool {
/// Default implementation is that all items are transferable.
fn can_transfer(_collection: &Self::CollectionId, _item: &Self::ItemId) -> bool {
true
}
}
/// Interface for enumerating assets in existence or owned by a given account over many collections
/// Interface for enumerating items in existence or owned by a given account over many collections
/// of NFTs.
pub trait InspectEnumerable<AccountId>: Inspect<AccountId> {
/// Returns an iterator of the asset classes in existence.
fn classes() -> Box<dyn Iterator<Item = Self::ClassId>>;
/// Returns an iterator of the collections in existence.
fn collections() -> Box<dyn Iterator<Item = Self::CollectionId>>;
/// Returns an iterator of the instances of an asset `class` in existence.
fn instances(class: &Self::ClassId) -> Box<dyn Iterator<Item = Self::InstanceId>>;
/// Returns an iterator of the items of a `collection` in existence.
fn items(collection: &Self::CollectionId) -> Box<dyn Iterator<Item = Self::ItemId>>;
/// Returns an iterator of the asset instances of all classes owned by `who`.
fn owned(who: &AccountId) -> Box<dyn Iterator<Item = (Self::ClassId, Self::InstanceId)>>;
/// Returns an iterator of the items of all collections owned by `who`.
fn owned(who: &AccountId) -> Box<dyn Iterator<Item = (Self::CollectionId, Self::ItemId)>>;
/// Returns an iterator of the asset instances of `class` owned by `who`.
fn owned_in_class(
class: &Self::ClassId,
/// Returns an iterator of the items of `collection` owned by `who`.
fn owned_in_collection(
collection: &Self::CollectionId,
who: &AccountId,
) -> Box<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> {
/// Create a `class` of nonfungible assets to be owned by `who` and managed by `admin`.
fn create_class(class: &Self::ClassId, who: &AccountId, admin: &AccountId) -> DispatchResult;
/// Create a `collection` of nonfungible items to be owned by `who` and managed by `admin`.
fn create_collection(
collection: &Self::CollectionId,
who: &AccountId,
admin: &AccountId,
) -> DispatchResult;
}
/// Trait for providing the ability to destroy classes of nonfungible assets.
/// Trait for providing the ability to destroy collections of nonfungible items.
pub trait Destroy<AccountId>: Inspect<AccountId> {
/// The witness data needed to destroy an asset.
/// The witness data needed to destroy an item.
type DestroyWitness;
/// Provide the appropriate witness data needed to destroy an asset.
fn get_destroy_witness(class: &Self::ClassId) -> Option<Self::DestroyWitness>;
/// Provide the appropriate witness data needed to destroy an item.
fn get_destroy_witness(collection: &Self::CollectionId) -> Option<Self::DestroyWitness>;
/// Destroy an existing fungible asset.
/// * `class`: The `ClassId` to be destroyed.
/// Destroy an existing fungible item.
/// * `collection`: The `CollectionId` to be destroyed.
/// * `witness`: Any witness data that needs to be provided to complete the operation
/// successfully.
/// * `maybe_check_owner`: An optional account id that can be used to authorize the destroy
/// command. If not provided, we will not do any authorization checks before destroying the
/// asset.
/// item.
///
/// If successful, this function will return the actual witness data from the destroyed asset.
/// If successful, this function will return the actual witness data from the destroyed item.
/// This may be different than the witness data provided, and can be used to refund weight.
fn destroy(
class: Self::ClassId,
collection: Self::CollectionId,
witness: Self::DestroyWitness,
maybe_check_owner: Option<AccountId>,
) -> Result<Self::DestroyWitness, DispatchError>;
}
/// Trait for providing an interface for multiple classes of NFT-like assets which may be minted,
/// burned and/or have attributes set on them.
/// Trait for providing an interface for multiple collections of NFT-like items which may be
/// minted, burned and/or have attributes set on them.
pub trait Mutate<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.
fn mint_into(
_class: &Self::ClassId,
_instance: &Self::InstanceId,
_collection: &Self::CollectionId,
_item: &Self::ItemId,
_who: &AccountId,
) -> DispatchResult {
Err(TokenError::Unsupported.into())
}
/// Burn some asset `instance` of `class`.
/// Burn some `item` of `collection`.
///
/// By default, this is not a supported operation.
fn burn(
_class: &Self::ClassId,
_instance: &Self::InstanceId,
_collection: &Self::CollectionId,
_item: &Self::ItemId,
_maybe_check_owner: Option<&AccountId>,
) -> DispatchResult {
Err(TokenError::Unsupported.into())
}
/// Set attribute `value` of asset `instance` of `class`'s `key`.
/// Set attribute `value` of `item` of `collection`'s `key`.
///
/// By default, this is not a supported operation.
fn set_attribute(
_class: &Self::ClassId,
_instance: &Self::InstanceId,
_collection: &Self::CollectionId,
_item: &Self::ItemId,
_key: &[u8],
_value: &[u8],
) -> DispatchResult {
Err(TokenError::Unsupported.into())
}
/// Attempt to set the strongly-typed attribute `value` of `instance` of `class`'s `key`.
/// Attempt to set the strongly-typed attribute `value` of `item` of `collection`'s `key`.
///
/// By default this just attempts to use `set_attribute`.
fn set_typed_attribute<K: Encode, V: Encode>(
class: &Self::ClassId,
instance: &Self::InstanceId,
collection: &Self::CollectionId,
item: &Self::ItemId,
key: &K,
value: &V,
) -> DispatchResult {
key.using_encoded(|k| value.using_encoded(|v| Self::set_attribute(class, instance, k, v)))
key.using_encoded(|k| value.using_encoded(|v| Self::set_attribute(collection, item, k, v)))
}
/// Set attribute `value` of asset `class`'s `key`.
/// Set attribute `value` of `collection`'s `key`.
///
/// By default, this is not a supported operation.
fn set_class_attribute(_class: &Self::ClassId, _key: &[u8], _value: &[u8]) -> DispatchResult {
fn set_collection_attribute(
_collection: &Self::CollectionId,
_key: &[u8],
_value: &[u8],
) -> DispatchResult {
Err(TokenError::Unsupported.into())
}
/// Attempt to set the strongly-typed attribute `value` of `class`'s `key`.
/// Attempt to set the strongly-typed attribute `value` of `collection`'s `key`.
///
/// By default this just attempts to use `set_attribute`.
fn set_typed_class_attribute<K: Encode, V: Encode>(
class: &Self::ClassId,
fn set_typed_collection_attribute<K: Encode, V: Encode>(
collection: &Self::CollectionId,
key: &K,
value: &V,
) -> DispatchResult {
key.using_encoded(|k| value.using_encoded(|v| Self::set_class_attribute(class, k, v)))
key.using_encoded(|k| {
value.using_encoded(|v| Self::set_collection_attribute(collection, k, v))
})
}
}
/// Trait for providing a non-fungible sets of assets which can only be transferred.
/// Trait for providing a non-fungible sets of items which can only be transferred.
pub trait Transfer<AccountId>: Inspect<AccountId> {
/// Transfer asset `instance` of `class` into `destination` account.
/// Transfer `item` of `collection` into `destination` account.
fn transfer(
class: &Self::ClassId,
instance: &Self::InstanceId,
collection: &Self::CollectionId,
item: &Self::ItemId,
destination: &AccountId,
) -> DispatchResult;
}