Skip to content

Instantly share code, notes, and snippets.

@domwoe
Created November 19, 2016 01:17
Show Gist options
  • Save domwoe/fa7f2e605220256c0e8ba25a1940d4e2 to your computer and use it in GitHub Desktop.
Save domwoe/fa7f2e605220256c0e8ba25a1940d4e2 to your computer and use it in GitHub Desktop.
contract pool {
address reinsurer;
address underwriter;
uint reinsuranceFee;
uint insuredID = 0;
uint claimID = 0;
uint totalClaims = 0;
bool blockWithdraw = true;
event Reinsurance(
uint amount
);
modifier underwritingApproved() {
if (insurences[msg.sender].paymentPending != true) throw;
_;
}
modifier onlyUnderwriter() {
if (msg.sender != underwriter) throw;
_;
}
// check validity
struct Insurance {
address beneficiary;
uint premium;
uint insurableAmount;
bool paymentPending;
}
mapping(address => Insurance) public insurences;
mapping(address => bool) public approved;
mapping(uint => address) public insureds;
mapping(uint => address) public claims;
mapping(address => uint) public balances;
function Pool(address _reinsurer, address _underwriter, uint _reinsuranceFee) {
reinsurer = _reinsurer;
underwriter = _underwriter;
reinsuranceFee = _reinsuranceFee;
}
function approveUnderwriting(address insured, address beneficiary, uint premium, uint insurableAmount) onlyUnderwriter {
insurences[insured] = Insurance(beneficiary,premium,insurableAmount,true);
}
function addClaim(address insured) onlyUnderwriter {
claims[claimID] = insured;
claimID++;
}
function doSettlement() {
for(uint i = 0; i < claimID; i++) {
balances[insurences[claims[i]].beneficiary] = insurences[claims[i]].insurableAmount;
totalClaims = totalClaims + insurences[claims[i]].insurableAmount;
}
if (totalClaims > this.balance) {
Reinsurance(this.balance-totalClaims);
}
for(uint j = 0; j < insuredID; j++) {
//insurences[insureds[insuredID]].
}
}
function withdrawBalance() {
}
function getBalance() {
}
function addInsured(address insured) {
insureds[insuredID] = insured;
insuredID++;
insurences[insured].paymentPending = false;
}
function payPremium() underwritingApproved {
// Throw if value is below premium
if (msg.value < insurences[msg.sender].premium) throw;
addInsured(msg.sender);
// Be nice and send back amount paid above premium
if (msg.value > insurences[msg.sender].premium) {
msg.sender.send(msg.value - insurences[msg.sender].premium);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment