This repository has been archived by the owner on Nov 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Uniques V2] Minting options (#12483)
* Basics * WIP: change the data format * Refactor * Remove redundant new() method * Rename settings * Enable tests * Chore * Change params order * Delete the config on collection removal * Chore * Remove redundant system features * Rename force_item_status to force_collection_status * Update node runtime * Chore * Remove thaw_collection * Chore * Connect collection.is_frozen to config * Allow to lock the collection in a new way * Move free_holding into settings * Connect collection's metadata locker to feature flags * DRY * Chore * Connect pallet level feature flags * Prepare tests for the new changes * Implement Item settings * Allow to lock the metadata or attributes of an item * Common -> Settings * Extract settings related code to a separate file * Move feature flag checks inside the do_* methods * Split settings.rs into parts * Extract repeated code into macro * Extract macros into their own file * Chore * Fix traits * Fix traits * Test SystemFeatures * Fix benchmarks * Add missing benchmark * Fix node/runtime/lib.rs * ".git/.scripts/bench-bot.sh" pallet dev pallet_nfts * Keep item's config on burn if it's not empty * Fix the merge artifacts * Fmt * Add SystemFeature::NoSwaps check * Rename SystemFeatures to PalletFeatures * Rename errors * Add docs * Change error message * Change the format of CollectionConfig to store more data * Move max supply to the CollectionConfig and allow to change it * Remove ItemConfig from the mint() function and use the one set in mint settings * Add different mint options * Allow to change the mint settings * Add a force_mint() method * Check mint params * Some optimisations * Cover with tests * Remove merge artifacts * Chore * Use the new has_role() method * Rework item deposits * More tests * Refactoring * Address comments * Refactor lock_collection() * Update frame/nfts/src/types.rs Co-authored-by: Squirrel <gilescope@gmail.com> * Update frame/nfts/src/types.rs Co-authored-by: Squirrel <gilescope@gmail.com> * Update frame/nfts/src/lib.rs Co-authored-by: Squirrel <gilescope@gmail.com> * Update frame/nfts/src/lib.rs Co-authored-by: Squirrel <gilescope@gmail.com> * Private => Issuer * Add more tests * Fix benchmarks * Add benchmarks for new methods * [Uniques v2] Refactoring (#12570) * Move do_set_price() and do_buy_item() to buy_sell.rs * Move approvals to feature file * Move metadata to feature files * Move the rest of methods to feature files * Remove artifacts * Split force_collection_status into 2 methods * Fix benchmarks * Fix benchmarks * Update deps Co-authored-by: command-bot <> Co-authored-by: Squirrel <gilescope@gmail.com>
- Loading branch information
1 parent
1813960
commit afd4c18
Showing
22 changed files
with
1,856 additions
and
1,198 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// This file is part of Substrate. | ||
|
||
// Copyright (C) 2017-2022 Parity Technologies (UK) Ltd. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
//! Various pieces of common functionality. | ||
|
||
use super::*; | ||
|
||
impl<T: Config<I>, I: 'static> Pallet<T, I> { | ||
/// Get the owner of the item, if the item exists. | ||
pub fn owner(collection: T::CollectionId, item: T::ItemId) -> Option<T::AccountId> { | ||
Item::<T, I>::get(collection, item).map(|i| i.owner) | ||
} | ||
|
||
/// Get the owner of the item, if the item exists. | ||
pub fn collection_owner(collection: T::CollectionId) -> Option<T::AccountId> { | ||
Collection::<T, I>::get(collection).map(|i| i.owner) | ||
} | ||
|
||
#[cfg(any(test, feature = "runtime-benchmarks"))] | ||
pub fn set_next_id(id: T::CollectionId) { | ||
NextCollectionId::<T, I>::set(Some(id)); | ||
} | ||
|
||
#[cfg(test)] | ||
pub fn get_next_id() -> T::CollectionId { | ||
NextCollectionId::<T, I>::get().unwrap_or(T::CollectionId::initial_value()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
// This file is part of Substrate. | ||
|
||
// Copyright (C) 2022 Parity Technologies (UK) Ltd. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
use crate::*; | ||
use frame_support::pallet_prelude::*; | ||
|
||
impl<T: Config<I>, I: 'static> Pallet<T, I> { | ||
pub(crate) fn do_approve_transfer( | ||
maybe_check_origin: Option<T::AccountId>, | ||
collection: T::CollectionId, | ||
item: T::ItemId, | ||
delegate: T::AccountId, | ||
maybe_deadline: Option<<T as SystemConfig>::BlockNumber>, | ||
) -> DispatchResult { | ||
ensure!( | ||
Self::is_pallet_feature_enabled(PalletFeature::Approvals), | ||
Error::<T, I>::MethodDisabled | ||
); | ||
let mut details = | ||
Item::<T, I>::get(&collection, &item).ok_or(Error::<T, I>::UnknownItem)?; | ||
|
||
let collection_config = Self::get_collection_config(&collection)?; | ||
ensure!( | ||
collection_config.is_setting_enabled(CollectionSetting::TransferableItems), | ||
Error::<T, I>::ItemsNonTransferable | ||
); | ||
|
||
if let Some(check_origin) = maybe_check_origin { | ||
let is_admin = Self::has_role(&collection, &check_origin, CollectionRole::Admin); | ||
let permitted = is_admin || check_origin == details.owner; | ||
ensure!(permitted, Error::<T, I>::NoPermission); | ||
} | ||
|
||
let now = frame_system::Pallet::<T>::block_number(); | ||
let deadline = maybe_deadline.map(|d| d.saturating_add(now)); | ||
|
||
details | ||
.approvals | ||
.try_insert(delegate.clone(), deadline) | ||
.map_err(|_| Error::<T, I>::ReachedApprovalLimit)?; | ||
Item::<T, I>::insert(&collection, &item, &details); | ||
|
||
Self::deposit_event(Event::ApprovedTransfer { | ||
collection, | ||
item, | ||
owner: details.owner, | ||
delegate, | ||
deadline, | ||
}); | ||
|
||
Ok(()) | ||
} | ||
|
||
pub(crate) fn do_cancel_approval( | ||
maybe_check_origin: Option<T::AccountId>, | ||
collection: T::CollectionId, | ||
item: T::ItemId, | ||
delegate: T::AccountId, | ||
) -> DispatchResult { | ||
let mut details = | ||
Item::<T, I>::get(&collection, &item).ok_or(Error::<T, I>::UnknownItem)?; | ||
|
||
let maybe_deadline = details.approvals.get(&delegate).ok_or(Error::<T, I>::NotDelegate)?; | ||
|
||
let is_past_deadline = if let Some(deadline) = maybe_deadline { | ||
let now = frame_system::Pallet::<T>::block_number(); | ||
now > *deadline | ||
} else { | ||
false | ||
}; | ||
|
||
if !is_past_deadline { | ||
if let Some(check_origin) = maybe_check_origin { | ||
let is_admin = Self::has_role(&collection, &check_origin, CollectionRole::Admin); | ||
let permitted = is_admin || check_origin == details.owner; | ||
ensure!(permitted, Error::<T, I>::NoPermission); | ||
} | ||
} | ||
|
||
details.approvals.remove(&delegate); | ||
Item::<T, I>::insert(&collection, &item, &details); | ||
|
||
Self::deposit_event(Event::ApprovalCancelled { | ||
collection, | ||
item, | ||
owner: details.owner, | ||
delegate, | ||
}); | ||
|
||
Ok(()) | ||
} | ||
|
||
pub(crate) fn do_clear_all_transfer_approvals( | ||
maybe_check_origin: Option<T::AccountId>, | ||
collection: T::CollectionId, | ||
item: T::ItemId, | ||
) -> DispatchResult { | ||
let mut details = | ||
Item::<T, I>::get(&collection, &item).ok_or(Error::<T, I>::UnknownCollection)?; | ||
|
||
if let Some(check_origin) = maybe_check_origin { | ||
let is_admin = Self::has_role(&collection, &check_origin, CollectionRole::Admin); | ||
let permitted = is_admin || check_origin == details.owner; | ||
ensure!(permitted, Error::<T, I>::NoPermission); | ||
} | ||
|
||
details.approvals.clear(); | ||
Item::<T, I>::insert(&collection, &item, &details); | ||
|
||
Self::deposit_event(Event::AllApprovalsCancelled { | ||
collection, | ||
item, | ||
owner: details.owner, | ||
}); | ||
|
||
Ok(()) | ||
} | ||
} |
Oops, something went wrong.