hyperledger/iroha
Iroha - A simple, decentralized ledger http://iroha.tech
blocks_query_template.hpp
Go to the documentation of this file.
1 
6 #ifndef IROHA_PROTO_BLOCKS_QUERY_BUILDER_TEMPLATE_HPP
7 #define IROHA_PROTO_BLOCKS_QUERY_BUILDER_TEMPLATE_HPP
8 
14 #include "module/irohad/common/validators_config.hpp"
15 #include "queries.pb.h"
17 
18 namespace shared_model {
19  namespace proto {
20 
29  template <int S = 0,
31  typename BT = UnsignedWrapper<BlocksQuery>>
32  class [[deprecated]] TemplateBlocksQueryBuilder {
33  private:
34  template <int, typename, typename>
36 
37  enum RequiredFields {
38  CreatedTime,
39  CreatorAccountId,
40  QueryCounter,
41  TOTAL
42  };
43 
44  template <int s>
46 
47  using ProtoBlocksQuery = iroha::protocol::BlocksQuery;
48 
49  template <int Sp>
52  : query_(o.query_), stateless_validator_(o.stateless_validator_) {}
53 
60  template <int Fields, typename Transformation>
61  auto transform(Transformation t) const {
62  NextBuilder<Fields> copy = *this;
63  t(copy.query_);
64  return copy;
65  }
66 
67  TemplateBlocksQueryBuilder(const SV &validator)
68  : stateless_validator_(validator) {}
69 
70  public:
71  // we do such default initialization only because it is deprecated and
72  // used only in tests
75  SV(iroha::test::kTestsValidatorsConfig)) {}
76 
77  auto createdTime(interface::types::TimestampType created_time) const {
78  return transform<CreatedTime>([&](auto &qry) {
79  auto *meta = qry.mutable_meta();
80  meta->set_created_time(created_time);
81  });
82  }
83 
85  const interface::types::AccountIdType &creator_account_id) const {
86  return transform<CreatorAccountId>([&](auto &qry) {
87  auto *meta = qry.mutable_meta();
88  meta->set_creator_account_id(creator_account_id);
89  });
90  }
91 
92  auto queryCounter(interface::types::CounterType query_counter) const {
93  return transform<QueryCounter>([&](auto &qry) {
94  auto *meta = qry.mutable_meta();
95  meta->set_query_counter(query_counter);
96  });
97  }
98 
99  auto build() const {
100  static_assert(S == (1 << TOTAL) - 1, "Required fields are not set");
101  auto result = BlocksQuery(iroha::protocol::BlocksQuery(query_));
102  auto answer = stateless_validator_.validate(result);
103  if (answer.hasErrors()) {
104  throw std::invalid_argument(answer.reason());
105  }
106  return BT(std::move(result));
107  }
108 
109  static const int total = RequiredFields::TOTAL;
110 
111  private:
112  ProtoBlocksQuery query_;
113  SV stateless_validator_;
114  };
115  } // namespace proto
116 } // namespace shared_model
117 
118 #endif // IROHA_PROTO_BLOCKS_QUERY_BUILDER_TEMPLATE_HPP
BlocksQueryValidator< FieldValidator > DefaultUnsignedBlocksQueryValidator
Definition: default_validator.hpp:71
Definition: blocks_query_template.hpp:32
auto build() const
Definition: blocks_query_template.hpp:99
TemplateBlocksQueryBuilder()
Definition: blocks_query_template.hpp:73
auto createdTime(interface::types::TimestampType created_time) const
Definition: blocks_query_template.hpp:77
Definition: block_query.hpp:14
std::string AccountIdType
Type of account id.
Definition: types.hpp:39
auto creatorAccountId(const interface::types::AccountIdType &creator_account_id) const
Definition: blocks_query_template.hpp:84
uint64_t CounterType
Type of counter.
Definition: types.hpp:66
Definition: command_executor.hpp:12
Definition: proto_blocks_query.hpp:16
auto queryCounter(interface::types::CounterType query_counter) const
Definition: blocks_query_template.hpp:92
uint64_t TimestampType
Type of timestamp.
Definition: types.hpp:64