diff --git a/e-voting-system/backend/routes/votes.py b/e-voting-system/backend/routes/votes.py index 0422d57..9953b9c 100644 --- a/e-voting-system/backend/routes/votes.py +++ b/e-voting-system/backend/routes/votes.py @@ -480,6 +480,7 @@ async def get_blockchain( Récupérer l'état complet de la blockchain pour une élection. Retourne tous les blocs et l'état de vérification. + Requête d'abord aux validateurs PoA, puis fallback sur blockchain locale. """ # Vérifier que l'élection existe election = services.ElectionService.get_election(db, election_id) @@ -489,6 +490,18 @@ async def get_blockchain( detail="Election not found" ) + # Try to get blockchain state from PoA validators first + try: + async with BlockchainClient() as poa_client: + blockchain_data = await poa_client.get_blockchain_state(election_id) + if blockchain_data: + logger.info(f"Got blockchain state from PoA for election {election_id}") + return blockchain_data + except Exception as e: + logger.warning(f"Failed to get blockchain from PoA: {e}") + + # Fallback to local blockchain manager + logger.info(f"Falling back to local blockchain for election {election_id}") blockchain = blockchain_manager.get_or_create_blockchain(election_id) return blockchain.get_blockchain_data()