Skip to content

Commit 2046ea4

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent 82064e3 commit 2046ea4

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

blockchain/proof_of_stake.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import random
22

3+
34
class Validator:
45
def __init__(self, name: str, stake: int) -> None:
56
"""
@@ -12,6 +13,7 @@ def __init__(self, name: str, stake: int) -> None:
1213
self.name = name
1314
self.stake = stake
1415

16+
1517
def choose_validator(validators: list[Validator]) -> Validator:
1618
"""
1719
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:
3234
"""
3335
total_stake = sum(v.stake for v in validators)
3436
weighted_validators = [(v, v.stake / total_stake) for v in validators]
35-
selected = random.choices([v[0] for v in weighted_validators],
36-
weights=[v[1] for v in weighted_validators])
37+
selected = random.choices(
38+
[v[0] for v in weighted_validators], weights=[v[1] for v in weighted_validators]
39+
)
3740
return selected[0]

0 commit comments

Comments
 (0)