Skip to content

Commit

Permalink
Create insurance_contract.py
Browse files Browse the repository at this point in the history
  • Loading branch information
KOSASIH authored Nov 26, 2024
1 parent bfdb11e commit df7073c
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions QuantumNexusProtocol/src/smart_contracts/insurance_contract.py
Original file line number Diff line number Diff line change
@@ -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);
}
}

0 comments on commit df7073c

Please sign in to comment.