nascarsid / Boolien-Smart-Contracts

0 stars 1 forks source link

Remove `id` from SaleOrder Struct #6

Closed mudgen closed 2 years ago

mudgen commented 2 years ago

The id variable in the SaleOrder struct is not needed by the contract so I recommend removing it. Removing it would reduce gas cost in some of the functions.

The ItemExists(uint256 id) is below. It checks the id but it does not need to.

 /**
    @dev Modifier to check whether Item sales exist.
     */
    modifier ItemExists(uint256 id) {
        require(
            id < itemsForSale.length && itemsForSale[id].id == id,
            "Could not find requested item"
        );
        _;
    }

The ItemExists(uint256 id) modifier could be written like this instead:

 /**
    @dev Modifier to check whether Item sales exist.
     */
    modifier ItemExists(uint256 id) {
        require(id < itemsForSale.length, "Could not find requested item");
        _;
    }

The other require statements that check id can be removed without affecting anything.