Skip to content

Instantly share code, notes, and snippets.

@quin2
Last active March 14, 2021 04:06
Show Gist options
  • Save quin2/fe514e99edde43e5f402521bbd8a0c0e to your computer and use it in GitHub Desktop.
Save quin2/fe514e99edde43e5f402521bbd8a0c0e to your computer and use it in GitHub Desktop.
ranking
pragma solidity >=0.7.0 <0.8.0;
contract rankingApp
{
uint256 nThings;
address private owner;
mapping (string => uint256) public things;
mapping (uint256 => uint256) public ratings;
constructor() {
owner = msg.sender;
}
modifier isOwner() {
require(msg.sender == owner, "Caller is not owner");
_;
}
function addItemToRate(string memory item) public isOwner {
nThings++;
things[item]=nThings;
ratings[nThings]=1;
}
function downVote(string memory toDownVote) public{
uint256 ind = things[toDownVote];
if(ind == 0){
revert();
}
ratings[ind]--;
}
function upVote(string memory toUpVote) public{
uint256 ind = things[toUpVote];
if(ind == 0){
revert();
}
ratings[ind]++;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment