t are one of the most essential parts of the human-centered blockchain structure. It creates a direct link between the Web3 Coin ecosystem applications and the user, beyond performing the transaction verification task systematically.
Copy pragma solidity ^0.8.0;
import "@openzeppelin/contracts/utils/Strings.sol" ;
contract Vote {
using Strings for uint256 ;
address private immutable owner;
string_baseUri;
uint256 totalVote;
struct Votes {
uint256 startTime;
uint256 endTime;
uint256 selection;
string question;
mapping ( uint256 => uint256 ) selections;
mapping ( address => uint256 ) voter;
}
mapping ( uint256 => votes)_votes;
constructor ( string memory base_Uri_) {
owner = msg.sender;
_baseUri = base_Uri_;
}
modifier onlyOwner () {
require (msg.sender == owner , "You are not owner." );
_;
}
function questionURL ( uint256 vote_) internal view returns ( string memory ) {
return string (abi. encodePacked (_basedUri , _votes[vote_].selection. toString ()));
}
function setBaseURI ( string memory base_Uri_) external only Owner {
_baseUri = base_Uri_;
}
function getQuestion () public view returns ( string memory ) {
return_votes[totalVote].question;
}
function vote ( uint256 selection) public {
require (block.timestamp > _votes[totalVote].startTime &&
block.timestamp < _votes[totalVote].endTime);
require (selection <= _votes[]totalVote.selection && selection > 0 );
require (_votes[totalVote].voter[msg.sender] == 0 );
_votes[totalVote].voter[msg.sender] = selection;
}
function setVote (
uint256 startTime ,
uint256 endTime ,
uint256 selection ,
string memory question)
public
onlyOwner {
totalVote ++ ;
_votes[totalVote].startTime = startTime;
_votes[totalVote].endTime = endTime;
_votes[totalVote].selection = selection;
_votes[totalVote].question = question;
}
}