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=
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; | |
contract Ulysses { | |
struct Contract { | |
string description; | |
uint stakedAmount; | |
uint weightDif; | |
string massUnit; | |
address contractOwner; | |
uint secretWordIndex; | |
uint start; | |
uint duration; | |
bool voted; | |
bool complete; | |
} | |
address public adminAddres = 0xe66273cC443F774653E885496f76b486F956B47F; | |
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 == adminAddres); | |
_; | |
} | |
modifier referee { | |
require(msg.sender==adminAddres || referees[msg.sender]); | |
_; | |
} | |
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 referee{ | |
require(contracts[index].complete == false ); | |
contracts[index].complete = true; | |
if ( judgment == true ) { | |
contracts[index].voted = true; | |
adminAddres.transfer(fee); | |
contracts[index].contractOwner.transfer(contracts[index].stakedAmount-fee); | |
} else { | |
adminAddres.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 setMinStake(uint price) public admin{ | |
minStake = price; | |
} | |
function setMaxStake(uint price) public admin{ | |
maxStake = price; | |
} | |
function setFee(uint price) public admin{ | |
require(price <= 0.03 ether); | |
fee = price; | |
} | |
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; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment