mirror of
https://github.com/blackboxprogramming/BlackRoad-Operating-System.git
synced 2026-03-17 06:57:17 -05:00
Merge commit '509747d4d9a6310520542db16b004b6c7cd049a5'
This commit is contained in:
@@ -3,7 +3,7 @@ from fastapi import APIRouter, Depends, HTTPException, status, BackgroundTasks
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
from sqlalchemy import select, and_, or_, desc, func
|
||||
from typing import List, Optional
|
||||
from pydantic import BaseModel
|
||||
from pydantic import BaseModel, Field
|
||||
from datetime import datetime
|
||||
|
||||
from app.database import get_db
|
||||
@@ -16,9 +16,12 @@ from app.services.crypto import WalletKeyDecryptionError
|
||||
router = APIRouter(prefix="/api/blockchain", tags=["Blockchain"])
|
||||
|
||||
|
||||
MIN_TRANSACTION_AMOUNT = 0.0001
|
||||
|
||||
|
||||
class TransactionCreate(BaseModel):
|
||||
to_address: str
|
||||
amount: float
|
||||
amount: float = Field(gt=0, description="Amount to transfer; must be positive")
|
||||
message: Optional[str] = None
|
||||
|
||||
|
||||
@@ -93,6 +96,18 @@ async def create_transaction(
|
||||
db: AsyncSession = Depends(get_db)
|
||||
):
|
||||
"""Create a new transaction"""
|
||||
if tx_data.amount <= 0:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_400_BAD_REQUEST,
|
||||
detail="Transaction amount must be greater than zero"
|
||||
)
|
||||
|
||||
if tx_data.amount < MIN_TRANSACTION_AMOUNT:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_400_BAD_REQUEST,
|
||||
detail=f"Transactions must be at least {MIN_TRANSACTION_AMOUNT} tokens"
|
||||
)
|
||||
|
||||
# Check balance
|
||||
if current_user.balance < tx_data.amount:
|
||||
raise HTTPException(
|
||||
@@ -128,6 +143,11 @@ async def create_transaction(
|
||||
)
|
||||
|
||||
# Update balances (simplified - in production would be done on block confirmation)
|
||||
if tx_data.amount <= 0:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_400_BAD_REQUEST,
|
||||
detail="Transaction amount must be greater than zero"
|
||||
)
|
||||
current_user.balance -= tx_data.amount
|
||||
recipient.balance += tx_data.amount
|
||||
|
||||
|
||||
Reference in New Issue
Block a user