Created
January 7, 2018 07:51
-
-
Save anonymous/b8ac69cfaa8ed1d94e29ce8c0c84ed7e 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.19+commit.c4cbbb05.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.16; | |
| contract AcademicRegistry { | |
| struct Certificate { | |
| string admissionNumber; | |
| uint enrollmentDate; | |
| string degreeCode; | |
| uint unitsTaken; | |
| bool feesPaid; | |
| bool isCleared; | |
| bool completedUnits; | |
| bytes32 issuedDocument; | |
| } | |
| address Publisher; | |
| mapping(uint256 => Certificate) public certificates; | |
| uint256 certificateId; | |
| function AcademicRegistry() public { | |
| Publisher = msg.sender; | |
| } | |
| event CertificateChanges(string _msg, uint256 certificateId); | |
| modifier isPublisher() { | |
| // Check if user has rights to publish on the chain | |
| if (Publisher != msg.sender) { | |
| revert(); | |
| } | |
| _; | |
| } | |
| function publishCertificate( | |
| string admissionNumber, | |
| uint enrollmentDate, | |
| string degreeCode, | |
| uint unitsTaken, | |
| bool feesPaid, | |
| bool isCleared, | |
| bool completedUnits, | |
| bytes32 issuedDocument | |
| ) isPublisher public returns(bool success) | |
| { | |
| // Check if candidate meets requirements | |
| require(feesPaid); | |
| require(isCleared); | |
| require(completedUnits); | |
| require(issuedDocument != ""); | |
| require(unitsTaken > 0); | |
| certificateId++; | |
| Certificate memory certificate; | |
| certificate.admissionNumber = admissionNumber; | |
| certificate.enrollmentDate = enrollmentDate; | |
| certificate.degreeCode = degreeCode; | |
| certificate.unitsTaken = unitsTaken; | |
| certificate.feesPaid = feesPaid; | |
| certificate.isCleared = isCleared; | |
| certificate.completedUnits = completedUnits; | |
| certificate.issuedDocument = issuedDocument; | |
| certificates[certificateId] = certificate; | |
| // Log changes | |
| CertificateChanges("Published", certificateId); | |
| return true; | |
| } | |
| function getCertificate(uint256 queriedCertId) public constant returns (uint256 resultCertId, string admissionNumber) { | |
| var certificate = certificates[queriedCertId]; | |
| return (queriedCertId, certificate.admissionNumber); | |
| } | |
| } |
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) { | |
| chairperson = msg.sender; | |
| voters[chairperson].weight = 1; | |
| proposals.length = _numProposals; | |
| } | |
| /// Give $(voter) the right to vote on this ballot. | |
| /// May only be called by $(chairperson). | |
| function giveRightToVote(address voter) { | |
| if (msg.sender != chairperson || voters[voter].voted) return; | |
| voters[voter].weight = 1; | |
| } | |
| /// Delegate your vote to the voter $(to). | |
| function delegate(address to) { | |
| Voter 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 delegate = voters[to]; | |
| if (delegate.voted) | |
| proposals[delegate.vote].voteCount += sender.weight; | |
| else | |
| delegate.weight += sender.weight; | |
| } | |
| /// Give a single vote to proposal $(proposal). | |
| function vote(uint8 proposal) { | |
| Voter sender = voters[msg.sender]; | |
| if (sender.voted || proposal >= proposals.length) return; | |
| sender.voted = true; | |
| sender.vote = proposal; | |
| proposals[proposal].voteCount += sender.weight; | |
| } | |
| function winningProposal() constant returns (uint8 winningProposal) { | |
| uint256 winningVoteCount = 0; | |
| for (uint8 proposal = 0; proposal < proposals.length; proposal++) | |
| if (proposals[proposal].voteCount > winningVoteCount) { | |
| winningVoteCount = proposals[proposal].voteCount; | |
| winningProposal = proposal; | |
| } | |
| } | |
| } |
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.16; | |
| contract Administrator { | |
| address admin; | |
| function Administrator() public { | |
| admin = msg.sender; | |
| } | |
| modifier isAdmin() { | |
| if (admin != msg.sender) { | |
| revert(); | |
| } | |
| _; | |
| } | |
| function getAdmin() private constant returns(address) { | |
| return admin; | |
| } | |
| } | |
| contract CoursesRegister is Administrator { | |
| struct Course { | |
| string name; | |
| string code; | |
| } | |
| mapping(string => Course) courses; | |
| function registerNewCourse(string _courseName, string _courseCode) isAdmin public returns(Course) { | |
| Course memory course; | |
| course.name = _courseName; | |
| course.code = _courseCode; | |
| // Add course to list of courses using its code to make it unique | |
| courses[_courseCode] = course; | |
| return course; | |
| } | |
| } | |
| contract Registration is CoursesRegister{ | |
| // Register student and assign them admission numbers | |
| struct Candidate { | |
| string admissionNumber; | |
| uint32 enrollmentDate; | |
| Course course; | |
| } | |
| mapping(string => Candidate) candidates; | |
| function registerNewCandidate(string _admissionNumber, uint32 _enrollmentDate) isAdmin public returns (Candidate) { | |
| // Register student to a course and maintain a list of all candidates | |
| Candidate memory candidate; | |
| candidate.admissionNumber = _admissionNumber; | |
| candidate.enrollmentDate = _enrollmentDate; | |
| // Add candidate to list of other candidates | |
| // Use admissionNumber as key to avoid duplicates | |
| candidates[_admissionNumber] = candidate; | |
| return candidate; | |
| } | |
| function addCandidateToCourse(string _admissionNumber, string _courseCode) isAdmin public returns(bool) { | |
| // Find course based on the provided _courseCode | |
| Course memory course = courses[_courseCode]; | |
| // Find candidate based on the provided _admissionNumber | |
| Candidate memory candidate = candidates[_admissionNumber]; | |
| // Finaly update the candidate course details | |
| candidate.course = course; | |
| return true; | |
| } | |
| } | |
| contract DegreeRegistry is Registration{ | |
| function DegreeRegistry() public{ | |
| } | |
| } |
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.16; | |
| contract Owner{ | |
| address sender; | |
| function Owner() public { | |
| sender = msg.sender; | |
| } | |
| modifier ifOwner() { | |
| if(sender != msg.sender){ | |
| revert(); | |
| } | |
| _; | |
| } | |
| function sayHi() public constant returns(string greetings) { | |
| return 'Hi there fam'; | |
| } | |
| } | |
| contract DeliveryContract is Owner{ | |
| string greeting; | |
| function DeliveryContract() public { | |
| } | |
| modifier checkGreeting(){ | |
| _; | |
| } | |
| function getSender() public constant ifOwner returns(address _sender) { | |
| return sender; | |
| } | |
| } |
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.15; | |
| contract HelloWorldContract { | |
| string public word = "Hello world"; | |
| address issuer; | |
| event updateStatus(string _msg, string newWord); | |
| function HelloWorldContract() public{ | |
| issuer = msg.sender; | |
| } | |
| modifier isIssuer(){ | |
| if (issuer != msg.sender) { | |
| revert(); | |
| } | |
| _; | |
| } | |
| function getWord() public constant returns (string) { | |
| return word; | |
| } | |
| function setWord(string newWord) isIssuer public returns (string) { | |
| word = newWord; | |
| updateStatus('Word value changed', newWord); | |
| return word; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment