feat: emit completion event in mark_completed() for off-chain credential tracking - #271
Merged
Conversation
…mission - Updated mark_completed() to emit completion_ledger (env.ledger().sequence()) in event payload - Event now publishes (student, admin, completion_ledger) instead of (student, admin) - Added test_mark_completed_event_contains_full_completion_details() to verify event includes all required components - Updated test_events_emitted_for_admin_operations to extract and validate the new ledger sequence field - All 207 tests pass
|
@Ugasutun 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! 🚀 |
2 tasks
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.
Closes #122
Description
Problem
mark_completed() in contracts/hamplard/src/lib.rs updates the enrollment record in storage but does not emit a Soroban event. As a result, off-chain credential management systems and student dashboards have no way to detect completions in real time — they'd have to poll every enrollment record, which doesn't scale and defeats real-time progress tracking and notifications.
Fix
Adds event emission to mark_completed(), publishing student address, course ID, completing admin, and the ledger sequence at time of completion — giving off-chain systems a reliable, real-time signal instead of requiring polling.
Changes
contracts/hamplard/src/lib.rs:
After the enrollment record is updated to completed in storage, emit a Soroban event with:
student — the student's address
course_id — the course identifier
admin — the address of the admin who marked completion
ledger_sequence — env.ledger().sequence() at the time of completion
Event topic follows existing event-naming conventions in the contract (e.g. ("mark_completed", student) or similar, matched to what other events in the contract already use).
Testing
Added tests verifying:
Event is emitted when mark_completed() succeeds.
Event contains the correct student address, course ID, admin address, and ledger sequence.
Event is not emitted if mark_completed() fails/reverts (e.g. unauthorized caller, already-completed enrollment), so no false-positive completion signals are published.
Ledger sequence in the event matches env.ledger().sequence() at call time.
Notes for reviewers
Followed the existing event topic/data structure conventions used elsewhere in the contract for consistency — happy to adjust naming if there's a preferred schema for this event type.
No changes to storage layout or existing mark_completed() return behavior — this is additive (event emission only).