Skip to content

Instantly share code, notes, and snippets.

@Quevin
Created June 11, 2018 15:30
Show Gist options
  • Save Quevin/a695899da0d80d31a1c302d4788a1ee0 to your computer and use it in GitHub Desktop.
Save Quevin/a695899da0d80d31a1c302d4788a1ee0 to your computer and use it in GitHub Desktop.
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.4.24+commit.e67f0147.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;
contract Bank {
uint private value;
function deposit(uint amount) {
value += amount;
}
function withdraw(uint amount) {
value -= amount;
}
function balance() returns (uint) {
return value;
}
}
contract myFirstContract is Bank {
string private name;
uint private age;
function setName(string newName) {
name = newName;
}
function getName() returns (string) {
return name;
}
function setAge(uint newAge) {
age = newAge;
}
function getAge() returns (uint) {
return age;
}
}
{
"accounts": {
"account{-1}": null
},
"linkReferences": {},
"transactions": [
{
"timestamp": 1528730187236,
"record": {
"value": "0",
"parameters": [],
"abi": "0xdfcbe054725ea501056a95ff91530c2a83371e15ec9d05619f12c76baa92ee2f",
"contractName": "myFirstContract",
"bytecode": "608060405234801561001057600080fd5b5061042c806100206000396000f300608060405260043610610083576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff16806317d7de7c146100885780632e1a7d4d14610118578063967e6e6514610145578063b69ef8a814610170578063b6b55f251461019b578063c47f0027146101c8578063d5dcf12714610231575b600080fd5b34801561009457600080fd5b5061009d61025e565b6040518080602001828103825283818151815260200191508051906020019080838360005b838110156100dd5780820151818401526020810190506100c2565b50505050905090810190601f16801561010a5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b34801561012457600080fd5b5061014360048036038101908080359060200190929190505050610300565b005b34801561015157600080fd5b5061015a610312565b6040518082815260200191505060405180910390f35b34801561017c57600080fd5b5061018561031c565b6040518082815260200191505060405180910390f35b3480156101a757600080fd5b506101c660048036038101908080359060200190929190505050610325565b005b3480156101d457600080fd5b5061022f600480360381019080803590602001908201803590602001908080601f0160208091040260200160405190810160405280939291908181526020018383808284378201915050505050509192919290505050610337565b005b34801561023d57600080fd5b5061025c60048036038101908080359060200190929190505050610351565b005b606060018054600181600116156101000203166002900480601f0160208091040260200160405190810160405280929190818152602001828054600181600116156101000203166002900480156102f65780601f106102cb576101008083540402835291602001916102f6565b820191906000526020600020905b8154815290600101906020018083116102d957829003601f168201915b5050505050905090565b80600080828254039250508190555050565b6000600254905090565b60008054905090565b80600080828254019250508190555050565b806001908051906020019061034d92919061035b565b5050565b8060028190555050565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f1061039c57805160ff19168380011785556103ca565b828001600101855582156103ca579182015b828111156103c95782518255916020019190600101906103ae565b5b5090506103d791906103db565b5090565b6103fd91905b808211156103f95760008160009055506001016103e1565b5090565b905600a165627a7a72305820b37e849a652a1e4684b15342838517f5d138f5a199fb557235046a1205629cef0029",
"linkReferences": {},
"name": "",
"type": "constructor",
"from": "account{-1}"
}
}
],
"abis": {
"0xdfcbe054725ea501056a95ff91530c2a83371e15ec9d05619f12c76baa92ee2f": [
{
"constant": false,
"inputs": [],
"name": "getName",
"outputs": [
{
"name": "",
"type": "string"
}
],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": false,
"inputs": [
{
"name": "amount",
"type": "uint256"
}
],
"name": "withdraw",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": false,
"inputs": [],
"name": "getAge",
"outputs": [
{
"name": "",
"type": "uint256"
}
],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": false,
"inputs": [],
"name": "balance",
"outputs": [
{
"name": "",
"type": "uint256"
}
],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": false,
"inputs": [
{
"name": "amount",
"type": "uint256"
}
],
"name": "deposit",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": false,
"inputs": [
{
"name": "newName",
"type": "string"
}
],
"name": "setName",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": false,
"inputs": [
{
"name": "newAge",
"type": "uint256"
}
],
"name": "setAge",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
}
]
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment