Created
December 10, 2018 10:45
-
-
Save kanlanc/874639fb1d2c2f5381c1a0dcd03eb2f0 to your computer and use it in GitHub Desktop.
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.5.0+commit.1d4f565a.js&optimize=false&gist=
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity ^0.4.10; | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity >0.4.99 <0.6.0; | |
contract InsuranceClaimFactory{ | |
address public claimer; | |
InsuranceClaim[] public deployedInsuranceClaim; | |
function createInsuranceClaim () public { | |
InsuranceClaim newInsuranceClaim = new InsuranceClaim(msg.sender); | |
deployedInsuranceClaim.push(newInsuranceClaim); | |
} | |
function getDeployedInsuranceClaims () public view returns (InsuranceClaim[] memory){ | |
return deployedInsuranceClaim; | |
} | |
} | |
contract InsuranceClaim{ | |
struct Request { | |
address payable insuranceRecipient; | |
string personName; | |
uint value; | |
address payable hospitalRecipient; | |
bool complete; | |
bool paymentRecieved; | |
} | |
Request[] public requests; | |
address public claimer; | |
constructor (address creator) public{ | |
claimer = creator; | |
} | |
modifier restricted(){ | |
require(msg.sender==claimer); | |
_; | |
} | |
function createRequest(string memory personName,address payable insuranceRecipient,uint value,address payable hospitalRecipient) public payable restricted{ | |
Request memory newRequest = Request({ | |
insuranceRecipient:insuranceRecipient, | |
value:value, | |
personName:personName, | |
hospitalRecipient:hospitalRecipient, | |
paymentRecieved:false, | |
complete:false | |
}); | |
require(msg.value>10000); | |
requests.push(newRequest); | |
} | |
function contribute (uint index) public payable { | |
Request storage request=requests[index]; | |
require(msg.sender==request.insuranceRecipient); | |
require(msg.value==request.value); | |
request.paymentRecieved=true; | |
} | |
function finalizeRequest (uint index) public payable restricted{ | |
Request storage request = requests[index]; | |
require(!request.complete); | |
require(request.paymentRecieved); | |
request.hospitalRecipient.transfer(request.value); | |
request.complete = true; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment