-
-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
32 additions
and
0 deletions.
There are no files selected for viewing
32 changes: 32 additions & 0 deletions
32
QuantumNexusProtocol/src/smart_contracts/insurance_contract.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |