From: Ismaƫl Bouya Date: Fri, 12 Jan 2018 10:04:32 +0000 (+0100) Subject: Add split shares smart contract for Ethereum X-Git-Tag: v0.1~47 X-Git-Url: https://git.immae.eu/?p=perso%2FImmae%2FProjets%2FCryptomonnaies%2FCryptoportfolio%2FTrader.git;a=commitdiff_plain;h=e9e2694d8a97e3a13eb8f35f8febf5ebb48905ee Add split shares smart contract for Ethereum --- 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); + } + } +}