Allow to clear attributes via traits (#13055)

This commit is contained in:
Jegor Sidorenko authored and GitHub committed 2023-01-04 08:31:24 +00:00
1 parent 25b4f8c688
commit 7ead16802e
4 files changed
+122

No files matched your search

@@ -127,6 +127,20 @@ pub trait Mutate<AccountId, ItemConfig>: Inspect<AccountId> {
) -> DispatchResult {
key.using_encoded(|k| value.using_encoded(|v| Self::set_attribute(item, k, v)))
}
/// Clear attribute of `item`'s `key`.
///
/// By default, this is not a supported operation.
fn clear_attribute(_item: &Self::ItemId, _key: &[u8]) -> DispatchResult {
Err(TokenError::Unsupported.into())
}
/// Attempt to clear the strongly-typed attribute of `item`'s `key`.
///
/// By default this just attempts to use `clear_attribute`.
fn clear_typed_attribute<K: Encode>(item: &Self::ItemId, key: &K) -> DispatchResult {
key.using_encoded(|k| Self::clear_attribute(item, k))
}
}
/// Trait for transferring a non-fungible item.
@@ -234,6 +248,16 @@ impl<
value,
)
}
fn clear_attribute(item: &Self::ItemId, key: &[u8]) -> DispatchResult {
<F as nonfungibles::Mutate<AccountId, ItemConfig>>::clear_attribute(&A::get(), item, key)
}
fn clear_typed_attribute<K: Encode>(item: &Self::ItemId, key: &K) -> DispatchResult {
<F as nonfungibles::Mutate<AccountId, ItemConfig>>::clear_typed_attribute(
&A::get(),
item,
key,
)
}
}
impl<
@@ -244,6 +244,45 @@ pub trait Mutate<AccountId, ItemConfig>: Inspect<AccountId> {
value.using_encoded(|v| Self::set_collection_attribute(collection, k, v))
})
}
/// Clear attribute of `item` of `collection`'s `key`.
///
/// By default, this is not a supported operation.
fn clear_attribute(
_collection: &Self::CollectionId,
_item: &Self::ItemId,
_key: &[u8],
) -> DispatchResult {
Err(TokenError::Unsupported.into())
}
/// Attempt to clear the strongly-typed attribute of `item` of `collection`'s `key`.
///
/// By default this just attempts to use `clear_attribute`.
fn clear_typed_attribute<K: Encode>(
collection: &Self::CollectionId,
item: &Self::ItemId,
key: &K,
) -> DispatchResult {
key.using_encoded(|k| Self::clear_attribute(collection, item, k))
}
/// Clear attribute of `collection`'s `key`.
///
/// By default, this is not a supported operation.
fn clear_collection_attribute(_collection: &Self::CollectionId, _key: &[u8]) -> DispatchResult {
Err(TokenError::Unsupported.into())
}
/// Attempt to clear the strongly-typed attribute of `collection`'s `key`.
///
/// By default this just attempts to use `clear_attribute`.
fn clear_typed_collection_attribute<K: Encode>(
collection: &Self::CollectionId,
key: &K,
) -> DispatchResult {
key.using_encoded(|k| Self::clear_collection_attribute(collection, k))
}
}
/// Trait for transferring non-fungible sets of items.