-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsolidity_coding_challenge.sol
More file actions
46 lines (37 loc) · 1.02 KB
/
solidity_coding_challenge.sol
File metadata and controls
46 lines (37 loc) · 1.02 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
pragma solidity ^0.4.9;
// THIS CONTRACT CONTAINS BUGS - DO NOT USE
contract InsecureAndMessy {
/// Mapping of ether shares of the contract.
mapping(address => uint) shares;
address owner;
address[] shareholders;
event FailedSend(address, uint);
function InseceureAndMessy() {
owner = msg.sender;
}
function () payable {
shares[msg.sender] = msg.value;
}
function addShareholder(address shareholder) {
require(tx.origin == owner);
shareholders.push(shareholder);
}
/// Withdraw your share.
function withdraw() {
if (msg.sender.send(shares[msg.sender])) {
shares[msg.sender] = 0;
} else {
FailedSend(msg.sender, shares[msg.sender]);
}
}
function dispense() {
require(msg.sender == owner);
address shareholder;
for (var i = 0; i < shareholders.length; i++) {
shareholder = shareholders[i];
uint sh = shares[shareholder];
shares[shareholder] = 0;
shareholder.send(sh);
}
}
}