Skip to content

Instantly share code, notes, and snippets.

@zhangsoledad
Created June 29, 2018 04:00
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/95c0da85d20190232404dd98582a3c8e to your computer and use it in GitHub Desktop.
Save zhangsoledad/95c0da85d20190232404dd98582a3c8e 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.24+commit.e67f0147.js&optimize=false&gist=
pragma solidity ^0.4.0;
import "./Ownable.sol";
import "./SafeMath.sol";
contract HackathonFactory is Ownable {
address public owner;
event HackathonCreated(
address indexed _owner,
address indexed _contract
);
function HackathonFactory() public {
}
function CreateHackathon(
bool _hasUpperLimit,
uint256 _crowdUpperLimit,
uint256 _crowdLowerLimit,
uint256 _closingCrowd,
uint256 _closingSignUp,
uint256 _closingMatch,
uint256 _closingVote,
uint256 _deposit,
uint256 _signUpFee,
uint256 _champBonus,
uint256 _secondBonus,
uint256 _thirdBonus,
uint256 _voteBonus
) public payable {
Hackathon hackathon = new Hackathon(
_hasUpperLimit,
_crowdUpperLimit,
_crowdLowerLimit,
_closingCrowd,
_closingSignUp,
_closingMatch,
_closingVote,
_deposit,
_signUpFee,
_champBonus,
_secondBonus,
_thirdBonus,
_voteBonus
);
HackathonCreated(msg.sender, address(hackathon));
}
}
contract HackathonState {
enum State { Created, Offering, SignUp, Matching, Voting, End } // Enum
State state;
// Modifiers can receive arguments:
modifier requireState(State _state) {
require(state == _state);
_;
}
}
contract Hackathon is Ownable, HackathonState {
using SafeMath for uint256;
uint256 public initFound;
uint256 public totalFound;
bool public hasUpperLimit;
uint256 public crowdUpperLimit;
uint256 public crowdLowerLimit;
uint256 public closingCrowd;
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;
mapping(address => uint256) public crowds;
function Hackathon(
bool _hasUpperLimit,
uint256 _crowdUpperLimit,
uint256 _crowdLowerLimit,
uint256 _closingCrowd,
uint256 _closingSignUp,
uint256 _closingMatch,
uint256 _closingVote,
uint256 _deposit,
uint256 _signUpFee,
uint256 _champBonus,
uint256 _secondBonus,
uint256 _thirdBonus,
uint256 _voteBonus
) public payable {
require(_crowdLowerLimit >= msg.value);
if (_hasUpperLimit) {
require(_crowdLowerLimit <= _crowdUpperLimit);
}
require(_closingCrowd > block.timestamp);
require(_closingCrowd < _closingSignUp);
require(_closingSignUp < _closingMatch);
require(_closingMatch < _closingVote);
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;
crowdUpperLimit = _crowdUpperLimit;
crowdLowerLimit = _crowdLowerLimit;
closingCrowd = _closingCrowd;
closingSignUp = _closingSignUp;
closingMatch = _closingMatch;
closingVote = _closingVote;
deposit = _deposit;
signUpFee = _signUpFee;
champBonus = _champBonus;
secondBonus = _secondBonus;
thirdBonus = _thirdBonus;
voteBonus = _voteBonus;
}
}
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;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment