Contract Overview
Balance:
0 Ether
More Info
My Name Tag:
Not Available
[ Download CSV Export ]
Contract Name:
YerevanVotes
Compiler Version
v0.5.7+commit.6da8b019
Optimization Enabled:
Yes with 200 runs
Other Settings:
default evmVersion
Contract Source Code (Solidity)
/** *Submitted for verification at Etherscan.io on 2019-05-03 */ pragma solidity ^0.5.0; pragma solidity ^0.5.0; /** * @title SafeMath * @dev Unsigned math operations with safety checks that revert on error. */ library SafeMath { /** * @dev Multiplies two unsigned integers, reverts on overflow. */ function mul(uint256 a, uint256 b) internal pure returns (uint256) { // Gas optimization: this is cheaper than requiring 'a' not being zero, but the // benefit is lost if 'b' is also tested. // See: https://github.com/OpenZeppelin/openzeppelin-solidity/pull/522 if (a == 0) { return 0; } uint256 c = a * b; require(c / a == b, "SafeMath: multiplication overflow"); return c; } /** * @dev Integer division of two unsigned integers truncating the quotient, reverts on division by zero. */ function div(uint256 a, uint256 b) internal pure returns (uint256) { // Solidity only automatically asserts when dividing by 0 require(b > 0, "SafeMath: division by zero"); uint256 c = a / b; // assert(a == b * c + a % b); // There is no case in which this doesn't hold return c; } /** * @dev Subtracts two unsigned integers, reverts on overflow (i.e. if subtrahend is greater than minuend). */ function sub(uint256 a, uint256 b) internal pure returns (uint256) { require(b <= a, "SafeMath: subtraction overflow"); uint256 c = a - b; return c; } /** * @dev Adds two unsigned integers, reverts on overflow. */ function add(uint256 a, uint256 b) internal pure returns (uint256) { uint256 c = a + b; require(c >= a, "SafeMath: addition overflow"); return c; } /** * @dev Divides two unsigned integers and returns the remainder (unsigned integer modulo), * reverts when dividing by zero. */ function mod(uint256 a, uint256 b) internal pure returns (uint256) { require(b != 0, "SafeMath: modulo by zero"); return a % b; } } pragma solidity ^0.5.0; /** * @title Ownable * @dev The Ownable contract has an owner address, and provides basic authorization control * functions, this simplifies the implementation of "user permissions". */ contract Ownable { address private _owner; event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); /** * @dev The Ownable constructor sets the original `owner` of the contract to the sender * account. */ constructor () internal { _owner = msg.sender; emit OwnershipTransferred(address(0), _owner); } /** * @return the address of the owner. */ function owner() public view returns (address) { return _owner; } /** * @dev Throws if called by any account other than the owner. */ modifier onlyOwner() { require(isOwner(), "Ownable: caller is not the owner"); _; } /** * @return true if `msg.sender` is the owner of the contract. */ function isOwner() public view returns (bool) { return msg.sender == _owner; } /** * @dev Allows the current owner to relinquish control of the contract. * It will not be possible to call the functions with the `onlyOwner` * modifier anymore. * @notice Renouncing ownership will leave the contract without an owner, * thereby removing any functionality that is only available to the owner. */ function renounceOwnership() public onlyOwner { emit OwnershipTransferred(_owner, address(0)); _owner = address(0); } /** * @dev Allows the current owner to transfer control of the contract to a newOwner. * @param newOwner The address to transfer ownership to. */ function transferOwnership(address newOwner) public onlyOwner { _transferOwnership(newOwner); } /** * @dev Transfers control of the contract to a newOwner. * @param newOwner The address to transfer ownership to. */ function _transferOwnership(address newOwner) internal { require(newOwner != address(0), "Ownable: new owner is the zero address"); emit OwnershipTransferred(_owner, newOwner); _owner = newOwner; } } /////////////////////Active Citizen project voting smart contract for Yerevan city. //Developed by “Center for management technologies of Yerevan” CJSC for Yerevan City 2019 //Holds all projects and all votes from citizens for them irrevertably. contract YerevanVotes is Ownable { using SafeMath for uint256; struct Project { //Placeholder for each project that needs to be voted uint256[] votedIDs; //Citizen id list that voted on the project mapping(uint256 => bool) idVoted; //Indicate if citizen already voted mapping(uint256 => uint256) idsVote; //The vote value for the Citizen mapping(uint256 => uint256) voteDate; //When did the Citizen voted uint256 voteCount; //Overall count of Votes for the project uint256 likes; //Overall count of likes on the project uint256 dislikes; //Overall count of dislikes for the project. string shortDescribtion; //Short describtion of the project uint256 projectCreationDate; //Project creation date on blockchain bool isActive; //If the project is active for votes } mapping (uint256 => Project) public projects; //Mapping of all projects by their number uint256[] public projectList; //Reverse lookup for project list by array //Adds new project for voting function addProject(uint256 projectID, string memory shortDescribtion) public onlyOwner { require(0 == projects[projectID].projectCreationDate, "Error: Project already exists."); projects[projectID].isActive = true; projects[projectID].shortDescribtion = shortDescribtion; projects[projectID].projectCreationDate = now; projectList.push(projectID); } //Votes on a project for user function vote(uint256 projectID, uint256 citizenID, uint256 citizenVote) public onlyOwner { require(true == projects[projectID].isActive, "Error: Project is inactive."); require(0 != projects[projectID].projectCreationDate, "Error: Project does not exist."); require(false == projects[projectID].idVoted[citizenID], "Error: Citizen already voted."); if(citizenVote == 1) { projects[projectID].dislikes++; } else if(citizenVote == 2) { projects[projectID].likes++; } projects[projectID].voteCount++; projects[projectID].idsVote[citizenID] = citizenVote; projects[projectID].idVoted[citizenID] = true; projects[projectID].voteDate[citizenID] = now; projects[projectID].votedIDs.push(citizenID); } //Gets all basic information for project status function getProjectData(uint256 projectID) public view returns( uint256 voteCount, uint256 likes, uint256 dislikes, string memory shortDescribtion, uint256 projectCreationDate, bool isActive) { return (projects[projectID].voteCount, projects[projectID].likes, projects[projectID].dislikes, projects[projectID].shortDescribtion, projects[projectID].projectCreationDate, projects[projectID].isActive); } //For the given project returns vote value and time of the citizen function getCitizensVote(uint256 projectID, uint256 citizenID) public view returns(uint256 idsVote, uint256 voteDate) { require(true == projects[projectID].idVoted[citizenID], "Citizen did not voted"); return(projects[projectID].idsVote[citizenID], projects[projectID].voteDate[citizenID]); } //Gets all citizens that voted on project function getVotedIDs(uint256 projectID) public view returns(uint256[] memory votedIDs) { return projects[projectID].votedIDs; } //Gets the list of all projects that have been added function getAllProjects() public view returns(uint256[] memory projectIDs) { return projectList; } //Activates inactivates project function setProjectActivity(uint256 projectID, bool isActive) public onlyOwner { require(0 != projects[projectID].projectCreationDate, "Error: Project does not exist."); projects[projectID].isActive = isActive; } //TODO maybe add a lookup for each citizen's all votes in future. //TODO maybe add event logs in future. }
[{"constant":true,"inputs":[{"name":"","type":"uint256"}],"name":"projects","outputs":[{"name":"voteCount","type":"uint256"},{"name":"likes","type":"uint256"},{"name":"dislikes","type":"uint256"},{"name":"shortDescribtion","type":"string"},{"name":"projectCreationDate","type":"uint256"},{"name":"isActive","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"projectID","type":"uint256"},{"name":"shortDescribtion","type":"string"}],"name":"addProject","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"projectID","type":"uint256"}],"name":"getProjectData","outputs":[{"name":"voteCount","type":"uint256"},{"name":"likes","type":"uint256"},{"name":"dislikes","type":"uint256"},{"name":"shortDescribtion","type":"string"},{"name":"projectCreationDate","type":"uint256"},{"name":"isActive","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"","type":"uint256"}],"name":"projectList","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[],"name":"renounceOwnership","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"projectID","type":"uint256"}],"name":"getVotedIDs","outputs":[{"name":"votedIDs","type":"uint256[]"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"getAllProjects","outputs":[{"name":"projectIDs","type":"uint256[]"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"projectID","type":"uint256"},{"name":"citizenID","type":"uint256"},{"name":"citizenVote","type":"uint256"}],"name":"vote","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"owner","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"isOwner","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"projectID","type":"uint256"},{"name":"citizenID","type":"uint256"}],"name":"getCitizensVote","outputs":[{"name":"idsVote","type":"uint256"},{"name":"voteDate","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"projectID","type":"uint256"},{"name":"isActive","type":"bool"}],"name":"setProjectActivity","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"anonymous":false,"inputs":[{"indexed":true,"name":"previousOwner","type":"address"},{"indexed":true,"name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"}]
Contract Creation Code
60806040819052600080546001600160a01b03191633178082556001600160a01b0316917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0908290a3610e2f806100576000396000f3fe608060405234801561001057600080fd5b50600436106100cf5760003560e01c806380d038291161008c5780638f32d59b116100665780638f32d59b14610355578063b49315be14610371578063e5b0291c146103ad578063f2fde38b146103d2576100cf565b806380d03829146103005780638a6655d6146103085780638da5cb5b14610331576100cf565b8063107046bd146100d457806355a027a11461019057806358f36c131461023f57806360570b2e1461025c578063715018a61461028b5780637c01f55614610293575b600080fd5b6100f1600480360360208110156100ea57600080fd5b50356103f8565b604051808781526020018681526020018581526020018060200184815260200183151515158152602001828103825285818151815260200191508051906020019080838360005b83811015610150578181015183820152602001610138565b50505050905090810190601f16801561017d5780820380516001836020036101000a031916815260200191505b5097505050505050505060405180910390f35b61023d600480360360408110156101a657600080fd5b813591908101906040810160208201356401000000008111156101c857600080fd5b8201836020820111156101da57600080fd5b803590602001918460018302840111640100000000831117156101fc57600080fd5b91908080601f0160208091040260200160405190810160405280939291908181526020018383808284376000920191909152509295506104d0945050505050565b005b6100f16004803603602081101561025557600080fd5b5035610600565b6102796004803603602081101561027257600080fd5b50356106e4565b60408051918252519081900360200190f35b61023d610702565b6102b0600480360360208110156102a957600080fd5b5035610796565b60408051602080825283518183015283519192839290830191858101910280838360005b838110156102ec5781810151838201526020016102d4565b505050509050019250505060405180910390f35b6102b06107f8565b61023d6004803603606081101561031e57600080fd5b5080359060208101359060400135610851565b610339610a8f565b604080516001600160a01b039092168252519081900360200190f35b61035d610a9e565b604080519115158252519081900360200190f35b6103946004803603604081101561038757600080fd5b5080359060200135610aaf565b6040805192835260208301919091528051918290030190f35b61023d600480360360408110156103c357600080fd5b50803590602001351515610b59565b61023d600480360360208110156103e857600080fd5b50356001600160a01b0316610c2c565b6001602052806000526040600020600091509050806004015490806005015490806006015490806007018054600181600116156101000203166002900480601f0160208091040260200160405190810160405280929190818152602001828054600181600116156101000203166002900480156104b65780601f1061048b576101008083540402835291602001916104b6565b820191906000526020600020905b81548152906001019060200180831161049957829003601f168201915b50505050600883015460099093015491929160ff16905086565b6104d8610a9e565b61051a5760408051600160e51b62461bcd0281526020600482018190526024820152600080516020610de4833981519152604482015290519081900360640190fd5b600082815260016020526040902060080154156105815760408051600160e51b62461bcd02815260206004820152601e60248201527f4572726f723a2050726f6a65637420616c7265616479206578697374732e0000604482015290519081900360640190fd5b600082815260016020818152604090922060098101805460ff191690921790915582516105b692600790920191840190610d25565b505060008181526001602081905260408220426008909101556002805491820181559091527f405787fa12a823e0f2b7631cc41b3ba8828b3321ca811111fa75cd3aa3bb5ace0155565b60008181526001602081815260408084206004810154600582015460068301546008840154600985015460079095018054875160026101009b8316159b909b026000190190911699909904601f810189900489028a018901909752868952899889986060988a9889989796959360ff90911692909185918301828280156106c85780601f1061069d576101008083540402835291602001916106c8565b820191906000526020600020905b8154815290600101906020018083116106ab57829003601f168201915b5050505050925095509550955095509550955091939550919395565b600281815481106106f157fe5b600091825260209091200154905081565b61070a610a9e565b61074c5760408051600160e51b62461bcd0281526020600482018190526024820152600080516020610de4833981519152604482015290519081900360640190fd5b600080546040516001600160a01b03909116907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0908390a3600080546001600160a01b0319169055565b6000818152600160209081526040918290208054835181840281018401909452808452606093928301828280156107ec57602002820191906000526020600020905b8154815260200190600101908083116107d8575b50505050509050919050565b6060600280548060200260200160405190810160405280929190818152602001828054801561084657602002820191906000526020600020905b815481526020019060010190808311610832575b505050505090505b90565b610859610a9e565b61089b5760408051600160e51b62461bcd0281526020600482018190526024820152600080516020610de4833981519152604482015290519081900360640190fd5b60008381526001602081905260409091206009015460ff1615151461090a5760408051600160e51b62461bcd02815260206004820152601b60248201527f4572726f723a2050726f6a65637420697320696e6163746976652e0000000000604482015290519081900360640190fd5b6000838152600160205260409020600801546109705760408051600160e51b62461bcd02815260206004820152601e60248201527f4572726f723a2050726f6a65637420646f6573206e6f742065786973742e0000604482015290519081900360640190fd5b6000838152600160208181526040808420868552909201905290205460ff16156109e45760408051600160e51b62461bcd02815260206004820152601d60248201527f4572726f723a20436974697a656e20616c726561647920766f7465642e000000604482015290519081900360640190fd5b8060011415610a0d57600083815260016020819052604090912060060180549091019055610a32565b8060021415610a32576000838152600160208190526040909120600501805490910190555b600092835260016020818152604080862060048101805485019055858752600281018352818720949094558383018252808620805460ff191684179055600384018252852042905581815282549182018355918452922090910155565b6000546001600160a01b031690565b6000546001600160a01b0316331490565b60008281526001602081815260408084208585528301909152822054829160ff909116151514610b295760408051600160e51b62461bcd02815260206004820152601560248201527f436974697a656e20646964206e6f7420766f7465640000000000000000000000604482015290519081900360640190fd5b50506000918252600160209081526040808420928452600283018252808420546003909301909152909120549091565b610b61610a9e565b610ba35760408051600160e51b62461bcd0281526020600482018190526024820152600080516020610de4833981519152604482015290519081900360640190fd5b600082815260016020526040902060080154610c095760408051600160e51b62461bcd02815260206004820152601e60248201527f4572726f723a2050726f6a65637420646f6573206e6f742065786973742e0000604482015290519081900360640190fd5b600091825260016020526040909120600901805460ff1916911515919091179055565b610c34610a9e565b610c765760408051600160e51b62461bcd0281526020600482018190526024820152600080516020610de4833981519152604482015290519081900360640190fd5b610c7f81610c82565b50565b6001600160a01b038116610cca57604051600160e51b62461bcd028152600401808060200182810382526026815260200180610dbe6026913960400191505060405180910390fd5b600080546040516001600160a01b03808516939216917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e091a3600080546001600160a01b0319166001600160a01b0392909216919091179055565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f10610d6657805160ff1916838001178555610d93565b82800160010185558215610d93579182015b82811115610d93578251825591602001919060010190610d78565b50610d9f929150610da3565b5090565b61084e91905b80821115610d9f5760008155600101610da956fe4f776e61626c653a206e6577206f776e657220697320746865207a65726f20616464726573734f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572a165627a7a72305820fc3418e0549f8883c40e12134765bf68fc508d617193424599b3af4636be1dda0029
Swarm Source
bzzr://fc3418e0549f8883c40e12134765bf68fc508d617193424599b3af4636be1dda
A contract address hosts a smart contract, which is a set of code stored on the blockchain that runs when predetermined conditions are met. Learn more about addresses in our Knowledge Base.