You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// SPDX-License-Identifier: MIT// Contract to provide flight delay insurance
coco FlightDelayInsurance{// Owner of the contract
var owner: address
// Percentage of the flight ticket price as premium (between 0 and 100)
var premiumPercentage: uint256
// Total amount of collected premiums
var totalPoolAmount: uint256
// Total number of insured flights
var totalFlights: uint256
// Total number of cancelled flights
var totalCancelledFlights: uint256
// Mapping of user addresses to their paid premiums
var userPremiums:map(address, uint256)// Mapping of user addresses to their coverage amount
var userCoverage:map(address, uint256)// Constructor function to set the premium percentage
constructor(_premiumPercentage: uint256){
owner := msg.sender
premiumPercentage := _premiumPercentage
}// Function to calculate premium amount based on the flight ticket price
func calculatePremium(flightTicketPrice: uint256) -> uint256{
return (flightTicketPrice * premiumPercentage) / 100}// Function to allow users to purchase insurance
func purchaseInsurance(flightTicketPrice: uint256) payable {
assert(msg.value > 0, "Premium must be greater than 0")let premium := calculatePremium(flightTicketPrice)
assert(msg.value >= premium,"Insufficient premium amount")
totalPoolAmount += premium
userPremiums[msg.sender] += premium
}// Function to determine coverage amount if all flights get cancelled
func determineCoverageAmount() -> uint256 {// Calculate coverage amount based on the ratio of cancelled flights to total flightsreturn(totalPoolAmount * totalCancelledFlights) / totalFlights
}// Function to distribute coverage amount to users in proportion to their premium paid
func distributeCoverageAmount(){let totalCoverage := determineCoverageAmount()
let totalPremiums := totalPoolAmount
// Cocolang iterators are different from Solidity loopsfor(user, premium)in userPremiums {let userShare := (premium * totalCoverage) / totalPremiums
userCoverage[user] += userShare
}}// Function to withdraw coverage amount
func withdrawCoverage(){let coverage := userCoverage[msg.sender]
assert(coverage > 0,"No coverage available")
userCoverage[msg.sender]:= 0transfer(msg.sender, coverage)}}
The text was updated successfully, but these errors were encountered:
The text was updated successfully, but these errors were encountered: