Skip to content

Instantly share code, notes, and snippets.

@bornatalebi
Created June 20, 2020 12:05
Show Gist options
  • Save bornatalebi/234e444940977fb35bb42cbab800e5aa to your computer and use it in GitHub Desktop.
Save bornatalebi/234e444940977fb35bb42cbab800e5aa 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.6.6+commit.6c089d02.js&optimize=false&gist=
pragma solidity >=0.4.22 <0.7.0;
contract a {
address public accAddr = address(this);
uint8 public res;
enum userType {yek, doo}
userType public num;
function dd(userType _usrType) public{
num = _usrType;
}
}
pragma solidity >=0.4.22 <0.7.0;
import "./a.sol";
import "./User.sol";
contract b {
//enum t {aval, dovom}
//t public aa = t.aval;
address v;
function sa(address _addd) public{
v = _addd;
}
function gg(address payable _receiver, string memory _descriptions, address payable _projectId) public{
User U = User(_receiver);
U.AddjudgeRequest(_receiver, _descriptions, _projectId);
//a tw = a(v);
//tw.dd(t.dovom);
}
}
pragma solidity >=0.4.22 <0.7.0;
import "./User.sol";
contract judgement{
address public owner;
address public accAddr = address(this);// use for payment
constructor (address payable _projectID, address payable _accuser, string memory _description, uint256 _cost) public{
owner = msg.sender;
//MyComplaint.compID = address(this);
MyComplaint.ProjectID = _projectID;
MyComplaint.Accuser = _accuser;
MyComplaint.Description = _description;
MyComplaint.costInPercent = _cost;
MyComplaint.createTime = now;
MyComplaint.CompStat = Statuses.waitingForPayment;
}
//enums
enum Statuses {closed, running, finished, waitingForPayment}
// structs
struct complaint{
address payable ProjectID;
address payable Accuser;
string Description;
uint256 costInPercent;
uint256 createTime;
Statuses CompStat;
}
//
complaint public MyComplaint;
// judge mapping
address[] public judges;
// modifier
modifier onlyOwner {
require(owner == msg.sender,"not owner");
_;
}
//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);
// check if we reach miniumm and maximum number of judges
}
}
//TO DO
// select judge and add to list
// function judge selection
// function recieve response from users
}
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;
}
}
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 ++ ;
}
// TODO finish 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);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment