Created
June 22, 2020 19:15
-
-
Save bornatalebi/b461451a7d796a52e4f777b3f1f4086e 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&gist=
This file contains 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.22 <0.7.0; | |
import "./User.sol"; | |
contract judgement{ | |
address public owner; | |
address public accAddr = address(this);// use for payment | |
uint public accuserVotes; | |
uint public accuseeVotes; | |
address payable public winner; | |
address payable public loser; | |
uint private sum; | |
constructor (address payable _projectID, address payable _accuser, address payable _accusee, string memory _description, uint256 _cost, string memory _accuserDefence, string memory _accuseeDefence ) public{ | |
owner = msg.sender; | |
//MyComplaint.compID = address(this); | |
MyComplaint.ProjectID = _projectID; | |
MyComplaint.Accuser = _accuser; | |
MyComplaint.Accusee = _accusee; | |
MyComplaint.Description = _description; | |
MyComplaint.costInPercent = _cost; | |
MyComplaint.createTime = now; | |
MyComplaint.CompStat = Statuses.waitingForPayment; | |
MyComplaint.accuserDefence = _accuserDefence; | |
MyComplaint.accuseeDefence = _accuseeDefence; | |
accuserVotes = 0; | |
accuseeVotes = 0; | |
} | |
//enums | |
enum Statuses {closed, running, finished, waitingForPayment} | |
// structs | |
struct complaint{ | |
address payable ProjectID; | |
address payable Accuser; | |
address payable Accusee; | |
string Description; | |
string accuserDefence; | |
string accuseeDefence; | |
uint256 costInPercent; | |
uint256 createTime; | |
Statuses CompStat; | |
} | |
struct vote{ | |
address winnerID; | |
address voteID;// use judgeID as voteId | |
} | |
// | |
complaint public MyComplaint; | |
// judge list | |
address[] public judges; | |
// modifier | |
modifier onlyOwner { | |
require(owner == msg.sender,"not owner"); | |
_; | |
} | |
//checks if all judges voted | |
modifier allvoted { | |
require(sum == judges.length,"not all judges voted"); | |
_; | |
} | |
//mapings | |
mapping(address => vote) public votes; | |
//voting functions | |
function addVote(address _winnerAddress)public{ | |
for(uint i=0 ; i< judges.length ; i++){ | |
if(judges[i] == msg.sender ){ | |
votes[msg.sender] = vote(_winnerAddress, msg.sender); | |
if (_winnerAddress == MyComplaint.Accuser){ | |
accuserVotes += 1; | |
sum +=1; | |
} | |
if (_winnerAddress == MyComplaint.Accusee){ | |
accuseeVotes += 1; | |
sum +=1; | |
} | |
} | |
} | |
} | |
// | |
function calculateWinner()public onlyOwner allvoted { | |
if (accuserVotes > accuseeVotes){ | |
winner = MyComplaint.Accuser; | |
loser = MyComplaint.Accusee; | |
} | |
if (accuseeVotes > accuserVotes){ | |
winner = MyComplaint.Accusee; | |
loser = MyComplaint.Accuser; | |
} | |
MyComplaint.CompStat = Statuses.finished; | |
} | |
function sendLoserWarning(string memory _description) public{ | |
User U = User(loser); | |
U.AddWarnings(MyComplaint.ProjectID,_description); | |
} | |
//function recieve payment to start judge selection | |
mapping (address => uint256) public balance; | |
// | |
function Receives() external payable { | |
require(msg.value >= 1 ether * MyComplaint.costInPercent / 100 );//check if the amount sent is enough | |
MyComplaint.CompStat = Statuses.running; | |
balance[accAddr] += msg.value; | |
} | |
// function send request to Users | |
function SendRequest(address payable _receiver, string memory _descriptions, address payable _projectId) public{ | |
User U = User(_receiver); | |
U.AddjudgeRequest(_receiver, _descriptions, _projectId); | |
} | |
function RecieveRespons (bool _answer, address _judgeID) public{ | |
// id, his addr , his answer in boll | |
if(_answer == true){ | |
judges.push(_judgeID); | |
} | |
} | |
} |
This file contains 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.22 <0.7.0; | |
contract project{ | |
// constructor | |
address public owner; | |
address public accAddr = address(this);// use for payment | |
//constructor | |
constructor(address payable _freelancer, address payable _employer, string memory _title, uint256 _costInPercent) public{ | |
owner = msg.sender; | |
MyProject.ProjectId = address(this); | |
MyProject.FreelancerId = _freelancer; | |
MyProject.EmployerId = _employer; | |
MyProject.ProjStat = Statuses.waitingForPayment; | |
MyProject.CreateTime = now; | |
MyProject.title = _title; | |
MyProject.costInPercent = _costInPercent; | |
} | |
// End of constructor | |
// enum | |
enum Statuses {closed, running, finished, waitingForPayment} | |
// proj struct | |
struct projectStruct{ | |
string title; | |
address payable ProjectId; | |
address payable FreelancerId; | |
address payable EmployerId; | |
uint256 CreateTime; | |
Statuses ProjStat; | |
uint256 costInPercent; | |
} | |
//// | |
projectStruct public MyProject; | |
//// | |
// modifier | |
modifier onlyOwner { | |
require(owner == msg.sender,"not owner"); | |
_; | |
} | |
// functions | |
//close project function | |
function CloseProject() external onlyOwner{ | |
MyProject.ProjStat = Statuses.closed; | |
} | |
// | |
function FinishProject() external payable onlyOwner{ | |
MyProject.ProjStat = Statuses.finished; | |
} | |
// recive payment and change status | |
mapping (address => uint256) public balance; | |
receive() external payable { | |
require(msg.value >= 1 ether * MyProject.costInPercent / 100 );//check if the amount sent is enough | |
MyProject.ProjStat = Statuses.running; //start the project | |
balance[accAddr] += msg.value; | |
} | |
} |
This file contains 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.22 <0.7.0; | |
import "./judgement.sol"; | |
contract User { | |
address public owner; | |
address public accAddr = address(this);// used for payments | |
//constructor | |
constructor (string memory _name, string memory _lastname, string memory _email, | |
string memory _password, uint256 _Melicode, userTypes _userType) public{ | |
owner = msg.sender; | |
SetUser(_name, _lastname, _email, _password, _Melicode, _userType); | |
} | |
modifier onlyOwner { | |
require(owner == msg.sender,"not owner"); | |
_; | |
} | |
// enums | |
enum userTypes {Freelancer, Employer, Judge} | |
// mappings | |
mapping(address => string) public UserProjects; | |
mapping(uint256 => UserWarnings) public warning; | |
mapping(address => JudgeRequest) public Req; | |
// structs | |
struct UserWarnings{ | |
string descriptions; | |
address projectID; | |
uint256 date; | |
} | |
struct JudgeRequest{ | |
address receiver; | |
string descriptions; | |
address payable projectId; | |
} | |
struct user{ | |
address id; | |
string Firstname; | |
string lastname; | |
string pass; | |
string email; | |
uint256 Melicode; | |
uint256 warningsCount; | |
bool banUser; | |
userTypes Utype; | |
uint256 CreateTime; | |
} | |
// our user | |
user private thisUser; | |
// | |
function SetUser (string memory _name, string memory _lastname, string memory _email, | |
string memory _password, uint256 _Melicode, userTypes _userType) internal{ | |
thisUser.id = address(this); | |
thisUser.Firstname = _name; | |
thisUser.lastname = _lastname; | |
thisUser.pass = _password; | |
thisUser.email = _email; | |
thisUser.Melicode = _Melicode; | |
thisUser.CreateTime = now; | |
thisUser.Utype = _userType; | |
thisUser.warningsCount = 0; | |
thisUser.banUser = false; | |
} | |
//function add project | |
function Addproject(string memory _title, address _Pid) public onlyOwner { | |
UserProjects[_Pid] = _title; | |
} | |
//function Addwarnings() | |
function AddWarnings(address _projectAddr, string memory _description) public onlyOwner{ | |
uint256 Warid = thisUser.warningsCount; | |
uint256 time = now; | |
warning[Warid] = UserWarnings (_description, _projectAddr, time); | |
thisUser.warningsCount ++ ; | |
if (thisUser.warningsCount == 3){ | |
thisUser.banUser = true; | |
} | |
} | |
// get function ) | |
function getuser () public view onlyOwner returns(address, string memory, string memory, string memory, | |
string memory, uint256, uint256, bool, userTypes, uint256){ | |
return (thisUser.id, thisUser.Firstname, thisUser.lastname, thisUser.pass, thisUser.email, thisUser.Melicode, thisUser.warningsCount, thisUser.banUser, thisUser.Utype, thisUser.CreateTime); | |
} | |
//function to send and receive ether | |
mapping (address => uint256) public balance; | |
//function Receives() | |
receive() external payable { | |
balance[accAddr] += msg.value; | |
} | |
function sendETH (address payable _receiveer,uint256 _amountInPercenr) public payable onlyOwner{ | |
_receiveer.transfer(1 ether * _amountInPercenr / 100); | |
} | |
// judgeRequests functions | |
function AddjudgeRequest (address _receiver, string memory _descriptions, address payable _projectId) public { | |
require(thisUser.Utype == userTypes.Judge, "user is not a judge"); | |
Req[_projectId] = JudgeRequest (_receiver, _descriptions, _projectId);// add requsts to lists | |
} | |
function ResponseJudgeRequest(address payable _receiver, bool _answer) public{ | |
judgement J = judgement(_receiver); | |
J.RecieveRespons(_answer, accAddr); | |
} | |
function ADDvote(address payable _receiver, address _winnerAddress)public onlyOwner{ | |
judgement J = judgement(_receiver); | |
J.addVote(_winnerAddress); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment