Implement wallet transfer service with idempotency, ledger, and concurrency safety - #106
Open
ashish-kumar-1 wants to merge 14 commits into
Open
Implement wallet transfer service with idempotency, ledger, and concurrency safety#106ashish-kumar-1 wants to merge 14 commits into
ashish-kumar-1 wants to merge 14 commits into
Conversation
…potent replay, ledger correctness
…ansfer for concurrent duplicate keys
…epoint-guarded idempotency claims
There was a problem hiding this comment.
Pull request overview
Implements a small Go HTTP wallet-to-wallet transfer service with idempotent request handling, double-entry ledger posting, and concurrency-safe balance updates, along with a Postgres-backed repository, an in-memory test store, and a basic server wiring.
Changes:
- Added
TransferServiceimplementing validation, idempotency claim/replay, wallet locking, balance updates, ledger posting, and transfer state transitions. - Introduced a repository contract (
TxStore/Tx) with Postgres and in-memory implementations plus a Postgres schema. - Added unit, HTTP handler, and concurrency tests plus supporting documentation.
Reviewed changes
Copilot reviewed 17 out of 18 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| WALLET_TRANSFER_README.md | Documents architecture, schema, idempotency, concurrency, and how to run/test |
| internal/service/transfer_service.go | Core transfer business logic: idempotency + locking + ledger workflow |
| internal/service/transfer_service_test.go | Service-level tests for validation, idempotency, failure modes, and ledger balancing |
| internal/service/concurrency_test.go | Concurrency tests for overdraw prevention and duplicate idempotency keys |
| internal/repository/repository.go | Defines persistence interfaces and idempotency record contract |
| internal/repository/postgres/postgres.go | Postgres implementation: row locks, savepointed idempotency claim, persistence operations |
| internal/repository/memory/memory.go | In-memory TxStore for tests |
| internal/idgen/idgen.go | Random ID generation helper used for transfers/ledger entries |
| internal/handler/http_handler.go | HTTP transport layer mapping domain/service errors to HTTP responses |
| internal/handler/http_handler_test.go | HTTP handler tests for status codes and idempotent replay |
| internal/domain/wallet.go | Wallet entity definition |
| internal/domain/transfer.go | Transfer state machine + ledger entry domain types |
| internal/domain/errors.go | Domain sentinel errors consumed by handler/service |
| db/schema.sql | Postgres DDL for wallets, transfers, ledger entries, idempotency records |
| cmd/server/main.go | Server wiring: DB, store, service, handler, routing |
| go.mod | Go module definition and pgx dependency |
| go.sum | Dependency checksums |
| AI_USAGE.md | AI usage disclosure template |
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.
Summary
Describe your solution briefly.
AI disclosure
Detail how you used AI to help with your submission (including the tools you used, how
you used them and what your prompts were).
Include these points in detail
Schema Design
Describe the tables, constraints, and indexes you introduced.
Idempotency Strategy
Explain how duplicate requests are handled safely.
Concurrency Strategy
Explain how you prevent race conditions and double spending.
How to Run
How to Test
Tradeoffs / Assumptions
Checklist