Repository navigation
feat: payment ledger & reconciliation reports API (#246) - #264
Open
Manager-dev1515 wants to merge 1 commit into
Open
Manager-dev1515 wants to merge 1 commit into
Manager-dev1515 wants to merge 1 commit into
Conversation
|
@Manager-dev1515 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! 🚀 |
Add payment ledger service that reads from escrow_transaction_logs, separating confirmed entries from pending transactions and computing funded/released/refunded/remaining balances with filtering by contract, user, token, and date range. Add reconciliation service that compares blockchain-level payment data against application-level records to surface discrepancies (amount mismatches, missing events, duplicate entries, status mismatches). Add CSV export endpoints for both ledger and reconciliation reports. Add DB migration with dedup unique index and reconciliation tables. Add RBAC permissions for ledger:view, ledger:export, reconciliation:view, reconciliation:run, reconciliation:resolve. All entries are immutable; corrections use compensating entries. Duplicate blockchain events are prevented by a DB-level unique index and application-level pre-checks. Failed reconciliation jobs are logged and marked as failed. Closes Lumina-eX#246
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.
What was built
Payment Ledger (lib/payment-ledger/ + app/api/payment-ledger/):
Reads from the existing escrow_transaction_logs table — no duplicate financial data
Separates confirmed entries from pending via the status column
Computes funded/released/refunded/remaining balances per contract+currency
Filters by contract, user, token, date range, entry type, and status
CSV export endpoint with empty/error state handling
Access-scoped: non-admins only see entries on contracts they participate in
Reconciliation (lib/reconciliation/ + app/api/reconciliation/):
Compares blockchain-level data against application-level records
Detects 5 discrepancy types: amount mismatches, missing blockchain events, missing application records, duplicate entries, and status mismatches
Report lifecycle: pending → completed / discrepancies_found / failed
Discrepancy resolution with notes and resolver tracking
CSV export of discrepancies
Duplicate prevention: DB-level unique index on (transaction_hash, transaction_type, contract_id) + application-level pre-check returning 409
Immutability: Entries are never modified; corrections use compensating entries via metadata.reversesEntryId
RBAC: 5 new permissions added to
constants.ts
— ledger:view/ledger:export for all roles, reconciliation:view/run/resolve for admin only
CSV utility (
csv.ts
): RFC 4180 compliant serializer with proper escaping
Verification
47 new tests, all passing
pnpm build succeeds with all new routes registered
Pre-existing 22 test failures (3 files) confirmed present on base branch — not caused by this change
No merge conflicts with main
Closes #246