aboutsummaryrefslogtreecommitdiff
path: root/splitShares.sol
diff options
context:
space:
mode:
authorIsmaël Bouya <ismael.bouya@normalesup.org>2018-01-12 11:04:32 +0100
committerIsmaël Bouya <ismael.bouya@normalesup.org>2018-01-12 11:50:20 +0100
commite9e2694d8a97e3a13eb8f35f8febf5ebb48905ee (patch)
tree84b55e8a01e8b208dfb8b23ea9956bf63defae13 /splitShares.sol
parent73e777420f63616e883393c50f0684243ac19bed (diff)
downloadTrader-e9e2694d8a97e3a13eb8f35f8febf5ebb48905ee.tar.gz
Trader-e9e2694d8a97e3a13eb8f35f8febf5ebb48905ee.tar.zst
Trader-e9e2694d8a97e3a13eb8f35f8febf5ebb48905ee.zip
Add split shares smart contract for Ethereum
Diffstat (limited to 'splitShares.sol')
-rw-r--r--splitShares.sol35
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 @@
1pragma solidity ^0.4.0;
2contract 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}