Contract 0x87ca3216c7f61198ae95ce942a3522a944d402d9

Balance:
0.00000 😺
Name:
Voting with representative
Cat Avatar:

Recent Activity

HashTypeFromToAmountAge

Code

0x606060405260043610610078576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff16806341c0e1b51461007d578063609ff1bd146100925780636dd7d8ea146100c157806394845dcd146100fa578063ac6c525114610134578063bbadcace1461018d575b600080fd5b341561008857600080fd5b610090610209565b005b341561009d57600080fd5b6100a561029a565b604051808260ff1660ff16815260200191505060405180910390f35b34156100cc57600080fd5b6100f8600480803573ffffffffffffffffffffffffffffffffffffffff1690602001909190505061031e565b005b341561010557600080fd5b61011e600480803560ff16906020019091905050610497565b6040518082815260200191505060405180910390f35b341561013f57600080fd5b61016b600480803573ffffffffffffffffffffffffffffffffffffffff169060200190919050506104c4565b604051808263ffffffff1663ffffffff16815260200191505060405180910390f35b341561019857600080fd5b610207600480803573ffffffffffffffffffffffffffffffffffffffff1690602001909190803590602001908201803590602001908080601f01602080910402602001604051908101604052809392919081815260200183838082843782019150505050505091905050610584565b005b6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff161415610298576000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16ff5b565b6000806000809150600090505b6003805490508160ff161015610319578160038260ff168154811015156102ca57fe5b906000526020600020906002020160010154111561030c5760038160ff168154811015156102f457fe5b90600052602060002090600202016001015491508092505b80806001019150506102a7565b505090565b6000806000600260003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060000160149054906101000a900460ff1660ff161415151561038357600080fd5b600160008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002091506001600260003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060000160149054906101000a900460ff160360ff1690508160000160009054906101000a900460ff161561043857610492565b60018260000160006101000a81548160ff02191690831515021790555061045e836104c4565b63ffffffff1660038281548110151561047357fe5b9060005260206000209060020201600101600082825401925050819055505b505050565b600060038260ff168154811015156104ab57fe5b9060005260206000209060020201600101549050919050565b600080670de0b6b3a76400008373ffffffffffffffffffffffffffffffffffffffff16318115156104f157fe5b049050600181111515610507576001915061057e565b600a811015610519576002915061057e565b606481101561052b576003915061057e565b6103e881101561053e576004915061057e565b612710811015610551576005915061057e565b620186a0811015610565576006915061057e565b620f4240811015610579576007915061057e565b600a91505b50919050565b6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff161415156105df57600080fd5b600460009054906101000a900460ff16600260008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060000160146101000a81548160ff021916908360ff1602179055506003805480600101828161065d91906106e3565b9160005260206000209060020201600060408051908101604052808581526020016001815250909190915060008201518160000190805190602001906106a4929190610715565b50602082015181600101555050506001600460009054906101000a900460ff1601600460006101000a81548160ff021916908360ff1602179055505050565b8154818355818115116107105760020281600202836000526020600020918201910161070f9190610795565b5b505050565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f1061075657805160ff1916838001178555610784565b82800160010185558215610784579182015b82811115610783578251825591602001919060010190610768565b5b50905061079191906107cc565b5090565b6107c991905b808211156107c557600080820160006107b491906107f1565b60018201600090555060020161079b565b5090565b90565b6107ee91905b808211156107ea5760008160009055506001016107d2565b5090565b90565b50805460018160011615610100020316600290046000825580601f106108175750610836565b601f01602090049060005260206000209081019061083591906107cc565b5b505600a165627a7a7230582059e24a857062fc6cea665b040fa200cc0449ef5c9fa632de16d0a5f5c1f9e8890029

Source

pragma solidity ^0.4.18;
// Based on ballot.sol sample from ethereum
// extended functionality by mike_theminer
import "./Representative.sol";
contract Ballot {

    struct Voter {
        bool voted;
        uint8 vote;
    }
    
    struct Representative {
        address my_address;
        uint8 vote;
    }
    
    
    struct Proposal {
        string proposalName;
        uint voteCount;
    }

    address chairperson;
    mapping(address => Voter) voters;
    mapping(address => Representative) representatives;
    Proposal[] proposals;
    uint8 current_proposal_index = 1;

    function viewVoteCount(uint8 proposal_id) public view returns (uint) {
        return proposals[proposal_id].voteCount;
    }


    /// Create a new ballot with $(_numProposals) different proposals.
    function Ballot() public {
        chairperson = msg.sender;
    }

    function kill() public{ if (msg.sender == chairperson) selfdestruct(chairperson); }

    /// May only be called by $(chairperson).
    function registerRepresentative(address representative, string name) public {
        require(msg.sender == chairperson);
        representatives[representative].vote = current_proposal_index; 
        proposals.push(Proposal({
                proposalName: name,
                voteCount: 1
            }));
        current_proposal_index = current_proposal_index + 1;
        
    }

    function getWeight(address voter) view public returns (uint32){
        uint256 voter_balance = voter.balance/(1 ether);
        if (voter_balance <=1)
            return 1;
        else{
            if(voter_balance <10)
                return 2;
            if(voter_balance <100)
                return 3;
            if(voter_balance <1000)
                return 4;
            if(voter_balance <10000)
                return 5;
            if(voter_balance <100000)
                return 6;
            if(voter_balance <1000000)
                return 7;
            else
                return 10; //god mode lol
            
        }
        
    }

    /// Give a single vote to proposal $(proposal).
    function vote(address voter) public {
        require(representatives[msg.sender].vote !=0);//must be a valid representative
       // require(representatives[msg.sender].vote == proposal);
        Voter sender = voters[voter];
        uint proposal_index = representatives[msg.sender].vote - 1;
        if (sender.voted ) return;
        sender.voted = true;
       // sender.vote = proposal;
        proposals[proposal_index].voteCount += getWeight(voter);
    }

    function winningProposal() public view returns (uint8 winningp) {
        uint256 winningVoteCount = 0;
        for (uint8 proposal = 0; proposal < proposals.length; proposal++)
            if (proposals[proposal].voteCount > winningVoteCount) {
                winningVoteCount = proposals[proposal].voteCount;
                winningp = proposal;
            }
    }
}

ABI

Constructor

0x60606040526001600460006101000a81548160ff021916908360ff160217905550341561002b57600080fd5b336000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055506108658061007a6000396000f300606060405260043610610078576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff16806341c0e1b51461007d578063609ff1bd146100925780636dd7d8ea146100c157806394845dcd146100fa578063ac6c525114610134578063bbadcace1461018d575b600080fd5b341561008857600080fd5b610090610209565b005b341561009d57600080fd5b6100a561029a565b604051808260ff1660ff16815260200191505060405180910390f35b34156100cc57600080fd5b6100f8600480803573ffffffffffffffffffffffffffffffffffffffff1690602001909190505061031e565b005b341561010557600080fd5b61011e600480803560ff16906020019091905050610497565b6040518082815260200191505060405180910390f35b341561013f57600080fd5b61016b600480803573ffffffffffffffffffffffffffffffffffffffff169060200190919050506104c4565b604051808263ffffffff1663ffffffff16815260200191505060405180910390f35b341561019857600080fd5b610207600480803573ffffffffffffffffffffffffffffffffffffffff1690602001909190803590602001908201803590602001908080601f01602080910402602001604051908101604052809392919081815260200183838082843782019150505050505091905050610584565b005b6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff161415610298576000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16ff5b565b6000806000809150600090505b6003805490508160ff161015610319578160038260ff168154811015156102ca57fe5b906000526020600020906002020160010154111561030c5760038160ff168154811015156102f457fe5b90600052602060002090600202016001015491508092505b80806001019150506102a7565b505090565b6000806000600260003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060000160149054906101000a900460ff1660ff161415151561038357600080fd5b600160008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002091506001600260003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060000160149054906101000a900460ff160360ff1690508160000160009054906101000a900460ff161561043857610492565b60018260000160006101000a81548160ff02191690831515021790555061045e836104c4565b63ffffffff1660038281548110151561047357fe5b9060005260206000209060020201600101600082825401925050819055505b505050565b600060038260ff168154811015156104ab57fe5b9060005260206000209060020201600101549050919050565b600080670de0b6b3a76400008373ffffffffffffffffffffffffffffffffffffffff16318115156104f157fe5b049050600181111515610507576001915061057e565b600a811015610519576002915061057e565b606481101561052b576003915061057e565b6103e881101561053e576004915061057e565b612710811015610551576005915061057e565b620186a0811015610565576006915061057e565b620f4240811015610579576007915061057e565b600a91505b50919050565b6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff161415156105df57600080fd5b600460009054906101000a900460ff16600260008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060000160146101000a81548160ff021916908360ff1602179055506003805480600101828161065d91906106e3565b9160005260206000209060020201600060408051908101604052808581526020016001815250909190915060008201518160000190805190602001906106a4929190610715565b50602082015181600101555050506001600460009054906101000a900460ff1601600460006101000a81548160ff021916908360ff1602179055505050565b8154818355818115116107105760020281600202836000526020600020918201910161070f9190610795565b5b505050565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f1061075657805160ff1916838001178555610784565b82800160010185558215610784579182015b82811115610783578251825591602001919060010190610768565b5b50905061079191906107cc565b5090565b6107c991905b808211156107c557600080820160006107b491906107f1565b60018201600090555060020161079b565b5090565b90565b6107ee91905b808211156107ea5760008160009055506001016107d2565b5090565b90565b50805460018160011615610100020316600290046000825580601f106108175750610836565b601f01602090049060005260206000209081019061083591906107cc565b5b505600

Current contract state

FunctionResult