Skip to content

Commit

Permalink
[NFTs] Emit new PalletAttributeSet event (paritytech#13525)
Browse files Browse the repository at this point in the history
* Emit new PalletAttributeSet event

* Chore
  • Loading branch information
jsidorenko authored and ukint-vs committed Apr 10, 2023
1 parent 0f19239 commit b08b8c5
Showing 1 changed file with 24 additions and 9 deletions.
33 changes: 24 additions & 9 deletions frame/nfts/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,14 @@ pub mod pallet {
item: T::ItemId,
namespace: AttributeNamespace<T::AccountId>,
},
/// A new attribute in the `Pallet` namespace was set for the `collection` or an `item`
/// within that `collection`.
PalletAttributeSet {
collection: T::CollectionId,
item: Option<T::ItemId>,
attribute: PalletAttributes<T::CollectionId>,
value: BoundedVec<u8, T::ValueLimit>,
},
}

#[pallet::error]
Expand Down Expand Up @@ -804,32 +812,39 @@ pub mod pallet {
let MintWitness { owner_of_item } =
witness_data.ok_or(Error::<T, I>::BadWitness)?;

let has_item = Account::<T, I>::contains_key((
let owns_item = Account::<T, I>::contains_key((
&caller,
&collection_id,
&owner_of_item,
));
ensure!(has_item, Error::<T, I>::BadWitness);
ensure!(owns_item, Error::<T, I>::BadWitness);

let attribute_key = Self::construct_attribute_key(
PalletAttributes::<T::CollectionId>::UsedToClaim(collection)
.encode(),
)?;
let pallet_attribute =
PalletAttributes::<T::CollectionId>::UsedToClaim(collection);

let key = (
&collection_id,
Some(owner_of_item),
AttributeNamespace::Pallet,
&attribute_key,
&Self::construct_attribute_key(pallet_attribute.encode())?,
);
let already_claimed = Attribute::<T, I>::contains_key(key.clone());
ensure!(!already_claimed, Error::<T, I>::AlreadyClaimed);

let value = Self::construct_attribute_value(vec![0])?;
let attribute_value = Self::construct_attribute_value(vec![])?;
Attribute::<T, I>::insert(
key,
(value, AttributeDeposit { account: None, amount: Zero::zero() }),
(
attribute_value.clone(),
AttributeDeposit { account: None, amount: Zero::zero() },
),
);
Self::deposit_event(Event::PalletAttributeSet {
collection,
item: Some(item),
attribute: pallet_attribute,
value: attribute_value,
});
},
_ => {},
}
Expand Down

0 comments on commit b08b8c5

Please sign in to comment.