Verified contractPartial
Vote
Address0xb2beb6634b590422cdc3dbc7d160b0a03cc7bd58
- Balance
0 ETH
- Transactions
0
- Compiler
solc 0.4.11
- Same code
1 more contract
Details
- Compiler
- solc 0.4.11+commit.68ef5810
- Language
- solidity
- Optimization
- No
- License
- Not stated
- Match
- Partialcreation code: yes, runtime code: yes
- Verified on Sourcify
- Created in block
- 3,801,095
- Creation transaction
- 0x978c03772e…f706c98963
VoteFactory.sol
// Recovered by EthereumHistory (ethereumhistory.com) -sw
pragma solidity ^0.4.10;
contract VoteFactory {
address public owner;
uint public numPolls;
uint public nextEndTime;
Vote public yesContract;
Vote public noContract;
mapping(uint => string) public voteDescription;
mapping(address => mapping(uint => bool)) public hasVoted;
mapping(uint => uint) public numVoters; // number of voters per round
mapping(uint => mapping(uint => address)) public voter; // [voteId][voterNumber] => address
mapping(uint => uint) public yesCount; // number of yes for a given round
mapping(uint => uint) public noCount;
event transferredOwner(address newOwner);
event startedNewVote(address initiator, uint duration, string description, uint voteId);
event voted(address voter, bool isYes);
modifier onlyOwner {
if (msg.sender != owner)
throw;
_;
}
function transferOwner(address newOwner) onlyOwner {
owner = newOwner;
transferredOwner(newOwner);
}
function payOut() onlyOwner {
// just in case we accumulate a balance here, we have to be able to retrieve it
owner.send(this.balance);
}
function VoteFactory() {
owner = msg.sender;
// constructor deploys yes and no contract
yesContract = new Vote();
noContract = new Vote();
}
function() payable {
// default function starts new poll if previous poll is over for at least 10 minutes
if (nextEndTime < now + 10 minutes)
startNewVote(10 minutes, "Vote on tax reimbursements");
}
function newVote(uint duration, string description) onlyOwner {
// only admin is able to start vote with arbitrary duration
startNewVote(duration, description);
}
function startNewVote(uint duration, string description) internal {
// do not allow to start new vote if there's still something ongoing
if (now <= nextEndTime)
throw;
nextEndTime = now + duration;
voteDescription[numPolls] = description;
startedNewVote(msg.sender, duration, description, ++numPolls);
}
function vote(bool isYes, address voteSender) {
// voting should just be able via voting contract (use them as SWIS contracts)
if (msg.sender != address(yesContract) && msg.sender != address(noContract))
throw;
// throw if time is over
if (now > nextEndTime)
throw;
// throw if sender has already voted before
if (hasVoted[voteSender][numPolls])
throw;
hasVoted[voteSender][numPolls] = true;
voter[numPolls][numVoters[numPolls]++] = voteSender;
if (isYes)
yesCount[numPolls]++;
else
noCount[numPolls]++;
voted(voteSender, isYes);
}
}
contract Vote {
VoteFactory public myVoteFactory;
function Vote() {
// constructor expects to be called by VoteFactory contract
myVoteFactory = VoteFactory(msg.sender);
}
function () payable {
// make payable so that wallets that cannot send tx with 0 Wei still work
myVoteFactory.vote(this == myVoteFactory.yesContract(), msg.sender);
}
function payOut() {
// just to collect accidentally accumulated funds
msg.sender.send(this.balance);
}
}Compiler settingsShow
{
"optimizer": {
"runs": 200,
"enabled": false
}
}Source code and metadata: Sourcify.
The source code belongs to the authors of the contract.