From d364b895afdd203d7ce8753425c5c089dc35a0ee Mon Sep 17 00:00:00 2001 From: Daniel Shiposha Date: Tue, 24 May 2022 14:23:31 +0000 Subject: [PATCH] fix: last_collection_idx --- --- a/pallets/proxy-rmrk-core/src/lib.rs +++ b/pallets/proxy-rmrk-core/src/lib.rs @@ -46,6 +46,10 @@ type Event: From> + IsType<::Event>; } + #[pallet::storage] + #[pallet::getter(fn collection_index)] + pub type CollectionIndex = StorageValue<_, RmrkCollectionId, ValueQuery>; + #[pallet::pallet] #[pallet::generate_store(pub(super) trait Store)] pub struct Pallet(_); @@ -143,6 +147,8 @@ ].into_iter() )?; + >::mutate(|n| *n += 1); + Self::deposit_event(Event::CollectionCreated { issuer: sender, collection_id: collection_id.0 @@ -378,6 +384,10 @@ .map_err(Self::map_common_err_to_proxy) } + pub fn last_collection_idx() -> RmrkCollectionId { + >::get() + } + pub fn get_nft_collection(collection_id: CollectionId) -> Result, DispatchError> { let collection = >::try_get(collection_id) .map_err(|_| >::CollectionUnknown)? --- a/runtime/common/src/runtime_apis.rs +++ b/runtime/common/src/runtime_apis.rs @@ -142,7 +142,7 @@ RmrkTheme > for Runtime { fn last_collection_idx() -> Result { - Ok(>::get().0) // todo storage from proxy pallet + Ok(RmrkCore::last_collection_idx()) } fn collection_by_id(collection_id: RmrkCollectionId) -> Result>, DispatchError> { // TODO decide on displacement to palettes -- does RMRK belong there, spread across common and nonfungible? @@ -155,7 +155,7 @@ let collection_id = CollectionId(collection_id); let collection = >::get_typed_nft_collection(collection_id, CollectionType::Regular)?; - + let metadata = BoundedVec::try_from( >::get_collection_property(collection_id, RmrkProperty::Metadata)?.into_inner() ).map_err(|_| >::PropertyKeyIsTooLong)?; @@ -179,7 +179,7 @@ let collection_id = CollectionId(collection_id); let nft_id = TokenId(nft_by_id); - + let owner = match (dispatch_unique_runtime!(collection_id.token_owner(nft_id)) as Result, DispatchError>)? { Some(owner) => match ::CrossTokenAddressMapping::address_to_token(&owner) { Some((col, tok)) => RmrkAccountIdOrCollectionNftTuple::CollectionAndNftTuple(col.0, tok.0), @@ -202,7 +202,7 @@ ).unwrap() ) .collect::>(); - + let allowance = pallet_nonfungible::Allowance::::get((collection_id, nft_id)); Ok(Some(RmrkInstanceInfo { @@ -384,7 +384,7 @@ //.map_err(|_| ) // no need, tis a filter_map .unwrap() .rmrk_nft_type()?; - + // dislocate to rmrkproxycore and simply send an array of keys let keys = [ //RmrkProperty::PartId)?, @@ -392,7 +392,7 @@ RmrkProperty::ZIndex, RmrkProperty::EquippableList, ]; - + let properties = keys.into_iter().map( |key| BoundedVec::try_from( >::get_nft_property(collection_id, *token_id, key).unwrap().into_inner() @@ -431,7 +431,7 @@ let nft_type = >::get((collection_id, token_id)) .unwrap() .rmrk_nft_type()?; - + match nft_type { Theme => Some( >::get_nft_property( -- gitstuff