mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-14 01:41:09 +00:00
Trading trait and deal with metadata in Mutate trait for nonfungibles_v2 (#1561)
I have added some Traits that are missing and are useful for dealing with non-fungible tokens on other pallets and their implementations for NFTs pallet. - In the Mutate trait, added methods for dealing with the metadata: `set_metadata`, `set_collection_metadata`, `clear_metadata` and `clear_collection_metadata`. The motivation of adding this methods coming from a StackExchange question asking for it: [Setting metadata of an item of the Nfts pallet in a custom pallet](https://substrate.stackexchange.com/questions/9974/setting-metadata-of-an-item-of-the-nfts-pallet-in-a-custom-pallet) - A Trait for trading non-fungible items. The methods in that Trait are `buy_item`, `set_price` and `item_price` An example of where this Trait can be useful is a pallet that deals with [NFT Royalties](https://forum.polkadot.network/t/nfts-royalty-pallet/3766) and needs to perform this actions. --------- Co-authored-by: Jegor Sidorenko <5252494+jsidorenko@users.noreply.github.com>
This commit is contained in:
@@ -320,6 +320,33 @@ impl<T: Config<I>, I: 'static> Mutate<<T as SystemConfig>::AccountId, ItemConfig
|
||||
})
|
||||
}
|
||||
|
||||
fn set_item_metadata(
|
||||
who: Option<&T::AccountId>,
|
||||
collection: &Self::CollectionId,
|
||||
item: &Self::ItemId,
|
||||
data: &[u8],
|
||||
) -> DispatchResult {
|
||||
Self::do_set_item_metadata(
|
||||
who.cloned(),
|
||||
*collection,
|
||||
*item,
|
||||
Self::construct_metadata(data.to_vec())?,
|
||||
None,
|
||||
)
|
||||
}
|
||||
|
||||
fn set_collection_metadata(
|
||||
who: Option<&T::AccountId>,
|
||||
collection: &Self::CollectionId,
|
||||
data: &[u8],
|
||||
) -> DispatchResult {
|
||||
Self::do_set_collection_metadata(
|
||||
who.cloned(),
|
||||
*collection,
|
||||
Self::construct_metadata(data.to_vec())?,
|
||||
)
|
||||
}
|
||||
|
||||
fn clear_attribute(
|
||||
collection: &Self::CollectionId,
|
||||
item: &Self::ItemId,
|
||||
@@ -362,6 +389,21 @@ impl<T: Config<I>, I: 'static> Mutate<<T as SystemConfig>::AccountId, ItemConfig
|
||||
<Self as Mutate<T::AccountId, ItemConfig>>::clear_collection_attribute(collection, k)
|
||||
})
|
||||
}
|
||||
|
||||
fn clear_item_metadata(
|
||||
who: Option<&T::AccountId>,
|
||||
collection: &Self::CollectionId,
|
||||
item: &Self::ItemId,
|
||||
) -> DispatchResult {
|
||||
Self::do_clear_item_metadata(who.cloned(), *collection, *item)
|
||||
}
|
||||
|
||||
fn clear_collection_metadata(
|
||||
who: Option<&T::AccountId>,
|
||||
collection: &Self::CollectionId,
|
||||
) -> DispatchResult {
|
||||
Self::do_clear_collection_metadata(who.cloned(), *collection)
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Config<I>, I: 'static> Transfer<T::AccountId> for Pallet<T, I> {
|
||||
@@ -398,6 +440,31 @@ impl<T: Config<I>, I: 'static> Transfer<T::AccountId> for Pallet<T, I> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Config<I>, I: 'static> Trading<T::AccountId, ItemPrice<T, I>> for Pallet<T, I> {
|
||||
fn buy_item(
|
||||
collection: &Self::CollectionId,
|
||||
item: &Self::ItemId,
|
||||
buyer: &T::AccountId,
|
||||
bid_price: &ItemPrice<T, I>,
|
||||
) -> DispatchResult {
|
||||
Self::do_buy_item(*collection, *item, buyer.clone(), *bid_price)
|
||||
}
|
||||
|
||||
fn set_price(
|
||||
collection: &Self::CollectionId,
|
||||
item: &Self::ItemId,
|
||||
sender: &T::AccountId,
|
||||
price: Option<ItemPrice<T, I>>,
|
||||
whitelisted_buyer: Option<T::AccountId>,
|
||||
) -> DispatchResult {
|
||||
Self::do_set_price(*collection, *item, sender.clone(), price, whitelisted_buyer)
|
||||
}
|
||||
|
||||
fn item_price(collection: &Self::CollectionId, item: &Self::ItemId) -> Option<ItemPrice<T, I>> {
|
||||
ItemPriceOf::<T, I>::get(collection, item).map(|a| a.0)
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Config<I>, I: 'static> InspectEnumerable<T::AccountId> for Pallet<T, I> {
|
||||
type CollectionsIterator = KeyPrefixIterator<<T as Config<I>>::CollectionId>;
|
||||
type ItemsIterator = KeyPrefixIterator<<T as Config<I>>::ItemId>;
|
||||
|
||||
Reference in New Issue
Block a user