diff --git a/.gitignore b/.gitignore index 0cc252c..fed61f6 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ venv/ build/ dist/ blockshell/ +blockshell.egg-info/ diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..d5be28f --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2018 Daxeel Soni + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md index 398b024..9ba3058 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,71 @@ -# blockshell -A command line utility for learning Blockchain. +# BlockShell +A command line utility for learning Blockchain technical concepts likechaining, mining, proof of work etc. + + + + +## About +Anyone who wants to understand how blockchain technology works, then BlockShell should be a great start. Because I have created BlockShell keeping blockchain fundamentals in the center of development. With BlockShell you will actually create a tiny blockchain in your system where you can create blocks with data, explore blocks etc. + +So, by using BlockShell anyone can learn following blockchain concepts, +* Block & Chaining +* Hashing +* Mining +* Proof of Work + +## BlockShell Web Explorer +

BlockShell comes with built-in blockchain explorer by which you can actully see how blocks are mined and what is stored and where.

+ +Latest Mined Blocks | Block Details +:------------------------------:|:-------------------------: +![](https://preview.ibb.co/iZa5jG/Screen_Shot_2018_01_25_at_11_25_22_PM.png) | ![](https://preview.ibb.co/cDB0Jb/Screen_Shot_2018_01_25_at_11_25_35_PM.png) + +## Installation +Step 1 - Create project directory +``` +mkdir && cd project_name +``` + +Step 2 - Create new virtual environment +``` +virtualenv venv +``` + +Step 3 - Activate virtual environment +``` +source venv/bin/activate +``` + +Step 4 - Clone this repo +``` +git clone https://github.com/daxeel/blockshell.git +``` + +Step 5 - Change directory to cloned one +``` +cd blockshell +``` + +Step 6 - Install blockshell +``` +python setup.py install +``` + +Step 7 - Try "blockshell" command and test installation! +``` +blockshell +``` + +Output in terminal after calling BlockShell command + + +## Lanuch BlockShell Web +Step 1 - Start new terminal window, go to cloned directory + +Step 2 - Start web.py +``` +python web.py +``` + +Step 3 - Go to 127.0.0.1:5000 address in browser and boom! + diff --git a/bscli.py b/bscli.py index 4423018..4c02c65 100644 --- a/bscli.py +++ b/bscli.py @@ -1,11 +1,25 @@ # -*- coding: utf-8 -*- -# import modules +# ================================================== +# ==================== META DATA =================== +# ================================================== +__author__ = "Daxeel Soni" +__url__ = "https://daxeel.github.io" +__email__ = "daxeelsoni44@gmail.com" +__license__ = "MIT" +__version__ = "0.1" +__maintainer__ = "Daxeel Soni" + +# ================================================== +# ================= IMPORT MODULES ================= +# ================================================== import click import urllib import json from blockchain.chain import Block, Blockchain -# Supported commands +# ================================================== +# ===== SUPPORTED COMMANDS LIST IN BLOCKSHELL ====== +# ================================================== SUPPORTED_COMMANDS = [ 'dotx', 'allblocks', @@ -19,9 +33,14 @@ coin = Blockchain() # Create group of commands @click.group() def cli(): + """ + Create a group of commands for CLI + """ pass -# Start lbc cli +# ================================================== +# ============= BLOCKSHELL CLI COMMAND ============= +# ================================================== @cli.command() @click.option("--difficulty", default=3, help="Difine dufficulty level of blockchain.") def init(difficulty): @@ -36,19 +55,23 @@ def init(difficulty): > A command line utility for learning Blockchain concepts. > Type 'help' to see supported commands. + > Project by Daxeel Soni - https://daxeel.github.io """ # Set difficulty of blockchain coin.difficulty = difficulty - # Start lbc chell + # Start blockshell shell while True: cmd = raw_input("[BlockShell] $ ") processInput(cmd) -# Process input from LBC shell +# Process input from Blockshell shell def processInput(cmd): + """ + Method to process user input from Blockshell CLI. + """ userCmd = cmd.split(" ")[0] if len(cmd) > 0: if userCmd in SUPPORTED_COMMANDS: @@ -58,10 +81,14 @@ def processInput(cmd): msg = "Command not found. Try help command for documentation" throwError(msg) -# ------------------------------------ -# Supported Commands Methods -# ------------------------------------ + +# ================================================== +# =========== BLOCKSHELL COMMAND METHODS =========== +# ================================================== def dotx(cmd): + """ + Do Transaction - Method to perform new transaction on blockchain. + """ txData = cmd.split("dotx ")[-1] if "{" in txData: txData = json.loads(txData) @@ -69,12 +96,18 @@ def dotx(cmd): coin.addBlock(Block(data=txData)) def allblocks(cmd): + """ + Method to list all mined blocks. + """ print "" for eachBlock in coin.chain: print eachBlock.hash print "" def getblock(cmd): + """ + Method to fetch the details of block for given hash. + """ blockHash = cmd.split(" ")[-1] for eachBlock in coin.chain: if eachBlock.hash == blockHash: @@ -83,10 +116,16 @@ def getblock(cmd): print "" def help(cmd): + """ + Method to display supported commands in Blockshell + """ print "Commands:" print " dotx Create new transaction" print " allblocks Fetch all mined blocks in blockchain" print " getblock Fetch information about particular block" def throwError(msg): + """ + Method to throw an error from Blockshell. + """ print "Error : " + msg diff --git a/web.py b/web.py index ca809d5..1bf2c48 100644 --- a/web.py +++ b/web.py @@ -1,10 +1,28 @@ +# -*- coding: utf-8 -*- +# ================================================== +# ==================== META DATA =================== +# ================================================== +__author__ = "Daxeel Soni" +__url__ = "https://daxeel.github.io" +__email__ = "daxeelsoni44@gmail.com" +__license__ = "MIT" +__version__ = "0.1" +__maintainer__ = "Daxeel Soni" + +# ================================================== +# ================= IMPORT MODULES ================= +# ================================================== from flask import Flask, render_template, jsonify import json +# Init flask app app = Flask(__name__) @app.route('/') -def blocks(): +def mined_blocks(): + """ + Endpoint to list all mined blocks. + """ f = open("chain.txt", "r") data = json.loads(f.read()) f.close() @@ -12,6 +30,9 @@ def blocks(): @app.route('/block/') def block(hash): + """ + Endpoint which shows all the data for given block hash. + """ f = open("chain.txt", "r") data = json.loads(f.read()) f.close() @@ -19,6 +40,6 @@ def block(hash): if eachBlock['hash'] == hash: return render_template('blockdata.html', data=eachBlock) - +# Run flask app if __name__ == '__main__': app.run(debug=True)