Skip to content

feat: wallet clone - atomic transfers, append-only ledger, integer paise (bounty #6) - #26

Open
Kasuki354 wants to merge 7 commits into
quicksilverj2:mainfrom
Kasuki354:bounty-6-wallet-clone
Open

feat: wallet clone - atomic transfers, append-only ledger, integer paise (bounty #6)#26
Kasuki354 wants to merge 7 commits into
quicksilverj2:mainfrom
Kasuki354:bounty-6-wallet-clone

Conversation

@Kasuki354

Copy link
Copy Markdown

Summary

Implements bounty #6: Wallet clone (atomic transfers + ledger + integer paise + idempotency)

Invariant

50 concurrent full-balance debits of one account -> exactly one succeeds, balance never goes negative, zero 5xx. Same idempotency key + different body -> 409.

Implementation

Backend:

  • Wallet model: id, ownerId (unique), balancePaise (BigInt), cloneSlug
  • LedgerEntry model: append-only, fromWalletId, toWalletId, amountPaise (BigInt), idempotencyKey (unique), fingerprint
  • POST /clones/:slug/wallets: create wallet with initial balance
  • GET /wallets/:id: check balance
  • POST /clones/:slug/transfers: atomic transfer via prisma. (debit + credit + ledger entry in one tx)
    • Insufficient balance -> 409 (checked inside transaction)
    • Self-transfer -> 400
    • Idempotency via unique on idempotencyKey: same key + same body -> 200, same key + different body -> 409
    • Wallet not found -> 404
  • GET /clones/:slug/ledger: last 100 ledger entries (append-only audit trail)
  • All amounts as BigInt paise (1 rupee = 100 paise, no floating point)
  • Metrics updated with wallet + transfer counts

Frontend:

  • /clones/wallet page with create wallet, transfer, and check balance forms

Tests:

  • Happy path: create + transfer + balance check
  • Idempotent retry: same key + same body -> 200
  • Concurrency: 50 concurrent full-balance debits -> 1 success + 49 rejected + zero 5xx
  • Error: key conflict (409), insufficient balance (409), 404, negative/zero amount (400), self-transfer (400)

Resolves #6

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.

[bounty] Wallet clone (atomic transfers + ledger)

1 participant