blockchain.proof_of_stake ========================= .. py:module:: blockchain.proof_of_stake Classes ------- .. autoapisummary:: blockchain.proof_of_stake.Validator Functions --------- .. autoapisummary:: blockchain.proof_of_stake.choose_validator Module Contents --------------- .. py:class:: Validator(name: str, stake: int) .. py:attribute:: name .. py:attribute:: stake .. py:function:: choose_validator(validators: list[Validator]) -> Validator Selects a validator to create the next block based on the weight of their stake. The higher the stake, the greater the chance to be selected. Args: validators (list[Validator]): A list of Validator objects. Returns: Validator: The selected validator based on weighted random selection. Example: >>> validators = [Validator("Alice", 50), Validator("Bob", 30)] >>> chosen = choose_validator(validators) >>> isinstance(chosen, Validator) True