-
Notifications
You must be signed in to change notification settings - Fork 0
/
HealthInsurance.sol
49 lines (38 loc) · 1.46 KB
/
HealthInsurance.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
pragma solidity ^0.5.17;
contract HealthInsurance{
address SmartContractOwner;
struct person{
bool authorised;
string name;
uint insuranceAmount;
}
mapping(address=>person) public personmapping;
mapping(address=>bool) public doctormapping;
constructor() public{
SmartContractOwner = msg.sender;
}
modifier onlySmartContractOwner(){
require(SmartContractOwner == msg.sender);
_;
}
function setDoctor(address _address) public onlySmartContractOwner{
require(!doctormapping[_address]);
doctormapping[_address] = true;
}
function setPerson(string memory _name,uint _insuranceAmount) public onlySmartContractOwner returns (address){
address uid = address(bytes20(sha256(abi.encodePacked(msg.sender,block.timestamp))));
require(!personmapping[uid].authorised);
personmapping[uid].authorised = true;
personmapping[uid].name = _name;
personmapping[uid].insuranceAmount = _insuranceAmount;
return uid;
}
function claimInsurance(address _uid,uint _insuranceAmountUsed) public returns (string memory){
require(!doctormapping[msg.sender]);
if(personmapping[_uid].insuranceAmount < _insuranceAmountUsed){
revert();
}
personmapping[_uid].insuranceAmount -= _insuranceAmountUsed;
return "Amount debited from your insurance";
}
}