Skip to content

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 

Repository files navigation

DecodeLabs Blockchain Project 1 — Mini-Blockchain Implementation

Project Overview

This repository contains Project 1 (Mini-Blockchain) from the DecodeLabs Blockchain Technology internship program. It is built purely using Python 3 and standard library modules (hashlib, json, time, unittest).


Key Features & Architecture

1. Block Structure (blockchain.py)

  • index (int): Sequential block number.
  • timestamp (float): Unix epoch creation timestamp.
  • data (Any): Transaction payload string or object.
  • previous_hash (str): 64-character SHA-256 hash of the preceding block ("0" for Genesis).
  • nonce (int): Counter variable used in Proof of Work mining.
  • hash (str): Deterministic SHA-256 string generated via calculate_hash().

2. Blockchain Manager (blockchain.py)

  • Maintains an append-only block list (self.chain).
  • Automatically initializes Block #0 (Genesis Block).
  • add_block(data): Mines and appends a new block linked to the latest block.
  • is_chain_valid(): Cryptographically verifies stored hashes, chain pointers, and Proof of Work targets.

3. Proof of Work Mining

  • Implements mine_block(difficulty) where difficulty = 4.
  • Iteratively increments nonce until hash.startswith("0" * difficulty).

How to Run

Note for macOS users: Use python3 instead of python in your terminal commands.

1. Run Main Demonstration

python3 main.py

2. Run Comprehensive Unit Tests

python3 test_blockchain.py

or:

python3 -m unittest

About

Decodelabd internship project 1

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages