-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathdocument.sol
More file actions
138 lines (125 loc) · 2.65 KB
/
Copy pathdocument.sol
File metadata and controls
138 lines (125 loc) · 2.65 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
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
138
contract Document
{
string data;
address[] authors;
address[] sources;
mapping (address => uint) weights;
modifier onlyAuthors
{
bool x = false;
for(uint i = 0; x==false && i < authors.length; i++)
{
if(msg.sender == authors[i])
{
x = true;
}
}
if(x == false)
{
throw;
}
}
function Document(string dataHash, address[] authorAddresses, uint[] authorWeights)
{
data = dataHash;
authors = authorAddresses;
for(uint i = 0; i < authorWeights.length; i++)
{
weights[authorAddresses[i]] = authorWeights[i];
}
}
function getData() constant returns(string)
{
return data;
}
function addSource(address source, uint weight) onlyAuthors
{
sources.push(source);
weights[source] = weight;
}
function modifySourceWeight(address source, uint newValue) onlyAuthors
{
weights[source] = newValue;
}
function removeSource(address source) onlyAuthors
{
address[] memory newSources = new address[] (sources.length - 1);
uint j = 0;
for(uint i = 0; i < sources.length; i++)
{
if(source != sources[i])
{
newSources[j] = sources[i];
j++;
}
}
sources = newSources;
}
function getWeight(address requestedAddress) constant returns(uint)
{
return weights[requestedAddress];
}
function modifyAuthor(address[] newAuthors) onlyAuthors
{
authors = newAuthors;
}
function getAuthors() constant returns(address[])
{
return authors;
}
function setAuthorWeight(uint weight) onlyAuthors
{
weights[msg.sender] = weight;
}
function getTotalWeight() returns(uint)
{
uint total = 0;
for(uint j = 0; j < authors.length; j++)
{
total += weights[authors[j]];
}
for(uint i = 0; i < sources.length; i++)
{
total += weights[sources[i]];
}
return total;
}
function pay()
{
var amount = msg.value;
var total = getTotalWeight();
for(uint i = 0; i < authors.length; i++)
{
if(authors[i].send(amount*(weights[authors[i]]/total)) == false)
{
throw;
}
}
for(uint j = 0; j < sources.length; j++)
{
if(sources[j].send(weights[sources[j]]/total) == false)
{
throw;
}
}
}
function payout()
{
var amount = this.balance;
var total = getTotalWeight();
for(uint i = 0; i < authors.length; i++)
{
if(authors[i].send(amount*(weights[authors[i]]/total)) == false)
{
throw;
}
}
for(uint k = 0; k < sources.length; k++)
{
if(sources[k].send(weights[sources[k]]/total) == false)
{
throw;
}
}
}
}