Add on-chain service rating system for subscription services#3
Open
Clawue884 wants to merge 8 commits intoPiNetwork:mainfrom
Open
Add on-chain service rating system for subscription services#3Clawue884 wants to merge 8 commits intoPiNetwork:mainfrom
Clawue884 wants to merge 8 commits intoPiNetwork:mainfrom
Conversation
Add tests for service rating system
Khus1996
approved these changes
Apr 18, 2026
Update test.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
ServiceRatingstruct to store:total_scoretotal_ratersThis 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:
On success:
rateeventget_service_rating(...)Returns the aggregate rating data for a service:
total_scoretotal_ratersAverage rating can be derived as:
average = total_score / total_raters
Error Handling
Added new contract errors:
InvalidRatingAlreadyRatedThese ensure rating integrity and prevent invalid or duplicate submissions.
Benefits
This feature adds:
Backward Compatibility
This PR is backward compatible: