Voting hazi update
parent
4838feac74
commit
18c554b886
|
@ -1,25 +1,36 @@
|
|||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
pragma solidity ^0.8.11;
|
||||
|
||||
/* nem sikerült: megcsinálni, hogy hogyan kell a bool type-ot megváltoztatni, amikor már szavazott az addres;
|
||||
beállítani, hogy melyek address-ek szavazhatnak */
|
||||
|
||||
contract VoteforBest {
|
||||
uint public NFT;
|
||||
uint public ERC20;
|
||||
uint public DAO;
|
||||
bool public voted;
|
||||
mapping(address => bool) private Voters;
|
||||
|
||||
|
||||
address public owner;
|
||||
|
||||
struct Voter{
|
||||
bool voted;
|
||||
address addr;
|
||||
bool voteSpent;
|
||||
uint weight;
|
||||
}
|
||||
|
||||
mapping(address=> Voter ) public voters;
|
||||
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"))) {
|
||||
|
@ -29,5 +40,20 @@ contract VoteforBest {
|
|||
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";
|
||||
}
|
||||
|
||||
|
||||
}
|
Loading…
Reference in New Issue