Skip to content
Verified contractPartial

Ballot

Address0xc97d9b8e78699655bc56576455d7ebf9050a7261
Balance

0 ETH

 

Transactions

2

 

Compiler

solc 0.1.3

 

Same code

Only this contract

 

Details

Compiler
solc 0.1.3+commit.028f561d
Language
solidity
Optimization
No
License
Not stated
Match
Partialcreation code: no, runtime code: yes
Verified on Sourcify
Created in block
200,059
Creation transaction
0xb022d5de74…9b52cae141

Ballot.sol

// Recovered by EthereumHistory (ethereumhistory.com) -sw
contract Ballot {
    address chairperson;
    uint8 numProposals;
    mapping(address => uint) voterWeight;
    mapping(address => bool) voted;
    mapping(address => uint8) votes;
    mapping(address => address) delegations;
    mapping(uint8 => uint) voteCounts;

    function Ballot(uint8 _numProposals) {
        address myAddress = msg.sender;
        chairperson = myAddress;
        numProposals = _numProposals;
    }

    function giveRightToVote(address voter) {
        if (voted[voter]) return;
        voterWeight[voter] = 1;
    }

    function winningProposal() constant returns (uint8 winningProposal) {
        uint winningVoteCount = 0;
        uint8 proposal = 0;
        while (proposal < numProposals) {
            if (voteCounts[proposal] > winningVoteCount) {
                winningVoteCount = voteCounts[proposal];
                winningProposal = proposal;
            }
            ++proposal;
        }
    }

    function vote(uint8 proposal) {
        address myAddress = msg.sender;
        if (voted[myAddress] || proposal >= numProposals) return;
        voted[myAddress] = true;
        votes[myAddress] = proposal;
        voteCounts[proposal] += voterWeight[myAddress];
    }

    function delegate(address to) {
        address myAddress = 0x123;
        if (voted[myAddress]) return;
        while (delegations[to] != address(0) && delegations[to] != myAddress)
            to = delegations[to];
        if (to == myAddress) return;
        voted[myAddress] = true;
        delegations[myAddress] = to;
        if (voted[to]) voteCounts[votes[to]] += voterWeight[myAddress];
        else voterWeight[to] += voterWeight[myAddress];
    }
}
Compiler settingsShow
{
  "optimizer": {
    "runs": 200,
    "enabled": false
  }
}

Source code and metadata: Sourcify.

The source code belongs to the authors of the contract.