========== Blockchain ========== This is the documentation of **Blockchain** a simple implementation in Python to get familiar with Python and the basic concepts of Blockchains. **Short Disclaimer:** It is just a private ``Python 3.7.2`` project. Its purposes is to get a little bit familiar with the Python projects and the concepts of Blockchains. Therefore it is not intended for production usage, and any warranties are excluded. Getting Started =============== The easiest way to get up a single miner or a whole blockchain network is to use Docker. This repository offers the needed ``Dockerfile`` and ``docker-compose.yaml`` in the directory ``docker``. Do the following steps: 1. Change to ``docker`` directory 2. Run ``docker build --no-cache -t blockchain .`` 3. Run ``docker-compose up`` This starts a Blockchain network with 3 miners and forwards their ports (12345, 12346, 12347) to your host system. It uses the directory ``~/.blockchain/`` on your host system to save the created files for each miner. Install the CLI Locally ----------------------- 1. Clone this repository: ``git clone git@github.com:se-jaeger/blockchain.git`` 2. Open the clone directory: ``cd blockchain`` 3. Create a virtual env: ``python -m venv venv`` 4. Activate the virtual env: ``source venv/bin/activate`` 5. Install all dependencies: ``pip install -r requirements.txt`` 6. Install the ``blockchain`` CLI, run the following in the root directory of this project: ``pip install -e .`` 7. Check available commands: ``blockchain --help`` How Does This Blockchain Implementation Work? ============================================= This implementation produces a simple ``CLI``, ``Miner`` and ``UI``. It is necessary to get up and running a local Miner. The CLI, as well as the UI, uses the Miners ``REST`` interface to interact with it. Created ``messages`` get synchronized with all other known Miners (``neighbours``) in the Blockchain network. A Miner asks all its neighbours periodically (if not max amount of neighbours is reached) to send unknown Miner and connects to them. Also in a periodical manner, Miner synchronizes their local Blockchain with the chains of there neighbours and use the longest valid chain in the network. Miner Implementation -------------------- **This Miner implementation offers a REST API with the following endpoints:** - ``/add`` (PUT): needs the URL parameter ``message``. Adds the message to the local cache of unprocessed data. - ``response`` (200): JSON with message: 'Message added!' - ``response`` (400): JSON with message: 'No Message added!' - ``/chain`` (GET): Returns the miners local chain. - ``response`` (200): JSON with the actual chain and its length. - ``/neighbours`` (GET): Returns the miners neighbours. - ``response`` (200): JSON with the actual neighbours and its length. - ``/data`` (GET): Returns the miners local cache of unprocessed data. - ``response`` (200): JSON with the actual list of unprocessed data. | **The miner uses a set of files for normal operation:** - ``.chain``: Representation of the actual file. - ``.hash``: ``SHA-256`` of the actual chain file. Is used to check if the local chain differs from its on disc representation. - ``__