git ssb

0+

dangerousbeans / Entropy_contracts



Tree: e2d16c3510e7763b548d4c0110a89fa0924236d6

Files: e2d16c3510e7763b548d4c0110a89fa0924236d6 / contracts / Entropy.sol

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

Built with git-ssb-web