
- Built complete CEX platform with FastAPI and Python - JWT-based authentication system with secure password hashing - Multi-currency crypto wallet support (BTC, ETH, USDT) - Fiat account management (USD, EUR, GBP) - Local transaction signing without external APIs - Comprehensive transaction handling (send/receive/deposit/withdraw) - SQLAlchemy models with Alembic migrations - Security middleware (rate limiting, headers, logging) - Input validation and sanitization - Encrypted private key storage with PBKDF2 - Standardized codebase architecture with service layer pattern - Complete API documentation with health endpoints - Comprehensive README with setup instructions Features: - User registration and authentication - Crypto wallet creation and management - Secure transaction signing using local private keys - Fiat deposit/withdrawal system - Transaction history and tracking - Rate limiting and security headers - Input validation for all endpoints - Error handling and logging
84 lines
2.6 KiB
Python
84 lines
2.6 KiB
Python
from fastapi import APIRouter, Depends, HTTPException, status
|
|
from sqlalchemy.orm import Session
|
|
from typing import List
|
|
from app.schemas.wallet import WalletCreate, WalletResponse, FiatAccountCreate, FiatAccountResponse
|
|
from app.services.wallet import WalletService
|
|
from app.services.auth import get_current_user
|
|
from app.db.session import get_db
|
|
from app.models.user import User
|
|
|
|
router = APIRouter(prefix="/wallets", tags=["Wallets"])
|
|
|
|
|
|
@router.post("/crypto", response_model=WalletResponse)
|
|
def create_crypto_wallet(
|
|
wallet_data: WalletCreate,
|
|
current_user: User = Depends(get_current_user),
|
|
db: Session = Depends(get_db)
|
|
):
|
|
wallet_service = WalletService(db)
|
|
wallet = wallet_service.create_crypto_wallet(current_user, wallet_data)
|
|
return wallet
|
|
|
|
|
|
@router.post("/fiat", response_model=FiatAccountResponse)
|
|
def create_fiat_account(
|
|
account_data: FiatAccountCreate,
|
|
current_user: User = Depends(get_current_user),
|
|
db: Session = Depends(get_db)
|
|
):
|
|
wallet_service = WalletService(db)
|
|
account = wallet_service.create_fiat_account(current_user, account_data)
|
|
return account
|
|
|
|
|
|
@router.get("/crypto", response_model=List[WalletResponse])
|
|
def get_crypto_wallets(
|
|
current_user: User = Depends(get_current_user),
|
|
db: Session = Depends(get_db)
|
|
):
|
|
wallet_service = WalletService(db)
|
|
wallets = wallet_service.get_user_wallets(current_user)
|
|
return wallets
|
|
|
|
|
|
@router.get("/fiat", response_model=List[FiatAccountResponse])
|
|
def get_fiat_accounts(
|
|
current_user: User = Depends(get_current_user),
|
|
db: Session = Depends(get_db)
|
|
):
|
|
wallet_service = WalletService(db)
|
|
accounts = wallet_service.get_user_fiat_accounts(current_user)
|
|
return accounts
|
|
|
|
|
|
@router.get("/crypto/{wallet_id}", response_model=WalletResponse)
|
|
def get_crypto_wallet(
|
|
wallet_id: int,
|
|
current_user: User = Depends(get_current_user),
|
|
db: Session = Depends(get_db)
|
|
):
|
|
wallet_service = WalletService(db)
|
|
wallet = wallet_service.get_wallet_by_id(wallet_id, current_user)
|
|
if not wallet:
|
|
raise HTTPException(
|
|
status_code=status.HTTP_404_NOT_FOUND,
|
|
detail="Wallet not found"
|
|
)
|
|
return wallet
|
|
|
|
|
|
@router.get("/fiat/{account_id}", response_model=FiatAccountResponse)
|
|
def get_fiat_account(
|
|
account_id: int,
|
|
current_user: User = Depends(get_current_user),
|
|
db: Session = Depends(get_db)
|
|
):
|
|
wallet_service = WalletService(db)
|
|
account = wallet_service.get_fiat_account_by_id(account_id, current_user)
|
|
if not account:
|
|
raise HTTPException(
|
|
status_code=status.HTTP_404_NOT_FOUND,
|
|
detail="Fiat account not found"
|
|
)
|
|
return account |