mirror of
https://github.com/blackboxprogramming/BlackRoad-Operating-System.git
synced 2026-03-17 02:57:12 -05:00
Use timezone-aware timestamps and update tests
This commit is contained in:
@@ -12,6 +12,8 @@ import httpx
|
||||
from enum import Enum
|
||||
import logging
|
||||
|
||||
from app.utils import utc_now
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@@ -93,23 +95,23 @@ class APIClient:
|
||||
if response.status_code < 500:
|
||||
self.status = APIStatus.CONNECTED
|
||||
self.error_message = None
|
||||
self.last_check = datetime.utcnow()
|
||||
self.last_check = utc_now()
|
||||
return True
|
||||
else:
|
||||
self.status = APIStatus.ERROR
|
||||
self.error_message = f"Server error: {response.status_code}"
|
||||
self.last_check = datetime.utcnow()
|
||||
self.last_check = utc_now()
|
||||
return False
|
||||
|
||||
except httpx.TimeoutException:
|
||||
self.status = APIStatus.ERROR
|
||||
self.error_message = "Connection timeout"
|
||||
self.last_check = datetime.utcnow()
|
||||
self.last_check = utc_now()
|
||||
return False
|
||||
except Exception as e:
|
||||
self.status = APIStatus.ERROR
|
||||
self.error_message = str(e)
|
||||
self.last_check = datetime.utcnow()
|
||||
self.last_check = utc_now()
|
||||
logger.error(f"Health check failed for {self.name}: {e}")
|
||||
return False
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
"""Blockchain service"""
|
||||
import hashlib
|
||||
import json
|
||||
from datetime import datetime
|
||||
from typing import List, Optional
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
from sqlalchemy import select, desc
|
||||
@@ -9,6 +8,7 @@ from app.models.blockchain import Block, Transaction, Wallet
|
||||
from app.models.user import User
|
||||
from app.config import settings
|
||||
from app.services.crypto import wallet_crypto, WalletKeyDecryptionError
|
||||
from app.utils import utc_now
|
||||
import secrets
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ class BlockchainService:
|
||||
if existing:
|
||||
return existing
|
||||
|
||||
timestamp = datetime.utcnow()
|
||||
timestamp = utc_now()
|
||||
genesis_hash = BlockchainService.calculate_hash(0, str(timestamp), "0", [], 0)
|
||||
|
||||
genesis_block = Block(
|
||||
@@ -69,7 +69,7 @@ class BlockchainService:
|
||||
latest_block = await BlockchainService.create_genesis_block(db)
|
||||
|
||||
new_index = latest_block.index + 1
|
||||
timestamp = datetime.utcnow()
|
||||
timestamp = utc_now()
|
||||
previous_hash = latest_block.hash
|
||||
difficulty = settings.BLOCKCHAIN_DIFFICULTY
|
||||
|
||||
@@ -117,7 +117,7 @@ class BlockchainService:
|
||||
tx.block_index = new_block.index
|
||||
tx.is_confirmed = True
|
||||
tx.confirmations = 1
|
||||
tx.confirmed_at = datetime.utcnow()
|
||||
tx.confirmed_at = utc_now()
|
||||
|
||||
# Reward miner
|
||||
user.balance += settings.MINING_REWARD
|
||||
@@ -152,7 +152,7 @@ class BlockchainService:
|
||||
) from exc
|
||||
|
||||
# Generate transaction hash
|
||||
tx_data = f"{from_address}{to_address}{amount}{datetime.utcnow()}"
|
||||
tx_data = f"{from_address}{to_address}{amount}{utc_now()}"
|
||||
transaction_hash = hashlib.sha256(tx_data.encode()).hexdigest()
|
||||
|
||||
# Sign transaction (simplified)
|
||||
|
||||
Reference in New Issue
Block a user