hyperledger/iroha
Iroha - A simple, decentralized ledger http://iroha.tech
signable_validator.hpp
Go to the documentation of this file.
1 
6 #ifndef IROHA_SHARED_MODEL_SIGNABLE_VALIDATOR_HPP
7 #define IROHA_SHARED_MODEL_SIGNABLE_VALIDATOR_HPP
8 
9 #include "validators/answer.hpp"
10 
11 namespace shared_model {
12  namespace validation {
13 
14  template <typename ModelValidator,
15  typename Model,
16  typename FieldValidator,
17  bool SignatureRequired = true>
18  class SignableModelValidator : public ModelValidator {
19  private:
20  template <typename Validator>
21  Answer validateImpl(const Model &model, Validator &&validator) const {
22  auto answer = std::forward<Validator>(validator)(model);
23  std::string reason_name = "Signature";
24  ReasonsGroupType reason(reason_name, GroupedReasons());
25  if (SignatureRequired or not model.signatures().empty()) {
26  field_validator_.validateSignatures(
27  reason, model.signatures(), model.payload());
28  }
29  if (not reason.second.empty()) {
30  answer.addReason(std::move(reason));
31  }
32  return answer;
33  }
34 
35  public:
37  FieldValidator &&validator = FieldValidator())
38  : ModelValidator(validator), field_validator_(std::move(validator)) {}
39 
40  Answer validate(const Model &model,
41  interface::types::TimestampType current_timestamp) const {
42  return validateImpl(model, [&, current_timestamp](const Model &m) {
43  return ModelValidator::validate(m, current_timestamp);
44  });
45  }
46 
47  Answer validate(const Model &model) const {
48  return validateImpl(
49  model, [&](const Model &m) { return ModelValidator::validate(m); });
50  }
51 
52  private:
53  FieldValidator field_validator_;
54  };
55  } // namespace validation
56 } // namespace shared_model
57 #endif // IROHA_SHARED_MODEL_SIGNABLE_VALIDATOR_HPP
SignableModelValidator(FieldValidator &&validator=FieldValidator())
Definition: signable_validator.hpp:36
Definition: signable_validator.hpp:18
Definition: peer.hpp:48
void validateSignatures(ReasonsGroupType &reason, const interface::types::SignatureRangeType &signatures, const crypto::Blob &source) const
Definition: field_validator.cpp:304
string(REPLACE".""/"CMAKE_SWIG_OUTDIR ${SWIG_JAVA_PKG}) else() set(CMAKE_SWIG_FLAGS"") endif() myswig_add_library(irohajava LANGUAGE java SOURCES bindings.i) unset(CMAKE_SWIG_FLAGS) swig_link_libraries(irohajava $
Definition: CMakeLists.txt:54
Answer validate(const Model &model) const
Definition: signable_validator.hpp:47
Answer validate(const Model &model, interface::types::TimestampType current_timestamp) const
Definition: signable_validator.hpp:40
std::vector< ConcreteReasonType > GroupedReasons
Definition: answer.hpp:20
std::pair< ReasonsGroupName, GroupedReasons > ReasonsGroupType
Definition: answer.hpp:22
Definition: command_executor.hpp:12
Definition: answer.hpp:28
uint64_t TimestampType
Type of timestamp.
Definition: types.hpp:61