From ea59ba3e3a06abb9106ed9a4cf26dc37f6761001 Mon Sep 17 00:00:00 2001 From: chungquantin <56880684+chungquantin@users.noreply.github.com> Date: Tue, 21 Jan 2025 23:33:45 +0700 Subject: [PATCH] feat: add AttributeSet event --- pallets/api/src/nonfungibles/mod.rs | 30 +++++++++++++++++++++++++-- pallets/api/src/nonfungibles/tests.rs | 9 ++++++++ 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/pallets/api/src/nonfungibles/mod.rs b/pallets/api/src/nonfungibles/mod.rs index e6600e3fb..8c5a93fda 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 0b3c52b39..02d875070 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,