Metadata-Version: 2.0
Name: tinyblock
Version: 0.1.4
Summary: A simple blockchain package.
Home-page: https://github.com/zshvvhm/tinyblock
Author: zshvvhm
Author-email: zshvvhm95@gmail.com
License: MIT
Project-URL: Source, https://github.com/zshvvhm/tinyblock
Project-URL: Bug Reports, https://github.com/zshvvhm/tinyblock/issues
Description-Content-Type: UNKNOWN
Keywords: simple tiny blockchain
Platform: UNKNOWN
Classifier: Topic :: Software Development
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 2
Classifier: Programming Language :: Python :: 2.6
Classifier: Programming Language :: Python :: 2.7
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.3
Classifier: Programming Language :: Python :: 3.4
Classifier: Programming Language :: Python :: 3.5
Classifier: Programming Language :: Python :: 3.6
Classifier: Programming Language :: Python :: 3.7
Requires-Python: >=2.6, !=3.0.*, !=3.1.*, !=3.2.*, <4

Tiny Block: A Simple Blockchain
================================

.. image:: https://travis-ci.org/zshvvhm/tinyblock.svg?branch=master
    :target: https://travis-ci.org/zshvvhm/tinyblock

.. image:: https://img.shields.io/pypi/v/tinyblock.svg
    :target: https://pypi.python.org/pypi/tinyblock

.. image:: https://img.shields.io/pypi/l/tinyblock.svg
    :target: https://pypi.python.org/pypi/tinyblock

.. image:: https://img.shields.io/pypi/pyversions/tinyblock.svg
    :target: https://pypi.python.org/pypi/tinyblock

Installation
------------

Install and update using `pip`_:

.. code-block:: bash

    $ pip install tinyblock

Block
-------------

.. code-block:: python

    dict({'previous_hash'(str): '...',
          'timestamp'(int): '...',
          'data'(any): '...',
          'nonce'(int): '...',
          'next_hash'(str): '...'})

Usage
-------------

* Define a simple blockchain:

  .. code-block:: python

      from tinyblock import tinyblock
      #The initial variable should be a list of blocks. If not set it, the default chain would be an empty list.
      my_blockchain = tinyblock()

* Add a block to the chain:

  .. code-block:: python

      #The parameter is the data of this block
      my_blockchain.add('This is a block.')

* Find a block with statement:

  .. code-block:: python

      #Find the blocks with features below. The return elements will content the index in origin chain list.
      #Completely match: previous_hash, nonce, next_hash.
      #Partly match: data. (Currently support str, int, float, list, dict, bool and tuple)
      #Range match: timestamp.(Could be an int, list or tuple)
      my_blockchain.find(previous_hash='', timestamp='', data='', nonce='', next_hash='')

* Pop the last block of the chain:

  .. code-block:: python

      my_blockchain.pop()

* Check wether the blockchain is anything correct:

  .. code-block:: python

      my_blockchain.chainCheck(print_option=True)

* Fix the blockchain(with start and stop index):

  .. code-block:: python

      my_blockchain.chainFix(start=0, stop=4)

* Get the block list:

  .. code-block:: python

      my_blockchain.getChain()

* Customise the rule for mining new block:

  .. code-block:: python

      #The default rule is hash start with '0000'.
      #To change the rule, you can override the mineRule function.
      def newRule(hash):
          if hash[0:5] == '0'*5:
              return True
          return False

      my_blockchain.mineRule = newRule

.. _pip: https://pip.pypa.io/en/stable/quickstart/

