Skip to content

Instantly share code, notes, and snippets.

@Bashta
Last active February 6, 2022 17:36
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 Bashta/35f9d778ca2822fb130c2041866a546c to your computer and use it in GitHub Desktop.
Save Bashta/35f9d778ca2822fb130c2041866a546c 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=builtin&optimize=false&runs=200&gist=
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.7;
// MARK : ------------------------------------------------------------
// Defines the Main Contract Interface
contract Assignment {
// Actors partecipating in the contract. Entities in the real world
address public reviewer1;
address public reviewer2;
address public reviewer3;
address public studentBeingReviwed;
address public additionalExaminer1;
address public additionalExaminer2;
address public paperArbiter;
ContractStatus public status;
// Contract properties
// Property that will be used as the final grade for the contract
uint public assigmentGrade;
// 1st round
uint public reviewer1Mark;
uint public reviewer2Mark;
uint public reviewer3Mark;
// 2nd round
uint public additionalExaminer1Mark;
uint public additionalExaminer2Mark;
// 3rd round?
// Contract entry point.
// We dont acare about initializing any properties at this point as they will have custom setters by repsective actors.
// Actors can also be injected at contract creation if they are predefined
constructor () {
//.....Initilaize first 3 marks here
// reviewer1Mark = _reviewer1Mark
// reviewer2Mark = _reviewer3Mark
// reviewer3Mark = _reviewer4Mark
//.....
// Ste initial status when contract first created to open
status = ContractStatus.Open;
// Try to imediatly resolve the contract if possible
resolveContract();
}
// Private functions
// Check if first requirement is passed! "marks are with 10 pints of each other"
function areAdditionalActorsNeeded() private returns (bool) {
// Insert logic here then return
// return true;
}
// Calculate average mark if three first requirement is passed
function calculateGradeForThreeReviewers() private returns (uint) {
// Insert logic here then return
return 85;
}
function higestMark() private returns (uint) {
// Cycle through the marks and find the highest
uint tempValue;
return tempValue;
}
function lowestMark() private returns (uint) {
// Cycle through the marks and find the lowest
uint tempValue;
return tempValue;
}
function resolveContract() private {
status = ContractStatus.Reviewing;
if (areAdditionalActorsNeeded() == false) {
assigmentGrade = calculateGradeForThreeReviewers();
status = ContractStatus.Accepted;
} else {
assigmentGrade = calculateMarkForSecoondRound();
}
}
// Calculates mark after additianl review
function calculateMarkForSecoondRound() private returns (uint) {
// Insert logic here and calculate last price based on buisness rules
// Return the price
}
// Public functions
// Called after additional reviewers have marked the assignemtn
function updateWithAdditionalReviewersMarks(uint _mark1, uint _mark2) public {
// Request other reviewers to take actions and send their review.
additionalExaminer1Mark = _mark1;
additionalExaminer2Mark = _mark2;
// Try to resolve contract after getting new values
resolveContract();
}
}
// MARK : ------------------------------------------------------------
// State machine to show the status of the Asigment review status
enum ContractStatus {
Open, // Contract is opened
Reviewing, // At least one actor has inititated the review process.
additionalReviewReuired, // More actors need to be involved for the reolution of this contract
Accepted, // Contract has been accepted
Rejected, // Contract Rejected
Canceled // Cancelled
}
// MARK : ------------------------------------------------------------
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment