def get_result(self, request: Request): version = request.operation.get(GET_TXN_AUTHOR_AGREEMENT_AML_VERSION) timestamp = request.operation.get( GET_TXN_AUTHOR_AGREEMENT_AML_TIMESTAMP) if version is not None: path = StaticTAAHelper.state_path_taa_aml_version(version) data, proof = self._get_value_from_state(path, with_proof=True) return self._return_txn_author_agreement_aml(request, proof, data=data) if timestamp is not None: head_hash = self.database_manager.ts_store.get_equal_or_prev( timestamp, CONFIG_LEDGER_ID) if head_hash is None: return self._return_txn_author_agreement_aml(request, None) head_hash = head_hash if head_hash else self.state.committedHeadHash data, proof = self._get_value_from_state( StaticTAAHelper.state_path_taa_aml_latest(), head_hash, with_proof=True) return self._return_txn_author_agreement_aml(request, proof, data=data) path = StaticTAAHelper.state_path_taa_aml_latest() data, proof = self._get_value_from_state(path, with_proof=True) return self._return_txn_author_agreement_aml(request, proof, data=data)
def set_aml(txn_author_agreement_handler): txn_author_agreement_handler.state.set( StaticTAAHelper.state_path_taa_aml_latest(), encode_state_value("value", "seqNo", "txnTime", serializer=config_state_serializer))
def _update_txn_author_agreement_acceptance_mechanisms( self, payload, seq_no, txn_time): serialized_data = encode_state_value( payload, seq_no, txn_time, serializer=config_state_serializer) version = payload[AML_VERSION] self.state.set(StaticTAAHelper.state_path_taa_aml_latest(), serialized_data) self.state.set(StaticTAAHelper.state_path_taa_aml_version(version), serialized_data)
def update_state(self, txn, prev_result, request, is_committed=False): self._validate_txn_type(txn) payload = get_payload_data(txn) seq_no = get_seq_no(txn) txn_time = get_txn_time(txn) serialized_data = encode_state_value(payload, seq_no, txn_time, serializer=config_state_serializer) version = payload[AML_VERSION] self.state.set(StaticTAAHelper.state_path_taa_aml_latest(), serialized_data) self.state.set(StaticTAAHelper.state_path_taa_aml_version(version), serialized_data)
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 self.state.get(StaticTAAHelper.state_path_taa_aml_latest()) is None: raise InvalidClientRequest(identifier, req_id, "TAA txn is forbidden until TAA AML is set. Send TAA AML first.") version = operation[TXN_AUTHOR_AGREEMENT_VERSION] if StaticTAAHelper.get_taa_digest(self.state, version, isCommitted=False) is not None: raise InvalidClientRequest(identifier, req_id, "Changing existing version of transaction author agreement is forbidden")
def dynamic_validation(self, request: Request, req_pp_time: Optional[int]): self._validate_request_type(request) self.authorize(request) operation, identifier, req_id = request.operation, request.identifier, request.reqId aml_latest, _, _ = self.get_from_state(StaticTAAHelper.state_path_taa_aml_latest()) if aml_latest is None: raise InvalidClientRequest(identifier, req_id, "TAA txn is forbidden until TAA AML is set. Send TAA AML first.") version = operation[TXN_AUTHOR_AGREEMENT_VERSION] digest = StaticTAAHelper.get_taa_digest(self.state, version, isCommitted=False) if digest is None: if req_pp_time is None: raise LogicError("Cannot validate TAA transaction outside of normal ordering") self._validate_add_taa(request, req_pp_time) else: self._validate_update_taa(request, digest)
def test_update_state(txn_author_agreement_aml_handler, domain_state, aml_request): seq_no = 1 txn_time = 1560241033 txn_id = "id" txn = reqToTxn(aml_request) payload = get_payload_data(txn) version = payload[AML_VERSION] append_txn_metadata(txn, seq_no, txn_time, txn_id) txn_author_agreement_aml_handler.update_state(txn, None, aml_request) assert txn_author_agreement_aml_handler.get_from_state( StaticTAAHelper.state_path_taa_aml_latest()) == (payload, seq_no, txn_time) assert txn_author_agreement_aml_handler.get_from_state( StaticTAAHelper.state_path_taa_aml_version(version)) == (payload, seq_no, txn_time)
def set_aml(txn_author_agreement_handler): txn_author_agreement_handler.state.set( StaticTAAHelper.state_path_taa_aml_latest(), "value")