@@ -111,6 +111,7 @@ where
111111 issuer : T :: AccountId ,
112112 item : ( CollectionId , NftId ) ,
113113 equipper : ( CollectionId , NftId ) ,
114+ resource_id : ResourceId ,
114115 base_id : BaseId ,
115116 slot_id : SlotId ,
116117 ) -> Result < ( CollectionId , NftId , BaseId , SlotId , bool ) , DispatchError > {
@@ -223,49 +224,29 @@ where
223224
224225 // Equipper must have a resource that is associated with the provided base ID
225226 // First we iterate through the resources added to this NFT in search of the base ID
226- let mut found_base_resource_on_nft = false ;
227- let resources_matching_base_iter = pallet_rmrk_core:: Resources :: < T > :: iter_prefix_values ( (
227+ ensure ! (
228+ pallet_rmrk_core:: Pallet :: <T >:: composable_resources ( (
228229 equipper_collection_id,
229230 equipper_nft_id,
230- ) ) ;
231-
232- for resource in resources_matching_base_iter {
233- match resource. resource {
234- ResourceTypes :: Composable ( res) => {
235- if res. base == base_id {
236- found_base_resource_on_nft = true ;
237- }
238- } ,
239- _ => ( ) ,
240- }
241-
242- }
243-
244- // If we don't find a matching base resource, we raise a NoResourceForThisBaseFoundOnNft
245- // error
246- ensure ! ( found_base_resource_on_nft, Error :: <T >:: NoResourceForThisBaseFoundOnNft ) ;
231+ // resource_id,
232+ base_id
233+ ) )
234+ . is_some( ) ,
235+ Error :: <T >:: NoResourceForThisBaseFoundOnNft
236+ ) ;
247237
248238 // The item being equipped must be have a resource that is equippable into that base.slot
249- let mut found_base_slot_resource_on_nft = false ;
250-
251- // initialized so the compiler doesn't complain, though it will be overwritten if it
252- // resource exists
253- let mut to_equip_resource_id: ResourceId = 0_u32 . into ( ) ;
254-
255- let resources_matching_base_iter =
256- pallet_rmrk_core:: Resources :: < T > :: iter_prefix_values ( ( item_collection_id, item_nft_id) ) ;
257-
258- for resource in resources_matching_base_iter {
259- match resource. resource {
260- ResourceTypes :: Slot ( res) =>
261- if res. slot == slot_id && res. base == base_id {
262- found_base_slot_resource_on_nft = true ;
263- to_equip_resource_id = resource. id ;
264- } ,
265- _ => ( ) ,
266- }
267- }
268- ensure ! ( found_base_slot_resource_on_nft, Error :: <T >:: ItemHasNoResourceToEquipThere ) ;
239+ ensure ! (
240+ pallet_rmrk_core:: Pallet :: <T >:: slot_resources( (
241+ item_collection_id,
242+ item_nft_id,
243+ resource_id,
244+ base_id,
245+ slot_id
246+ ) )
247+ . is_some( ) ,
248+ Error :: <T >:: ItemHasNoResourceToEquipThere
249+ ) ;
269250
270251 // Part must exist
271252 ensure ! ( Self :: parts( base_id, slot_id) . is_some( ) , Error :: <T >:: PartDoesntExist ) ;
@@ -290,7 +271,7 @@ where
290271 // Equip item (add to Equippings)
291272 Equippings :: < T > :: insert (
292273 ( ( equipper_collection_id, equipper_nft_id) , base_id, slot_id) ,
293- to_equip_resource_id ,
274+ resource_id ,
294275 ) ;
295276
296277 // Update item's equipped property
0 commit comments