This project implements a simple blockchain and a basic API to interact with it. The blockchain includes functionalities for mining new blocks, creating new transactions, and achieving consensus among nodes.
- Genesis Block Creation: The first block, known as the genesis block, is created with a predefined proof and previous hash.
- Transaction Management: Add new transactions that will be recorded in the next mined block.
- Mining: Implement a simple proof-of-work algorithm to mine new blocks and add them to the blockchain.
- Node Registration: Nodes can be registered to the network.
- Consensus Algorithm: Implement a basic consensus algorithm to resolve conflicts by ensuring the longest valid chain is adopted.
-
Clone the repository:
git clone https://github.com/CollectingMangos/MangoChain.git cd MangoChain -
Create and activate a virtual environment:
python3 -m venv venv source venv/bin/activate -
Install dependencies:
pip install -r requirements.txt
To start the MangoChain application, run the main.py file:
python main.pyThe application will start running on http://0.0.0.0:9000.
- URL:
/mine_block - Method:
GET - Description: Mines a new block and adds it to the Mangochain.
-
URL:
/add_new_transaction -
Method:
POST -
Description: Adds a new transaction to the next mined block.
-
Request Body:
{ "sender": "address_of_sender", "recipient": "address_of_recipient", "amount": {int} }
- URL:
/return_chain - Method:
GET - Description: Returns the current state of the Mangochain.
-
URL:
/register_node -
Method:
POST -
Description: Registers a new node to the network.
-
Request Body:
{ "nodes": ["http://192.168.0.5:5000", "http://192.168.0.6:5000"] }
- URL:
/resolve_node - Method:
GET - Description: Resolves conflicts by replacing the chain with the longest one in the network.
main.py: The main entry point for running the application.blockchain.py: Contains the main logic for the Mangochain including block creation, transaction management, mining, and consensus algorithm.mineBlock.py: Handles the endpoint for mining new blocks.addNewTransaction.py: Handles the endpoint for adding new transactions.registerNode.py: Handles the endpoint for registering new nodes.resolveNode.py: Handles the endpoint for resolving conflicts.exampleOfBlock.txt: An example of a block structure.requirements.txt: Contains the project dependencies.
- Flask: A micro web framework for Python.
- Requests: A simple HTTP library for Python.
- Hashlib: A library for hashing in Python.
- Json: A library for handling JSON data.
- UUID: A library for generating unique identifiers.
- Urllib: A library for URL parsing.
This project is licensed under the MIT License.