I am getting the declaration error and I am not sure why. The error is in this line " function getSpaceAvailability(uint _space) view returns(bool) { return spaceDB[_space].spaceIsAvailable; }"
Here is the affected code -
// SPDX-License-Identifier: MIT
pragma solidity >=0.7.0 < 0.9.0;
/// @title This contract will create an Air BNB type system
/// @notice Development Purposes Only!
/// @dev Feel free to contribute or fix bugs or errors
/// @custom:experimental This is an experimental contract
/**
* @title Setup the cUSD token contract interface
*/
interface CUSDToken {
function approve(address, uint256) external returns (bool);
function balanceOf(address) external view returns (uint256);
function transferFrom(address, address, uint256) external returns (bool);
}
contract celoBNB {
// ***************
// DEFINITIONS
// ***************
// Define the addresses as 'payable' so we can send funds
address payable lessorAddress;
address payable leaseeAddress;
// We define the home or apartment as a struct
// We need to store the price, the Celo address of the current occupant
// and if the space is available.
struct space {
uint256 pricecUSD;
address currentOccupant;
bool spaceIsAvailable;
}
// For testing purposes we will assume the owner has 8 spaces to rent.
// In production we would make this flexible
// and allow the owner to add and remove spaces as desired
space[8] spaceDB;
/// @notice cUSD default contract address: 0x874069Fa1Eb16D44d622F2e0Ca25eeA172369bC1
address internal cUsdTokenAddress;
// We'll use a modifier to limit who can call to the owner
modifier ownerOnly() {
require(msg.sender == lessorAddress);
_;
}
// We will run this once only when the contract is created
constructor() public {
// This stores the address that creates the contract as 'lessorAddress'
lessorAddress = msg.sender;
// Let's fill the array with test data
// (all spaces available, even # spaces cost 1 cUSD, odd #s cost 2 cUSD)
// We don't have to use but this gives us some testing data
for (uint i=0; i<8; i++) {
spaceDB[i].spaceIsAvailable = true;
}
}
// ***************
// GETTERS
// ***************
// This getter tells us if a space is available or not
function getSpaceAvailability(uint _space) public view returns(bool) {
return spaceDB[_space].spaceIsAvailable;
}
// This getter tells us the price of space
function getPriceOfSpace(uint _space) public view returns(uint256) {
return spaceDB[_space].pricecUSD;
}
// This getter tells us who's renting the space at the moment
function getCurrentOccupant(uint _space) public view returns(address) {
return spaceDB[_space].currentOccupant;
}
// ***************
// SETTERS
// ***************
// This function sets the availability of a space
function setSpaceAvailability(uint8 _space, bool _newAvailability) lessorOnly public {
spaceDB[_space].spaceIsAvailable = _newAvailability;
// if the space is to be set as "available", let's remove the current occupant
// There is no 'null' in Solidity, and an address can't be set to 0 (type mismatch)
// So we need to use address(0)
if (_newAvailability) {
spaceDB[_space].currentOccupant = address(0);
}
}
// This function sets the price of the space
// Can only be called by the lessor
function setPriceOfSpace(uint8 _space, uint256 _priceInWei) lessorOnly public {
spaceDB[_space].pricecUSD = _pricecUSD;
}
// This function handles the renting
function rentASpace(uint8 _space) public payable returns(uint256) {
// Look, a tenant!
leaseeAddress = msg.sender;
// Let's check if the tenant is sending the right amount
// The modulo operator will be true if the amount is zero,
// so we have to use &&
if (msg.value % spaceDB[_space].pricecUSD == 0 && msg.value > 0 && spaceDB[_space].spaceIsAvailable == true) {
// We calculate how many days the tenant has just paid for
uint256 numberOfNightsPaid = msg.value / spaceDB[_space].pricecUSD;
// Set the availability to false
spaceDB[_space].spaceIsAvailable = false;
// Set the tenant address in spaceDB
spaceDB[_space].currentOccupant = leaseeAddress;
// Send the rent to the owner
lessorAddress.transfer(msg.value);
// The function returns the number of days paid
// You can use this info on the frontend
return numberOfNightsPaid;
// What is the tenant sent the wrong amount?
// Well we send it back
} else {
// we send back the funds (minus gas)
leaseeAddress.transfer(msg.value);
// we return 0 days;
return 0;
}
}
}`