Procedures
We proceed to declare the procedures that we will use in the RentOnZilliqa Smart Contract. We will declare the following types of procedures in this section. The source code.
General Procedures
Since we will send messages on multiple occasions in the contract, we create the send_message
procedure to send messages.
send_message
This procedure creates a message with the passed arguments. It uses the one_msg
library function to create a list of messages and then proceeds to send it. Note that the _recipient
is always the implicit variable _sender
.
Arguments | Description | Type |
---|---|---|
amount | The amount to be sent with the message | Uint128 |
code | The message code to be sent with the message | Int32 |
Listing Management Procedures
This group of procedures is used in the transitions that a host account user may use to manage their listings.
set_listing_details
This procedure creates or updates the Listing Details for the given ID. It is used by the create_listing
and update_listing
transitions.
Arguments | Description | Type |
---|---|---|
id | The ID of the listing | Uint128 |
name | The name of the listing | String |
description | The description of the listing | String |
price | The price of the listing | Uint128 |
rooms | The number of rooms in the listing | Uint32 |
bathrooms | The number of bathrooms in the listing | Uint32 |
image | A URL to an image of the listing | String |
location | A Google Maps Plus Code for the location of the listing | String |
wifi | The availability of WiFi at the listing | String |
laundry | The availability of a Landry at the listing | String |
hvac | The availability of an HVAC at the listing | String |
tv | The availability of a TV at the listing | String |
kitchen | The availability of a Kitchen at the listing | String |
claim_rent_by_id
This procedure is used in conjunction with the claim_rent
transition. The accumulated rent is checked for the listing with the given ID, in the listing_accumulated_rent
field. If the rent is missing or empty, the corresponding messages are sent using the send_message
procedure. If there is non-zero accumulated rent, it is sent to the _sender
using the send_message
procedure. The accumulated rent is passed as an argument to send_message
, along with the rent_claimed
message code. A "Rent Claimed" event is also emitted. The accumulated rent in the listing_accumulated_rent
field is set to zero for that ID, as it is claimed by the host account.
Arguments | Description | Type |
---|---|---|
id | The ID of the listing | Uint128 |
delete_listing_by_id
This procedure is used in conjunction with the delete_listing
transition. It deletes the Listing Details entries for the listing with the given ID.
Arguments | Description | Type |
---|---|---|
id | The ID of the listing | Uint128 |
Listing Booking Procedures
check_listing_available
This procedure is used in conjunction with the book_listing
transition. It checks if the listing is available by checking the listing_rented_till
field. If it is not available, the listing_unavailable
message is sent back. When the listing is available, the check_amount_and_book
procedure is called with the id
.
Arguments | Description | Type |
---|---|---|
id | The ID of the listing | Uint128 |
check_amount_and_book
This procedure is used in conjunction with the book_listing
transition. It is called after the listing's availibility is checked by the check_listing_available
procedure. It checks if the sent amount is equal to the listing_price
. If not, the wrong_amount_sent
is sent back. If the correct amount is sent, the book_listing_by_id
procedure is called with the id
.
Arguments | Description | Type |
---|---|---|
id | The ID of the listing | Uint128 |
book_listing_by_id
This procedure is used in conjunction with the book_listing
transition. In this procedure, the accept
command is called. The night_duration
is added to the current BLOCKNUMBER
and assigned to the listing_rented_till
field. The _sender
wallet address is assigned to the listing_renter
field. The rent amount is added to the listing_accumulated_rent
field, after subtracting the commission set in the owners_commission
field. A "ListingBooked" event is emitted and a listing_booked
message is sent.
As the commission amount is stored in the contract balance, it can be claimed by the contract owner via the _balance
implicit variable.
Arguments | Description | Type |
---|---|---|
id | The ID of the listing | Uint128 |