59 lines
1.5 KiB
Solidity
59 lines
1.5 KiB
Solidity
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
pragma solidity ^0.8.11;
|
|
|
|
|
|
contract VoteforBest {
|
|
uint public NFT;
|
|
uint public ERC20;
|
|
uint public DAO;
|
|
mapping(address => bool) private Voters;
|
|
|
|
|
|
|
|
struct Voter{
|
|
bool voteSpent;
|
|
uint weight;
|
|
}
|
|
|
|
struct Proposal{
|
|
uint votenumber;
|
|
}
|
|
|
|
address public chairman;
|
|
|
|
mapping(address => Voter ) public voters;
|
|
|
|
|
|
|
|
function Vote (string memory _choice) public {
|
|
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;
|
|
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++;
|
|
}}
|
|
|
|
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";
|
|
}
|
|
|
|
|
|
} |