blockchain.proof_of_stake

Classes

Validator

Functions

choose_validator(→ Validator)

Selects a validator to create the next block based on the weight of their stake.

Module Contents

class blockchain.proof_of_stake.Validator(name: str, stake: int)
name
stake
blockchain.proof_of_stake.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