| 1 | # Use-case 0003 Implementation — Deposit
|
|---|
| 2 |
|
|---|
| 3 | **Initiating actor:** Trader. **Source file:** `server/account.go`, function `Deposit`.
|
|---|
| 4 |
|
|---|
| 5 | ## Scenario (implemented)
|
|---|
| 6 |
|
|---|
| 7 | 1. **User** chooses `[2] Deposit virtual funds`.
|
|---|
| 8 | 2. **System** prompts for an amount in USD.
|
|---|
| 9 | 3. **User** enters `2500`.
|
|---|
| 10 | 4. **System** opens a database transaction and runs:
|
|---|
| 11 |
|
|---|
| 12 | ```sql
|
|---|
| 13 | BEGIN;
|
|---|
| 14 | UPDATE users
|
|---|
| 15 | SET available_balance = available_balance + $1,
|
|---|
| 16 | updated_at = now()
|
|---|
| 17 | WHERE id = $2;
|
|---|
| 18 | INSERT INTO transactions (user_id, type, amount, currency, description)
|
|---|
| 19 | VALUES ($2, 'deposit', $1, 'USD', 'Virtual deposit');
|
|---|
| 20 | COMMIT;
|
|---|
| 21 | ```
|
|---|
| 22 |
|
|---|
| 23 | 
|
|---|
| 24 |
|
|---|
| 25 | 5. **System** confirms: `Deposited 2500.0000 USD.`
|
|---|
| 26 |
|
|---|
| 27 | ## Verification
|
|---|
| 28 |
|
|---|
| 29 | Right after the deposit, `[1] View balance` runs:
|
|---|
| 30 |
|
|---|
| 31 | ```sql
|
|---|
| 32 | SELECT available_balance, invested_balance FROM users WHERE id = $1;
|
|---|
| 33 | ```
|
|---|
| 34 |
|
|---|
| 35 | In the screenshot above, alice starts from the seed state (available 8250.00,
|
|---|
| 36 | invested 1750.00) and ends at available **10750.00** — increased by exactly the
|
|---|
| 37 | 2500.00 deposited, with `invested_balance` untouched.
|
|---|