forked from maticnetwork/ethindia-workshop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Airbnb.sol
95 lines (71 loc) · 2.77 KB
/
Airbnb.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
pragma solidity ^0.5.7;
contract Airbnb {
// INSERT struct Property
// Unique and sequential propertyId for every new property
uint256 public propertyId;
// mapping of propertyId to Property object
mapping(uint256 => Property) public properties;
// INSERT struct Booking
uint256 public bookingId;
// mapping of bookingId to Booking object
mapping(uint256 => Booking) public bookings;
// This event is emitted when a new property is put up for sale
event NewProperty (
uint256 indexed propertyId
);
// This event is emitted when a NewBooking is made
event NewBooking (
uint256 indexed propertyId,
uint256 indexed bookingId
);
/**
* @dev Put up your funky space on the market
* @param name Name of the property
* @param description Short description of your property
* @param price Price per day in wei (1 ether = 10^18 wei)
*/
function rentOutproperty(string memory name, string memory description, uint256 price) public {
// create a property object
// Persist `property` object to the "permanent" storage
// emit an event to notify the clients
}
/**
* @dev Make an Airbnb booking
* @param _propertyId id of the property to rent out
* @param checkInDate Check-in date
* @param checkoutDate Check-out date
*/
function rentProperty(uint256 _propertyId, uint256 checkInDate, uint256 checkoutDate) public payable {
// Retrieve `property` object from the storage
// Assert that property is active
// Assert that property is available for the dates
// Check the customer has sent an amount equal to (pricePerDay * numberOfDays)
// send funds to the owner of the property
_sendFunds(property.owner, msg.value);
// conditions for a booking are satisfied, so make the booking
_createBooking(_propertyId, checkInDate, checkoutDate);
}
function _sendFunds (address beneficiary, uint256 value) internal {
// address(uint160()) is a weird solidity quirk
// Read more here: https://solidity.readthedocs.io/en/v0.5.10/050-breaking-changes.html?highlight=address%20payable#explicitness-requirements
address(uint160(beneficiary)).transfer(value);
}
function _createBooking(uint256 _propertyId, uint256 checkInDate, uint256 checkoutDate) internal {
// Create a new booking object
// persist to storage
// Retrieve `property` object from the storage
// Mark the property booked on the requested dates
// Emit an event to notify clients
}
/**
* @dev Take down the property from the market
* @param _propertyId Property ID
*/
function markPropertyAsInactive(uint256 _propertyId) public {
require(
properties[_propertyId].owner == msg.sender,
"THIS IS NOT YOUR PROPERTY"
);
properties[_propertyId].isActive = false;
}
}