-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathshareHold.sol
More file actions
67 lines (60 loc) · 1.8 KB
/
shareHold.sol
File metadata and controls
67 lines (60 loc) · 1.8 KB
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
contract shareHold {
address public initiator;
mapping ( address => uint ) public sharesMap;
mapping ( uint => address ) public holdersMap;
uint holdersCount;
uint public totalShare;
uint public totalRevenue;
uint[] public revenuesHistory;
bool open;
function shareHold() {
initiator = msg.sender;
holdersCount = 0;
totalShare = 0;
totalRevenue = 0;
open = true;
}
event record(address _sender, uint _value);
function invest(address target, uint amount) {
if(msg.sender != initiator) throw;
else {
target.send(amount);
record(target, amount);
}
}
function joinShare() returns(bool){
if(!open) throw;
if(msg.sender == initiator) {
open = false;
return false;
}
if(sharesMap[msg.sender] > 0) {
sharesMap[msg.sender] += msg.value;
totalShare += msg.value;
record(msg.sender, msg.value);
return true;
}
else {
sharesMap[msg.sender] = msg.value;
holdersMap[holdersCount] = msg.sender;
holdersCount += 1;
totalShare += msg.value;
record(msg.sender, msg.value);
return true;
}
}
function collectRevenue() {
revenuesHistory.push(msg.value);
totalRevenue += msg.value;
//dispenseRevenue(msg.value);
}
function dispenseRevenue(uint amount) {
if(msg.sender != initiator) throw;
else {
for(uint i=0; i < holdersCount; i++){
holdersMap[i].send(amount*sharesMap[holdersMap[i]]/totalShare);
record(holdersMap[i],amount*sharesMap[holdersMap[i]]/totalShare);
}
}
}
}