feat: event type filtering, batch notifications, audit logging#209
Open
ScriptedBro wants to merge 2 commits into
Open
Conversation
- Add NotificationCategory and NotificationPriority as trailing topics on all emitted events so off-chain consumers can filter by type - Add batch_schedule_notifications: create up to 50 notifications in a single transaction with all-or-nothing validation and a summary event - Add AuditRecord type and append-only on-chain audit log tracking the full notification lifecycle (created, delivery attempt, delivery failed, acknowledged, cancelled, expired) - Add query endpoints: get_audit_log and get_notification_audit - Add explicit audit write helpers: record_delivery_attempt, record_delivery_failure, record_acknowledgment - Add BatchTooLarge error variant - Add AuditAction enum and AuditRecordAppended, BatchNotificationsCreated events - Add 179-test suite: payload_validation_test, batch_notification_test, audit_log_test (all passing)
|
@ScriptedBro 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! 🚀 |
Collaborator
|
please resolve conflicts and fix Ci |
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.
Pull Request: Event Type Filtering, Batch Notifications & Audit Logging
Branch
feature/event-type-filtering-batch-notifications-audit-loggingCloses
Closes #102 · Closes #40 · Closes #181 · Closes #173
Overview
This PR delivers three interconnected features that improve how the NotifyChain contract communicates lifecycle events to off-chain consumers, reduce the operational cost of sending notifications at scale, and give organisations a complete, immutable audit trail for compliance and monitoring.
Changes Summary
1. Event Type Filtering — closes #102
Off-chain consumers previously had no way to selectively subscribe to specific notification categories without decoding every event. Every emitted event now carries two additional trailing topics:
NotificationCategory—Group,Admin,Financial, orNotificationNotificationPriority—Low,Medium,High, orCriticalBoth are appended as the last two topics of every event, preserving full backward compatibility: existing listeners that only read the event name and prior topics are unaffected.
Files changed
src/base/events.rs— addedNotificationCategoryandNotificationPriorityenums; all event structs updatedsrc/base/types.rs—AutoShareDetailscarriespriorityfieldsrc/autoshare_logic.rs— all emit sites pass category + priorityAcceptance criteria met
notification_test.rs,payload_validation_test.rs)2. Batch Notification Creation — closes #40
Creating notifications individually at scale inflates transaction costs and operational overhead. A new
batch_schedule_notificationsentry point allows up to 50 notifications to be created in a single transaction.How it works
idsandttl_secondsvectors — must be the same lengthNotificationScheduledevent per notification, plus a singleBatchNotificationsCreatedsummary event carrying the count and full id listCreatedaudit record (see below)New error variant
BatchTooLarge = 26— returned when the batch exceeds 50 entriesFiles changed
src/base/errors.rs—BatchTooLargevariantsrc/base/events.rs—BatchNotificationsCreatedeventsrc/autoshare_logic.rs—batch_schedule_notificationsimplementationsrc/lib.rs—batch_schedule_notificationspublic entry pointAcceptance criteria met
batch_notification_test.rs)3. Audit Logging — closes #181 & #173
Organisations require visibility into delivery attempts and outcomes for compliance and operational monitoring. An append-only, on-chain audit log now records every stage of the notification lifecycle.
Lifecycle actions recorded
Createdschedule_notification,batch_schedule_notificationsDeliveryAttemptrecord_delivery_attemptDeliveryFailedrecord_delivery_failureAcknowledgedrecord_acknowledgmentCancelledcancel_notificationExpiredexpire_notificationStorage model
DataKey::AuditLog— singleVec<AuditRecord>in persistent storage; append-only, never modified after writeDataKey::AuditSeq— monotonically increasing counter in instance storageAuditRecordcarries:seq,notification_id,action,actor,timestampQuery endpoints
get_audit_log()— returns the full log in creation orderget_notification_audit(notification_id)— returns all records for a specific notificationNew write helpers (pause-aware, auth-required)
record_delivery_attempt(notification_id, actor)record_delivery_failure(notification_id, actor)record_acknowledgment(notification_id, actor)Files changed
src/base/events.rs—AuditActionenum,AuditRecordAppendedeventsrc/base/types.rs—AuditRecordtypesrc/autoshare_logic.rs—append_audit_record(private), all query and write helperssrc/lib.rs— all audit public entry pointsAcceptance criteria met
AuditRecordAppendedevent emitted for every record so off-chain indexers can sync in real time (audit_log_test.rs)Testing
New test files
batch_notification_test.rsaudit_log_test.rspayload_validation_test.rsTotal suite: 179 tests — 179 passing, 0 failing
Running the tests
Files Changed
Modified (5)
src/autoshare_logic.rssrc/base/errors.rsBatchTooLarge = 26src/base/events.rsAuditAction,AuditRecordAppended,BatchNotificationsCreated; importVecsrc/base/types.rsAuditRecord; importAuditActionsrc/lib.rsNew (3)
src/tests/batch_notification_test.rssrc/tests/audit_log_test.rssrc/tests/payload_validation_test.rsTotal: 8 files · +1,915 insertions · -6 deletions
Backward Compatibility
All changes are fully backward compatible:
Deployment Checklist
cargo test— all 179 tests must passBatchTooLargeerror code (26) does not collide with any client-side error handlingCommit
Ready for Review ✅