changes to nfts pallet for xcm integration (#14395)

* Use Incrementable from frame_support::traits

* Chore

* make incremental fallible and new nfts function for custom collection ids

* fmt

* fix benchmark tests nfts

* add test

* fmt

* add safety comment to CollectionId

* fmt

* add comments to Incrementable

* line wrapping

* rewrap comments

* address feedback

* fmt

* change unwrap for expect

---------

Co-authored-by: Jegor Sidorenko <jegor@parity.io>
Co-authored-by: parity-processbot <>
This commit is contained in:
Just van Stam
2023-07-25 10:02:39 +02:00
committed by GitHub
parent 5e6bbfa0a6
commit ae018a01a4
9 changed files with 145 additions and 29 deletions
+21 -8
View File
@@ -132,24 +132,37 @@ macro_rules! impl_incrementable {
($($type:ty),+) => {
$(
impl Incrementable for $type {
fn increment(&self) -> Self {
fn increment(&self) -> Option<Self> {
let mut val = self.clone();
val.saturating_inc();
val
Some(val)
}
fn initial_value() -> Self {
0
fn initial_value() -> Option<Self> {
Some(0)
}
}
)+
};
}
/// For example: allows new identifiers to be created in a linear fashion.
pub trait Incrementable {
fn increment(&self) -> Self;
fn initial_value() -> Self;
/// A trait representing an incrementable type.
///
/// The `increment` and `initial_value` functions are fallible.
/// They should either both return `Some` with a valid value, or `None`.
pub trait Incrementable
where
Self: Sized,
{
/// Increments the value.
///
/// Returns `Some` with the incremented value if it is possible, or `None` if it is not.
fn increment(&self) -> Option<Self>;
/// Returns the initial value.
///
/// Returns `Some` with the initial value if it is available, or `None` if it is not.
fn initial_value() -> Option<Self>;
}
impl_incrementable!(u8, u16, u32, u64, u128, i8, i16, i32, i64, i128);
@@ -198,6 +198,13 @@ pub trait Create<AccountId, CollectionConfig>: Inspect<AccountId> {
admin: &AccountId,
config: &CollectionConfig,
) -> Result<Self::CollectionId, DispatchError>;
fn create_collection_with_id(
collection: Self::CollectionId,
who: &AccountId,
admin: &AccountId,
config: &CollectionConfig,
) -> Result<(), DispatchError>;
}
/// Trait for providing the ability to destroy collections of nonfungible items.