blockchain.blockchain package

Submodules

blockchain.blockchain.block module

class blockchain.blockchain.block.Block(index: int, data: blockchain.blockchain.data.Data, proof: int, previous_hash: str)[source]

Bases: object

__bytes__() → bytes[source]

Uses the encoded string representation of this Block object as bytes representation.

Returns:byte representation of Block object.
Return type:bytes
__eq__(other: object) → bool[source]

Method for comparing two Block objects.

Parameters:other (Block) – Block object to compare with self.
Returns:True if blocks are equal. False otherwise.
Return type:bool
__repr__() → str[source]

String representation of Block object.

Returns:String representation of Block object.
Return type:str
data
index
previous_hash
proof
timestamp

blockchain.blockchain.blockchain module

class blockchain.blockchain.blockchain.Blockchain(path_to_chain: str, json_format: bool, force_new_chain: bool)[source]

Bases: object

_load_chain() → None[source]

Helper method to load chain from disk. Raises an error if no chain is found.

Raises:ChainNotFoundError – Will be raised if no local chain could be found.
add_new_block(data: blockchain.blockchain.data.Data, proof: int, previous_hash: str) → blockchain.blockchain.block.Block[source]

Adds a new Block to the existing chain.

Parameters:
  • data (Data) – Data that is attached to this block.
  • proof (int) – The proof value for this block.
  • previous_hash (str) – Hash value of previous block in chain.
chain
genesis_block = | ================================================================================ | index: 0 | time: 1581268480.1071372 | proof: None | prev. hash: None | __________________________________________________________________ | data: | id: 7134c40e0c604549b68bf48b63608fc8 | | message: This is the workload of the very first Block in this chain! | _________________________________________________________________ | ================================================================================
genesis_block_hash = '9ac2b6f3f9f89f0686727a82f8c783e03bb8c4a4486ebe7288710d4b6426e98b'
json_format
last_block
path_to_chain
save_chain() → None[source]

Helper method to save chain to disk. Creates intermediate directories and backups an existing chain file if necessary.

blockchain.blockchain.data module

class blockchain.blockchain.data.Data(message: str)[source]

Bases: object

__hash__()[source]

Needed to use Set``s of ``Data objects.

id
message

Module contents