From 18c554b8864e7c7cbb2e846dfd96acaec64de90a Mon Sep 17 00:00:00 2001 From: itsfine Date: Fri, 25 Mar 2022 14:54:00 +0100 Subject: [PATCH] Voting hazi update --- Voting hazi.sol | 40 +++++++++++++++++++++++++++++++++------- 1 file changed, 33 insertions(+), 7 deletions(-) diff --git a/Voting hazi.sol b/Voting hazi.sol index bdad8b5..735b889 100644 --- a/Voting hazi.sol +++ b/Voting hazi.sol @@ -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"; + } + } \ No newline at end of file