Skip to content

feat(ledger): implement allocate_credits service [REN-76] - #107

Merged
Scott Graham (cheddarfox) merged 1 commit into
devfrom
REN-76-ledger-allocate-credits
Mar 9, 2026
Merged

Scott Graham (cheddarfox) merged 1 commit into
devfrom
REN-76-ledger-allocate-credits

Conversation

@cheddarfox

Copy link
Copy Markdown
Member

Summary

  • Add core/ledger/service.py with allocate_credits() and get_balance() async functions
  • SELECT FOR UPDATE row locking for concurrent safety on balance reads
  • Idempotent via UNIQUE constraint on (reference_id, direction) + IntegrityError fallback
  • Zero/negative amount validation with ValueError
  • Structured audit logging via structlog

Test plan

  • allocate_credits creates entry with correct balance_after
  • Duplicate reference_id returns existing entry (idempotent)
  • Zero amount raises ValueError
  • Negative amount raises ValueError
  • get_balance returns Decimal("0.0000") for user with no entries
  • ruff check core/ledger/ passes clean

🤖 Generated with Claude Code

…N-76]

Add credit ledger service layer with allocate_credits() and get_balance()
functions. Uses SELECT FOR UPDATE row locking for concurrent safety and
UNIQUE constraint + IntegrityError fallback for idempotent allocation.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@cheddarfox

Copy link
Copy Markdown
Member Author

ARCHitect Review — REN-76 ✅ APPROVED

SELECT FOR UPDATE + idempotency via UNIQUE constraint + IntegrityError fallback. Clean TYPE_CHECKING usage. LGTM.

🤖 Generated with Claude Code

@cheddarfox
Scott Graham (cheddarfox) merged commit 6b21dfc into dev Mar 9, 2026
15 of 17 checks passed
@cheddarfox
Scott Graham (cheddarfox) deleted the REN-76-ledger-allocate-credits branch March 9, 2026 22:52
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.

1 participant