Skip to content

feat: add decentralized invoice rating oracle (#877) - #909

Merged
Kingsman-99 merged 2 commits into
Stellar-split:mainfrom
jacobjacobb4242:feat/issue-877-invoice-rating-oracle
Sep 30, 2026
Merged

Kingsman-99 merged 2 commits into
Stellar-split:mainfrom
jacobjacobb4242:feat/issue-877-invoice-rating-oracle

Conversation

@jacobjacobb4242

Copy link
Copy Markdown

Issue #877 — Add decentralized invoice rating oracle

Adds a new rating_oracle_ext.rs module implementing a two-channel
decentralized rating system: payer-submitted ratings and admin-registered
oracle node ratings.

Core functionality

Oracle node management (admin only):

  • register_rating_oracle(admin, oracle) — add an oracle node.
  • remove_rating_oracle(admin, oracle) — remove an oracle node.
  • is_rating_oracle(oracle) — membership check.

Payer ratings:

  • rate_invoice(payer, invoice_id, score, comment)
    • Score 1–5; optional comment ≤ 280 bytes.
    • Caller must have paid the invoice at least once.
    • Each payer may rate once per invoice.
    • Scores are aggregated (sum + count) for efficient average calculation.

Oracle ratings:

  • push_oracle_rating(oracle, invoice_id, score) — oracle node pushes a score (1–5). Latest push overwrites; useful for live credit-score feeds.

Read-only:

  • get_invoice_rating(invoice_id) → InvoiceRatingSummary { score_sum, count, raters }
  • get_oracle_rating(invoice_id) → Option<u32>

Events

Topic Data
(split, ora_add) oracle
(split, ora_rem) oracle
(split, inv_rat, invoice_id) (payer, score, comment)
(split, ora_rat, invoice_id) (oracle, score)

Storage

Local RatingOracleKey enum:

  • RatingSummary(invoice_id) — aggregate struct in persistent storage.
  • OracleScore(invoice_id) — latest oracle score in persistent storage.
  • OracleNodes — registered oracle node list in instance storage.

New type

InvoiceRatingSummary { score_sum: u64, count: u32, raters: Vec<Address> }

Tests

9 unit tests:

  • Payer can rate invoice
  • Non-payer cannot rate
  • Double rating rejected
  • Invalid score (0) rejected
  • Oracle can push rating
  • Non-oracle cannot push
  • Oracle rating defaults to None
  • Oracle rating overwritten on re-push
  • Register and remove oracle
  • Multiple payers aggregate correctly

Files changed

File Change
contracts/split/src/rating_oracle_ext.rs New
contracts/split/src/lib.rs Added mod rating_oracle_ext;

Closes #877

Add rating_oracle_ext.rs implementing two parallel rating channels:
1. Payer ratings (1-5 stars; aggregated sum+count per invoice)
2. Oracle node ratings (admin-registered nodes push external scores)

Entry points:
- register_rating_oracle / remove_rating_oracle / is_rating_oracle (admin)
- rate_invoice(payer, invoice_id, score, comment) - payers only, once each
- push_oracle_rating(oracle, invoice_id, score) - oracle nodes; overwrites
- get_invoice_rating(invoice_id) -> InvoiceRatingSummary
- get_oracle_rating(invoice_id) -> Option<u32>

Events: ora_add, ora_rem, inv_rat, ora_rat
Storage: local RatingOracleKey enum (persistent + instance)
Tests: 9 unit tests covering all paths and guard conditions

Closes Stellar-split#877
@drips-wave

drips-wave Bot commented Sep 30, 2026

Copy link
Copy Markdown

@jacobjacobb4242 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@Kingsman-99
Kingsman-99 merged commit 1fe4301 into Stellar-split:main Sep 30, 2026
1 of 4 checks passed
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.

Add decentralized invoice rating oracle

2 participants