git ssb

0+

dangerousbeans / Entropy_contracts



Tree: add0bd87861d967eab275b060a95b4f5576f5d59

Files: add0bd87861d967eab275b060a95b4f5576f5d59 / contracts / Entropy.sol

6632 bytesRaw
1pragma solidity ^0.4.8;
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 // Setup crowdsale for 60 days from now
76 deadline = now + 60 * 1 days;
77
78 // Set the creator as a Citizen, as Trusted and as a Guardian
79 totalSupply = 1;
80 balances[msg.sender] = 1;
81 NewCitizen(msg.sender);
82
83 trusted_citizen[msg.sender] = true;
84 NewTrust(msg.sender, msg.sender);
85
86 guardians[msg.sender] = true;
87 NewGuardian(msg.sender, msg.sender);
88 }
89
90 /**
91 * Fallback function
92 * This runs whenever ether is sent to Entropy without any other information
93 */
94 function() {
95 // Buy tokens ๐Ÿช
96 buyTokens();
97 }
98
99
100 // Token Selling related ๐Ÿช
101
102 /**
103 * Alters the safety limit for the maximum value of tokens bought
104 */
105 function changeSafeyLimit(uint _new_limit)
106 onlyGuardians // ๐Ÿ’‚
107 returns (bool success) {
108 // Limit can only be increased
109 if(_new_limit < safety_limit) throw;
110
111 // Set new safety limit
112 safety_limit = _new_limit;
113 SafetyLimitChange(msg.sender, _new_limit);
114 }
115
116 /**
117 * Actions
118 *
119 * Trusted citizens ๐Ÿƒ can create an action, which then can be voted on for 5 days
120 */
121 function newAction(
122 uint _etherAmount, // Amount of Ether, in wei, to unlock (optional)
123 string _description // The idea, task or destination
124 )
125 onlyTrusted // Only trusted Citizens ๐Ÿƒ
126 returns (uint actionID)
127 {
128 actionID = actions.length++;
129 Action a = actions[actionID];
130 a.amount = _etherAmount;
131 a.description = _description;
132 a.actionHash = sha3(_etherAmount, _description);
133 a.votingDeadline = now + 5 days;
134 a.done = false;
135 a.actionPassed = false;
136 a.numberOfVotes = 0;
137 ActionAdded(actionID, _etherAmount, _description);
138 actions_count = actionID + 1;
139 }
140
141
142 /**
143 * Voting
144 */
145 function vote(uint actionId, bool in_favour)
146 onlyTrusted
147 returns (uint voteID)
148 {
149 Action action = actions[actionId];
150
151 // Check to make sure this person has not already voted
152 if (action.voted[msg.sender] == true) throw;
153
154 voteID = action.votes.length++;
155 action.votes[voteID] = Vote({inSupport: in_favour, citizen: msg.sender});
156 action.voted[msg.sender] = true;
157 action.numberOfVotes = voteID + 1;
158 Voted(actionId, in_favour, msg.sender);
159 }
160
161
162 /**
163 * Guardians ๐Ÿ’‚
164 */
165
166 // Set someone as a Guardian
167 function setGuardian(address _person, bool _is_guardian)
168 onlyGuardians // ๐Ÿ’‚
169 returns (bool success) {
170 guardians[_person] = _is_guardian;
171
172 NewGuardian(_person, msg.sender);
173 return true;
174 }
175
176 // Guardianship of an address
177 function isGuardian(address _citizen) public constant returns (bool guardian) {
178 return guardians[_citizen];
179 }
180
181 // Protect a function so only guardians ๐Ÿ’‚ can run it
182 modifier onlyGuardians {
183 if (isGuardian(msg.sender) == false) throw;
184 _;
185 }
186
187 /**
188 * Citizens ๐Ÿƒ
189 */
190
191 // Set someone as a Trusted Citizen
192 function setTrust(address _person, bool _is_trusted)
193 onlyGuardians // ๐Ÿ’‚
194 returns (bool success) {
195 trusted_citizen[_person] = _is_trusted;
196
197 if(_is_trusted)
198 {
199 NewTrust(_person, msg.sender);
200 }
201 else
202 {
203 TrustLost(_person, msg.sender);
204 }
205
206 return true;
207 }
208
209 function isTrusted(address _citizen) public constant returns (bool trusted) {
210 return trusted_citizen[_citizen];
211 }
212
213 // Protect a function so only trusted citizens can run it
214 modifier onlyTrusted {
215 if (isTrusted(msg.sender) == false) throw;
216 _;
217 }
218
219 // Citizenship of an address
220 function isCitizen(address _citizen) public constant returns (bool citizen) {
221 return balanceOf(_citizen) > 0;
222 }
223
224 modifier onlyCitizens {
225 if (isCitizen(msg.sender) == false) throw;
226 _;
227 }
228
229
230 /**
231 * Events
232 *
233 * Important changes to the state of Entropy
234 */
235
236 // TODO: This doesn't work:
237 // event NewCitizen(address indexed _citizen);
238
239
240 event ActionAdded(uint actionID, uint amount, string description);
241
242 // Vote
243 event Voted(uint actionId, bool in_favour, address citizen);
244
245 // A new guardian has been elected
246 event NewGuardian(address indexed _guardian, address indexed _creator);
247
248 // A new person has been trusted
249 event NewTrust(address indexed _citizen, address indexed _guardian);
250
251 // A person is no longer trusted
252 event TrustLost(address indexed _citizen, address indexed _guardian);
253
254 // Safety Limit has been increased
255 event SafetyLimitChange(address indexed _guardian, uint indexed limit);
256}
257

Built with git-ssb-web