From 2046ea45bcc55f7e76822984f0a3288ecc546a5b Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 10 Oct 2024 16:03:50 +0000 Subject: [PATCH] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- blockchain/proof_of_stake.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/blockchain/proof_of_stake.py b/blockchain/proof_of_stake.py index 1cb29ce1e..b988bfe2f 100644 --- a/blockchain/proof_of_stake.py +++ b/blockchain/proof_of_stake.py @@ -1,5 +1,6 @@ import random + class Validator: def __init__(self, name: str, stake: int) -> None: """ @@ -12,6 +13,7 @@ class Validator: self.name = name self.stake = stake + def choose_validator(validators: list[Validator]) -> Validator: """ Selects a validator to create the next block based on the weight of their stake. @@ -32,6 +34,7 @@ def choose_validator(validators: list[Validator]) -> Validator: """ total_stake = sum(v.stake for v in validators) weighted_validators = [(v, v.stake / total_stake) for v in validators] - selected = random.choices([v[0] for v in weighted_validators], - weights=[v[1] for v in weighted_validators]) + selected = random.choices( + [v[0] for v in weighted_validators], weights=[v[1] for v in weighted_validators] + ) return selected[0]