forked from viser9/skyline
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathskynew.sol
103 lines (92 loc) · 2.85 KB
/
skynew.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
// SPDX-License-Identifier: MIT
pragma solidity >=0.6.12 <0.9.0;
contract Flights {
struct Flight {
string id;
string image;
string name;
string model;
}
struct Maintenance {
string flightId;
string fuelCapacity;
string engineStatus;
string safety;
string atcR;
string emission;
string time;
}
struct Logs {
string flightId;
string details;
string duration;
string blackBox;
string fuelConsum;
}
Flight[] public flightArray;
Maintenance[] public maintenanceArray;
Logs[] public logsArray;
// Add this function to get the flight index
function getFlightIndex(string memory _sid) internal view returns (uint8) {
for (uint8 i = 0; i < flightArray.length; i++) {
if (keccak256(abi.encodePacked(flightArray[i].id)) == keccak256(abi.encodePacked(_sid))) {
return i;
}
}
revert("Flight not found");
}
function addFlights(string memory _image, string memory _name, string memory _model, string memory _id) external {
Flight memory newFlight;
newFlight.image = _image;
newFlight.name = _name;
newFlight.model = _model;
newFlight.id = _id;
flightArray.push(newFlight);
}
function addLogs(
string memory _flightId,
string memory _details,
string memory _duration,
string memory _blackBox,
string memory _fuelConsum
) external {
Logs memory newLog;
newLog.flightId = _flightId;
newLog.details = _details;
newLog.duration = _duration;
newLog.blackBox = _blackBox;
newLog.fuelConsum = _fuelConsum;
logsArray.push(newLog);
}
function addMaintenance(
string memory _flightId,
string memory _fuelCapacity,
string memory _engineStatus,
string memory _safety,
string memory _atcR,
string memory _emission,
string memory _time
) external {
Maintenance memory newMaintenance;
newMaintenance.flightId = _flightId;
newMaintenance.fuelCapacity = _fuelCapacity;
newMaintenance.engineStatus = _engineStatus;
newMaintenance.safety = _safety;
newMaintenance.atcR = _atcR;
newMaintenance.emission = _emission;
newMaintenance.time = _time;
maintenanceArray.push(newMaintenance);
}
// Get all Flight details
function getAllFlights() external view returns (Flight[] memory) {
return flightArray;
}
// Get all Maintenance records
function getAllMaintenanceDetails() external view returns (Maintenance[] memory) {
return maintenanceArray;
}
// Get all Logs
function getAllLogs() external view returns (Logs[] memory) {
return logsArray;
}
}