Skip to content

Add on-chain service rating system for subscription services#3

Open
Clawue884 wants to merge 8 commits intoPiNetwork:mainfrom
Clawue884:main
Open

Add on-chain service rating system for subscription services#3
Clawue884 wants to merge 8 commits intoPiNetwork:mainfrom
Clawue884:main

Conversation

@Clawue884
Copy link
Copy Markdown

Summary

This PR introduces an on-chain service rating system for subscription services.

Subscribers can now rate services on a scale of 1 to 5, while the contract stores aggregate rating data on-chain.
This adds a lightweight reputation layer to merchant services without affecting the existing subscription workflow.


Features Added

New Rating Model

Introduced a new ServiceRating struct to store:

  • total_score
  • total_raters

This enables calculation of average ratings on-chain.


New Storage Keys

Added new persistent storage entries:

  • ServiceRating(service_id)
    Stores aggregate rating data for each service.

  • RatingGiven(subscriber, service_id)
    Prevents duplicate ratings by the same subscriber.


New Contract Methods

rate_service(...)

Allows a subscriber to rate a service from 1 to 5.

Validation includes:

  • service must exist
  • score must be between 1 and 5
  • duplicate ratings are rejected

On success:

  • updates aggregate rating
  • records subscriber rating status
  • emits a rate event

get_service_rating(...)

Returns the aggregate rating data for a service:

  • total_score
  • total_raters

Average rating can be derived as:

average = total_score / total_raters


Error Handling

Added new contract errors:

  • InvalidRating
  • AlreadyRated

These ensure rating integrity and prevent invalid or duplicate submissions.


Benefits

This feature adds:

  • an on-chain reputation layer for services
  • merchant quality visibility
  • subscriber feedback transparency
  • groundwork for future ranking or reputation systems

Backward Compatibility

This PR is backward compatible:

  • existing subscription flows are unchanged
  • no breaking API changes
  • rating functions are fully additive

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants