Skip to content

Instantly share code, notes, and snippets.

@ismailmayat
Forked from anonymous/CogCoin.sol
Created February 24, 2018 17:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ismailmayat/c6fa6ac4870d85039d69c5ea500328ee to your computer and use it in GitHub Desktop.
Save ismailmayat/c6fa6ac4870d85039d69c5ea500328ee 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=
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;
}
}
}
pragma solidity ^0.4.0;
import './Ownable.sol';
contract CogCoin is Ownable {
string coinName;
string coinSymbol;
uint256 public totalSupply;
uint256 public dailyTransferLimit;
mapping (address => uint256) public wallets;
event OverDailyLimit(uint256 dailyLimit);
function CogCoin(string _coinName,string _coinSymbol,uint256 _totalSupply,uint256 _dailyTransferLimit) public{
coinName = _coinName;
totalSupply = _totalSupply;
coinSymbol = _coinSymbol;
dailyTransferLimit = _dailyTransferLimit;
}
function setDailyLimit(uint _limit) public onlyOwner returns (bool success){
if(_limit<=0){
return false;
}
if(_limit>totalSupply){
return false;
}
else{
dailyTransferLimit = _limit;
return true;
}
}
function transfer(address _to, uint256 _value) onlyOwner public returns (bool success){
if(_value>dailyTransferLimit){
OverDailyLimit(dailyTransferLimit);
return false;
}
if(_value<=totalSupply){
wallets[_to]+=_value;
totalSupply -=_value;
Transfer(msg.sender,_to,_value);
return true;
}
return false;
}
function totalSupply() constant returns (uint256 totalSupply);
function balanceOf(address _owner) constant returns (uint256 balance){
return wallets[_owner];
}
function transferFrom(address _from, address _to, uint256 _value) returns (bool success){
}
function approve(address _spender, uint256 _value) returns (bool success){
}
function allowance(address _owner, address _spender) constant returns (uint256 remaining){
}
event Transfer(address indexed _from, address indexed _to, uint256 _value);
event Approval(address indexed _owner, address indexed _spender, uint256 _value);
}
pragma solidity ^0.4.18;
/**
* @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;
}
}
pragma solidity ^0.4.0;
contract Score{
uint myScore;
address owner;
string description; //what this score represents
event ScoreSet(uint); //notify that this event happens because u do not know when it was mined.
//use this to secure functions
modifier onlyOwner(){
if(msg.sender == owner){
_;
}
}
//only called on deployment
//going to make deployer the owner
function Score() public{
owner = msg.sender;
}
function getScore() public view returns (uint) {
return myScore;
}
//can only call from outside
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