-
Notifications
You must be signed in to change notification settings - Fork 8
/
ico_dividends.sol
117 lines (98 loc) · 3.77 KB
/
ico_dividends.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
pragma solidity ^0.4.11;
contract MBToken {
address public owner;
function Owned() {
owner = msg.sender;
}
modifier onlyOwner {
if (msg.sender != owner) throw;
_;
}
string public name;
string public symbol;
uint8 public decimals;
uint256 public _tokenPrice;
bool public _allowManualTokensGeneration;
uint256 public shareholdersBalance;
uint public totalShareholders;
mapping (address => bool) registeredShareholders;
mapping (uint => address) shareholders;
/* This creates an array with all balances */
mapping (address => uint256) public balanceOf;
event Transfer(address indexed from, address indexed to, uint256 value);
function MBToken(string tokenName, string tokenSymbol, uint8 tokenDecimals, uint256 tokenStartBalance, uint tokenPrice, bool allowManualTokensGeneration) {
balanceOf[msg.sender] = tokenStartBalance;
name = tokenName;
symbol = tokenSymbol;
decimals = tokenDecimals;
_tokenPrice = tokenPrice;
_allowManualTokensGeneration = allowManualTokensGeneration;
owner = msg.sender;
totalShareholders = 0;
}
/* Send coins */
function transfer(address _to, uint256 _value) returns (bool) {
if (balanceOf[msg.sender] < _value) return false; // Check if the sender has enough
if (balanceOf[_to] + _value < balanceOf[_to]) return false; // Check for overflows
balanceOf[msg.sender] -= _value; // Subtract from the sender
balanceOf[_to] += _value; // Add the same to the recipient
/* Adding to shareholders count if tokens spent from owner to others */
if (msg.sender == owner && _to != owner) {
shareholdersBalance += _value;
}
/* Remove from shareholders count if tokens spent from holder to owner */
if (msg.sender != owner && _to == owner) {
shareholdersBalance -= _value;
}
if (owner == _to) {
// sender is owner
} else {
insertShareholder(_to);
}
/* Notify anyone listening that this transfer took place */
Transfer(msg.sender, _to, _value);
return true;
}
function addSomeTokens(uint256 numTokens) onlyOwner {
if (_allowManualTokensGeneration) {
balanceOf[msg.sender] += numTokens;
Transfer(0, msg.sender, numTokens);
} else {
throw;
}
}
/* Buy Token 1 token for 1 ether */
function mint() payable external {
if (msg.value == 0) throw;
if (msg.value < _tokenPrice) throw;
var numTokens = msg.value / _tokenPrice;
balanceOf[msg.sender] += numTokens;
Transfer(0, msg.sender, numTokens);
if (msg.sender != owner) {
shareholdersBalance += numTokens;
}
}
function payDividends() onlyOwner {
if (this.balance > 0 && totalShareholders > 0) {
uint256 balance = this.balance;
for (uint i = 1; i <= totalShareholders; i++) {
uint256 currentBalance = balanceOf[shareholders[i]];
if (currentBalance > 0) {
uint256 amount = balance * currentBalance / shareholdersBalance;
shareholders[i].transfer(amount);
}
}
}
}
function receiveFunds() payable {}
function insertShareholder(address _shareholder) internal returns (bool) {
if (registeredShareholders[_shareholder] == true) {
} else {
totalShareholders += 1;
shareholders[totalShareholders] = _shareholder;
registeredShareholders[_shareholder] = true;
return true;
}
return false;
}
}