blockchain.client package¶
Submodules¶
blockchain.client.miner module¶
-
class
blockchain.client.miner.Miner(path_to_chain: str, json_format: bool, port: int, difficulty: int, neighbours: list, force_new_chain: bool)[source]¶ Bases:
object-
_check_for_longest_chain() → None[source]¶ Consensus Algorithm:
Ask eachneighbourfor thatneighbours. Add all unknown miner toneighboursset until maximum amount of neighbours is reached.
-
_fetch_unprocessed_data() → None[source]¶ Periodical thread to get unprocessed data form neighbours. => Broadcasts unprocessed data around the network.
-
static
_hash(block: blockchain.blockchain.block.Block) → str[source]¶ Hash a
Blockobject with SHA-256.Parameters: block (Block) – Object of class Blockto hash.Returns: Hex representation of blockhash.Return type: str Raises: ValueError– Will be raised if noBlockobject is passed.
-
_is_chain_valid(chain: list = None) → bool[source]¶ - Checks if the given
chainsatisfies the following rules: - The first (genesis) block:
index= 0previous_hash= Noneproof= None
- each and every following block:
index: step size 1 and monotonically increasing (1, 2, 3, 4, …)previous_hash: SHA-256 of the string representation of the preceding blockproof: has to be valid -> see:is_proof_of_work_valid()timestamp: higher than the timestamp of of preceding block
Parameters: chain (list) – Optional chain if Noneinternal representation is used.Returns: Trueifchainis valid,Falseotherwise.Return type: bool - Checks if the given
-
_is_data_processed(data: blockchain.blockchain.data.Data) → bool[source]¶ Checks if
datais already in local chain.Parameters: data (Data) – Dataobject to check if it exists in the actual chain.Returns: Trueif unprocessed.Return type: bool
-
static
_is_proof_of_work_valid(last_proof: int, proof: int, difficulty: int) → bool[source]¶ Checks if the proof of work was correct. The hash value of
last_proofconcatenated withproofhas to bedifficultytrailing 0s.Parameters: Returns: Trueif proof of work is correct,Falseotherwise.Return type: Raises: ValueError– Will be raised ifdifficultyis not a positive integer value.
-
_mine() → None[source]¶ Blocking Mining loop.
If
not_processed_messagesare available it uses a random message an mines a new block.
-
_new_message(message: str) → None[source]¶ - Adds the new
messageto its local cache.Parameters: message (str) –
-
_proof_of_work(last_proof: int, difficulty: int) → int[source]¶ Simple proof of work:
Find a numberpthat when hashed with the previousblock’s solution a hash withdifficultytrailing 0s is produced.Parameters: Returns: Solution for this proof of work quiz.
Return type: Raises: ValueError– Will be raised ifdifficultyis not a positive integer value.
-
_update_neighbours() → None[source]¶ Periodical thread to update neighbours if limit is not exceeded.
-
blockchain¶
-
difficulty¶
-
jobs¶
-
neighbours¶
-
port¶
-
queue¶
-
server_process¶
-
start() → None[source]¶ Starts some background
Jobs for the Gossip Protocol, Chain syncing, Data syncing, communication thread as well as the server functionalities as process. Starts the blocking functionmine().
-
stop() → None[source]¶ Function that gets called when Python was killed. Takes care to shutting down all threads/process and saves the chain to disc.
-
unprocessed_data¶
-