Skip to content

Instantly share code, notes, and snippets.

@gvandriel
Created October 15, 2019 15:25
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 gvandriel/31aa5c1181318269400e375cbe7afb67 to your computer and use it in GitHub Desktop.
Save gvandriel/31aa5c1181318269400e375cbe7afb67 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.4.22+commit.4cb486ee.js&optimize=false&gist=
pragma solidity ^0.4.22;
contract Ulysses {
struct Contract {
string description;
uint stakedAmount;
uint weightDif;
string massUnit;
address contractOwner;
uint secretWordIndex;
uint start;
uint duration;
bool voted;
bool complete;
}
bool public canCreate = true;
uint public fee = 0.005 ether;
uint public minStake = 0.060 ether;
uint public maxStake = 0.60 ether;
mapping(address => bool) public referees;
Contract[] public contracts;
address[] public refereeArray;
modifier admin {
require(msg.sender == 0x993235528CDE5f17770A614A43625A76c38F1729 || msg.sender == 0xd1275Df91bf079FE02bC9A1fAD5E7d1a1fB42F4f);
_;
}
modifier referee {
require(referees[msg.sender] || msg.sender == 0x993235528CDE5f17770A614A43625A76c38F1729 || msg.sender == 0xd1275Df91bf079FE02bC9A1fAD5E7d1a1fB42F4f);
_;
}
function createContract(string memory input, uint timeLength, uint weight, string memory unit) public payable {
require(msg.value >= minStake + fee && msg.value <= maxStake +fee);
require(timeLength >= 7 days && weight>0 && canCreate ==true);
Contract memory newContract = Contract({
description: input,
stakedAmount: msg.value,
contractOwner: msg.sender,
secretWordIndex: uint256(keccak256(block.timestamp, block.difficulty))%401,
weightDif: weight,
massUnit: unit,
start: now,
duration: timeLength,
voted: false,
complete: false
});
contracts.push(newContract);
}
function judgeContract(uint index, bool judgment) public admin{
require(contracts[index].complete == false );
contracts[index].complete = true;
if ( judgment == true ) {
contracts[index].voted = true;
0x993235528CDE5f17770A614A43625A76c38F1729.transfer(fee);
contracts[index].contractOwner.transfer(contracts[index].stakedAmount-fee);
} else {
0x993235528CDE5f17770A614A43625A76c38F1729.transfer(fee);
0x000000000000000000000000000000000000dEaD.transfer(contracts[index].stakedAmount-fee);
}
}
function refundContract(uint index) public admin{
require(contracts[index].complete == false );
contracts[index].complete = true;
contracts[index].voted = true;
contracts[index].contractOwner.transfer(contracts[index].stakedAmount);
}
function canCreateContract(bool input) public admin{
canCreate = input;
}
function addReferee(address refereeAddress) public admin {
referees[refereeAddress] = true;
refereeArray.push(refereeAddress);
}
function removeReferee(address refereeAddress) public admin {
referees[refereeAddress] = false;
}
function getContractsCount() public view returns (uint) {
return contracts.length;
}
function getRefereeCount() public view returns (uint) {
return refereeArray.length;
}
function getNow() public view returns(uint){
return now;
}
function setMinStake(uint price) public{
minStake = price;
}
function setMaxStake(uint price) public{
maxStake = price;
}
function setFee(uint price) public{
fee = price;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment