diff --git a/QuantumNexusProtocol/src/smart_contracts/insurance_contract.py b/QuantumNexusProtocol/src/smart_contracts/insurance_contract.py new file mode 100644 index 000000000..43235b7c3 --- /dev/null +++ b/QuantumNexusProtocol/src/smart_contracts/insurance_contract.py @@ -0,0 +1,32 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.0; + +contract InsuranceContract { + struct Policy { + address insured; + uint256 premium; + uint256 coverageAmount; + bool isActive; + } + + mapping(address => Policy) public policies; + + event PolicyCreated(address indexed insured, uint256 premium, uint256 coverageAmount); + event PolicyClaimed(address indexed insured, uint256 amount); + + function createPolicy(uint256 premium, uint256 coverageAmount) external payable { + require(msg.value == premium, "Premium must be paid"); + policies[msg.sender] = Policy(msg.sender, premium, coverageAmount, true); + emit PolicyCreated(msg.sender, premium, coverageAmount); + } + + function claim() external { + Policy storage policy = policies[msg.sender]; + require(policy.isActive, "No active policy"); + require(address(this).balance >= policy.coverageAmount, "Insufficient funds for claim"); + + policy.isActive = false; + payable(msg.sender).transfer(policy.coverageAmount); + emit PolicyClaimed(msg.sender, policy.coverageAmount); + } +}