
- 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
83 lines
2.9 KiB
Python
83 lines
2.9 KiB
Python
from fastapi import APIRouter, Depends, HTTPException, status, Query
|
|
from sqlalchemy.orm import Session
|
|
from typing import List
|
|
from app.schemas.transaction import TransactionCreate, TransactionResponse, FiatTransactionCreate, FiatTransactionResponse
|
|
from app.services.transaction import TransactionService
|
|
from app.services.auth import get_current_user
|
|
from app.db.session import get_db
|
|
from app.models.user import User
|
|
|
|
router = APIRouter(prefix="/transactions", tags=["Transactions"])
|
|
|
|
|
|
@router.post("/crypto/send", response_model=TransactionResponse)
|
|
def send_crypto(
|
|
transaction_data: TransactionCreate,
|
|
current_user: User = Depends(get_current_user),
|
|
db: Session = Depends(get_db)
|
|
):
|
|
transaction_service = TransactionService(db)
|
|
transaction = transaction_service.send_crypto(current_user, transaction_data)
|
|
return transaction
|
|
|
|
|
|
@router.post("/fiat/deposit", response_model=FiatTransactionResponse)
|
|
def deposit_fiat(
|
|
transaction_data: FiatTransactionCreate,
|
|
current_user: User = Depends(get_current_user),
|
|
db: Session = Depends(get_db)
|
|
):
|
|
transaction_service = TransactionService(db)
|
|
transaction = transaction_service.deposit_fiat(current_user, transaction_data)
|
|
return transaction
|
|
|
|
|
|
@router.post("/fiat/withdraw", response_model=FiatTransactionResponse)
|
|
def withdraw_fiat(
|
|
transaction_data: FiatTransactionCreate,
|
|
current_user: User = Depends(get_current_user),
|
|
db: Session = Depends(get_db)
|
|
):
|
|
transaction_service = TransactionService(db)
|
|
transaction = transaction_service.withdraw_fiat(current_user, transaction_data)
|
|
return transaction
|
|
|
|
|
|
@router.get("/crypto", response_model=List[TransactionResponse])
|
|
def get_crypto_transactions(
|
|
limit: int = Query(50, ge=1, le=100),
|
|
offset: int = Query(0, ge=0),
|
|
current_user: User = Depends(get_current_user),
|
|
db: Session = Depends(get_db)
|
|
):
|
|
transaction_service = TransactionService(db)
|
|
transactions = transaction_service.get_user_transactions(current_user, limit, offset)
|
|
return transactions
|
|
|
|
|
|
@router.get("/fiat", response_model=List[FiatTransactionResponse])
|
|
def get_fiat_transactions(
|
|
limit: int = Query(50, ge=1, le=100),
|
|
offset: int = Query(0, ge=0),
|
|
current_user: User = Depends(get_current_user),
|
|
db: Session = Depends(get_db)
|
|
):
|
|
transaction_service = TransactionService(db)
|
|
transactions = transaction_service.get_user_fiat_transactions(current_user, limit, offset)
|
|
return transactions
|
|
|
|
|
|
@router.get("/crypto/{transaction_id}", response_model=TransactionResponse)
|
|
def get_crypto_transaction(
|
|
transaction_id: int,
|
|
current_user: User = Depends(get_current_user),
|
|
db: Session = Depends(get_db)
|
|
):
|
|
transaction_service = TransactionService(db)
|
|
transaction = transaction_service.get_transaction_by_id(transaction_id, current_user)
|
|
if not transaction:
|
|
raise HTTPException(
|
|
status_code=status.HTTP_404_NOT_FOUND,
|
|
detail="Transaction not found"
|
|
)
|
|
return transaction |