pragma solidity ^0.4.22; contract Insurance { struct customer { bool isUidGenerated; string name; uint amountInsured; } mapping (address => customer) public customerMapping; mapping (address => bool) public doctorRegistered; address Owner; constructor() public { Owner = msg.sender; } modifier onlyOwner() { require (Owner == msg.sender); _; } function registerDoctor(address _address) public onlyOwner { require (!doctorRegistered[_address], "Doctor already registered!"); doctorRegistered[_address] = true; } function generateCustomer(string _name, uint _amountInsured) public onlyOwner returns (address) { address uniqueId = address(sha256(msg.sender, now)); require (!customerMapping[uniqueId].isUidGenerated, "Error occurred! Try again!"); customerMapping[uniqueId].isUidGenerated = true; customerMapping[uniqueId].name = _name; customerMapping[uniqueId].amountInsured = _amountInsured; return uniqueId; } function useInsurance(address _uniqueId, uint _amount) public returns (string) { require (doctorRegistered[msg.sender], "Unauthorised access denied!"); require (customerMapping[_uniqueId].amountInsured < _amount, "Invalid amount!"); customerMapping[_uniqueId].amountInsured -= _amount; return "Transaction successful!"; } }
0.4.22