Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //SPDX-License-Identifier: GPL-3.0
- pragma solidity 0.8.7;
- import "hardhat/console.sol";
- contract Voting {
- address public owner;
- address[5] private allAddresses;
- uint private voteEnd;
- uint private totalVotes;
- string[5] private allVotes;
- struct Voter {
- bool voted;
- string vote;
- }
- constructor () {
- owner = msg.sender;
- voteEnd = block.timestamp + 20;
- totalVotes = 0;
- }
- modifier notOwner {
- require(msg.sender != owner, "Owners cannot participate in the auction.");
- _;
- }
- modifier votesDone {
- require(block.timestamp >= voteEnd, "The vote is not yet finished.");
- _;
- }
- modifier onlyOwner {
- require(msg.sender == owner, "You are not the owner.");
- _;
- }
- mapping(address => Voter) public voter;
- function submitVote (address _voter, string memory _vote) public notOwner {
- require(voter[_voter].voted == false, "You've already voted.");
- voter[_voter].vote = _vote;
- voter[_voter].voted = true;
- allVotes[totalVotes] = _vote;
- allAddresses[totalVotes] = _voter;
- totalVotes++;
- }
- function getVotes () public votesDone onlyOwner view {
- for (uint _x = 0; _x < totalVotes; _x++) {
- console.log(allAddresses[_x], allVotes[_x]);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement