diff --git a/pallets/api/src/nonfungibles/mod.rs b/pallets/api/src/nonfungibles/mod.rs index e6600e3f..8c5a93fd 100644 --- a/pallets/api/src/nonfungibles/mod.rs +++ b/pallets/api/src/nonfungibles/mod.rs @@ -114,6 +114,17 @@ pub mod pallet { /// The administrator of the collection. admin: AccountIdOf, }, + /// Event emitted when an attribute is set for a token. + AttributeSet { + /// The collection identifier. + collection: CollectionIdOf, + /// The item which attribute is set. + item: Option>, + /// The key for the attribute. + key: Vec, + /// The data for the attribute. + data: Vec, + }, } #[pallet::call] @@ -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. @@ -266,7 +278,21 @@ pub mod pallet { key: BoundedVec, value: BoundedVec, ) -> DispatchResult { - NftsOf::::set_attribute(origin, collection, item, namespace, key, value) + NftsOf::::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. diff --git a/pallets/api/src/nonfungibles/tests.rs b/pallets/api/src/nonfungibles/tests.rs index 0b3c52b3..02d87507 100644 --- a/pallets/api/src/nonfungibles/tests.rs +++ b/pallets/api/src/nonfungibles/tests.rs @@ -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,