From df7073c4399ccd7aee14ecff55f86bd41a29df2f Mon Sep 17 00:00:00 2001 From: KOSASIH Date: Tue, 26 Nov 2024 14:52:41 +0700 Subject: [PATCH] Create insurance_contract.py --- .../src/smart_contracts/insurance_contract.py | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 QuantumNexusProtocol/src/smart_contracts/insurance_contract.py 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); + } +}