@@ -11,9 +11,9 @@ use sp_runtime::{traits::StaticLookup, DispatchError, Permill};
1111use sp_std:: convert:: TryInto ;
1212
1313use rmrk_traits:: {
14- primitives:: * , AccountIdOrCollectionNftTuple , Collection , CollectionInfo , Nft , NftInfo ,
15- Priority , Property , Resource , ResourceInfo , RoyaltyInfo ,
16- ResourceTypes , BasicResource , SlotResource , ComposableResource
14+ primitives:: * , AccountIdOrCollectionNftTuple , BasicResource , Collection , CollectionInfo ,
15+ ComposableResource , Nft , NftInfo , Priority , Property , Resource , ResourceInfo , ResourceTypes ,
16+ RoyaltyInfo , SlotResource ,
1717} ;
1818use sp_std:: result:: Result ;
1919
@@ -29,8 +29,7 @@ pub type InstanceInfoOf<T> = NftInfo<
2929 <T as frame_system:: Config >:: AccountId ,
3030 BoundedVec < u8 , <T as pallet_uniques:: Config >:: StringLimit > ,
3131> ;
32- pub type ResourceOf < T , R , P > = ResourceInfo <
33- BoundedVec < u8 , R > ,
32+ pub type ResourceOf < T , P > = ResourceInfo <
3433 BoundedVec < u8 , <T as pallet_uniques:: Config >:: StringLimit > ,
3534 BoundedVec < PartId , P > ,
3635> ;
@@ -90,7 +89,15 @@ pub mod pallet {
9089 /// Next available Resource ID.
9190 #[ pallet:: storage]
9291 #[ pallet:: getter( fn next_resource_id) ]
93- pub type NextResourceId < T : Config > = StorageValue < _ , ResourceId , ValueQuery > ;
92+ pub type NextResourceId < T : Config > = StorageDoubleMap <
93+ _ ,
94+ Twox64Concat ,
95+ CollectionId ,
96+ Twox64Concat ,
97+ NftId ,
98+ ResourceId ,
99+ ValueQuery ,
100+ > ;
94101
95102 #[ pallet:: storage]
96103 #[ pallet:: getter( fn collections) ]
@@ -142,12 +149,40 @@ pub mod pallet {
142149 (
143150 NMapKey < Blake2_128Concat , CollectionId > ,
144151 NMapKey < Blake2_128Concat , NftId > ,
145- NMapKey < Blake2_128Concat , BoundedResource < T :: ResourceSymbolLimit > > ,
152+ NMapKey < Blake2_128Concat , ResourceId > ,
146153 ) ,
147- ResourceOf < T , T :: ResourceSymbolLimit , T :: PartsLimit > ,
154+ ResourceOf < T , T :: PartsLimit > ,
148155 OptionQuery ,
149156 > ;
150157
158+ #[ pallet:: storage]
159+ #[ pallet:: getter( fn composable_resources) ]
160+ /// Stores resource info
161+ pub type ComposableResources < T : Config > = StorageNMap <
162+ _ ,
163+ (
164+ NMapKey < Blake2_128Concat , CollectionId > ,
165+ NMapKey < Blake2_128Concat , NftId > ,
166+ NMapKey < Blake2_128Concat , BaseId > ,
167+ ) ,
168+ ( ) ,
169+ > ;
170+
171+ #[ pallet:: storage]
172+ #[ pallet:: getter( fn slot_resources) ]
173+ /// Stores resource info
174+ pub type SlotResources < T : Config > = StorageNMap <
175+ _ ,
176+ (
177+ NMapKey < Blake2_128Concat , CollectionId > ,
178+ NMapKey < Blake2_128Concat , NftId > ,
179+ NMapKey < Blake2_128Concat , ResourceId > ,
180+ NMapKey < Blake2_128Concat , BaseId > ,
181+ NMapKey < Blake2_128Concat , SlotId > ,
182+ ) ,
183+ ( ) ,
184+ > ;
185+
151186 #[ pallet:: storage]
152187 #[ pallet:: getter( fn properties) ]
153188 /// Metadata of an asset class.
@@ -229,19 +264,19 @@ pub mod pallet {
229264 } ,
230265 ResourceAdded {
231266 nft_id : NftId ,
232- resource_id : BoundedResource < T :: ResourceSymbolLimit > ,
267+ resource_id : ResourceId ,
233268 } ,
234269 ResourceAccepted {
235270 nft_id : NftId ,
236- resource_id : BoundedResource < T :: ResourceSymbolLimit > ,
271+ resource_id : ResourceId ,
237272 } ,
238273 ResourceRemoval {
239274 nft_id : NftId ,
240- resource_id : BoundedResource < T :: ResourceSymbolLimit > ,
275+ resource_id : ResourceId ,
241276 } ,
242277 ResourceRemovalAccepted {
243278 nft_id : NftId ,
244- resource_id : BoundedResource < T :: ResourceSymbolLimit > ,
279+ resource_id : ResourceId ,
245280 } ,
246281 PrioritySet {
247282 collection_id : CollectionId ,
@@ -258,6 +293,7 @@ pub mod pallet {
258293 StorageOverflow ,
259294 TooLong ,
260295 NoAvailableCollectionId ,
296+ NoAvailableResourceId ,
261297 MetadataNotSet ,
262298 RecipientNotSet ,
263299 NoAvailableNftId ,
@@ -582,16 +618,14 @@ pub mod pallet {
582618 origin : OriginFor < T > ,
583619 collection_id : CollectionId ,
584620 nft_id : NftId ,
585- resource_id : BoundedResource < T :: ResourceSymbolLimit > ,
586621 resource : BasicResource < StringLimitOf < T > > ,
587622 ) -> DispatchResult {
588623 let sender = ensure_signed ( origin. clone ( ) ) ?;
589624
590- Self :: resource_add (
625+ let resource_id = Self :: resource_add (
591626 sender,
592627 collection_id,
593628 nft_id,
594- resource_id. clone ( ) ,
595629 ResourceTypes :: Basic ( resource) ,
596630 ) ?;
597631
@@ -611,11 +645,10 @@ pub mod pallet {
611645 ) -> DispatchResult {
612646 let sender = ensure_signed ( origin. clone ( ) ) ?;
613647
614- Self :: resource_add (
648+ let resource_id = Self :: resource_add (
615649 sender,
616650 collection_id,
617651 nft_id,
618- resource_id. clone ( ) ,
619652 ResourceTypes :: Composable ( resource) ,
620653 ) ?;
621654
@@ -630,16 +663,14 @@ pub mod pallet {
630663 origin : OriginFor < T > ,
631664 collection_id : CollectionId ,
632665 nft_id : NftId ,
633- resource_id : BoundedResource < T :: ResourceSymbolLimit > ,
634666 resource : SlotResource < StringLimitOf < T > > ,
635667 ) -> DispatchResult {
636668 let sender = ensure_signed ( origin. clone ( ) ) ?;
637669
638- Self :: resource_add (
670+ let resource_id = Self :: resource_add (
639671 sender,
640672 collection_id,
641673 nft_id,
642- resource_id. clone ( ) ,
643674 ResourceTypes :: Slot ( resource) ,
644675 ) ?;
645676
@@ -654,19 +685,19 @@ pub mod pallet {
654685 origin : OriginFor < T > ,
655686 collection_id : CollectionId ,
656687 nft_id : NftId ,
657- resource_id : BoundedResource < T :: ResourceSymbolLimit > ,
688+ resource_id : ResourceId ,
658689 ) -> DispatchResult {
659690 let sender = ensure_signed ( origin. clone ( ) ) ?;
660691 ensure ! (
661- Resources :: <T >:: get( ( collection_id, nft_id, resource_id. clone ( ) ) ) . is_some( ) ,
692+ Resources :: <T >:: get( ( collection_id, nft_id, resource_id) ) . is_some( ) ,
662693 Error :: <T >:: ResourceDoesntExist
663694 ) ;
664695
665696 let ( owner, _) = Pallet :: < T > :: lookup_root_owner ( collection_id, nft_id) ?;
666697 ensure ! ( owner == sender, Error :: <T >:: NoPermission ) ;
667698
668699 Resources :: < T > :: try_mutate_exists (
669- ( collection_id, nft_id, resource_id. clone ( ) ) ,
700+ ( collection_id, nft_id, resource_id) ,
670701 |resource| -> DispatchResult {
671702 if let Some ( res) = resource. into_mut ( ) {
672703 ensure ! ( res. pending, Error :: <T >:: ResourceNotPending ) ;
@@ -687,11 +718,11 @@ pub mod pallet {
687718 origin : OriginFor < T > ,
688719 collection_id : CollectionId ,
689720 nft_id : NftId ,
690- resource_id : BoundedResource < T :: ResourceSymbolLimit > ,
721+ resource_id : ResourceId ,
691722 ) -> DispatchResult {
692723 let sender = ensure_signed ( origin. clone ( ) ) ?;
693724
694- Self :: resource_remove ( sender, collection_id, nft_id, resource_id. clone ( ) ) ?;
725+ Self :: resource_remove ( sender, collection_id, nft_id, resource_id) ?;
695726
696727 Self :: deposit_event ( Event :: ResourceRemoval { nft_id, resource_id } ) ;
697728 Ok ( ( ) )
@@ -704,11 +735,11 @@ pub mod pallet {
704735 origin : OriginFor < T > ,
705736 collection_id : CollectionId ,
706737 nft_id : NftId ,
707- resource_id : BoundedResource < T :: ResourceSymbolLimit > ,
738+ resource_id : ResourceId ,
708739 ) -> DispatchResult {
709740 let sender = ensure_signed ( origin. clone ( ) ) ?;
710741
711- Self :: accept_removal ( sender, collection_id, nft_id, resource_id. clone ( ) ) ?;
742+ Self :: accept_removal ( sender, collection_id, nft_id, resource_id) ?;
712743
713744 Self :: deposit_event ( Event :: ResourceRemovalAccepted { nft_id, resource_id } ) ;
714745 Ok ( ( ) )
0 commit comments