From e9e2694d8a97e3a13eb8f35f8febf5ebb48905ee Mon Sep 17 00:00:00 2001 From: =?utf8?q?Isma=C3=ABl=20Bouya?= Date: Fri, 12 Jan 2018 11:04:32 +0100 Subject: [PATCH] Add split shares smart contract for Ethereum --- splitShares.sol | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 splitShares.sol diff --git a/splitShares.sol b/splitShares.sol new file mode 100644 index 0000000..cf3a537 --- /dev/null +++ b/splitShares.sol @@ -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); + } + } +} -- 2.41.0