forked from hyperledger/indy-plenum
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
INDY-2302: Add a new txn TXN_AUTHOR_AGREEMENT_DISABLE
Signed-off-by: toktar <renata.toktar@dsr-corporation.com>
- Loading branch information
Showing
19 changed files
with
235 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
from abc import ABCMeta | ||
|
||
from common.serializers.serialization import config_state_serializer | ||
from plenum.common.constants import TXN_AUTHOR_AGREEMENT, CONFIG_LEDGER_ID, TXN_AUTHOR_AGREEMENT_VERSION, \ | ||
TXN_AUTHOR_AGREEMENT_TEXT, TXN_AUTHOR_AGREEMENT_DIGEST, TXN_AUTHOR_AGREEMENT_RETIRED, \ | ||
TXN_AUTHOR_AGREEMENT_TIMESTAMP | ||
from plenum.common.exceptions import InvalidClientRequest | ||
from plenum.common.request import Request | ||
from plenum.common.txn_util import get_payload_data, get_seq_no, get_txn_time | ||
from plenum.common.util import SortedDict | ||
from plenum.server.database_manager import DatabaseManager | ||
from plenum.server.request_handlers.handler_interfaces.write_request_handler import WriteRequestHandler | ||
from plenum.server.request_handlers.static_taa_helper import StaticTAAHelper | ||
from plenum.server.request_handlers.utils import encode_state_value, decode_state_value | ||
|
||
|
||
class BaseTAAHandler(WriteRequestHandler, metaclass=ABCMeta): | ||
|
||
def _update_txn_author_agreement(self, digest, seq_no, txn_time, text=None, version=None, retired=None): | ||
taa_time = None | ||
ledger_taa = self.get_from_state(StaticTAAHelper.state_path_taa_digest(digest))[0] | ||
if ledger_taa: | ||
taa_time = ledger_taa.get(TXN_AUTHOR_AGREEMENT_TIMESTAMP) | ||
text = ledger_taa.get(TXN_AUTHOR_AGREEMENT_TEXT) | ||
version = ledger_taa.get(TXN_AUTHOR_AGREEMENT_VERSION) | ||
|
||
state_value = { | ||
TXN_AUTHOR_AGREEMENT_TEXT: text, | ||
TXN_AUTHOR_AGREEMENT_VERSION: version, | ||
TXN_AUTHOR_AGREEMENT_DIGEST: digest | ||
} | ||
if retired: | ||
state_value[TXN_AUTHOR_AGREEMENT_RETIRED] = retired | ||
state_value[TXN_AUTHOR_AGREEMENT_TIMESTAMP] = txn_time if taa_time is None else taa_time | ||
|
||
data = encode_state_value(state_value, seq_no, txn_time, | ||
serializer=config_state_serializer) | ||
|
||
self.state.set(StaticTAAHelper.state_path_taa_digest(digest), data) | ||
self.state.set(StaticTAAHelper.state_path_taa_version(version), digest) | ||
if not retired: | ||
self.state.set(StaticTAAHelper.state_path_taa_latest(), digest) | ||
|
||
# self.state.set(StaticTAAHelper.state_path_taa_digest(digest), data) | ||
# self.state.set(StaticTAAHelper.state_path_taa_latest(), digest) | ||
# self.state.set(StaticTAAHelper.state_path_taa_version(version), digest) | ||
|
||
def authorize(self, request): | ||
StaticTAAHelper.authorize(self.database_manager, request) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
plenum/server/request_handlers/txn_author_agreement_disable_handler.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
from common.serializers.serialization import config_state_serializer | ||
from plenum.common.constants import TXN_AUTHOR_AGREEMENT, CONFIG_LEDGER_ID, TXN_AUTHOR_AGREEMENT_VERSION, \ | ||
TXN_AUTHOR_AGREEMENT_TEXT, TXN_AUTHOR_AGREEMENT_DIGEST, TXN_AUTHOR_AGREEMENT_RETIRED, \ | ||
TXN_AUTHOR_AGREEMENT_TIMESTAMP, TXN_AUTHOR_AGREEMENT_DISABLE | ||
from plenum.common.exceptions import InvalidClientRequest | ||
from plenum.common.request import Request | ||
from plenum.common.txn_util import get_payload_data, get_seq_no, get_txn_time | ||
from plenum.common.util import SortedDict | ||
from plenum.server.database_manager import DatabaseManager | ||
from plenum.server.request_handlers.base_taa_handler import BaseTAAHandler | ||
from plenum.server.request_handlers.handler_interfaces.write_request_handler import WriteRequestHandler | ||
from plenum.server.request_handlers.static_taa_helper import StaticTAAHelper | ||
from plenum.server.request_handlers.utils import encode_state_value, decode_state_value | ||
import time | ||
|
||
from state.trie.pruning_trie import rlp_decode | ||
|
||
|
||
class TxnAuthorAgreementDisableHandler(BaseTAAHandler): | ||
|
||
def __init__(self, database_manager: DatabaseManager): | ||
super().__init__(database_manager, TXN_AUTHOR_AGREEMENT_DISABLE, CONFIG_LEDGER_ID) | ||
self.retired_time = int(time.time() // (2600 * 24)) | ||
|
||
def static_validation(self, request: Request): | ||
pass | ||
|
||
def dynamic_validation(self, request: Request): | ||
self._validate_request_type(request) | ||
self.authorize(request) | ||
operation, identifier, req_id = request.operation, request.identifier, request.reqId | ||
if not self.state.get(StaticTAAHelper.state_path_taa_latest(), isCommitted=False): | ||
raise InvalidClientRequest(identifier, req_id, | ||
"Transaction author agreement is already disabled.") | ||
|
||
def update_state(self, txn, prev_result, request, is_committed=False): | ||
self._validate_txn_type(txn) | ||
seq_no = get_seq_no(txn) | ||
txn_time = get_txn_time(txn) | ||
_, taa_list = self.state.generate_state_proof_for_keys_with_prefix(StaticTAAHelper.state_path_taa_digest(""), | ||
serialize=False, get_value=True) | ||
for encode_key, encode_data in taa_list.items(): | ||
# taa = rlp_decode(encode_data) | ||
# taa = self._decode_state_value(taa[0])[0] | ||
digest = encode_key.decode().split(":")[-1] | ||
self._update_txn_author_agreement(digest, seq_no, txn_time, retired=self.retired_time) | ||
self.state.remove(StaticTAAHelper.state_path_taa_latest()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
plenum/test/input_validation/test_client_taa_disable_op.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
from collections import OrderedDict | ||
|
||
from plenum.common.constants import TXN_AUTHOR_AGREEMENT_DISABLE | ||
from plenum.common.messages.client_request import ClientTxnAuthorAgreementDisableOperation | ||
from plenum.common.messages.fields import ConstantField | ||
|
||
TAA_DELAY_EXPECTED_ORDERED_FIELDS = OrderedDict([ | ||
("type", ConstantField), | ||
]) | ||
|
||
|
||
def check_schema(actual, expected): | ||
assert list(actual.keys()) == list(expected.keys()) | ||
for field, validator in expected.items(): | ||
assert isinstance(actual[field], validator) | ||
|
||
|
||
def test_taa_has_expected_schema(): | ||
schema = OrderedDict(ClientTxnAuthorAgreementDisableOperation.schema) | ||
check_schema(schema, TAA_DELAY_EXPECTED_ORDERED_FIELDS) | ||
assert schema["type"].value == TXN_AUTHOR_AGREEMENT_DISABLE |
Oops, something went wrong.