Last active
July 24, 2017 15:36
-
-
Save clar/97700cb9dc6419ab364659b47c9f2b48 to your computer and use it in GitHub Desktop.
Contribution.sol
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.11; | |
import "./SafeMath.sol"; | |
import "./Owned.sol"; | |
contract Contribution is SafeMath, Owned { | |
uint256 public constant MIN_FUND = (0.01 ether); | |
uint256 public constant CRAWDSALE_START_DAY = 1; | |
uint256 public constant CRAWDSALE_END_DAY = 7; | |
uint256 public dayCycle = 24 hours; | |
uint256 public fundingStartTime = 0; | |
address public ethFundDeposit = 0; | |
bool public isFinalize; | |
mapping (uint => uint) public dailyTotals; //每天收到的eth总量 | |
mapping (uint => mapping (address => uint)) public userBuys; // 每天每个用户用于购买ATM的eth总量 | |
uint256 public totalContributedETH = 0; | |
// events | |
event LogBuy (uint window, address user, uint amount); | |
event LogCreate (address tokenAddr, uint fundingStartTime, uint dayCycle); | |
event LogFinalize (uint finalizeTime); | |
function Contribution (address _ethFundDeposit, uint256 _fundingStartTime, uint256 _dayCycle) { | |
require( now < _fundingStartTime ); | |
require( _ethFundDeposit != address(0) ); | |
fundingStartTime = _fundingStartTime; | |
dayCycle = _dayCycle; | |
ethFundDeposit = _ethFundDeposit; | |
isFinalize = false; | |
LogCreate(ethFundDeposit, fundingStartTime, dayCycle); | |
} | |
//crawdsale entry | |
function () payable { | |
require(!isFinalize); | |
require( msg.value >= MIN_FUND ); //防止用户发起无转账金额的无效交易 | |
uint day = today(); | |
require( day >= CRAWDSALE_START_DAY && day <= CRAWDSALE_END_DAY ); | |
ethFundDeposit.transfer(msg.value); | |
//记录每个用户当天支付的ETH, 和当天所有收到的ETH | |
userBuys[day][msg.sender] += msg.value; | |
dailyTotals[day] += msg.value; | |
totalContributedETH += msg.value; | |
LogBuy(day, msg.sender, msg.value); | |
} | |
function kill() onlyOwner { | |
selfdestruct(owner); | |
} | |
function finalize() onlyOwner { | |
isFinalize = true; | |
LogFinalize(now); | |
} | |
function today() constant returns (uint) { | |
return sub(now, fundingStartTime) / dayCycle + 1; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment