-
Notifications
You must be signed in to change notification settings - Fork 98
/
Copy path0xd7aa94f17d60be06414973a45ffa77efd6443f0f-BTCQ-Bitcoin_Quick.sol
137 lines (107 loc) · 4.74 KB
/
0xd7aa94f17d60be06414973a45ffa77efd6443f0f-BTCQ-Bitcoin_Quick.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
pragma solidity ^0.4.16;
contract airDrop {
function verify(address _address, bytes32 _secret) public constant returns (bool _status);
}
contract BitcoinQuick {
string public constant symbol = "BTCQ";
string public constant name = "Bitcoin Quick";
uint public constant decimals = 8;
uint _totalSupply = 21000000 * 10 ** decimals;
uint public marketSupply;
uint public marketPrice;
address owner;
address airDropVerify;
uint public airDropAmount;
uint32 public airDropHeight;
mapping (address => bool) public airDropMembers;
mapping (address => uint) accounts;
mapping (address => mapping (address => uint)) allowed;
event Transfer(address indexed _from, address indexed _to, uint _value);
event Approval(address indexed _owner, address indexed _spender, uint _value);
function BitcoinQuick() public {
owner = msg.sender;
accounts[owner] = _totalSupply;
Transfer(address(0), owner, _totalSupply);
}
function totalSupply() public constant returns (uint __totalSupply) {
return _totalSupply;
}
function balanceOf(address _account) public constant returns (uint balance) {
return accounts[_account];
}
function allowance(address _account, address _spender) public constant returns (uint remaining) {
return allowed[_account][_spender];
}
function transfer(address _to, uint _amount) public returns (bool success) {
require(_amount > 0 && accounts[msg.sender] >= _amount);
accounts[msg.sender] -= _amount;
accounts[_to] += _amount;
Transfer(msg.sender, _to, _amount);
return true;
}
function transferFrom(address _from, address _to, uint _amount) public returns (bool success) {
require(_amount > 0 && accounts[_from] >= _amount && allowed[_from][msg.sender] >= _amount);
accounts[_from] -= _amount;
allowed[_from][msg.sender] -= _amount;
accounts[_to] += _amount;
Transfer(_from, _to, _amount);
return true;
}
function approve(address _spender, uint _amount) public returns (bool success) {
allowed[msg.sender][_spender] = _amount;
Approval(msg.sender, _spender, _amount);
return true;
}
function purchase() public payable returns (bool _status) {
require(msg.value > 0 && marketSupply > 0 && marketPrice > 0 && accounts[owner] > 0);
// Calculate available and required units
uint unitsAvailable = accounts[owner] < marketSupply ? accounts[owner] : marketSupply;
uint unitsRequired = msg.value / marketPrice;
uint unitsFinal = unitsAvailable < unitsRequired ? unitsAvailable : unitsRequired;
// Transfer funds
marketSupply -= unitsFinal;
accounts[owner] -= unitsFinal;
accounts[msg.sender] += unitsFinal;
Transfer(owner, msg.sender, unitsFinal);
// Calculate remaining ether amount
uint remainEther = msg.value - (unitsFinal * marketPrice);
// Return extra ETH to sender
if (remainEther > 0) {
msg.sender.transfer(remainEther);
}
return true;
}
function airDropJoin(bytes32 _secret) public payable returns (bool _status) {
// Checkout airdrop conditions and eligibility
require(!airDropMembers[msg.sender] && airDrop(airDropVerify).verify(msg.sender, _secret) && airDropHeight > 0 && airDropAmount > 0 && accounts[owner] >= airDropAmount);
// Transfer amount
accounts[owner] -= airDropAmount;
accounts[msg.sender] += airDropAmount;
airDropMembers[msg.sender] = true;
Transfer(owner, msg.sender, airDropAmount);
airDropHeight--;
// Return extra amount to sender
if (msg.value > 0) {
msg.sender.transfer(msg.value);
}
return true;
}
function airDropSetup(address _contract, uint32 _height, uint _units) public returns (bool _status) {
require(msg.sender == owner);
airDropVerify = _contract;
airDropHeight = _height;
airDropAmount = _units * 10 ** decimals;
return true;
}
function crowdsaleSetup(uint _supply, uint _perEther) public returns (bool _status) {
require(msg.sender == owner && accounts[owner] >= _supply * 10 ** decimals);
marketSupply = _supply * 10 ** decimals;
marketPrice = 1 ether / (_perEther * 10 ** decimals);
return true;
}
function withdrawFunds(uint _amount) public returns (bool _status) {
require(msg.sender == owner && _amount > 0 && this.balance >= _amount);
owner.transfer(_amount);
return true;
}
}