]> git.immae.eu Git - perso/Immae/Projets/Cryptomonnaies/Cryptoportfolio/Trader.git/commitdiff
Add split shares smart contract for Ethereum
authorIsmaël Bouya <ismael.bouya@normalesup.org>
Fri, 12 Jan 2018 10:04:32 +0000 (11:04 +0100)
committerIsmaël Bouya <ismael.bouya@normalesup.org>
Fri, 12 Jan 2018 10:50:20 +0000 (11:50 +0100)
splitShares.sol [new file with mode: 0644]

diff --git a/splitShares.sol b/splitShares.sol
new file mode 100644 (file)
index 0000000..cf3a537
--- /dev/null
@@ -0,0 +1,35 @@
+pragma solidity ^0.4.0;
+contract SplitIncomes {
+    mapping(address => uint256) withdrawn;
+    mapping(address => bool) inShares;
+    uint256 totalWithdrawn;
+    uint256 SharesCount;
+
+    function SplitIncomes(address[] addresses) public {
+        SharesCount = addresses.length;
+
+        for (uint i = 0; i < SharesCount; i++) {
+            inShares[addresses[i]] = true;
+        }
+    }
+
+    function () public payable {}
+
+    function balance() public view returns (uint256) {
+        if (!inShares[msg.sender]) {
+            return 0;
+        }
+
+        return (address(this).balance + totalWithdrawn) / SharesCount - withdrawn[msg.sender];
+    }
+
+    function withdraw() public {
+        require(inShares[msg.sender]);
+        uint256 available = balance();
+        if (available > 0) {
+            withdrawn[msg.sender] += available;
+            totalWithdrawn += available;
+            msg.sender.transfer(available);
+        }
+    }
+}