A production-grade, hybrid blockchain system designed for secure election auditing. It combines a private MySQL database for voter privacy and temporary storage with a public (anonymized) ledger for immutable verification.
- Hybrid Architecture: Private voting data (MySQL) + Public verification ledger (JSON/Decentralized).
- Cryptographic Integrity: SHA-256 salted hashing ensures votes cannot be tampered with.
- Privacy Preserving: Voter identities are salted and hashed before entering the public ledger.
- Production Ready: Includes connection pooling, logging, and robust error handling.
You can install this package directly from GitHub:
pip install git+https://github.com/E-voting-Using-Blockchain/Election-Hybrid-Blockchain-pkg.gitOr clone and install locally:
git clone https://github.com/E-voting-Using-Blockchain/Election-Hybrid-Blockchain-pkg.git
cd election-blockchain
pip install .Run the setup wizard to configure your .env and optionally import an existing SQL database:
python setup_wizard.py- Database Setup: Ensure you have MySQL running.
- Environment Variables: Create a
.envfile in your project root:
DB_HOST=localhost
DB_USER=root
DB_PASSWORD=your_password
DB_NAME=Blockchain
DB_POOL_SIZE=5
HASH_SALT=ProductionSecretKey_ChangeMeInRealLife!
LOG_LEVEL=INFO
PUBLIC_LEDGER_PATH=public_ledgerSee examples/simulation.py for a full runner.
from election_blockchain.block.blockchain import HybridBlockchain
from election_blockchain.config import setup_logging
# 1. Setup Logging
setup_logging()
# 2. Initialize
chain = HybridBlockchain()
# 3. Authorize Node
chain.authorize_node("Official_Node_1")
# 4. Submit Vote (Private)
chain.submit_vote("voter_secure_id", "Candidate A")
# 5. Mine Block (Public)
chain.mine_block("Official_Node_1")The system automatically checks hash integrity on load. You can also manually verify:
print(chain.is_chain_valid())You can run this anytime you suspect external manipulation:
python maintenance_scripts/restore_public_data.pyor
restore_public_data()election_blockchain/: Main package source.block/: Blockchain logic (Block, Chain).database/: storage logic (MySQL Pool).config.py: Configuration loader.
public_ledger/: Default storage for decentralized blocks.examples/: Usage demonstrations.
Ensure HASH_SALT is complex and kept secret. If HASH_SALT is leaked, voter anonymity could be compromised via brute-force attacks on the public ledger timestamps.