git ssb

0+

dangerousbeans / Entropy_contracts



Tree: ba1bbe9aa369edbcdf1f09df384fefc35d0b8725

Files: ba1bbe9aa369edbcdf1f09df384fefc35d0b8725 / contracts / Entropy.sol

6520 bytesRaw
1pragma solidity ^0.4.4;
2
3import "./tokens/EntropyToken.sol";
4
5contract Entropy is EntropyToken {
6
7 /**
8 * A Citizen ๐Ÿƒ is anyone who holds one or more Entropy Tokens ๐Ÿช
9 * Any address with a balance > 0 is considered a Citizen
10 */
11
12 /**
13 * Trusted Citizens ๐Ÿ‘ฌ hold equal voting rights to all
14 * trusted individuals in the Entropy Community
15 */
16 mapping(address => bool) trusted_citizen;
17
18 /**
19 * Guardians ๐Ÿ’‚ are the elected protectors of the project
20 * They are also able to mark Citizens as trusted, allowing for a human-based
21 * proof of individuality system.
22 */
23 mapping(address => bool) guardians;
24
25 /**
26 * Actions
27 * All Actions :bulb: can be voted :hand: on by the entire community for 5 days.
28 *
29 * For an Action :bulb: to be accepted, it must have *more than 50% approval*
30 * and at least as many votes :hand: as there are Guardian ๐Ÿ’‚ members
31 *
32 * After this period accepted Actions :bulb: will be added to the Action
33 * Stream :clipboard: until they are marked as complete by one of the Guardians :guardsman:
34 *
35 * Declined Actions :bulb: will be dismissed to the Archive :recycle:
36 *
37 * The Action Stream :clipboard: represents what the community is currently
38 * aiming to achieve.
39 *
40 * Any funds associated with Actions :bulb: in the Action Stream :clipboard:
41 * become available in the Slush Pool :moneybag: for the Guardians :guardsman:
42 * to use towards making those Actions :bulb: happen.
43 */
44 Action[] public actions;
45 uint public actions_count;
46 struct Action {
47 uint amount;
48 string description;
49 uint votingDeadline;
50 bool done;
51 bool actionPassed;
52 uint numberOfVotes;
53 bytes32 actionHash;
54 Vote[] votes;
55 mapping (address => bool) voted;
56 }
57
58 struct Vote {
59 bool inSupport;
60 address citizen;
61 }
62
63
64 /**
65 * Constructor
66 * ran once when the Entropy contract first comes into existence
67 */
68 function Entropy() {
69 // Setup token attributes
70 name = "Entropy";
71 decimals = 0; // 1 token cannot be devided
72 symbol = "ENT"; // identifier
73 safety_limit = 300 ether; // Inital safety cap
74
75 // Set the creator as Trusted, a Citizen and a Guardian
76 totalSupply = 1;
77 balances[msg.sender] = 1;
78 NewCitizen(msg.sender);
79
80 trusted_citizen[msg.sender] = true;
81 NewTrust(msg.sender, msg.sender);
82
83 guardians[msg.sender] = true;
84 NewGuardian(msg.sender, msg.sender);
85 }
86
87 /**
88 * Fallback function
89 * This runs whenever ether is sent to Entropy without any other information
90 */
91 function() {
92 // Buy tokens ๐Ÿช
93 buyTokens();
94 }
95
96
97 // Token Selling related ๐Ÿช
98
99 /**
100 * Alters the safety limit for the maximum value of tokens bought
101 */
102 function changeSafeyLimit(uint _new_limit)
103 onlyGuardians // ๐Ÿ’‚
104 returns (bool success) {
105 // Limit can only be increased
106 if(_new_limit < safety_limit) throw;
107
108 // Set new safety limit
109 safety_limit = _new_limit;
110 SafetyLimitChange(msg.sender, _new_limit);
111 }
112
113 /**
114 * Actions
115 *
116 * Trusted citizens can create an action, which then can be voted on for 5 days
117 */
118 function newAction(
119 uint _etherAmount, // Amount to unlock (optional)
120 string _description // The idea, task or destination
121 )
122 onlyTrusted // Only trusted Citizens
123 returns (uint actionID)
124 {
125 actionID = actions.length++;
126 Action a = actions[actionID];
127 a.amount = _etherAmount;
128 a.description = _description;
129 a.actionHash = sha3(_etherAmount, _description);
130 a.votingDeadline = now + 5 days;
131 a.done = false;
132 a.actionPassed = false;
133 a.numberOfVotes = 0;
134 ActionAdded(actionID, _etherAmount, _description);
135 actions_count = actionID + 1;
136 }
137
138
139
140
141 /**
142 * Voting
143 */
144 function vote(uint actionId, bool in_favour)
145 onlyTrusted
146 returns (uint voteID)
147 {
148 Action action = actions[actionId];
149
150 // Check to make sure this person has not already voted
151 if (action.voted[msg.sender] == true) throw;
152
153 voteID = action.votes.length++;
154 action.votes[voteID] = Vote({inSupport: in_favour, citizen: msg.sender});
155 action.voted[msg.sender] = true;
156 action.numberOfVotes = voteID + 1;
157 Voted(actionId, in_favour, msg.sender);
158 }
159
160
161 /**
162 * Guardians ๐Ÿ’‚
163 */
164
165 // Set someone as a Guardian
166 function setGuardian(address _person, bool _is_guardian)
167 onlyGuardians // ๐Ÿ’‚
168 returns (bool success) {
169 guardians[_person] = _is_guardian;
170
171 NewGuardian(_person, msg.sender);
172 return true;
173 }
174
175 // Guardianship of an address
176 function isGuardian(address _citizen) public constant returns (bool guardian) {
177 return guardians[_citizen];
178 }
179
180 // Protect a function so only guardians ๐Ÿ’‚ can run it
181 modifier onlyGuardians {
182 if (isGuardian(msg.sender) == false) throw;
183 _;
184 }
185
186 /**
187 * Citizens ๐Ÿƒ
188 */
189
190 // Set someone as a Trusted Citizen
191 function setTrust(address _person, bool _is_trusted)
192 onlyGuardians // ๐Ÿ’‚
193 returns (bool success) {
194 trusted_citizen[_person] = _is_trusted;
195
196 if(_is_trusted)
197 {
198 NewTrust(_person, msg.sender);
199 }
200 else
201 {
202 TrustLost(_person, msg.sender);
203 }
204
205 return true;
206 }
207
208 function isTrusted(address _citizen) public constant returns (bool trusted) {
209 return trusted_citizen[_citizen];
210 }
211
212 // Protect a function so only trusted citizens can run it
213 modifier onlyTrusted {
214 if (isTrusted(msg.sender) == false) throw;
215 _;
216 }
217
218 // Citizenship of an address
219 function isCitizen(address _citizen) public constant returns (bool citizen) {
220 return balanceOf(_citizen) > 0;
221 }
222
223 modifier onlyCitizens {
224 if (isCitizen(msg.sender) == false) throw;
225 _;
226 }
227
228
229 /**
230 * Events
231 *
232 * Important changes to the state of Entropy
233 */
234
235 // TODO: This doesn't work:
236 // event NewCitizen(address indexed _citizen);
237
238
239 event ActionAdded(uint actionID, uint amount, string description);
240
241 // Vote
242 event Voted(uint actionId, bool in_favour, address citizen);
243
244 // A new guardian has been elected
245 event NewGuardian(address indexed _guardian, address indexed _creator);
246
247 // A new person has been trusted
248 event NewTrust(address indexed _citizen, address indexed _guardian);
249
250 // A person is no longer trusted
251 event TrustLost(address indexed _citizen, address indexed _guardian);
252
253 // Safety Limit has been increased
254 event SafetyLimitChange(address indexed _guardian, uint indexed limit);
255}
256

Built with git-ssb-web