hyperledger/iroha
Iroha - A simple, decentralized ledger http://iroha.tech
postgres_specific_query_executor.hpp
Go to the documentation of this file.
1 
6 #ifndef IROHA_POSTGRES_SPECIFIC_QUERY_EXECUTOR_HPP
7 #define IROHA_POSTGRES_SPECIFIC_QUERY_EXECUTOR_HPP
8 
10 
11 #include <soci/soci.h>
12 #include "common/result.hpp"
14 #include "logger/logger_fwd.hpp"
15 
16 namespace shared_model {
17  namespace interface {
18  class PermissionToString;
19  class GetAccount;
20  class GetBlock;
21  class GetSignatories;
22  class GetAccountTransactions;
23  class GetAccountAssetTransactions;
24  class GetTransactions;
25  class GetAccountAssets;
26  class GetAccountDetail;
27  class GetRoles;
28  class GetRolePermissions;
29  class GetAssetInfo;
30  class GetPendingTransactions;
31  class GetPeers;
32  class GetEngineReceipts;
33  } // namespace interface
34 } // namespace shared_model
35 
36 namespace iroha {
37 
38  class PendingTransactionStorage;
39 
40  namespace ametsuchi {
41 
42  class BlockStorage;
43 
44  using QueryErrorType =
46 
50 
52  public:
54  soci::session &sql,
55  BlockStorage &block_store,
56  std::shared_ptr<PendingTransactionStorage> pending_txs_storage,
57  std::shared_ptr<shared_model::interface::QueryResponseFactory>
58  response_factory,
59  std::shared_ptr<shared_model::interface::PermissionToString>
60  perm_converter,
61  logger::LoggerPtr log);
62 
64  const shared_model::interface::Query &qry) override;
65 
66  bool hasAccountRolePermission(
68  const std::string &account_id) const override;
69 
70  QueryExecutorResult operator()(
74 
75  QueryExecutorResult operator()(
79 
80  QueryExecutorResult operator()(
84 
85  QueryExecutorResult operator()(
89 
90  QueryExecutorResult operator()(
94 
95  QueryExecutorResult operator()(
99 
100  QueryExecutorResult operator()(
103  const shared_model::interface::types::HashType &query_hash);
104 
105  QueryExecutorResult operator()(
108  const shared_model::interface::types::HashType &query_hash);
109 
110  QueryExecutorResult operator()(
113  const shared_model::interface::types::HashType &query_hash);
114 
115  QueryExecutorResult operator()(
118  const shared_model::interface::types::HashType &query_hash);
119 
120  QueryExecutorResult operator()(
123  const shared_model::interface::types::HashType &query_hash);
124 
125  QueryExecutorResult operator()(
128  const shared_model::interface::types::HashType &query_hash);
129 
130  QueryExecutorResult operator()(
133  const shared_model::interface::types::HashType &query_hash);
134 
135  QueryExecutorResult operator()(
138  const shared_model::interface::types::HashType &query_hash);
139 
140  private:
145  template <typename RangeGen, typename Pred, typename OutputIterator>
146  iroha::expected::Result<void, std::string> getTransactionsFromBlock(
147  uint64_t block_id,
148  RangeGen &&range_gen,
149  Pred &&pred,
150  OutputIterator dest_it);
151 
167  template <typename QueryTuple,
168  typename PermissionTuple,
169  typename QueryExecutor,
170  typename ResponseCreator,
171  typename PermissionsErrResponse>
172  QueryExecutorResult executeQuery(
173  QueryExecutor &&query_executor,
175  ResponseCreator &&response_creator,
176  PermissionsErrResponse &&perms_err_response);
177 
186  std::unique_ptr<shared_model::interface::QueryResponse>
187  logAndReturnErrorResponse(
189  QueryErrorMessageType error_body,
190  QueryErrorCodeType error_code,
191  const shared_model::interface::types::HashType &query_hash) const;
192 
208  template <typename Query,
209  typename QueryChecker,
210  typename QueryApplier,
211  typename... Permissions>
212  QueryExecutorResult executeTransactionsQuery(
213  const Query &query,
216  QueryChecker &&qry_checker,
217  char const *related_txs,
218  QueryApplier applier,
219  Permissions... perms);
220 
236  template <typename ReturnValueType>
237  bool existsInDb(const std::string &table_name,
238  const std::string &key_name,
239  const std::string &value_name,
240  const std::string &value) const;
241 
242  struct QueryFallbackCheckResult {
243  QueryFallbackCheckResult() = default;
244  QueryFallbackCheckResult(
246  error_code,
248  &&error_message)
249  : contains_error{true},
250  error_code{error_code},
251  error_message{std::move(error_message)} {}
252 
253  explicit operator bool() const {
254  return contains_error;
255  }
256  bool contains_error = false;
258  0;
260  error_message = "";
261  };
262 
263  soci::session &sql_;
264  BlockStorage &block_store_;
265  std::shared_ptr<PendingTransactionStorage> pending_txs_storage_;
266  std::shared_ptr<shared_model::interface::QueryResponseFactory>
267  query_response_factory_;
268  std::shared_ptr<shared_model::interface::PermissionToString>
269  perm_converter_;
270  logger::LoggerPtr log_;
271  std::string ordering_str_;
272  };
273 
274  } // namespace ametsuchi
275 } // namespace iroha
276 
277 #endif // IROHA_POSTGRES_SPECIFIC_QUERY_EXECUTOR_HPP
Definition: get_pending_transactions.hpp:21
Definition: hash.hpp:18
Definition: get_asset_info.hpp:17
Definition: error_query_response.hpp:30
Definition: query.hpp:36
Definition: get_transactions.hpp:14
std::string ErrorMessageType
Message type.
Definition: error_query_response.hpp:54
Definition: block_storage.hpp:23
shared_model::interface::ErrorQueryResponse ErrorQueryResponse
Definition: postgres_specific_query_executor.hpp:47
ErrorQueryResponse::ErrorCodeType QueryErrorCodeType
Definition: postgres_specific_query_executor.hpp:49
Definition: specific_query_executor.hpp:30
Definition: result_fwd.hpp:27
Definition: get_account_asset_transactions.hpp:21
std::shared_ptr< Logger > LoggerPtr
Definition: logger_fwd.hpp:22
Role
Definition: permissions.hpp:17
Definition: postgres_specific_query_executor.hpp:51
shared_model::interface::QueryResponseFactory::ErrorQueryType QueryErrorType
Definition: postgres_specific_query_executor.hpp:45
std::unique_ptr< shared_model::interface::QueryResponse > QueryExecutorResult
Definition: query_executor.hpp:23
Definition: get_signatories.hpp:18
Definition: get_account_transactions.hpp:21
Definition: block_query.hpp:15
std::string AccountIdType
Type of account id.
Definition: types.hpp:38
Definition: query_executor.hpp:25
Definition: get_roles.hpp:17
Definition: get_peers.hpp:17
Definition: get_account_detail.hpp:29
Definition: get_account.hpp:14
WsvCommandResult execute(soci::statement &st, Function &&error)
Definition: postgres_wsv_command.cpp:26
Definition: get_engine_receipts.hpp:17
ErrorQueryType
Definition: query_response_factory.hpp:110
uint32_t ErrorCodeType
Error code type.
Definition: error_query_response.hpp:62
Definition: get_block.hpp:14
ErrorQueryResponse::ErrorMessageType QueryErrorMessageType
Definition: postgres_specific_query_executor.hpp:48
Definition: get_role_permissions.hpp:18
Definition: command_executor.hpp:12
Definition: get_account_assets.hpp:20