Hi all, I am trying to exercise my solidity skills with a sample project. Would you have any feedback or improvement?
Project description: Santa’s list
- Create a user tracking dapp. Build a system for tracking who is on their nice list and who is on their naughty list.
- Allow for people to pay a fee to get themselves off of the naughty list.
- Let users on the nice list earn a portion of the fees based on how many other people are on the nice list.
I have tried to tackle point number 1 as follows, please let me know if I can improve this (please also note I have tried to avoid the iteration approach to be sensible on Gas usage)
pragma solidity 0.8.1;
contract SantasList {
mapping (string => uint) naughtyList;
mapping (string => uint) niceList;
mapping (string => bool) addedOrNot;
string[] addedPeople;
function addToList(string memory _name, bool _isnice) public {
if (addedOrNot[_name] == false){
if (_isnice == true){
addedPeople.push(_name);
niceList[_name] = addedPeople.length+1;
} else {
addedPeople.push(_name);
naughtyList[_name] = addedPeople.length+1;
}
}
}
function changeBehaviour (string memory _name, bool _isnice) public returns (string memory _location){
if (_isnice == true) {
if (niceList[_name] != 0){
return (“already nice”);
}else{
niceList[_name] = naughtyList[_name];
}
} else {
if (naughtyList[_name] != 0){
return (“already naughty”);
}else{
niceList[_name] = naughtyList[_name];
}
}
}
}