false
false

Contract Address Details

0x68A91b40Da30ff6F840e796EDA1386E4da721Bf9

Contract Name
cityDAO
Creator
0x864f78–c6436b at 0x3ce99d–15ccab
Balance
0
Tokens
Fetching tokens...
Transactions
0 Transactions
Transfers
0 Transfers
Gas Used
Fetching gas used...
Last Balance Update
15507298
Warning! Contract bytecode has been changed and doesn't match the verified one. Therefore, interaction with this smart contract may be risky.
Contract name:
cityDAO




Optimization enabled
true
Compiler version
v0.8.0+commit.c7dfd78e




Optimization runs
200
EVM Version
default




Verified at
2024-09-12T09:24:38.171530Z

Contract source code

Sol2uml
new
pragma solidity ^0.8.0;

contract cityDAO {
    struct Proposal {
        uint256 id;
        string description;
        uint256 yesVotes;
        uint256 noVotes;
        uint256 endTime;
        bool executed;
    }

    struct Voter {
        bool isRegistered;
        bool hasVoted;
        uint256 weight;
    }

    address public cityAdmin;
    mapping(uint256 => Proposal) public proposals;
    mapping(address => Voter) public voters;
    uint256 public proposalCount;
    uint256 public constant VOTING_PERIOD = 7 days;

    event VoterRegistered(address indexed voter);
    event ProposalCreated(uint256 indexed proposalId, string description);
    event Voted(uint256 indexed proposalId, bool support, address indexed voter);
    event ProposalExecuted(uint256 indexed proposalId);

    modifier onlyCityAdmin() {
        require(msg.sender == cityAdmin, "Only city admin can call this function");
        _;
    }

    modifier onlyRegisteredVoter() {
        require(voters[msg.sender].isRegistered, "Only registered voters can call this function");
        _;
    }

    constructor() {
        cityAdmin = msg.sender;
    }

    function registerVoter(address _voter) public onlyCityAdmin {
        require(!voters[_voter].isRegistered, "Voter already registered");
        voters[_voter] = Voter(true, false, 1);
        emit VoterRegistered(_voter);
    }

    function createProposal(string memory _description) public onlyCityAdmin {
        proposalCount++;
        proposals[proposalCount] = Proposal(
            proposalCount,
            _description,
            0,
            0,
            block.timestamp + VOTING_PERIOD,
            false
        );
        emit ProposalCreated(proposalCount, _description);
    }

    function vote(uint256 _proposalId, bool _support) public onlyRegisteredVoter {
        Proposal storage proposal = proposals[_proposalId];
        Voter storage sender = voters[msg.sender];

        require(block.timestamp <= proposal.endTime, "Voting has ended");
        require(!sender.hasVoted, "Already voted");
        require(!proposal.executed, "Proposal already executed");

        sender.hasVoted = true;

        if (_support) {
            proposal.yesVotes += sender.weight;
        } else {
            proposal.noVotes += sender.weight;
        }

        emit Voted(_proposalId, _support, msg.sender);
    }

    function executeProposal(uint256 _proposalId) public onlyCityAdmin {
        Proposal storage proposal = proposals[_proposalId];

        require(block.timestamp > proposal.endTime, "Voting period not ended");
        require(!proposal.executed, "Proposal already executed");

        proposal.executed = true;

        emit ProposalExecuted(_proposalId);

        // Here you would typically implement the actual execution of the proposal
        // This could involve calling other contracts or functions
    }

    function getProposalDetails(uint256 _proposalId) public view returns (uint256, string memory, uint256, uint256, uint256, bool) {
        Proposal memory proposal = proposals[_proposalId];
        return (proposal.id, proposal.description, proposal.yesVotes, proposal.noVotes, proposal.endTime, proposal.executed);
    }

    // Privacy-preserving function to get total votes without revealing individual votes
    function getProposalVotes(uint256 _proposalId) public view returns (uint256 yesVotes, uint256 noVotes) {
        Proposal memory proposal = proposals[_proposalId];
        return (proposal.yesVotes, proposal.noVotes);
    }
}
        

Contract ABI

[{"type":"constructor","stateMutability":"nonpayable","inputs":[]},{"type":"event","name":"ProposalCreated","inputs":[{"type":"uint256","name":"proposalId","internalType":"uint256","indexed":true},{"type":"string","name":"description","internalType":"string","indexed":false}],"anonymous":false},{"type":"event","name":"ProposalExecuted","inputs":[{"type":"uint256","name":"proposalId","internalType":"uint256","indexed":true}],"anonymous":false},{"type":"event","name":"Voted","inputs":[{"type":"uint256","name":"proposalId","internalType":"uint256","indexed":true},{"type":"bool","name":"support","internalType":"bool","indexed":false},{"type":"address","name":"voter","internalType":"address","indexed":true}],"anonymous":false},{"type":"event","name":"VoterRegistered","inputs":[{"type":"address","name":"voter","internalType":"address","indexed":true}],"anonymous":false},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"VOTING_PERIOD","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"address"}],"name":"cityAdmin","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"createProposal","inputs":[{"type":"string","name":"_description","internalType":"string"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"executeProposal","inputs":[{"type":"uint256","name":"_proposalId","internalType":"uint256"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"},{"type":"string","name":"","internalType":"string"},{"type":"uint256","name":"","internalType":"uint256"},{"type":"uint256","name":"","internalType":"uint256"},{"type":"uint256","name":"","internalType":"uint256"},{"type":"bool","name":"","internalType":"bool"}],"name":"getProposalDetails","inputs":[{"type":"uint256","name":"_proposalId","internalType":"uint256"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"yesVotes","internalType":"uint256"},{"type":"uint256","name":"noVotes","internalType":"uint256"}],"name":"getProposalVotes","inputs":[{"type":"uint256","name":"_proposalId","internalType":"uint256"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"proposalCount","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"id","internalType":"uint256"},{"type":"string","name":"description","internalType":"string"},{"type":"uint256","name":"yesVotes","internalType":"uint256"},{"type":"uint256","name":"noVotes","internalType":"uint256"},{"type":"uint256","name":"endTime","internalType":"uint256"},{"type":"bool","name":"executed","internalType":"bool"}],"name":"proposals","inputs":[{"type":"uint256","name":"","internalType":"uint256"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"registerVoter","inputs":[{"type":"address","name":"_voter","internalType":"address"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"vote","inputs":[{"type":"uint256","name":"_proposalId","internalType":"uint256"},{"type":"bool","name":"_support","internalType":"bool"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"bool","name":"isRegistered","internalType":"bool"},{"type":"bool","name":"hasVoted","internalType":"bool"},{"type":"uint256","name":"weight","internalType":"uint256"}],"name":"voters","inputs":[{"type":"address","name":"","internalType":"address"}]}]
              

Contract Creation Code

0x608060405234801561001057600080fd5b50600080546001600160a01b03191633179055610e24806100326000396000f3fe608060405234801561001057600080fd5b50600436106100a95760003560e01c806349c2a1a61161007157806349c2a1a614610138578063a3ec138d1461014b578063b1610d7e1461016d578063be7fe8eb14610182578063c9d27afe14610197578063da35c664146101aa576100a9565b8063013cf08b146100ae5780630d61b519146100dc57806338db6dd3146100f15780633b4d01a71461010457806347c6614014610117575b600080fd5b6100c16100bc366004610a94565b6101b2565b6040516100d396959493929190610d06565b60405180910390f35b6100ef6100ea366004610a94565b610272565b005b6100ef6100ff3660046109c5565b610339565b6100c1610112366004610a94565b610426565b61012a610125366004610a94565b61055b565b6040516100d3929190610d46565b6100ef6101463660046109f3565b610669565b61015e6101593660046109c5565b610793565b6040516100d393929190610b49565b6101756107b9565b6040516100d39190610cfd565b61018a6107c0565b6040516100d39190610b2a565b6100ef6101a5366004610aac565b6107cf565b610175610926565b6001602081905260009182526040909120805491810180546101d390610d6c565b80601f01602080910402602001604051908101604052809291908181526020018280546101ff90610d6c565b801561024c5780601f106102215761010080835404028352916020019161024c565b820191906000526020600020905b81548152906001019060200180831161022f57829003601f168201915b505050506002830154600384015460048501546005909501549394919390925060ff1686565b6000546001600160a01b031633146102a55760405162461bcd60e51b815260040161029c90610bab565b60405180910390fd5b6000818152600160205260409020600481015442116102d65760405162461bcd60e51b815260040161029c90610c9c565b600581015460ff16156102fb5760405162461bcd60e51b815260040161029c90610b74565b60058101805460ff1916600117905560405182907f712ae1383f79ac853f8d882153778e0260ef8f03b504e2866e0593e04d2b291f90600090a25050565b6000546001600160a01b031633146103635760405162461bcd60e51b815260040161029c90610bab565b6001600160a01b03811660009081526002602052604090205460ff161561039c5760405162461bcd60e51b815260040161029c90610c65565b604080516060810182526001808252600060208084018281528486018481526001600160a01b038816808552600290935286842095518654925115156101000261ff001991151560ff19909416939093171691909117855551939092019290925591517fb6be2187d059cc2a55fe29e0e503b566e1e0f8c8780096e185429350acffd3dd9190a250565b600060606000806000806000600160008981526020019081526020016000206040518060c00160405290816000820154815260200160018201805461046a90610d6c565b80601f016020809104026020016040519081016040528092919081815260200182805461049690610d6c565b80156104e35780601f106104b8576101008083540402835291602001916104e3565b820191906000526020600020905b8154815290600101906020018083116104c657829003601f168201915b505050505081526020016002820154815260200160038201548152602001600482015481526020016005820160009054906101000a900460ff1615151515815250509050806000015181602001518260400151836060015184608001518560a001519650965096509650965096505091939550919395565b6000806000600160008581526020019081526020016000206040518060c00160405290816000820154815260200160018201805461059890610d6c565b80601f01602080910402602001604051908101604052809291908181526020018280546105c490610d6c565b80156106115780601f106105e657610100808354040283529160200191610611565b820191906000526020600020905b8154815290600101906020018083116105f457829003601f168201915b505050505081526020016002820154815260200160038201548152602001600482015481526020016005820160009054906101000a900460ff1615151515815250509050806040015181606001519250925050915091565b6000546001600160a01b031633146106935760405162461bcd60e51b815260040161029c90610bab565b600380549060006106a383610da7565b91905055506040518060c001604052806003548152602001828152602001600081526020016000815260200162093a80426106de9190610d54565b8152600060209182018190526003548152600180835260409091208351815583830151805191936107149385019291019061092c565b5060408201518160020155606082015181600301556080820151816004015560a08201518160050160006101000a81548160ff0219169083151502179055509050506003547f9c770c289ab5bf7e57cb1d23c8ceae993aea46eb64847072fd3d78ca60d3e432826040516107889190610b61565b60405180910390a250565b6002602052600090815260409020805460019091015460ff808316926101009004169083565b62093a8081565b6000546001600160a01b031681565b3360009081526002602052604090205460ff166107fe5760405162461bcd60e51b815260040161029c90610bf1565b60008281526001602090815260408083203384526002909252909120600482015442111561083e5760405162461bcd60e51b815260040161029c90610cd3565b8054610100900460ff16156108655760405162461bcd60e51b815260040161029c90610c3e565b600582015460ff161561088a5760405162461bcd60e51b815260040161029c90610b74565b805461ff00191661010017815582156108c05780600101548260020160008282546108b59190610d54565b909155506108de9050565b80600101548260030160008282546108d89190610d54565b90915550505b336001600160a01b0316847f86abfce99b7dd908bec0169288797f85049ec73cbe046ed9de818fab3a497ae0856040516109189190610b3e565b60405180910390a350505050565b60035481565b82805461093890610d6c565b90600052602060002090601f01602090048101928261095a57600085556109a0565b82601f1061097357805160ff19168380011785556109a0565b828001600101855582156109a0579182015b828111156109a0578251825591602001919060010190610985565b506109ac9291506109b0565b5090565b5b808211156109ac57600081556001016109b1565b6000602082840312156109d6578081fd5b81356001600160a01b03811681146109ec578182fd5b9392505050565b60006020808385031215610a05578182fd5b823567ffffffffffffffff80821115610a1c578384fd5b818501915085601f830112610a2f578384fd5b813581811115610a4157610a41610dd8565b604051601f8201601f1916810185018381118282101715610a6457610a64610dd8565b6040528181528382018501881015610a7a578586fd5b818585018683013790810190930193909352509392505050565b600060208284031215610aa5578081fd5b5035919050565b60008060408385031215610abe578081fd5b8235915060208301358015158114610ad4578182fd5b809150509250929050565b60008151808452815b81811015610b0457602081850181015186830182015201610ae8565b81811115610b155782602083870101525b50601f01601f19169290920160200192915050565b6001600160a01b0391909116815260200190565b901515815260200190565b92151583529015156020830152604082015260600190565b6000602082526109ec6020830184610adf565b60208082526019908201527f50726f706f73616c20616c726561647920657865637574656400000000000000604082015260600190565b60208082526026908201527f4f6e6c7920636974792061646d696e2063616e2063616c6c20746869732066756040820152653731ba34b7b760d11b606082015260800190565b6020808252602d908201527f4f6e6c79207265676973746572656420766f746572732063616e2063616c6c2060408201526c3a3434b990333ab731ba34b7b760991b606082015260800190565b6020808252600d908201526c105b1c9958591e481d9bdd1959609a1b604082015260600190565b60208082526018908201527f566f74657220616c726561647920726567697374657265640000000000000000604082015260600190565b60208082526017908201527f566f74696e6720706572696f64206e6f7420656e646564000000000000000000604082015260600190565b60208082526010908201526f159bdd1a5b99c81a185cc8195b99195960821b604082015260600190565b90815260200190565b600087825260c06020830152610d1f60c0830188610adf565b905085604083015284606083015283608083015282151560a0830152979650505050505050565b918252602082015260400190565b60008219821115610d6757610d67610dc2565b500190565b600281046001821680610d8057607f821691505b60208210811415610da157634e487b7160e01b600052602260045260246000fd5b50919050565b6000600019821415610dbb57610dbb610dc2565b5060010190565b634e487b7160e01b600052601160045260246000fd5b634e487b7160e01b600052604160045260246000fdfea264697066735822122032d0c172ab9cea7e4b6418e359edd07bae529e1d4978f9e122c37985618c431264736f6c63430008000033

Deployed ByteCode

0x608060405234801561001057600080fd5b50600436106100a95760003560e01c806349c2a1a61161007157806349c2a1a614610138578063a3ec138d1461014b578063b1610d7e1461016d578063be7fe8eb14610182578063c9d27afe14610197578063da35c664146101aa576100a9565b8063013cf08b146100ae5780630d61b519146100dc57806338db6dd3146100f15780633b4d01a71461010457806347c6614014610117575b600080fd5b6100c16100bc366004610a94565b6101b2565b6040516100d396959493929190610d06565b60405180910390f35b6100ef6100ea366004610a94565b610272565b005b6100ef6100ff3660046109c5565b610339565b6100c1610112366004610a94565b610426565b61012a610125366004610a94565b61055b565b6040516100d3929190610d46565b6100ef6101463660046109f3565b610669565b61015e6101593660046109c5565b610793565b6040516100d393929190610b49565b6101756107b9565b6040516100d39190610cfd565b61018a6107c0565b6040516100d39190610b2a565b6100ef6101a5366004610aac565b6107cf565b610175610926565b6001602081905260009182526040909120805491810180546101d390610d6c565b80601f01602080910402602001604051908101604052809291908181526020018280546101ff90610d6c565b801561024c5780601f106102215761010080835404028352916020019161024c565b820191906000526020600020905b81548152906001019060200180831161022f57829003601f168201915b505050506002830154600384015460048501546005909501549394919390925060ff1686565b6000546001600160a01b031633146102a55760405162461bcd60e51b815260040161029c90610bab565b60405180910390fd5b6000818152600160205260409020600481015442116102d65760405162461bcd60e51b815260040161029c90610c9c565b600581015460ff16156102fb5760405162461bcd60e51b815260040161029c90610b74565b60058101805460ff1916600117905560405182907f712ae1383f79ac853f8d882153778e0260ef8f03b504e2866e0593e04d2b291f90600090a25050565b6000546001600160a01b031633146103635760405162461bcd60e51b815260040161029c90610bab565b6001600160a01b03811660009081526002602052604090205460ff161561039c5760405162461bcd60e51b815260040161029c90610c65565b604080516060810182526001808252600060208084018281528486018481526001600160a01b038816808552600290935286842095518654925115156101000261ff001991151560ff19909416939093171691909117855551939092019290925591517fb6be2187d059cc2a55fe29e0e503b566e1e0f8c8780096e185429350acffd3dd9190a250565b600060606000806000806000600160008981526020019081526020016000206040518060c00160405290816000820154815260200160018201805461046a90610d6c565b80601f016020809104026020016040519081016040528092919081815260200182805461049690610d6c565b80156104e35780601f106104b8576101008083540402835291602001916104e3565b820191906000526020600020905b8154815290600101906020018083116104c657829003601f168201915b505050505081526020016002820154815260200160038201548152602001600482015481526020016005820160009054906101000a900460ff1615151515815250509050806000015181602001518260400151836060015184608001518560a001519650965096509650965096505091939550919395565b6000806000600160008581526020019081526020016000206040518060c00160405290816000820154815260200160018201805461059890610d6c565b80601f01602080910402602001604051908101604052809291908181526020018280546105c490610d6c565b80156106115780601f106105e657610100808354040283529160200191610611565b820191906000526020600020905b8154815290600101906020018083116105f457829003601f168201915b505050505081526020016002820154815260200160038201548152602001600482015481526020016005820160009054906101000a900460ff1615151515815250509050806040015181606001519250925050915091565b6000546001600160a01b031633146106935760405162461bcd60e51b815260040161029c90610bab565b600380549060006106a383610da7565b91905055506040518060c001604052806003548152602001828152602001600081526020016000815260200162093a80426106de9190610d54565b8152600060209182018190526003548152600180835260409091208351815583830151805191936107149385019291019061092c565b5060408201518160020155606082015181600301556080820151816004015560a08201518160050160006101000a81548160ff0219169083151502179055509050506003547f9c770c289ab5bf7e57cb1d23c8ceae993aea46eb64847072fd3d78ca60d3e432826040516107889190610b61565b60405180910390a250565b6002602052600090815260409020805460019091015460ff808316926101009004169083565b62093a8081565b6000546001600160a01b031681565b3360009081526002602052604090205460ff166107fe5760405162461bcd60e51b815260040161029c90610bf1565b60008281526001602090815260408083203384526002909252909120600482015442111561083e5760405162461bcd60e51b815260040161029c90610cd3565b8054610100900460ff16156108655760405162461bcd60e51b815260040161029c90610c3e565b600582015460ff161561088a5760405162461bcd60e51b815260040161029c90610b74565b805461ff00191661010017815582156108c05780600101548260020160008282546108b59190610d54565b909155506108de9050565b80600101548260030160008282546108d89190610d54565b90915550505b336001600160a01b0316847f86abfce99b7dd908bec0169288797f85049ec73cbe046ed9de818fab3a497ae0856040516109189190610b3e565b60405180910390a350505050565b60035481565b82805461093890610d6c565b90600052602060002090601f01602090048101928261095a57600085556109a0565b82601f1061097357805160ff19168380011785556109a0565b828001600101855582156109a0579182015b828111156109a0578251825591602001919060010190610985565b506109ac9291506109b0565b5090565b5b808211156109ac57600081556001016109b1565b6000602082840312156109d6578081fd5b81356001600160a01b03811681146109ec578182fd5b9392505050565b60006020808385031215610a05578182fd5b823567ffffffffffffffff80821115610a1c578384fd5b818501915085601f830112610a2f578384fd5b813581811115610a4157610a41610dd8565b604051601f8201601f1916810185018381118282101715610a6457610a64610dd8565b6040528181528382018501881015610a7a578586fd5b818585018683013790810190930193909352509392505050565b600060208284031215610aa5578081fd5b5035919050565b60008060408385031215610abe578081fd5b8235915060208301358015158114610ad4578182fd5b809150509250929050565b60008151808452815b81811015610b0457602081850181015186830182015201610ae8565b81811115610b155782602083870101525b50601f01601f19169290920160200192915050565b6001600160a01b0391909116815260200190565b901515815260200190565b92151583529015156020830152604082015260600190565b6000602082526109ec6020830184610adf565b60208082526019908201527f50726f706f73616c20616c726561647920657865637574656400000000000000604082015260600190565b60208082526026908201527f4f6e6c7920636974792061646d696e2063616e2063616c6c20746869732066756040820152653731ba34b7b760d11b606082015260800190565b6020808252602d908201527f4f6e6c79207265676973746572656420766f746572732063616e2063616c6c2060408201526c3a3434b990333ab731ba34b7b760991b606082015260800190565b6020808252600d908201526c105b1c9958591e481d9bdd1959609a1b604082015260600190565b60208082526018908201527f566f74657220616c726561647920726567697374657265640000000000000000604082015260600190565b60208082526017908201527f566f74696e6720706572696f64206e6f7420656e646564000000000000000000604082015260600190565b60208082526010908201526f159bdd1a5b99c81a185cc8195b99195960821b604082015260600190565b90815260200190565b600087825260c06020830152610d1f60c0830188610adf565b905085604083015284606083015283608083015282151560a0830152979650505050505050565b918252602082015260400190565b60008219821115610d6757610d67610dc2565b500190565b600281046001821680610d8057607f821691505b60208210811415610da157634e487b7160e01b600052602260045260246000fd5b50919050565b6000600019821415610dbb57610dbb610dc2565b5060010190565b634e487b7160e01b600052601160045260246000fd5b634e487b7160e01b600052604160045260246000fdfea264697066735822122032d0c172ab9cea7e4b6418e359edd07bae529e1d4978f9e122c37985618c431264736f6c63430008000033