src.blockchain

Definition of block chains.

Classes

Blockchain() A block chain: a ordered, immutable list of valid blocks.
class src.blockchain.Blockchain

A block chain: a ordered, immutable list of valid blocks. The only ways to create a blockchain instance are the constructor, which will create a block chain containing only the genesis block, and the try_append method which creates a new block chain only if the given block is valid on top of self.

Variables:
  • blocks (List[Block]) – The blocks in this chain, oldest first.
  • block_indices (Dict[bytes, int]) – A dictionary allowing efficient lookup of the index of a block in this block chain by its hash value.
  • unspent_coins (Dict[TransactionInput, TransactionTarget]) – A dictionary mapping from (allowed/available) transaction inputs to the transaction output that created this coin.
compute_blockreward_next_block()

Compute the block reward that is expected for the block following this chain’s head.

Return type:int
compute_difficulty_next_block()

Compute the desired difficulty for the block following this chain’s head.

Return type:int
get_block_by_hash(hash_val)

Returns a block by its hash value, or None if it cannot be found.

Return type:Optional[Block]
head

The head of this block chain.

Return type:Block
try_append(block)

If block is valid on top of this chain, returns a new block chain including that block. Otherwise, it returns None.

Return type:Optional[Blockchain]