Skip to content

Carson-NNY/Blockchain--Voting-System

Repository files navigation

<<<<<<< HEAD Project: Blockchain Voting System

Instruction: DESIGN.md should describe the blockchain design, p2p protocol, and the demo application design.

Group member: Kechen Liu Guanhong Liu Kento Yanagishita

Task split: Kechen Liu: core blockchain design , peer node & tracker, CLI & web UI, tests Guanhong Liu: blockchain design Kento Yanagishita: p2p protocol design

  • keys/ — key‑generation helper for voter identities
  • tracker.py — bootstrap server that tracks live peers
  • p2p.py — simple TCP broadcast helper
  • blockchain.py — in‑memory chain, PoW mining, dynamic difficulty, fork handling
  • merkle.py — Merkle‑tree root computation
  • tx.pyVoteTx class with ECDSA signing & verification
  • node.py — peer node process: P2P, mining, block verification, CLI RPCs
  • cli.py — command‑line client for vote, tally, verify
  • web_ui.py, templates/, static/ — Flask web interface with Bootstrap & Chart.js
  • requirements.txt — Python dependencies

⚙️ Setup & Installation

  1. Clone & enter the project:

    git clone <the‑repo‑url> project_folder
    cd project_folder
    
  2. Create a virtual environment (recommended) and install dependencies: python3 -m venv .venv source .venv/bin/activate pip install -r requirements.txt

  3. Generate voter key‑pairs (one per voter ID):

python3 keys/generate_keys.py alice python3 keys/generate_keys.py bob python3 keys/generate_keys.py charlie

This produces:

keys/alice.pem (private key)

keys/alice.pub.pem (public key)

Running the System

  1. Start the Tracker python3 tracker.py

→ Tracker listening on 9000

  1. Launch Peer Nodes Open three separate terminals: python3 node.py --id node1 --port 8001 python3 node.py --id node2 --port 8002 python3 node.py --id node3 --port 8003

CLI Usage Even though I created a web_ui, u can still use the CLI client if you prefer:

  1. Cast a vote (choice IDs match your web_ui.py mapping, e.g. 0=Alice, 1=Bob, 2=Charlie): python3 cli.py vote --id alice --node 127.0.0.1:8001 --choice 0

→ Submitted vote for choice 0; your txid is ab12cd34…

  1. Check the tally: python3 cli.py tally --node 127.0.0.1:8001

→ {"0":1,"1":0,"2":0}

3.Verify a transaction: python3 cli.py verify --node 127.0.0.1:8001 --txid ab12cd34…

→ {"block":1,"timestamp":1681234567}

Web UI Usage 1.Install Flask: pip install flask

  1. Start the web server: python3 web_ui.py

3.Open your browser at http://localhost:5000:

Cast Vote: select your voter ID & candidate, submit → txid flash

Tally: view live bar chart (auto‑refresh if configured)

Verify: paste a txid to see its block & timestamp

Configuration Candidates list is defined near the top of web_ui.py (or loaded from candidates.json if you choose).

Dynamic difficulty targets ~5 s per block and adjusts up/down in blockchain.py.

Extra Credit Features Dynamic difficulty (auto‑tune to target block time)

Merkle‑tree vote inclusion

Fork resolution via heaviest‑chain rule

Beautiful web UI with Bootstrap and Chart.js

CLI fallback for scripting and testing

=======

Blockchain-Voting-System

origin/main

Blockchain--Voting-System

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors