Last active
March 14, 2021 04:06
-
-
Save quin2/fe514e99edde43e5f402521bbd8a0c0e to your computer and use it in GitHub Desktop.
ranking
This file contains hidden or 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
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