Code Monkey home page Code Monkey logo

python-blockchain's Introduction

Blockchain

A simple blockchain implementation using Python

There are 3 files in this repository:

  • main.py

    This is the main file that is used to run the program. Asks the user to input the number of blocks to add and then asks for the data for each of those blocks.

    The output of the file is as follows:

  index  time_of_block_creation
  data_entered
  block_sha256_hash
  • block.py

    Contains the Block class. Has a calculate_hash method that creates an SHA-256 hash using the index, timestamp, previous hash and the data entered and returns it. Also has a real_time method that simply takes the timestamp and prints it out as readable date and time.

  • blockchain.py

    The __init__ method creates a new list with a genesis block.
    Contains is_valid method that checks if the new block has the correct hash and whether it is allowed to be added to the blockchain.
    The add_block method appends a new block to the chain if and only if it is valid (checked by is_valid).
    The print_blockchain method simply pretty prints the complete chain as shown in main.py.

alt text Running the program in the terminal

python-blockchain's People

Contributors

rajatdiptabiswas 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.