forked from mojtaba-eshghie/Dynamit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
7.sol
75 lines (68 loc) · 1.73 KB
/
7.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
pragma solidity ^0.4.4;
// I will need 12 ethers to work!
contract Token {
function transfer(address _to, uint _value) returns (bool);
function balanceOf(address owner) returns(uint);
}
contract Owned {
address public owner;
function Owned() {
owner = msg.sender;
}
modifier onlyOwner() {
if (msg.sender != owner) throw;
_;
}
address newOwner;
function changeOwner(address _newOwner) onlyOwner {
newOwner = _newOwner;
}
function acceptOwnership() {
if (msg.sender == newOwner) {
owner = newOwner;
}
}
}
contract TokenReceivable is Owned {
event logTokenTransfer(address token, address to, uint amount);
function claimTokens(address _token, address _to) onlyOwner returns (bool) {
Token token = Token(_token);
uint balance = token.balanceOf(this);
if (token.transfer(_to, balance)) {
logTokenTransfer(_token, _to, balance);
return true;
}
return false;
}
}
contract FunFairSale is Owned, TokenReceivable {
uint public deadline = 1499436000;
uint public startTime = 1498140000;
uint public capAmount = 125000000 ether;
uint constant MAX_GAS_PRICE = 50 * 1024 * 1024 * 1024 wei;
constructor() public payable{
}
function shortenDeadline(uint t) onlyOwner {
if (t > deadline) throw;
deadline = t;
}
function () payable {
if (tx.gasprice > MAX_GAS_PRICE) throw;
if (block.timestamp < startTime || block.timestamp >= deadline) throw;
if (this.balance >= capAmount) throw;
if (this.balance + msg.value >= capAmount) {
deadline = block.timestamp;
}
}
function withdraw(address addr_, uint256 amount) public {
if (!addr_.call.value(amount)()) throw;
}
function setCap(uint _cap) onlyOwner {
capAmount = _cap;
}
function setStartTime(uint _startTime, uint _deadline) onlyOwner {
if (block.timestamp >= startTime) throw;
startTime = _startTime;
deadline = _deadline;
}
}