-
Notifications
You must be signed in to change notification settings - Fork 2
/
healthInsurnaceContract.sol
executable file
·154 lines (125 loc) · 4.32 KB
/
healthInsurnaceContract.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
/*******************************************************************
The information shall not be copied, reproduced in any form or stored in a retrieval system or database by Recipient without the
prior written consent of Discloser, except for such copies and storage as may resonably internally by Recipient for the Purpose.
Authors:
1. Punit Agarwal, [email protected]
2. Muskan Kalra, [email protected]
*******************************************************************/
pragma solidity ^0.4.0;
contract HealthInsuancePolicyAgreement {
/* This declares a new complex type which will hold the claim bills*/
struct ClaimAmounts{
uint id; /* The claim id*/
uint value; /* The amount of Bill that is claimed*/
}
struct PremiumPaid{
bool _premiumPaid;
uint value;
}
/* Claim Amounts, bill amount, policy number, policy holder, policy insurer, tenure, premiumAmount*/
ClaimAmounts[] public claimamounts;
PremiumPaid[] public premiumpaid;
uint public createdTimestamp;
uint public claimableAmount;
/* Maximum amount that can be claimed if all docs are verified*/
string public policyNumber;
address public policyInsurer;
address public policyHolder;
uint tenure;
uint premiumAmount;
enum State {Created, Started, Claimed, Terminated}
State public state;
function PolicyAgreement(uint _claimableAmount, string _policyNumber, uint _premiumAmount, uint _tenure) {
claimableAmount = _claimableAmount;
policyNumber = _policyNumber;
premiumAmount = _premiumAmount;
tenure = _tenure;
policyInsurer = msg.sender;
createdTimestamp = block.timestamp;
}
modifier require(bool _condition) {
if (!_condition) throw;
_;
}
modifier onlyPolicyInsurer() {
if (msg.sender != policyInsurer) throw;
_;
}
modifier onlyPolicyHolder() {
if (msg.sender != policyHolder) throw;
_;
}
modifier inState(State _state) {
if (state != _state) throw;
_;
}
/* We also have some getters so that we can read the values
from the blockchain at any time */
function getClaimedBills() internal returns (ClaimAmounts[]) {
return claimamounts;
}
function getPremiumPaid() internal returns (PremiumPaid[]) {
return premiumpaid;
}
function getPremiumAmunt() constant returns (uint) {
return premiumAmount;
}
function getPolicyInsurer() constant returns (address) {
return policyInsurer;
}
function getPolicyHolder() constant returns (address) {
return policyHolder;
}
function getClaimableAmount() constant returns (uint) {
return claimableAmount;
}
function getContractCreated() constant returns (uint) {
return createdTimestamp;
}
function getContractAddress() constant returns (address) {
return this;
}
function getState() returns (State) {
return state;
}
function setPremium() constant{
}
/* Events for DApps to listen to */
event agreementConfirmed();
event premiumPaid();
event insuranceClaimed();
event contractTerminated();
/* Confirm the lease agreement as policyHolder*/
function confirmAgreement()
inState(State.Created)
require(msg.sender != policyInsurer)
{
agreementConfirmed();
policyHolder = msg.sender;
state = State.Started;
}
function payPremium() onlyPolicyHolder() inState(State.Started){
premiumPaid();
policyInsurer.transfer(premiumAmount);
/*premiumpaid.push(PremiumPaid({
id: premiumpaid.length + 1,
value : premiumAmount
}));*/
}
/* Terminate the contract so the policyHolder can’t pay premium anymore,
and the contract is terminated */
function InsuranceClaimed() onlyPolicyInsurer() inState(State.Claimed){
insuranceClaimed();
claimamounts.push(ClaimAmounts({
id: claimamounts.length + 1,
value: msg.value
}));
}
function terminateContract() onlyPolicyInsurer()
{
contractTerminated();
policyInsurer.send(this.balance);
/* If there is any value on the contract send it to the policyInsurer*/
state = State.Terminated;
}
}