pragma solidity ^0.4.2; contract Insurance { address[] recipients; uint totalPaidOut = 0; mapping (address => uint) withdrawAmounts; function InsurancePay() public payable { } function () public payable { updateTotalPaidOut(); } function updateTotalPaidOut() internal { totalPaidOut += msg.value; } modifier canWithdraw() { bool contains = false; for(uint i = 0; i < recipients.length; i++) { if (recipients[i] == msg.sender) { contains = true; } } require(contains); _; } function withdraw() public canWithdraw { uint amountAllocated = totalPaidOut/recipients.length; uint amountWithdrawn = withdrawAmounts[msg.sender]; uint amount = amountAllocated - amountWithdrawn; withdrawAmounts[msg.sender] = amountWithdrawn + amount; if (amount > 0) { msg.sender.transfer(amount); } } }
0.4.24