Created
February 24, 2018 19:14
-
-
Save anonymous/92ea9647d036fe9f949b0e41b7ce590f to your computer and use it in GitHub Desktop.
Created using browser-solidity: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://ethereum.github.io/browser-solidity/#version=soljson-v0.4.20+commit.3155dd80.js&optimize=false&gist=
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| pragma solidity ^0.4.0; | |
| contract Ballot { | |
| struct Voter { | |
| uint weight; | |
| bool voted; | |
| uint8 vote; | |
| address delegate; | |
| } | |
| struct Proposal { | |
| uint voteCount; | |
| } | |
| address chairperson; | |
| mapping(address => Voter) voters; | |
| Proposal[] proposals; | |
| /// Create a new ballot with $(_numProposals) different proposals. | |
| function Ballot(uint8 _numProposals) public { | |
| chairperson = msg.sender; | |
| voters[chairperson].weight = 1; | |
| proposals.length = _numProposals; | |
| } | |
| /// Give $(toVoter) the right to vote on this ballot. | |
| /// May only be called by $(chairperson). | |
| function giveRightToVote(address toVoter) public { | |
| if (msg.sender != chairperson || voters[toVoter].voted) return; | |
| voters[toVoter].weight = 1; | |
| } | |
| /// Delegate your vote to the voter $(to). | |
| function delegate(address to) public { | |
| Voter storage sender = voters[msg.sender]; // assigns reference | |
| if (sender.voted) return; | |
| while (voters[to].delegate != address(0) && voters[to].delegate != msg.sender) | |
| to = voters[to].delegate; | |
| if (to == msg.sender) return; | |
| sender.voted = true; | |
| sender.delegate = to; | |
| Voter storage delegateTo = voters[to]; | |
| if (delegateTo.voted) | |
| proposals[delegateTo.vote].voteCount += sender.weight; | |
| else | |
| delegateTo.weight += sender.weight; | |
| } | |
| /// Give a single vote to proposal $(toProposal). | |
| function vote(uint8 toProposal) public { | |
| Voter storage sender = voters[msg.sender]; | |
| if (sender.voted || toProposal >= proposals.length) return; | |
| sender.voted = true; | |
| sender.vote = toProposal; | |
| proposals[toProposal].voteCount += sender.weight; | |
| } | |
| function winningProposal() public constant returns (uint8 _winningProposal) { | |
| uint256 winningVoteCount = 0; | |
| for (uint8 prop = 0; prop < proposals.length; prop++) | |
| if (proposals[prop].voteCount > winningVoteCount) { | |
| winningVoteCount = proposals[prop].voteCount; | |
| _winningProposal = prop; | |
| } | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| pragma solidity ^0.4.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 public owner; | |
| event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); | |
| /** | |
| * @dev The Ownable constructor sets the original `owner` of the contract to the sender | |
| * account. | |
| */ | |
| function Ownable() public { | |
| owner = msg.sender; | |
| } | |
| /** | |
| * @dev Throws if called by any account other than the owner. | |
| */ | |
| modifier onlyOwner() { | |
| require(msg.sender == owner); | |
| _; | |
| } | |
| /** | |
| * @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 { | |
| require(newOwner != address(0)); | |
| OwnershipTransferred(owner, newOwner); | |
| owner = newOwner; | |
| } | |
| } | |
| contract FredCoin is Ownable { | |
| string public name = "FredCoin"; | |
| string public symbol = "FRD"; | |
| mapping(address => uint) addressBalance; | |
| mapping(address => bool) whitelist; | |
| event whitelistAccessAtempt(address indexed _who); | |
| modifier onlyWhitelist{ | |
| if(whitelist[msg.sender] == true){ | |
| _; | |
| } | |
| else{ | |
| whitelistAccessAtempt(msg.sender); | |
| } | |
| } | |
| function addWhitelist(address _who) onlyOwner{ | |
| whitelist[_who] = true; | |
| } | |
| uint totalTokenSupply; | |
| uint tokenTransferLimit; | |
| function FredCoin(uint _totalSupply, uint _tokenLimit) public{ | |
| whitelist[msg.sender] = true; | |
| totalTokenSupply = _totalSupply; | |
| tokenTransferLimit = _tokenLimit; | |
| addressBalance[msg.sender] = 1000; | |
| } | |
| function totalSupply() constant onlyWhitelist returns (uint totalSupply){ | |
| totalSupply = totalTokenSupply; | |
| } | |
| function transferLimit() constant onlyWhitelist returns (uint transferLimit){ | |
| transferLimit = tokenTransferLimit; | |
| } | |
| function setTransferLimit (uint _value) onlyOwner{ | |
| tokenTransferLimit = _value; | |
| } | |
| function balanceOf(address _owner) onlyWhitelist constant returns (uint balance) { | |
| return addressBalance[_owner]; | |
| } | |
| event NotEnoughFundsTransactionAttempt(address indexed _from, address indexed _to, uint _value); | |
| modifier haveEnoughTokens (address _from, address _to, uint _value){ | |
| if(addressBalance[_from] > _value){ | |
| _; | |
| } | |
| else{ | |
| NotEnoughFundsTransactionAttempt(_from, _to, _value); | |
| } | |
| } | |
| event OverflowTransactionAttempt (address indexed _from, address indexed _to, uint _value); | |
| modifier stopOverflow (address _from, address _to, uint _value){ | |
| if( addressBalance[_to] < (addressBalance[_to] + _value) ){ | |
| _; | |
| } | |
| else{ | |
| OverflowTransactionAttempt(_from, _to, _value); | |
| } | |
| } | |
| event ExceedTransactionLimit (address indexed _from, address indexed _to, uint _value); | |
| modifier transferLimitExceed (address _from, address _to, uint _value){ | |
| if(_value < tokenTransferLimit){ | |
| _; | |
| } | |
| else{ | |
| ExceedTransactionLimit(_from, _to, _value); | |
| } | |
| } | |
| event Transfer(address indexed _from, address indexed _to, uint256 _value); | |
| function transfer(address _to, uint256 _value) onlyWhitelist haveEnoughTokens(msg.sender, _to, _value) stopOverflow(msg.sender, _to, _value) transferLimitExceed(msg.sender, _to, _value) returns (bool success) { | |
| addressBalance[msg.sender] = addressBalance[msg.sender] - _value; | |
| addressBalance[_to] = addressBalance[_to] + _value; | |
| Transfer(msg.sender, _to, _value); | |
| } | |
| mapping(address => mapping(address => uint)) approved; | |
| event Approval(address indexed _owner, address indexed _spender, uint256 _value); | |
| function approve(address _spender, uint256 _value) returns (bool success){ | |
| approved[msg.sender][_spender] = _value; | |
| Approval(msg.sender, _spender, _value); | |
| return true; | |
| } | |
| function allowance(address _owner, address _spender) constant returns (uint256 remaining){ | |
| remaining = approved[_owner][_spender]; | |
| } | |
| function transferFrom(address _from, address _to, uint256 _value) stopOverflow(_from, _to, _value) haveEnoughTokens(_from, _to, _value) returns (bool success) { | |
| if(allowance(_from, _to) > _value){ | |
| addressBalance[_from] = addressBalance[_from] - _value; | |
| addressBalance[_to] = addressBalance[_to] + _value; | |
| Transfer(_from, _to, _value); | |
| return true; | |
| } | |
| return false; | |
| } | |
| } | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| pragma solidity ^0.4.0; | |
| contract Score{ | |
| uint myScore; | |
| address owner; | |
| string description; | |
| event ScoreSet(uint); | |
| modifier onlyOwner(){ | |
| if(msg.sender == owner){ | |
| _; | |
| } | |
| } | |
| function Score() public { | |
| owner = msg.sender; | |
| } | |
| function getScore() public view returns (uint) { | |
| return myScore; | |
| } | |
| function setScore(uint _score) external { | |
| myScore = _score; | |
| ScoreSet(_score); | |
| } | |
| function setDescription (string _description) public onlyOwner { | |
| description = _description; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment