Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

decouple equip and unequip #190

Merged
merged 4 commits into from
Jul 28, 2022
Merged

Conversation

bmacer
Copy link
Contributor

@bmacer bmacer commented Jun 25, 2022

should fix #147,
i think it solves #185 as well.

@bmacer bmacer requested a review from ilionic June 25, 2022 04:35
@ilionic ilionic requested a review from HashWarlock July 4, 2022 12:19
pallet_uniques::Error::<T>::Locked
);

let item_is_equipped =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we repeat these 2 steps, should we create a helper functions like is_nft_equipped((collection_id, nft_id), base_id, slot_id) and nft_exists(collection_id, nft_id)? Could be useful for projects downstream in the future that use RMRK pallet as well. What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i went ahead and did this. initially i included returning as a Result, but that didn't work out, because...in the case of nft_exists, there was more action i needed to take; and in the case of is_nft_equipped, i couldn't throw an error because the two times we use it are in opposite cases, so the errors would be different (AlreadyEquipped in the case of equip, and NotEquipped in the case of unequip). But anyway, the more helper methods the better. Always appreciate the feedback and suggestions, as I'm just making it up as I go 👯

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done in e138584

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i went ahead and did this. initially i included returning as a Result, but that didn't work out, because...in the case of nft_exists, there was more action i needed to take; and in the case of is_nft_equipped, i couldn't throw an error because the two times we use it are in opposite cases, so the errors would be different (AlreadyEquipped in the case of equip, and NotEquipped in the case of unequip). But anyway, the more helper methods the better. Always appreciate the feedback and suggestions, as I'm just making it up as I go dancers

I see, I think returning a bool is the right solution & this allows for others to return the relevant error based on their downstream implementation.

@bmacer
Copy link
Contributor Author

bmacer commented Jul 8, 2022

in e138584 i also added a splitting of AlreadyEquipped error into SlotAlreadyEquipped and ItemAlreadyEquipped, as these should be distinct. also added some test for this. another quick peek would be appreciated.


// Item must exist
let item_exists =
pallet_rmrk_core::Pallet::<T>::nfts(item_collection_id, item_nft_id).is_some();
pallet_rmrk_core::Pallet::<T>::nft_exists((item_collection_id, item_nft_id));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do what you did on line 166 for this logic here:
ensure!(pallet_rmrk_core::Pallet::<T>::nft_exists((item_collection_id, item_nft_id)), Error::<T>::ItemDoesntExist);

Copy link
Contributor

@HashWarlock HashWarlock left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix conflicts before merge.

@ilionic ilionic merged commit b56ef02 into main Jul 28, 2022
@ilionic ilionic deleted the bug/147-decouple-equip-and-unequip branch July 28, 2022 11:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Decouple Equip Logic
4 participants