File size: 1,362 Bytes
ac46d48
bd98803
 
 
 
 
 
 
ac46d48
bd98803
 
ac46d48
bd98803
 
 
 
ac46d48
bd98803
 
 
ac46d48
bd98803
ac46d48
 
 
 
 
 
037c74d
 
ac46d48
 
 
 
 
 
 
 
 
 
 
 
 
bd98803
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49

#!/usr/bin/env python3
"""
Verify blockchain integrity and consistency.
"""

import sys
import json
import logging
from pathlib import Path

# Add parent directory to path
sys.path.insert(0, str(Path(__file__).parent.parent))

from blockchain.virtual_ledger import VirtualLedger

logging.basicConfig(level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s")

def main():
    """Verify blockchain integrity."""
    logging.info("Starting blockchain verification...")
    
    try:
        ledger = VirtualLedger()
        
        # Verify chain integrity
        is_valid = ledger.is_chain_valid()
        
        status_msg = "✓ VALID" if is_valid else "✗ INVALID"
        logging.info(f"Blockchain Integrity: {status_msg}")
        logging.info(f"Chain length: {len(ledger.chain)}")
        logging.info(f"Pending transactions: {len(ledger.pending_transactions)}")
        logging.info(f"Total NES minted: {ledger.nes_supply}")
        
        if not is_valid:
            logging.error("Blockchain integrity check failed!")
            return 1
        
        logging.info("Blockchain verification completed successfully!")
        return 0
        
    except Exception as e:
        logging.error(f"Critical error during blockchain verification: {e}", exc_info=True)
        return 1


if __name__ == "__main__":
    sys.exit(main())