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
+9 -3
View File
@@ -356,6 +356,8 @@ pub mod pallet {
PathError,
/// The provided path must consists of unique assets.
NonUniquePath,
/// It was not possible to get or increment the Id of the pool.
IncorrectPoolAssetId,
/// Unable to find an element in an array/vec that should have one-to-one correspondence
/// with another. For example, an array of assets constituting a `path` should have a
/// corresponding array of `amounts` along the path.
@@ -426,8 +428,10 @@ pub mod pallet {
MultiAssetIdConversionResult::Native => (),
}
let lp_token = NextPoolAssetId::<T>::get().unwrap_or(T::PoolAssetId::initial_value());
let next_lp_token_id = lp_token.increment();
let lp_token = NextPoolAssetId::<T>::get()
.or(T::PoolAssetId::initial_value())
.ok_or(Error::<T>::IncorrectPoolAssetId)?;
let next_lp_token_id = lp_token.increment().ok_or(Error::<T>::IncorrectPoolAssetId)?;
NextPoolAssetId::<T>::set(Some(next_lp_token_id));
T::PoolAssets::create(lp_token.clone(), pool_account.clone(), false, 1u32.into())?;
@@ -1223,7 +1227,9 @@ pub mod pallet {
/// Returns the next pool asset id for benchmark purposes only.
#[cfg(any(test, feature = "runtime-benchmarks"))]
pub fn get_next_pool_asset_id() -> T::PoolAssetId {
NextPoolAssetId::<T>::get().unwrap_or(T::PoolAssetId::initial_value())
NextPoolAssetId::<T>::get()
.or(T::PoolAssetId::initial_value())
.expect("Next pool asset ID can not be None")
}
}
}