@@ -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,9 +149,9 @@ 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
@@ -229,19 +236,19 @@ pub mod pallet {
229236 } ,
230237 ResourceAdded {
231238 nft_id : NftId ,
232- resource_id : BoundedResource < T :: ResourceSymbolLimit > ,
239+ resource_id : ResourceId ,
233240 } ,
234241 ResourceAccepted {
235242 nft_id : NftId ,
236- resource_id : BoundedResource < T :: ResourceSymbolLimit > ,
243+ resource_id : ResourceId ,
237244 } ,
238245 ResourceRemoval {
239246 nft_id : NftId ,
240- resource_id : BoundedResource < T :: ResourceSymbolLimit > ,
247+ resource_id : ResourceId ,
241248 } ,
242249 ResourceRemovalAccepted {
243250 nft_id : NftId ,
244- resource_id : BoundedResource < T :: ResourceSymbolLimit > ,
251+ resource_id : ResourceId ,
245252 } ,
246253 PrioritySet {
247254 collection_id : CollectionId ,
@@ -258,6 +265,7 @@ pub mod pallet {
258265 StorageOverflow ,
259266 TooLong ,
260267 NoAvailableCollectionId ,
268+ NoAvailableResourceId ,
261269 MetadataNotSet ,
262270 RecipientNotSet ,
263271 NoAvailableNftId ,
@@ -582,16 +590,14 @@ pub mod pallet {
582590 origin : OriginFor < T > ,
583591 collection_id : CollectionId ,
584592 nft_id : NftId ,
585- resource_id : BoundedResource < T :: ResourceSymbolLimit > ,
586593 resource : BasicResource < StringLimitOf < T > > ,
587594 ) -> DispatchResult {
588595 let sender = ensure_signed ( origin. clone ( ) ) ?;
589596
590- Self :: resource_add (
597+ let resource_id = Self :: resource_add (
591598 sender,
592599 collection_id,
593600 nft_id,
594- resource_id. clone ( ) ,
595601 ResourceTypes :: Basic ( resource) ,
596602 ) ?;
597603
@@ -611,11 +617,10 @@ pub mod pallet {
611617 ) -> DispatchResult {
612618 let sender = ensure_signed ( origin. clone ( ) ) ?;
613619
614- Self :: resource_add (
620+ let resource_id = Self :: resource_add (
615621 sender,
616622 collection_id,
617623 nft_id,
618- resource_id. clone ( ) ,
619624 ResourceTypes :: Composable ( resource) ,
620625 ) ?;
621626
@@ -630,16 +635,14 @@ pub mod pallet {
630635 origin : OriginFor < T > ,
631636 collection_id : CollectionId ,
632637 nft_id : NftId ,
633- resource_id : BoundedResource < T :: ResourceSymbolLimit > ,
634638 resource : SlotResource < StringLimitOf < T > > ,
635639 ) -> DispatchResult {
636640 let sender = ensure_signed ( origin. clone ( ) ) ?;
637641
638- Self :: resource_add (
642+ let resource_id = Self :: resource_add (
639643 sender,
640644 collection_id,
641645 nft_id,
642- resource_id. clone ( ) ,
643646 ResourceTypes :: Slot ( resource) ,
644647 ) ?;
645648
@@ -654,19 +657,19 @@ pub mod pallet {
654657 origin : OriginFor < T > ,
655658 collection_id : CollectionId ,
656659 nft_id : NftId ,
657- resource_id : BoundedResource < T :: ResourceSymbolLimit > ,
660+ resource_id : ResourceId ,
658661 ) -> DispatchResult {
659662 let sender = ensure_signed ( origin. clone ( ) ) ?;
660663 ensure ! (
661- Resources :: <T >:: get( ( collection_id, nft_id, resource_id. clone ( ) ) ) . is_some( ) ,
664+ Resources :: <T >:: get( ( collection_id, nft_id, resource_id) ) . is_some( ) ,
662665 Error :: <T >:: ResourceDoesntExist
663666 ) ;
664667
665668 let ( owner, _) = Pallet :: < T > :: lookup_root_owner ( collection_id, nft_id) ?;
666669 ensure ! ( owner == sender, Error :: <T >:: NoPermission ) ;
667670
668671 Resources :: < T > :: try_mutate_exists (
669- ( collection_id, nft_id, resource_id. clone ( ) ) ,
672+ ( collection_id, nft_id, resource_id) ,
670673 |resource| -> DispatchResult {
671674 if let Some ( res) = resource. into_mut ( ) {
672675 ensure ! ( res. pending, Error :: <T >:: ResourceNotPending ) ;
@@ -687,11 +690,11 @@ pub mod pallet {
687690 origin : OriginFor < T > ,
688691 collection_id : CollectionId ,
689692 nft_id : NftId ,
690- resource_id : BoundedResource < T :: ResourceSymbolLimit > ,
693+ resource_id : ResourceId ,
691694 ) -> DispatchResult {
692695 let sender = ensure_signed ( origin. clone ( ) ) ?;
693696
694- Self :: resource_remove ( sender, collection_id, nft_id, resource_id. clone ( ) ) ?;
697+ Self :: resource_remove ( sender, collection_id, nft_id, resource_id) ?;
695698
696699 Self :: deposit_event ( Event :: ResourceRemoval { nft_id, resource_id } ) ;
697700 Ok ( ( ) )
@@ -704,11 +707,11 @@ pub mod pallet {
704707 origin : OriginFor < T > ,
705708 collection_id : CollectionId ,
706709 nft_id : NftId ,
707- resource_id : BoundedResource < T :: ResourceSymbolLimit > ,
710+ resource_id : ResourceId ,
708711 ) -> DispatchResult {
709712 let sender = ensure_signed ( origin. clone ( ) ) ?;
710713
711- Self :: accept_removal ( sender, collection_id, nft_id, resource_id. clone ( ) ) ?;
714+ Self :: accept_removal ( sender, collection_id, nft_id, resource_id) ?;
712715
713716 Self :: deposit_event ( Event :: ResourceRemovalAccepted { nft_id, resource_id } ) ;
714717 Ok ( ( ) )
0 commit comments