Created
March 5, 2021 20:16
-
-
Save wafflemakr/3eb0b51d502e88fd3cb0010e05c8714d to your computer and use it in GitHub Desktop.
Using Enumerable Set From OZ
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SPDX-License-Identifier: agpl-3.0 | |
pragma solidity ^0.6.12; | |
import "./Enumerable.sol"; | |
contract Test{ | |
using EnumerableSet for EnumerableSet.UintSet; | |
mapping (address => EnumerableSet.UintSet) private ownedCards; | |
function addCardToUser(address user, uint cardId) external{ | |
ownedCards[user].add(cardId); | |
} | |
function removeCardFromUser(address user, uint cardId) external{ | |
ownedCards[user].remove(cardId); | |
} | |
function isCardOwned(address user, uint cardId) external view returns(bool){ | |
return ownedCards[user].contains(cardId); | |
} | |
function getAllCards(address user) external view returns(uint[] memory){ | |
uint totalCards = ownedCards[user].length(); | |
uint[] memory cards = new uint[](totalCards); | |
for(uint i=0; i<totalCards; i++){ | |
cards[i] = ownedCards[user].at(i); | |
} | |
return cards; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment