---
# System prepended metadata

title: AirBnB - Keagan

---

# AirBnB - Keagan

```
scilla_version 0

(***************************************************)
(*               Associated library                *)
(***************************************************)

import BoolUtils

library Airbnb

let one_msg = 
  fun (msg : Message) => 
    let nil_msg = Nil {Message} in
    Cons {Message} msg nil_msg

(* error codes library *)
let code_success = Uint32 0
let code_airbnb_not_found = Uint32 1
let code_airbnbid_exist = Uint32 4

(***************************************************)
(*             The contract definition             *)
(***************************************************)
contract Airbnb

(*  Parameters *)
(owner: ByStr20)

field members: Map ByStr20 (Pair (String) (Uint32))
                = Emp ByStr20 (Pair (String) (Uint32))

(* AirbnbID: last Airbnb ID issued *)
field airbnbid: Option Uint32 = None {Uint32}

(* AirbnbInventory will store a Map of Airbnb *)
field airbnbinventory: Map Uint32 (Pair (String) (Uint32))
                    = Emp Uint32 (Pair (String) (Uint32))

transition addAirbnb(address: String, price: Uint32, airbnbID: Uint32)

    airbnbs <- airbnbinventory;
    

    airbnbExists = builtin contains airbnbs airbnbid;
    match airbnbExists with
    | True =>
        msg = {_tag: "";
                    _recipient: _sender;
                    _amount: Uint128 0;
                    code: code_airbnbid_exist};
        msgs = one_msg msg;
        send msgs
    | False =>
        
        AirbnbInventory[airbnbID] := price;
        AirbnbInventory[airbnbID] := address;

        tmp = Some {Uint32} airbnbid;
        LastAirbnbID := tmp;

        msg = {_tag: ""; 
                _recipient: _sender; 
                _amount: Uint128 0; 
                code: code_success};

        msgs = one_msg msg;
        send msgs 
    end
end

transition removeAirbnb(Airbnb_id: Uint32)
    

    delete bookInventory[Airbnb_id]

end

transition BookAirbnb (Address: String, Price: Uint32, AirbnbID: Uint32)
  airbnbs <- AirbnbInventory;
    

    airbnbExists = builtin contains airbnbs AirbnbID;
  match airbnbExists with 
  | True =>
      accept; 
      delete bookInventory[Airbnb_id]
      msg  = {_tag : ""; _recipient : _sender; _amount : Uint128 0; 
              code : code_success};
      msgs = one_msg msg;
      e = { _eventname : "Booked"; donor : _sender; amount : _amount };
      event e;
      send msgs
    | False =>
      msg = {_tag: "";
                    _recipient: _sender;
                    _amount: Uint128 0;
                    code: code_airbnb_not_found};
        msgs = one_msg msg;
        send msgs
  end 
end
```