Voting_Homework/Voting hazi.sol

59 lines
1.5 KiB
Solidity
Raw Permalink Normal View History

2022-03-18 14:56:22 +00:00
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity ^0.8.11;
contract VoteforBest {
uint public NFT;
uint public ERC20;
uint public DAO;
2022-03-25 13:54:00 +00:00
mapping(address => bool) private Voters;
2022-03-18 14:56:22 +00:00
2022-03-25 13:54:00 +00:00
2022-03-18 14:56:22 +00:00
struct Voter{
2022-03-25 13:54:00 +00:00
bool voteSpent;
uint weight;
}
struct Proposal{
uint votenumber;
2022-03-18 14:56:22 +00:00
}
2022-03-25 13:54:00 +00:00
address public chairman;
mapping(address => Voter ) public voters;
2022-03-18 14:56:22 +00:00
function Vote (string memory _choice) public {
2022-03-25 13:54:00 +00:00
chairman = msg.sender;
Voter storage sender = voters[msg.sender];
require(!sender.voteSpent, 'Please do not vote more than once');
voters[chairman].weight = 1;
sender.voteSpent = true;
2022-03-18 14:56:22 +00:00
if (keccak256(abi.encodePacked(_choice)) == keccak256(abi.encodePacked("NFT"))) {
NFT++;}
else if (keccak256(abi.encodePacked(_choice)) == keccak256(abi.encodePacked("DAO"))) {
DAO++;}
else {
require(keccak256(abi.encodePacked(_choice)) == keccak256(abi.encodePacked("ERC20")), 'Please use valid vote option');
ERC20++;
}}
2022-03-25 13:54:00 +00:00
function showstatus () public view returns (uint NFT_, uint ERC20_, uint DAO_){
return (NFT, ERC20, DAO);
}
function Winner () public view returns (string memory){
if (NFT>ERC20 && NFT>DAO) {
return "NFT";}
else if (ERC20 > NFT && ERC20 > DAO) {
return "ERC20";}
else if (DAO > NFT && DAO > ERC20) {
return "DAO";}
return "No winner";
}
2022-03-18 14:56:22 +00:00
}