Skip to content

Commit

Permalink
feat: add AttributeSet event
Browse files Browse the repository at this point in the history
  • Loading branch information
chungquantin committed Jan 22, 2025
1 parent 0396644 commit ea59ba3
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
30 changes: 28 additions & 2 deletions pallets/api/src/nonfungibles/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,17 @@ pub mod pallet {
/// The administrator of the collection.
admin: AccountIdOf<T>,
},
/// Event emitted when an attribute is set for a token.
AttributeSet {
/// The collection identifier.
collection: CollectionIdOf<T>,
/// The item which attribute is set.
item: Option<ItemIdOf<T>>,
/// The key for the attribute.
key: Vec<u8>,
/// The data for the attribute.
data: Vec<u8>,
},
}

#[pallet::call]
Expand Down Expand Up @@ -252,7 +263,8 @@ pub mod pallet {
///
/// # Parameters
/// - `collection` - The collection whose item's metadata to set.
/// - `item` - The item whose metadata to set.
/// - `item` - The item whose metadata to set. If not provided, the collection's attribute
/// is set.
/// - `namespace` - Attribute's namespace.
/// - `key` - The key of the attribute.
/// - `value` - The value to which to set the attribute.
Expand All @@ -266,7 +278,21 @@ pub mod pallet {
key: BoundedVec<u8, T::KeyLimit>,
value: BoundedVec<u8, T::ValueLimit>,
) -> DispatchResult {
NftsOf::<T>::set_attribute(origin, collection, item, namespace, key, value)
NftsOf::<T>::set_attribute(
origin,
collection,
item,
namespace,
key.clone(),
value.clone(),
)?;
Self::deposit_event(Event::AttributeSet {
collection,
item,
key: key.to_vec(),
data: value.to_vec(),
});
Ok(())
}

/// Clear an attribute for the collection or item.
Expand Down
9 changes: 9 additions & 0 deletions pallets/api/src/nonfungibles/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,15 @@ fn set_attribute_works() {
attribute.clone(),
value.clone()
));
System::assert_last_event(
Event::AttributeSet {
collection,
item: Some(item),
key: attribute.to_vec(),
data: value.to_vec(),
}
.into(),
);
assert_eq!(
nfts::get_attribute(
collection,
Expand Down

0 comments on commit ea59ba3

Please sign in to comment.