Skip to content

Instantly share code, notes, and snippets.

@alexvandesande
Created January 29, 2016 20:33
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 alexvandesande/11ccaf75137e9640dd55 to your computer and use it in GitHub Desktop.
Save alexvandesande/11ccaf75137e9640dd55 to your computer and use it in GitHub Desktop.
Address:
0x85935ee5773319756973cfd8ce5d3eb5831827ce
ABI:
[ { "constant": true, "inputs": [ { "name": "", "type": "uint256", "typeShort": "uint", "bits": "256", "displayName": "", "template": "elements_input_uint" } ], "name": "proposals", "outputs": [ { "name": "recipient", "type": "address", "value": "0xd1220a0cf47c7b9be7a2e6ba89f429762e7b9adb", "displayName": "recipient" }, { "name": "amount", "type": "uint256", "value": "10", "displayName": "amount" }, { "name": "description", "type": "string", "value": "Refund 10 ethers to Avsa as a test of the DAO", "displayName": "description" }, { "name": "votingDeadline", "type": "uint256", "value": "1454093006", "displayName": "voting Deadline" }, { "name": "executed", "type": "bool", "value": true, "displayName": "executed" }, { "name": "proposalPassed", "type": "bool", "value": true, "displayName": "proposal Passed" }, { "name": "numberOfVotes", "type": "uint256", "value": "1", "displayName": "number Of Votes" }, { "name": "currentResult", "type": "int256", "value": "1", "displayName": "current Result" }, { "name": "proposalHash", "type": "bytes32", "value": "0xbf25444ad64b9d8d04e16dab76c4722a0c513266fc37e7fbd166293f5807de2e", "displayName": "proposal Hash" } ], "type": "function", "displayName": "proposals" }, { "constant": false, "inputs": [ { "name": "targetMember", "type": "address", "typeShort": "address", "bits": "", "displayName": "target Member", "template": "elements_input_address" }, { "name": "canVote", "type": "bool", "typeShort": "bool", "bits": "", "displayName": "can Vote", "template": "elements_input_bool" }, { "name": "canAddProposals", "type": "bool", "typeShort": "bool", "bits": "", "displayName": "can Add Proposals", "template": "elements_input_bool" }, { "name": "memberName", "type": "string", "typeShort": "string", "bits": "", "displayName": "member Name", "template": "elements_input_string" } ], "name": "changeMembership", "outputs": [], "type": "function", "displayName": "change Membership" }, { "constant": false, "inputs": [ { "name": "proposalNumber", "type": "uint256", "typeShort": "uint", "bits": "256", "displayName": "proposal Number", "template": "elements_input_uint" }, { "name": "transactionBytecode", "type": "bytes", "typeShort": "bytes", "bits": "", "displayName": "transaction Bytecode", "template": "elements_input_bytes" } ], "name": "executeProposal", "outputs": [ { "name": "result", "type": "int256" } ], "type": "function", "displayName": "execute Proposal" }, { "constant": true, "inputs": [ { "name": "", "type": "address", "typeShort": "address", "bits": "", "displayName": "", "template": "elements_input_address" } ], "name": "memberId", "outputs": [ { "name": "", "type": "uint256", "value": "0", "displayName": "" } ], "type": "function", "displayName": "member Id" }, { "constant": true, "inputs": [], "name": "numProposals", "outputs": [ { "name": "", "type": "uint256", "value": "1", "displayName": "" } ], "type": "function", "displayName": "num Proposals" }, { "constant": true, "inputs": [ { "name": "", "type": "uint256", "typeShort": "uint", "bits": "256", "displayName": "", "template": "elements_input_uint", "value": "3" } ], "name": "members", "outputs": [ { "name": "member", "type": "address", "value": "0x967bfaf76243cdb9403c67d2ceefdee90a3feb73", "displayName": "member" }, { "name": "canVote", "type": "bool", "value": true, "displayName": "can Vote" }, { "name": "canAddProposals", "type": "bool", "value": true, "displayName": "can Add Proposals" }, { "name": "name", "type": "string", "value": "Ming Chan", "displayName": "name" }, { "name": "memberSince", "type": "uint256", "value": "1454093232", "displayName": "member Since" } ], "type": "function", "displayName": "members" }, { "constant": true, "inputs": [], "name": "debatingPeriodInMinutes", "outputs": [ { "name": "", "type": "uint256", "value": "1440", "displayName": "" } ], "type": "function", "displayName": "debating Period In Minutes" }, { "constant": true, "inputs": [], "name": "minimumQuorum", "outputs": [ { "name": "", "type": "uint256", "value": "2", "displayName": "" } ], "type": "function", "displayName": "minimum Quorum" }, { "constant": true, "inputs": [], "name": "majorityMargin", "outputs": [ { "name": "", "type": "int256", "value": "1", "displayName": "" } ], "type": "function", "displayName": "majority Margin" }, { "constant": false, "inputs": [ { "name": "beneficiary", "type": "address", "typeShort": "address", "bits": "", "displayName": "beneficiary", "template": "elements_input_address" }, { "name": "etherAmount", "type": "uint256", "typeShort": "uint", "bits": "256", "displayName": "ether Amount", "template": "elements_input_uint" }, { "name": "JobDescription", "type": "string", "typeShort": "string", "bits": "", "displayName": " Job Description", "template": "elements_input_string" }, { "name": "transactionBytecode", "type": "bytes", "typeShort": "bytes", "bits": "", "displayName": "transaction Bytecode", "template": "elements_input_bytes" } ], "name": "newProposal", "outputs": [ { "name": "proposalID", "type": "uint256" } ], "type": "function", "displayName": "new Proposal" }, { "constant": false, "inputs": [ { "name": "minimumQuorumForProposals", "type": "uint256", "typeShort": "uint", "bits": "256", "displayName": "minimum Quorum For Proposals", "template": "elements_input_uint" }, { "name": "minutesForDebate", "type": "uint256", "typeShort": "uint", "bits": "256", "displayName": "minutes For Debate", "template": "elements_input_uint" }, { "name": "marginOfVotesForMajority", "type": "int256", "typeShort": "int", "bits": "256", "displayName": "margin Of Votes For Majority", "template": "elements_input_int" } ], "name": "changeVotingRules", "outputs": [], "type": "function", "displayName": "change Voting Rules" }, { "constant": false, "inputs": [ { "name": "proposalNumber", "type": "uint256", "typeShort": "uint", "bits": "256", "displayName": "proposal Number", "template": "elements_input_uint" }, { "name": "supportsProposal", "type": "bool", "typeShort": "bool", "bits": "", "displayName": "supports Proposal", "template": "elements_input_bool" }, { "name": "justificationText", "type": "string", "typeShort": "string", "bits": "", "displayName": "justification Text", "template": "elements_input_string" } ], "name": "vote", "outputs": [ { "name": "voteID", "type": "uint256" } ], "type": "function", "displayName": "vote" }, { "constant": true, "inputs": [ { "name": "proposalNumber", "type": "uint256", "typeShort": "uint", "bits": "256", "displayName": "proposal Number", "template": "elements_input_uint" }, { "name": "beneficiary", "type": "address", "typeShort": "address", "bits": "", "displayName": "beneficiary", "template": "elements_input_address" }, { "name": "etherAmount", "type": "uint256", "typeShort": "uint", "bits": "256", "displayName": "ether Amount", "template": "elements_input_uint" }, { "name": "transactionBytecode", "type": "bytes", "typeShort": "bytes", "bits": "", "displayName": "transaction Bytecode", "template": "elements_input_bytes" } ], "name": "checkProposalCode", "outputs": [ { "name": "codeChecksOut", "type": "bool", "value": false, "displayName": "code Checks Out" } ], "type": "function", "displayName": "check Proposal Code" }, { "constant": false, "inputs": [ { "name": "newAdministrator", "type": "address", "typeShort": "address", "bits": "", "displayName": "new Administrator", "template": "elements_input_address" } ], "name": "transferOwnership", "outputs": [], "type": "function", "displayName": "transfer Ownership" }, { "constant": true, "inputs": [], "name": "administrator", "outputs": [ { "name": "", "type": "address", "value": "0xd1220a0cf47c7b9be7a2e6ba89f429762e7b9adb", "displayName": "" } ], "type": "function", "displayName": "administrator" }, { "inputs": [ { "name": "minimumQuorumForProposals", "type": "uint256", "typeShort": "uint", "bits": "256", "displayName": "minimum Quorum For Proposals", "template": "elements_input_uint", "value": "1" }, { "name": "minutesForDebate", "type": "uint256", "typeShort": "uint", "bits": "256", "displayName": "minutes For Debate", "template": "elements_input_uint", "value": "5" }, { "name": "marginOfVotesForMajority", "type": "int256", "typeShort": "int", "bits": "256", "displayName": "margin Of Votes For Majority", "template": "elements_input_int", "value": "0" }, { "name": "congressLeader", "type": "address", "typeShort": "address", "bits": "", "displayName": "congress Leader", "template": "elements_input_address", "value": "" } ], "type": "constructor" }, { "anonymous": false, "inputs": [ { "indexed": false, "name": "proposalID", "type": "uint256" }, { "indexed": false, "name": "recipient", "type": "address" }, { "indexed": false, "name": "amount", "type": "uint256" }, { "indexed": false, "name": "description", "type": "string" } ], "name": "ProposalAdded", "type": "event" }, { "anonymous": false, "inputs": [ { "indexed": false, "name": "proposalID", "type": "uint256" }, { "indexed": false, "name": "position", "type": "bool" }, { "indexed": false, "name": "voter", "type": "address" }, { "indexed": false, "name": "justification", "type": "string" } ], "name": "Voted", "type": "event" }, { "anonymous": false, "inputs": [ { "indexed": false, "name": "proposalID", "type": "uint256" }, { "indexed": false, "name": "result", "type": "int256" }, { "indexed": false, "name": "quorum", "type": "uint256" }, { "indexed": false, "name": "active", "type": "bool" } ], "name": "ProposalTallied", "type": "event" }, { "anonymous": false, "inputs": [ { "indexed": false, "name": "member", "type": "address" }, { "indexed": false, "name": "isMember", "type": "bool" } ], "name": "MembershipChanged", "type": "event" }, { "anonymous": false, "inputs": [ { "indexed": false, "name": "minimumQuorum", "type": "uint256" }, { "indexed": false, "name": "debatingPeriodInMinutes", "type": "uint256" }, { "indexed": false, "name": "majorityMargin", "type": "int256" } ], "name": "ChangeOfRules", "type": "event" } ]
Compiled on jan 29, 2016 using Mist Wallet probably running solc v 0.2.0, 0.1.6 or 0.1.0-4b911329/Release-Darwin/clang/JIT (not sure which)
Source Code:
contract owned {
address public administrator;
function owned() {
administrator = msg.sender;
}
modifier onlyAdmin {
if (msg.sender != administrator) throw;
_
}
function transferOwnership(address newAdministrator) onlyAdmin {
administrator = newAdministrator;
}
}
contract Congress is owned {
/* Contract Variables and events */
uint public minimumQuorum;
uint public debatingPeriodInMinutes;
int public majorityMargin;
Proposal[] public proposals;
uint public numProposals;
mapping (address => uint) public memberId;
Member[] public members;
event ProposalAdded(uint proposalID, address recipient, uint amount, string description);
event Voted(uint proposalID, bool position, address voter, string justification);
event ProposalTallied(uint proposalID, int result, uint quorum, bool active);
event MembershipChanged(address member, bool isMember);
event ChangeOfRules(uint minimumQuorum, uint debatingPeriodInMinutes, int majorityMargin);
struct Proposal {
address recipient;
uint amount;
string description;
uint votingDeadline;
bool executed;
bool proposalPassed;
uint numberOfVotes;
int currentResult;
bytes32 proposalHash;
Vote[] votes;
mapping (address => bool) voted;
}
struct Member {
address member;
bool canVote;
bool canAddProposals;
string name;
uint memberSince;
}
struct Vote {
bool inSupport;
address voter;
string justification;
}
/* First time setup */
function Congress(uint minimumQuorumForProposals, uint minutesForDebate, int marginOfVotesForMajority, address congressLeader) {
minimumQuorum = minimumQuorumForProposals;
debatingPeriodInMinutes = minutesForDebate;
majorityMargin = marginOfVotesForMajority;
members.length++;
members[0] = Member({member: 0, canVote: false, canAddProposals: false, memberSince: now, name: ''});
if (congressLeader != 0) administrator = congressLeader;
}
/*make member*/
function changeMembership(address targetMember, bool canVote, bool canAddProposals, string memberName) onlyAdmin {
uint id;
if (memberId[targetMember] == 0) {
memberId[targetMember] = members.length;
id = members.length++;
members[id] = Member({member: targetMember, canVote: canVote, canAddProposals: canAddProposals, memberSince: now, name: memberName});
} else {
id = memberId[targetMember];
Member m = members[id];
m.canVote = canVote;
}
MembershipChanged(targetMember, canVote);
}
/*change rules*/
function changeVotingRules(uint minimumQuorumForProposals, uint minutesForDebate, int marginOfVotesForMajority) onlyAdmin {
minimumQuorum = minimumQuorumForProposals;
debatingPeriodInMinutes = minutesForDebate;
majorityMargin = marginOfVotesForMajority;
ChangeOfRules(minimumQuorum, debatingPeriodInMinutes, majorityMargin);
}
/* Function to create a new proposal */
function newProposal(address beneficiary, uint etherAmount, string JobDescription, bytes transactionBytecode) returns (uint proposalID) {
if (memberId[msg.sender] == 0 || !members[memberId[msg.sender]].canAddProposals) throw;
proposalID = proposals.length++;
Proposal p = proposals[proposalID];
p.recipient = beneficiary;
p.amount = etherAmount;
p.description = JobDescription;
p.proposalHash = sha3(beneficiary, etherAmount, transactionBytecode);
p.votingDeadline = now + debatingPeriodInMinutes * 1 minutes;
p.executed = false;
p.proposalPassed = false;
p.numberOfVotes = 0;
ProposalAdded(proposalID, beneficiary, etherAmount, JobDescription);
numProposals = proposalID+1;
}
/* function to check if a proposal code matches */
function checkProposalCode(uint proposalNumber, address beneficiary, uint etherAmount, bytes transactionBytecode) constant returns (bool codeChecksOut) {
Proposal p = proposals[proposalNumber];
return p.proposalHash == sha3(beneficiary, etherAmount, transactionBytecode);
}
function vote(uint proposalNumber, bool supportsProposal, string justificationText) returns (uint voteID){
if (memberId[msg.sender] == 0 || !members[memberId[msg.sender]].canVote) throw;
Proposal p = proposals[proposalNumber]; // Get the proposal
if (p.voted[msg.sender] == true) throw; // If has already voted, cancel
p.voted[msg.sender] = true; // Set this voter as having voted
p.numberOfVotes++; // Increase the number of votes
if (supportsProposal) { // If they support the proposal
p.currentResult++; // Increase score
} else { // If they don't
p.currentResult--; // Decrease the score
}
// Create a log of this event
Voted(proposalNumber, supportsProposal, msg.sender, justificationText);
}
function executeProposal(uint proposalNumber, bytes transactionBytecode) returns (int result) {
Proposal p = proposals[proposalNumber];
/* Check if the proposal can be executed */
if (now < p.votingDeadline // has the voting deadline arrived?
|| p.executed // has it been already executed?
|| p.proposalHash != sha3(p.recipient, p.amount, transactionBytecode) // Does the transaction code match the proposal?
|| p.numberOfVotes < minimumQuorum) // has minimum quorum?
throw;
/* execute result */
if (p.currentResult > majorityMargin) {
/* If difference between support and opposition is larger than margin */
p.recipient.call.value(p.amount * 1 ether)(transactionBytecode);
p.executed = true;
p.proposalPassed = true;
} else {
p.executed = true;
p.proposalPassed = false;
}
// Fire Events
ProposalTallied(proposalNumber, p.currentResult, p.numberOfVotes, p.proposalPassed);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment