Skip to content

Instantly share code, notes, and snippets.

@zhangsoledad
Created June 29, 2018 06:08
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 zhangsoledad/0107ad3cf4c992d171fe7c608d57dd94 to your computer and use it in GitHub Desktop.
Save zhangsoledad/0107ad3cf4c992d171fe7c608d57dd94 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=undefined&optimize=false&gist=
pragma solidity ^0.4.0;
import "./Ownable.sol";
import "./SafeMath.sol";
import "./State.sol";
contract HackathonFactory is Ownable {
address public owner;
event HackathonCreated(
address indexed _owner,
address indexed _contract
);
function HackathonFactory() public {
}
function CreateHackathon(
bool _hasUpperLimit,
uint256 _crowdFoundUpperLimit,
uint256 _crowdFoundLowerLimit,
uint256 _crowdFoundPeriod,
uint256 _signUpPeriod,
uint256 _matchPeriod,
uint256 _votePeriod,
uint256 _deposit,
uint256 _signUpFee,
uint256 _champBonus,
uint256 _secondBonus,
uint256 _thirdBonus,
uint256 _voteBonus
) public payable {
Hackathon hackathon = new Hackathon(
_hasUpperLimit,
_crowdFoundUpperLimit,
_crowdFoundLowerLimit,
_crowdFoundPeriod,
_signUpPeriod,
_matchPeriod,
_votePeriod,
_deposit,
_signUpFee,
_champBonus,
_secondBonus,
_thirdBonus,
_voteBonus
);
HackathonCreated(msg.sender, address(hackathon));
}
}
contract Hackathon is Ownable, HackathonState {
using SafeMath for uint256;
uint256 public initFound;
uint256 public totalCrowdFound;
uint256 public totalFound;
mapping(address => uint256) internal crowdFound;
bool public hasUpperLimit;
uint256 public crowdFoundUpperLimit;
uint256 public crowdFoundLowerLimit;
uint256 public crowdFoundPeriod;
uint256 public signUpPeriod;
uint256 public matchPeriod;
uint256 public votePeriod;
uint256 public closingCrowdFound;
uint256 public closingSignUp;
uint256 public closingMatch;
uint256 public closingVote;
uint256 public deposit;
uint256 public signUpFee;
uint256 public champBonus;
uint256 public secondBonus;
uint256 public thirdBonus;
uint256 public voteBonus;
mapping(address => bytes32) public teams;
function Hackathon(
bool _hasUpperLimit,
uint256 _crowdFoundUpperLimit,
uint256 _crowdFoundLowerLimit,
uint256 _crowdFoundPeriod,
uint256 _signUpPeriod,
uint256 _matchPeriod,
uint256 _votePeriod,
uint256 _deposit,
uint256 _signUpFee,
uint256 _champBonus,
uint256 _secondBonus,
uint256 _thirdBonus,
uint256 _voteBonus
) public payable {
if (_hasUpperLimit) {
require(_crowdFoundLowerLimit <= _crowdFoundUpperLimit);
}
require(_crowdFoundPeriod > 0);
require(_signUpPeriod > 0);
require(_matchPeriod > 0);
require(_votePeriod > 0);
require(_champBonus <= 100);
require(_secondBonus <= 100);
require(_thirdBonus <= 100);
require(_voteBonus <= 100);
require(_champBonus.add(_secondBonus).add(_thirdBonus).add(_voteBonus) == 100);
initFound = msg.value;
totalFound = msg.value;
hasUpperLimit = _hasUpperLimit;
crowdFoundUpperLimit = _crowdFoundUpperLimit;
crowdFoundLowerLimit = _crowdFoundLowerLimit;
crowdFoundPeriod = _crowdFoundPeriod;
signUpPeriod = _signUpPeriod;
matchPeriod = _matchPeriod;
votePeriod = _votePeriod;
deposit = _deposit;
signUpFee = _signUpFee;
champBonus = _champBonus;
secondBonus = _secondBonus;
thirdBonus = _thirdBonus;
voteBonus = _voteBonus;
}
function startCrowdFound() public requireState(State.Created) {
state = State.CrowFound;
closingCrowdFound = block.timestamp.add(crowdFoundPeriod);
}
function buy(address _beneficiary) public payable {
}
function goalReached() public view returns (bool) {
return totalCrowdFound >= crowdFoundLowerLimit;
}
function startSignUp() public requireState(State.CrowFound) {
require(block.timestamp > closingCrowdFound);
require(totalCrowdFound >= crowdFoundLowerLimit);
state = State.SignUp;
closingSignUp = block.timestamp.add(signUpPeriod);
}
}
pragma solidity ^0.4.0;
/**
* @title Ownable
* @dev The Ownable contract has an owner address, and provides basic authorization control
* functions, this simplifies the implementation of "user permissions".
*/
contract Ownable {
address public owner;
event OwnershipRenounced(address indexed previousOwner);
event OwnershipTransferred(
address indexed previousOwner,
address indexed newOwner
);
/**
* @dev The Ownable constructor sets the original `owner` of the contract to the sender
* account.
*/
function Ownable() public {
owner = msg.sender;
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
require(msg.sender == owner);
_;
}
/**
* @dev Allows the current owner to relinquish control of the contract.
* @notice Renouncing to ownership will leave the contract without an owner.
* It will not be possible to call the functions with the `onlyOwner`
* modifier anymore.
*/
function renounceOwnership() public onlyOwner {
OwnershipRenounced(owner);
owner = address(0);
}
/**
* @dev Allows the current owner to transfer control of the contract to a newOwner.
* @param _newOwner The address to transfer ownership to.
*/
function transferOwnership(address _newOwner) public onlyOwner {
_transferOwnership(_newOwner);
}
/**
* @dev Transfers control of the contract to a newOwner.
* @param _newOwner The address to transfer ownership to.
*/
function _transferOwnership(address _newOwner) internal {
require(_newOwner != address(0));
OwnershipTransferred(owner, _newOwner);
owner = _newOwner;
}
}
pragma solidity ^0.4.0;
/**
* @title SafeMath
* @dev Math operations with safety checks that throw on error
*/
library SafeMath {
/**
* @dev Multiplies two numbers, throws on overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256 c) {
// Gas optimization: this is cheaper than asserting 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-solidity/pull/522
if (a == 0) {
return 0;
}
c = a * b;
assert(c / a == b);
return c;
}
/**
* @dev Integer division of two numbers, truncating the quotient.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
// assert(b > 0); // Solidity automatically throws when dividing by 0
// uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return a / b;
}
/**
* @dev Subtracts two numbers, throws on overflow (i.e. if subtrahend is greater than minuend).
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
assert(b <= a);
return a - b;
}
/**
* @dev Adds two numbers, throws on overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256 c) {
c = a + b;
assert(c >= a);
return c;
}
}
pragma solidity ^0.4.0;
contract HackathonState {
enum State { Created, CrowFound, SignUp, Match, Vote, Final } // Enum
State state;
// Modifiers can receive arguments:
modifier requireState(State _state) {
require(state == _state);
_;
}
function HackathonState() public {
state = State.Created;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment