Detailed explanation of complex solidity cases (Part 1) Aircraft management and insurance compensation contracts

Front row reminder: The complete implementation of this case needs to be divided into seven smart contracts, and the internal logic between each smart contract code and the connection between each smart contract have been explained in detail. I believe that after reading them all, you will have a deeper understanding of smart contracts.

Overview of the contract: Blockchain technology is now used to implement the flight delay insurance system, adding passengers, airlines, and insurance companies to the blockchain network, and purchasing, Flight, insurance, policy and other information is stored in the distributed network of the blockchain, which is permanently valid and cannot be tampered with. In the scenario of ticket delay insurance, the passenger pre-deposits a premium of 10 yuan on the system after purchasing the ticket; the insurance company then pre-deposits the corresponding compensation of 1,000 yuan on the system; if the insurance company fails to pre-deposit the compensation on time, the system will directly return the premium to User; if the insurance company has pre-deposited the compensation, if the flight is not delayed or the delay is less than 4 hours, the system will transfer the passenger's pre-deposited premium to the insurance company and return the pre-deposited compensation to the insurance company. If the flight is delayed for more than 4 hours, the system will also transfer the premium to the insurance company, but will compensate the passenger with the compensation deposited by the insurance company.

b1ba884eb8584c8e8ff180e00b1e62ec.png

 

 

First, create contracts for the following roles according to requirements and implement some functions.

1.Roles.sol account contract

(Mainly providing environment for passenger A, airline V, and insurance company C in the back)

1. Check whether the added account is empty

2. Add and delete accounts.

// SPDX-License-Identifier: 3.0

pragma solidity ^0.8.20;

library Roles {
    struct Role {
        mapping (address => bool) bearer;
    }

Guess you like

Origin blog.csdn.net/2302_77339802/article/details/132840663