-
Notifications
You must be signed in to change notification settings - Fork 1
/
MyDonation.sol
135 lines (97 loc) · 3.14 KB
/
MyDonation.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
pragma solidity ^0.4.24;
// The contract for the locaToken instance
contract locaToken {
function transferFrom(address _from, address _to, uint _value) public returns (bool);
function allowance(address _owner, address _spender) public view returns (uint);
}
// Safemath library
library SafeMath {
function sub(uint _base, uint _value)
internal
pure
returns (uint) {
assert(_value <= _base);
return _base - _value;
}
function add(uint _base, uint _value)
internal
pure
returns (uint _ret) {
_ret = _base + _value;
assert(_ret >= _base);
}
function div(uint _base, uint _value)
internal
pure
returns (uint) {
assert(_value > 0 && (_base % _value) == 0);
return _base / _value;
}
function mul(uint _base, uint _value)
internal
pure
returns (uint _ret) {
_ret = _base * _value;
assert(0 == _base || _ret / _base == _value);
}
}
// The donation contract
contract Donation {
using SafeMath for uint;
// instance the locatoken
locaToken private token = locaToken(0xcDf9bAff52117711B33210AdE38f1180CFC003ed);
address private owner;
uint private _tokenGift;
// every donation is logged in the Blockchain
event Donated(address indexed buyer, uint tokens);
// Available tokens for donation
uint private _tokenDonation;
// constructor to set the contract owner
constructor() public {
owner = msg.sender;
}
modifier onlyOwner() {
require(msg.sender == owner);
_;
}
// Allow the donation to start
modifier allowStart() {
require(_tokenDonation == 0);
_;
}
// There have at least to be 25000000000 Loca tokens in balance to allow a valid donation
modifier allowDonation(){
require(_tokenDonation >= 25000000000);
_;
}
// Donation amount has to be between 0.02 and 0.03 ETH
// regardless the donation amount, 250 LOCAs will be send
modifier validDonation {
require (msg.value >= 20000000000000000 && msg.value <= 30000000000000000);
_;
}
function startDonation() public onlyOwner allowStart returns (uint) {
_tokenDonation = token.allowance(owner, address(this));
}
function DonateEther() public allowDonation validDonation payable {
// _tokensold = msg.value.mul(_convrate).div(Devider);
_tokenGift = 25000000000;
_tokenDonation = _tokenDonation.sub(_tokenGift);
emit Donated(msg.sender, _tokenGift);
token.transferFrom(owner, msg.sender, _tokenGift);
}
// Falsely send Ether will be reverted
function () public payable {
revert();
}
function TokenBalance () public view returns(uint){
return _tokenDonation;
}
// Withdraw Ether from the contract
function getDonation(address _to) public onlyOwner {
_to.transfer(address(this).balance);
}
function CloseDonation() public onlyOwner {
selfdestruct(owner);
}
}