Giter VIP home page Giter VIP logo

blockchain's Introduction

Build Status Maintainability Test Coverage

Summary

This project is work in progress on a fully TDD basic implementation of blockchain in Python.

Technologies

  • Python (Main language)
  • Flask (RESTful API for nodes)
  • Pytest (TDD)
  • Travis (CI)
  • Docker (Container)
  • Serverspec (TDD of docker build)

Design

Proof of work

Proof of work is based on locating a SHA256 hash of the current transactions, previous hash and a proof that begins with a definied sequence. In this case (to ensure non stubbed testing works in a reasonable time while development takes place) the proof is a simple 00. Over time additional digits can be required which increases the difficulty of finding the proof. Once obtained it is trivial to proof the block as confirming the hash once the proof is provided is computationally easy.

Public/Private Key encryption

Each wallet is produced with a public/private key pair. The public key is used as the wallet address whilst the private key should be kept securely. When sending a transaction the sender signs it with their private key and this can be verified with the public key for authenticity.

API

  • / GET - Homepage
  • /blockchain GET - Returns a json response of the entire blockchain
  • /mine POST - Mines a block
  • /wallet POST - Creates new public and private keys
  • /wallet GET - Loads existing public and private keys
  • /balance GET - Gets current balance
  • /peer POST - Adds a remote peer to this nodes peer list
  • /peer/ DELETE - Removes a peer from this nodes peer list
  • /peers GET - Returns the list of this nodes peers
  • /broadcast POST - Allows a transaction to be broadcast to this node from another peer node

Running a single node

To fire up a single node there is a lightweight Dockerfile based on Alpine linux which runs a node. To build clone the repo and run this locally:

docker build -t blockchain_node:latest . 
docker run -d -p 4000:4000 blockchain_node

You can then connect to http://localhost:4000 using postman and the APIs detailed above.

TODOS

  • Detail the APIs in more detail and add documentation of the backend design
  • Create docker-compose to automatically fire up multiple nodes
  • Add functionality to allow nodes to share created blocks with other nodes
  • Add functionality to allow a new node to sync to other nodes
  • Add SPA front end to control nodes locally and eliminate the need to use Postman
  • Add node autodiscovery so other nodes don't need to be added manually
  • Add increasing hash difficulty
  • Add docstrings

Credits

blockchain's People

Contributors

dependabot[bot] avatar thielsen avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.