hyperledger/iroha
Iroha - A simple, decentralized ledger http://iroha.tech
container_validator.hpp
Go to the documentation of this file.
1 
6 #ifndef IROHA_CONTAINER_VALIDATOR_HPP
7 #define IROHA_CONTAINER_VALIDATOR_HPP
8 
9 #include <boost/format.hpp>
10 #include "datetime/time.hpp"
13 #include "validators/answer.hpp"
14 
15 namespace shared_model {
16  namespace validation {
17 
21  template <typename Iface,
22  typename FieldValidator,
23  typename TransactionsCollectionValidator>
25  protected:
27  ReasonsGroupType &reason,
29  interface::types::TimestampType current_timestamp) const {
30  auto answer = transactions_collection_validator_.validate(
31  transactions, current_timestamp);
32  if (answer.hasErrors()) {
33  reason.second.push_back(answer.reason());
34  }
35  }
36 
37  public:
39  const FieldValidator &field_validator = FieldValidator(),
41  &transactions_collection_validator =
43  : transactions_collection_validator_(
44  transactions_collection_validator),
45  field_validator_(field_validator) {}
46 
47  template <typename Validator>
48  Answer validate(const Iface &cont,
49  const std::string &reason_name,
50  Validator &&validator) const {
51  Answer answer;
52  ReasonsGroupType reason;
53  reason.first = reason_name;
54  field_validator_.validateHeight(reason, cont.height());
55  std::forward<Validator>(validator)(reason, cont);
56 
57  validateTransactions(reason, cont.transactions(), cont.createdTime());
58  if (not reason.second.empty()) {
59  answer.addReason(std::move(reason));
60  }
61  return answer;
62  }
63 
64  Answer validate(const Iface &cont, const std::string &reason_name) const {
65  return validate(cont, reason_name, [](auto &, const auto &) {});
66  }
67 
68  private:
69  TransactionsCollectionValidator transactions_collection_validator_;
70 
71  protected:
72  FieldValidator field_validator_;
73  };
74 
75  } // namespace validation
76 } // namespace shared_model
77 
78 #endif // IROHA_CONTAINER_VALIDATOR_HPP
Definition: container_validator.hpp:24
void validateTransactions(ReasonsGroupType &reason, const interface::types::TransactionsCollectionType &transactions, interface::types::TimestampType current_timestamp) const
Definition: container_validator.hpp:26
void addReason(ReasonsGroupType &&reasons)
Definition: answer.hpp:64
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 Iface &cont, const std::string &reason_name) const
Definition: container_validator.hpp:64
FieldValidator field_validator_
Definition: container_validator.hpp:72
Answer validate(const interface::types::TransactionsForwardCollectionType &transactions) const
Definition: transactions_collection_validator.cpp:81
Answer validate(const Iface &cont, const std::string &reason_name, Validator &&validator) const
Definition: container_validator.hpp:48
ContainerValidator(const FieldValidator &field_validator=FieldValidator(), const TransactionsCollectionValidator &transactions_collection_validator=TransactionsCollectionValidator())
Definition: container_validator.hpp:38
std::pair< ReasonsGroupName, GroupedReasons > ReasonsGroupType
Definition: answer.hpp:22
Definition: command_executor.hpp:12
void validateHeight(ReasonsGroupType &reason, const interface::types::HeightType &height) const
Definition: field_validator.cpp:357
Definition: answer.hpp:28
Definition: transactions_collection_validator.hpp:21
uint64_t TimestampType
Type of timestamp.
Definition: types.hpp:61
boost::any_range< Transaction, boost::random_access_traversal_tag, const Transaction & > TransactionsCollectionType
Type of transactions&#39; collection.
Definition: range_types.hpp:29