Skip to content

Feat/9/wallet ledger 원장 기록 및 지갑/원장 조회 API 구현#11

Merged
ohhalim merged 5 commits into
developfrom
feat/9/wallet-ledger
May 14, 2026
Merged

Feat/9/wallet ledger 원장 기록 및 지갑/원장 조회 API 구현#11
ohhalim merged 5 commits into
developfrom
feat/9/wallet-ledger

Conversation

@ohhalim
Copy link
Copy Markdown
Owner

@ohhalim ohhalim commented May 14, 2026

Summary

  • WalletLedger 엔티티 및 레포지토리 추가 (LED-001)
  • 주문 생성/취소/체결 정산 시 원장 자동 기록 연결
  • GET /api/v1/wallets — 사용자 지갑 잔액 조회 API (WAL-001)
  • GET /api/v1/wallets/ledgers — 원장 내역 조회 API, asset 필터 지원 (WAL-002)

Changes

  • LedgerType enum: ORDER_LOCK, ORDER_CANCEL_RELEASE, TRADE_BUY_QUOTE_SETTLE, TRADE_BUY_BASE_CREDIT, TRADE_SELL_BASE_SETTLE, TRADE_SELL_QUOTE_CREDIT
  • OrderService: 주문 저장 후 ORDER_LOCK 기록, 취소 시 ORDER_CANCEL_RELEASE, 체결 정산 시 4종 ledger 기록
  • WalletController / WalletService / 응답 DTO 추가## 테스트 완료 사항

Test plan

  • GET /api/v1/wallets 응답 구조 검증
  • GET /api/v1/wallets/ledgers asset 필터 검증
  • 주문 생성 → ORDER_LOCK 원장 1건, orderId/delta/balance_after 값 검증
  • 주문 취소 → ORDER_CANCEL_RELEASE 원장 기록, 잔액 복원 검증
  • 체결 → TRADE 4종 원장 기록 검증 (매수자 2건, 매도자 2건)
  • 기존 32개 테스트 전체 통과

관련 이슈

closes #10

Summary by CodeRabbit

  • New Features
    • Added wallet balance endpoint to retrieve available and locked balances across assets.
    • Added transaction ledger endpoint to view complete wallet history, filterable by asset.
    • System now automatically records wallet transactions for order creation, cancellation, and trade settlement events.

Review Change Stack

ohhalim added 5 commits May 14, 2026 10:22
- LedgerType enum 정의 (ORDER_LOCK, ORDER_CANCEL_RELEASE, TRADE_BUY_QUOTE_SETTLE 등 7종)
- WalletLedger 엔티티 추가: delta, balance_after, order_id, trade_id 포함
- WalletLedgerRepository 추가: 사용자/자산별 최신순 조회
- 주문 생성 시 자산 lock 후 ORDER_LOCK 원장 기록
- 주문 취소 시 lock 해제 후 ORDER_CANCEL_RELEASE 원장 기록
- 체결 정산 시 TRADE_BUY_QUOTE_SETTLE, TRADE_BUY_BASE_CREDIT, TRADE_SELL_BASE_SETTLE, TRADE_SELL_QUOTE_CREDIT 4종 원장 기록
- GET /api/v1/wallets: 사용자 전체 지갑 잔액 조회
- GET /api/v1/wallets/ledgers: 원장 내역 조회 (asset 쿼리 파라미터로 필터)
주문 저장 후 원장을 기록하도록 순서 변경하여 order.getId()를 orderId로 전달
- GET /api/v1/wallets, GET /api/v1/wallets/ledgers API 응답 검증
- 주문 생성 시 ORDER_LOCK 원장 기록 검증
- 주문 취소 시 ORDER_CANCEL_RELEASE 원장 기록 검증
- 체결 시 TRADE_BUY/SELL 4종 원장 기록 검증
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 14, 2026

Caution

Review failed

Pull request was closed or merged during review

📝 Walkthrough

Walkthrough

This PR implements a complete wallet ledger auditing system that records all wallet state changes triggered by order operations. New domain layer defines ledger event types and persistence; OrderService is extended to emit ledger entries at lock, unlock, and settlement stages; REST API exposes wallet balances and ledger history with asset filtering; and integration tests verify correctness of ledger creation across order lifecycle events.

Changes

Wallet Ledger Tracking System

Layer / File(s) Summary
Ledger domain contracts and DTOs
src/main/java/com/coinflow/wallet/domain/LedgerType.java, src/main/java/com/coinflow/wallet/domain/WalletLedger.java, src/main/java/com/coinflow/wallet/repository/WalletLedgerRepository.java, src/main/java/com/coinflow/wallet/dto/WalletResponse.java, src/main/java/com/coinflow/wallet/dto/WalletLedgerResponse.java
LedgerType enum defines event taxonomy; WalletLedger entity and repository support append-only persistence; response DTOs serialize wallet state and ledger entries with string-formatted balances and deltas.
Ledger recording in order lifecycle
src/main/java/com/coinflow/order/service/OrderService.java
OrderService injects WalletLedgerRepository and creates ledger entries: ORDER_LOCK on order creation, ORDER_CANCEL_RELEASE on cancellation, and four settlement entries (buyer/seller quote settle + base credit) per matched trade, each linked by order/trade id.
Wallet query service and REST endpoints
src/main/java/com/coinflow/wallet/service/WalletService.java, src/main/java/com/coinflow/wallet/api/WalletController.java
WalletService queries wallets and ledgers with optional asset filtering; WalletController exposes GET endpoints at /api/v1/wallets and /api/v1/wallets/ledgers, extracting authenticated user id from JWT and delegating to service.
Wallet ledger integration tests
src/test/java/com/coinflow/wallet/WalletApiTest.java
Test suite verifies wallet/ledger endpoint access control, ledger list retrieval with asset filtering, and ledger side effects: ORDER_LOCK on order creation, ORDER_CANCEL_RELEASE on cancellation, and settlement entries for buyer/seller across KRW and BTC assets with correct delta values.

Sequence Diagram

sequenceDiagram
  participant Client
  participant WalletController
  participant WalletService
  participant OrderService
  participant WalletLedgerRepository
  Client->>WalletController: GET /api/v1/wallets (with JWT)
  WalletController->>WalletService: getWallets(userId)
  WalletService->>WalletService: map Wallet to WalletResponse
  WalletService-->>WalletController: List<WalletResponse>
  WalletController-->>Client: 200 wallets
  Client->>WalletController: GET /api/v1/wallets/ledgers?asset=BTC
  WalletController->>WalletService: getLedgers(userId, "BTC")
  WalletService->>WalletLedgerRepository: filtered query by userId+asset
  WalletService->>WalletService: map WalletLedger to WalletLedgerResponse
  WalletService-->>WalletController: List<WalletLedgerResponse>
  WalletController-->>Client: 200 ledger entries
  Client->>OrderService: create order (lock funds)
  OrderService->>WalletLedgerRepository: save ORDER_LOCK entry
  OrderService-->>Client: order created
  Client->>OrderService: cancel order (release funds)
  OrderService->>WalletLedgerRepository: save ORDER_CANCEL_RELEASE entry
  OrderService-->>Client: order canceled
Loading

Estimated Code Review Effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly Related PRs

  • ohhalim/CoinFlow#9: Extends the same OrderService.settle() method to add trade creation; main PR further extends that settlement path to persist ledger entries for each trade leg.
  • ohhalim/CoinFlow#7: Implements the initial order lifecycle (createOrder, cancelOrder) with wallet lock/unlock; main PR adds ledger recording checkpoints to those same methods.

Poem

🐰 A ledger appears, so clean and bright,
Every coin's movement, forever in sight,
From lock to release, each trade makes a mark—
No mystery left in the wallet's arc!
Append-only truth, forever we keep. ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 14.29% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title correctly describes the main changes: implementing wallet ledger recording and adding wallet/ledger query APIs.
Linked Issues check ✅ Passed The PR successfully implements all coding requirements from issue #10: WalletLedger entity/repository, LedgerType enum, ledger recording in order lifecycle (ORDER_LOCK, ORDER_CANCEL_RELEASE, TRADE settlement), and both wallet/ledger REST APIs with asset filtering.
Out of Scope Changes check ✅ Passed All changes are aligned with the scope of issue #10. No unrelated modifications detected; changes address wallet ledger infrastructure, API endpoints, and integration tests only.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/9/wallet-ledger

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@ohhalim
Copy link
Copy Markdown
Owner Author

ohhalim commented May 14, 2026

LGTM?

@ohhalim ohhalim merged commit 69c8d09 into develop May 14, 2026
1 of 2 checks passed
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.

[Feat]: WalletLedger 엔티티 및 원장 기록 구현

1 participant