• Stars
    star
    186
  • Rank 207,316 (Top 5 %)
  • Language
    Python
  • License
    MIT License
  • Created over 7 years ago
  • Updated about 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A Python Implementation of a simple blockchain

Pysimplechain

Python implementation of a blockchain in less than 200 lines of code

A Python Implementation of a simple blockchain. Less than 200 lines of code.

Build Status

Description

The Pysimplechain implementation is focused almost exclusively in the hashed ledger feature. It does not include any advanced feature like a distributed ledger or a consensus protocol via proof of work. Here you'll also find that the idea of the "transaction" is abstracted to a more general concept of "message" that can contain any type of data.

For that reason, the goal of this project is to explain and to make clearer how is a blockchain structured at the very core. It's not built with the intention to replicate an advanced blockchain like Bitcoin or Ethereum.

The following blockchain implemented in the simple_chain.py file is composed of 3 classes. The Message() class, the Block() class and the Chain().

A message is the basic data container. It is sealed when added to a block and has 2 hashes that identify it: the payload hash and the block hash. Each message is linked to the previous message via hash pointers (the prev_hash attribute). The validate message method will ensure the integrity of each message, but will not check if the hash pointers are correct. This is left to the validate method in the Block() class.

A block can contain 1,...,n messages that are linked sequentially one after the other. When a block is added to the chain, it's sealed and validated to ensure that the messages are correctly ordered and the hash pointers match. Once the block is sealed and hashed, it is validated by checking the expected vs the actual.

A chain can contain 1,...,m blocks that are linked sequentially one after another. The chain integrity can be validated at any time calling the validate method, which will call each block's validate method and will raise an InvalidBlockchain exception.

Interactivity:

A manager() function is provided to interact with the blockchain via the Terminal/Console. The basic actions are:

  • Add Message to Block: Allows to add a message to the current block.
  • Add Block to Chain: Allows to add the current block to the chain if it's not empty.
  • Show Block: Asks for an index and if exists a block with that index, returns some of the block attributes.
  • Show Chain: Returns some of the block attributes for each block in the chain.
  • Validate Integrity: Returns True if the integrity is validated, terminates the program raisiing the appropiate exception otherwise.
  • Exit: Terminates the program and deletes the blockchain.

Contribute

Hey there! New ideas are welcome: open/close issues, fork the repo and share your code with a Pull Request.

Clone this project to your computer:

git clone https://github.com/EricAlcaide/pysimplechain

Meta

Eric Alcaide – @eric_alcaide – [email protected]

More Repositories

1

MiniFold

MiniFold: Deep Learning for Protein Structure Prediction inspired by DeepMind AlphaFold algorithm
Jupyter Notebook
199
star
2

Rosetta_Project

Algorithms implemented in Python, JS and Go. Feel free to add another language!
C
70
star
3

rgn2-replica

Replication attempt for the Protein Folding Model described in https://www.biorxiv.org/content/10.1101/2021.08.02.454840v1
Python
38
star
4

ClynMut

To be a next-generation DL-based phenotype prediction from genome mutations.
Python
19
star
5

E-swish

Code for reproducibility of the E-swish paper experiments
Jupyter Notebook
16
star
6

keras-wrn

A package of Wide Residual Networks for image recognition in Keras.
Python
16
star
7

Math_of_Intelligence

Codes uploaded while following The Math of Intelligence course by Siraj Raval on Youtube
Jupyter Notebook
12
star
8

SimpleNet-Keras

SimpleNet paper implementation in keras
Jupyter Notebook
9
star
9

SearchMethods.jl

The Julia package for Search Methods algorithms.
Julia
4
star
10

memcaption

Side project to create funny captions for memes
HTML
3
star
11

dl_restapi

Side project to create funny captions for memes http://memcaption.herokuapp.com
2
star
12

TNLM

Temporal Non-Local Means for Biomedical Image Processing implemented in both Python and Julia
Jupyter Notebook
2
star
13

generalized-readout-phase

This is the code for the PrePrint "Improving Graph Property Prediction with Generalized Readout Functions"
Jupyter Notebook
2
star
14

tr_files

This repository is plenty of useful codes in written in Python - TensorFlow
Jupyter Notebook
1
star
15

bioinformatics

A collection of code developed while learning the basics of Bioinformatics
Jupyter Notebook
1
star
16

DSB2018

Code for the Kaggle Dta Science Bowl 2018
Jupyter Notebook
1
star
17

twittersimplesearch

Simple & Anonymous Twitter Search Engine
HTML
1
star