SolWorkshops/contracts/dummy_voting.sol

49 lines
1.2 KiB
Solidity

// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity ^0.8.13;
contract Voting{
struct Vote_state {
bool voted;
}
mapping(address => bool) private Voters;
uint256 nft = 0;
uint256 dao = 0;
uint256 token = 0;
constructor() {
Voters[0x5B38Da6a701c568545dCfcB03FcB875f56beddC4] = false;
}
function vote(uint256 option) external returns (bool) {
require(Voters[msg.sender] == false, "Already voted or non-existent.");
if (option == 1) {
Voters[msg.sender] = true;
nft = nft + 1;
return true;
}
if (option == 2) {
Voters[msg.sender] = true;
dao = dao + 1;
return true;
}
if (option == 3) {
Voters[msg.sender] = true;
token = token + 1;
return true;
}
return false;
}
function result() external view returns (string memory){
if (nft > dao && nft > token) {
return "nft";}
else if (dao > nft && dao > token){
return "dao";}
else if (token > nft && token > dao){
return "token";}
return "couldnt decide";
}
}