-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreateReservation.sol
38 lines (31 loc) · 1.53 KB
/
createReservation.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
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.18;
// Reservation Creation Contract
contract CreateReservation {
// Structure to hold reservation information
struct Reservation {
uint256 id; // Reservation ID
uint256 depositAmount; // Reservation deposit amount
address payable user; // User's address who made the reservation
address payable owner; // Owner's address of the store
ReservationStatus status; // Reservation status
}
// Enumeration for reservation status
enum ReservationStatus { Pending, Confirmed, CancelledByUser, CancelledByOwner, NoShow }
// Mapping to store reservation information based on reservation ID
mapping(uint256 => Reservation) public reservations;
// Event for reservation creation
event ReservationCreated(uint256 id, address user);
// Function to create a reservation
function createReservation(uint256 _reservationId, address payable _owner, uint256 _depositAmount) external {
// Check if a reservation with the same ID already exists
require(reservations[_reservationId].user == address(0), "Reservation with this ID already exists.");
// Create a new reservation
Reservation storage newReservation = reservations[_reservationId];
newReservation.id = _reservationId;
newReservation.depositAmount = _depositAmount * (10 ** 18);
newReservation.user = payable(msg.sender);
newReservation.owner = _owner;
newReservation.status = ReservationStatus.Pending;
}
}