Skip to main content

Rating System Contract Technical Reference

The RatingSystem contract enables the management of the rating system for providers in any initialized marketplace. It allows clients to rate providers and retrieve the average rating for a provider.

Structs

The Rating struct stores the sum of ratings and the count of ratings received by a provider.

struct Rating {
uint256 sum;
uint256 count;
}

State Variables

  • clientRatings: This is a mapping that stores the ratings given by clients to providers. It maps the marketplace ID to the client's address and the provider's address to the rating value.
  • providerRatings: This is a mapping that stores the ratings received by providers. It maps the marketplace ID to the provider's address and the Rating struct, which contains the sum of ratings and the count of ratings received.

Functions

getMarketplace

Retrieves the marketplace contract address.

function getMarketplace() public view returns(address)

Return values:

NameType
addressThe address of the marketplace contract.

setMarketplace

Sets the marketplace contract address.

function setMarketplace(Marketplace _marketplace) external onlyRole(DEFAULT_ADMIN_ROLE) returns (bool)

Parameters:

NameType
_marketplaceMarketplaceThe address of the marketplace contract.

Return values:

Type
boolWhether the setting was successful or not.

rateProvider

Allows a client to rate a provider for a specific deal.

function rateProvider(uint marketplaceId, uint256 dealId, uint8 rating) external

Parameters:

NameType
marketplaceIduintThe id of the marketplace.
dealIduint256The id of the deal.
ratinguint8The rating value (1-5).

removeRating

Allows a client to remove a rating for a provider.

function removeRating(uint marketplaceId, uint256 dealId) external

Parameters:

NameType
marketplaceIduintThe id of the marketplace.
dealIduint256The id of the deal.

getAverageRating

Retrieves the average rating for a provider.

function getAverageRating(uint marketplaceId, address provider) external view returns (uint256)

Parameters:

NameType
marketplaceIduintThe id of the marketplace.
provideraddressThe address of the provider.

Return values:

NameType
uint256The average rating for the provider.