From 0b0c24f418ffe4009227bb3ebb87aa4d6119fa5f Mon Sep 17 00:00:00 2001 From: KOSASIH Date: Tue, 6 Aug 2024 13:29:26 +0700 Subject: [PATCH] Create consensus.py --- blockchain/consensus/consensus.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 blockchain/consensus/consensus.py diff --git a/blockchain/consensus/consensus.py b/blockchain/consensus/consensus.py new file mode 100644 index 000000000..f580d7494 --- /dev/null +++ b/blockchain/consensus/consensus.py @@ -0,0 +1,13 @@ +from .pos import ProofOfStake +from .dpos import DelegatedProofOfStake + +def create_consensus(consensus_type: str, validators: list, block_time: int = 10): + if consensus_type == "pos": + return ProofOfStake(validators, block_time) + elif consensus_type == "dpos": + return DelegatedProofOfStake(validators, block_time) + else: + raise ValueError("Invalid consensus type") + +def run_consensus(consensus): + consensus.run_consensus()