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"
15 
16 namespace shared_model {
17  namespace validation {
18 
22  template <typename Iface,
23  typename FieldValidator,
24  typename TransactionsCollectionValidator>
26  protected:
28  ReasonsGroupType &reason,
30  interface::types::TimestampType current_timestamp) const {
31  auto answer = transactions_collection_validator_.validate(
32  transactions, current_timestamp);
33  if (answer.hasErrors()) {
34  reason.second.push_back(answer.reason());
35  }
36  }
37 
39  FieldValidator field_validator,
40  TransactionsCollectionValidator transactions_collection_validator)
41  : transactions_collection_validator_(
42  std::move(transactions_collection_validator)),
43  field_validator_(std::move(field_validator)) {}
44 
45  public:
46  explicit ContainerValidator(std::shared_ptr<ValidatorsConfig> config,
47  FieldValidator field_validator)
48  : field_validator_{std::move(field_validator)},
49  transactions_collection_validator_{std::move(config)} {}
50 
51  explicit ContainerValidator(std::shared_ptr<ValidatorsConfig> config)
52  : ContainerValidator(FieldValidator(config),
54 
55  template <typename Validator>
56  Answer validate(const Iface &cont,
57  const std::string &reason_name,
58  Validator &&validator) const {
59  Answer answer;
60  ReasonsGroupType reason;
61  reason.first = reason_name;
62  field_validator_.validateHeight(reason, cont.height());
63  std::forward<Validator>(validator)(reason, cont);
64 
65  validateTransactions(reason, cont.transactions(), cont.createdTime());
66  if (not reason.second.empty()) {
67  answer.addReason(std::move(reason));
68  }
69  return answer;
70  }
71 
72  Answer validate(const Iface &cont, const std::string &reason_name) const {
73  return validate(cont, reason_name, [](auto &, const auto &) {});
74  }
75 
76  private:
77  TransactionsCollectionValidator transactions_collection_validator_;
78 
79  protected:
80  FieldValidator field_validator_;
81  };
82 
83  } // namespace validation
84 } // namespace shared_model
85 
86 #endif // IROHA_CONTAINER_VALIDATOR_HPP
Definition: container_validator.hpp:25
void validateTransactions(ReasonsGroupType &reason, const interface::types::TransactionsCollectionType &transactions, interface::types::TimestampType current_timestamp) const
Definition: container_validator.hpp:27
void addReason(ReasonsGroupType &&reasons)
Definition: answer.hpp:64
Definition: peer.hpp:48
ContainerValidator(FieldValidator field_validator, TransactionsCollectionValidator transactions_collection_validator)
Definition: container_validator.hpp:38
Answer validate(const Iface &cont, const std::string &reason_name) const
Definition: container_validator.hpp:72
FieldValidator field_validator_
Definition: container_validator.hpp:80
Answer validate(const interface::types::TransactionsForwardCollectionType &transactions) const
Definition: transactions_collection_validator.cpp:89
Answer validate(const Iface &cont, const std::string &reason_name, Validator &&validator) const
Definition: container_validator.hpp:56
ContainerValidator(std::shared_ptr< ValidatorsConfig > config)
Definition: container_validator.hpp:51
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:359
ContainerValidator(std::shared_ptr< ValidatorsConfig > config, FieldValidator field_validator)
Definition: container_validator.hpp:46
Definition: answer.hpp:28
Definition: transactions_collection_validator.hpp:22
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