blockchain.simple_proof_of_work =============================== .. py:module:: blockchain.simple_proof_of_work .. autoapi-nested-parse:: Proof of Work (PoW) implementation. This algorithm is used in blockchain technology to reach consensus and secure the network Attributes ---------- .. autoapisummary:: blockchain.simple_proof_of_work.example_tx Functions --------- .. autoapisummary:: blockchain.simple_proof_of_work.proof_of_work Module Contents --------------- .. py:function:: proof_of_work(block_number: int, transactions: str, previous_hash: str, difficulty: int) -> tuple[int, str] Finds a nonce such that the SHA-256 hash of the block starts with a specific number of zeros (difficulty). >>> proof_of_work(1, "test", "abc", 1)[1].startswith("0") True >>> # Consistency check: same input must produce same output >>> res1 = proof_of_work(1, "data", "hash", 2) >>> res2 = proof_of_work(1, "data", "hash", 2) >>> res1 == res2 True >>> # Difficulty 0 should return nonce 0 immediately >>> proof_of_work(1, "data", "hash", 0)[0] 0 .. py:data:: example_tx :value: 'Alice sends 1 BTC to Bob'