add docstring for ReqHandler, rearrange methods
@@ -2,18 +2,35 @@ from binascii import unhexlify
from plenum.common.types import f
from plenum.common.request import Request
-from typing import Tuple, List
+from typing import List
from plenum.common.ledger import Ledger
from plenum.common.state import State
-from typing import Optional
class ReqHandler:
+ """
+ Base class for request handlers
+ Declares methods for validation, application of requests and
+ state control
+ """
- def __init__(self, ledger: Ledger, state: Optional[State] = None):
+ def __init__(self, ledger: Ledger, state: State):
self.ledger = ledger
self.state = state
+ def validateReq(self, req: Request, config):
+ pass
+
+ def applyReq(self, req: Request):
+ pass
+
+ def updateState(self, txns, isCommitted=False):
+ """
+ Updates current state with a number of committed or
+ not committed transactions
+ """
+ pass
+
def commit(self, txnCount, stateRoot, txnRoot) -> List:
"""
Commit a number of transactions
@@ -24,7 +41,8 @@ class ReqHandler:
:return: list of committed transactions
"""
- (seqNoStart, seqNoEnd), committedTxns = self.ledger.commitTxns(txnCount)
+ (seqNoStart, seqNoEnd), committedTxns = self.ledger.commitTxns(
+ txnCount)
stateRoot = unhexlify(stateRoot.encode())
txnRoot = self.ledger.hashToStr(unhexlify(txnRoot.encode()))
assert self.ledger.root_hash == txnRoot
@@ -33,16 +51,3 @@ class ReqHandler:
for txn, seqNo in zip(committedTxns, seqNos):
txn[f.SEQ_NO.nm] = seqNo
return committedTxns
\ No newline at end of file
-
- def validateReq(self, req: Request, config):
- pass
-
- def applyReq(self, req: Request):
- pass
-
- def updateState(self, txns, isCommitted=False):
- """
- Updates current state with a number of committed or
- not committed transactions
- """
- pass
