diff options
-rw-r--r-- | splitShares.sol | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/splitShares.sol b/splitShares.sol new file mode 100644 index 0000000..cf3a537 --- /dev/null +++ b/splitShares.sol | |||
@@ -0,0 +1,35 @@ | |||
1 | pragma solidity ^0.4.0; | ||
2 | contract SplitIncomes { | ||
3 | mapping(address => uint256) withdrawn; | ||
4 | mapping(address => bool) inShares; | ||
5 | uint256 totalWithdrawn; | ||
6 | uint256 SharesCount; | ||
7 | |||
8 | function SplitIncomes(address[] addresses) public { | ||
9 | SharesCount = addresses.length; | ||
10 | |||
11 | for (uint i = 0; i < SharesCount; i++) { | ||
12 | inShares[addresses[i]] = true; | ||
13 | } | ||
14 | } | ||
15 | |||
16 | function () public payable {} | ||
17 | |||
18 | function balance() public view returns (uint256) { | ||
19 | if (!inShares[msg.sender]) { | ||
20 | return 0; | ||
21 | } | ||
22 | |||
23 | return (address(this).balance + totalWithdrawn) / SharesCount - withdrawn[msg.sender]; | ||
24 | } | ||
25 | |||
26 | function withdraw() public { | ||
27 | require(inShares[msg.sender]); | ||
28 | uint256 available = balance(); | ||
29 | if (available > 0) { | ||
30 | withdrawn[msg.sender] += available; | ||
31 | totalWithdrawn += available; | ||
32 | msg.sender.transfer(available); | ||
33 | } | ||
34 | } | ||
35 | } | ||