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>
13 #include "logger/logger_fwd.hpp"
14 
15 namespace shared_model {
16  namespace interface {
17  class PermissionToString;
18  class GetAccount;
19  class GetBlock;
20  class GetSignatories;
21  class GetAccountTransactions;
22  class GetAccountAssetTransactions;
23  class GetTransactions;
24  class GetAccountAssets;
25  class GetAccountDetail;
26  class GetRoles;
27  class GetRolePermissions;
28  class GetAssetInfo;
29  class GetPendingTransactions;
30  class GetPeers;
31  } // namespace interface
32 } // namespace shared_model
33 
34 namespace iroha {
35 
36  class PendingTransactionStorage;
37 
38  namespace ametsuchi {
39 
40  class BlockStorage;
41 
42  using QueryErrorType =
44 
48 
50  public:
52  soci::session &sql,
53  BlockStorage &block_store,
54  std::shared_ptr<PendingTransactionStorage> pending_txs_storage,
55  std::shared_ptr<shared_model::interface::QueryResponseFactory>
56  response_factory,
57  std::shared_ptr<shared_model::interface::PermissionToString>
58  perm_converter,
59  logger::LoggerPtr log);
60 
62  const shared_model::interface::Query &qry) override;
63 
64  bool hasAccountRolePermission(
66  const std::string &account_id) const override;
67 
68  QueryExecutorResult operator()(
72 
73  QueryExecutorResult operator()(
77 
78  QueryExecutorResult operator()(
82 
83  QueryExecutorResult operator()(
87 
88  QueryExecutorResult operator()(
92 
93  QueryExecutorResult operator()(
97 
98  QueryExecutorResult operator()(
101  const shared_model::interface::types::HashType &query_hash);
102 
103  QueryExecutorResult operator()(
106  const shared_model::interface::types::HashType &query_hash);
107 
108  QueryExecutorResult operator()(
111  const shared_model::interface::types::HashType &query_hash);
112 
113  QueryExecutorResult operator()(
116  const shared_model::interface::types::HashType &query_hash);
117 
118  QueryExecutorResult operator()(
121  const shared_model::interface::types::HashType &query_hash);
122 
123  QueryExecutorResult operator()(
126  const shared_model::interface::types::HashType &query_hash);
127 
128  QueryExecutorResult operator()(
131  const shared_model::interface::types::HashType &query_hash);
132 
133  private:
138  template <typename RangeGen, typename Pred>
139  std::vector<std::unique_ptr<shared_model::interface::Transaction>>
140  getTransactionsFromBlock(uint64_t block_id,
141  RangeGen &&range_gen,
142  Pred &&pred);
143 
159  template <typename QueryTuple,
160  typename PermissionTuple,
161  typename QueryExecutor,
162  typename ResponseCreator,
163  typename PermissionsErrResponse>
164  QueryExecutorResult executeQuery(
165  QueryExecutor &&query_executor,
167  ResponseCreator &&response_creator,
168  PermissionsErrResponse &&perms_err_response);
169 
178  std::unique_ptr<shared_model::interface::QueryResponse>
179  logAndReturnErrorResponse(
181  QueryErrorMessageType error_body,
182  QueryErrorCodeType error_code,
183  const shared_model::interface::types::HashType &query_hash) const;
184 
200  template <typename Query,
201  typename QueryChecker,
202  typename QueryApplier,
203  typename... Permissions>
204  QueryExecutorResult executeTransactionsQuery(
205  const Query &query,
208  QueryChecker &&qry_checker,
209  const std::string &related_txs,
210  QueryApplier applier,
211  Permissions... perms);
212 
228  template <typename ReturnValueType>
229  bool existsInDb(const std::string &table_name,
230  const std::string &key_name,
231  const std::string &value_name,
232  const std::string &value) const;
233 
234  struct QueryFallbackCheckResult {
235  QueryFallbackCheckResult() = default;
236  QueryFallbackCheckResult(
238  error_code,
240  &&error_message)
241  : contains_error{true},
242  error_code{error_code},
243  error_message{std::move(error_message)} {}
244 
245  explicit operator bool() const {
246  return contains_error;
247  }
248  bool contains_error = false;
250  0;
252  error_message = "";
253  };
254 
255  soci::session &sql_;
256  BlockStorage &block_store_;
257  std::shared_ptr<PendingTransactionStorage> pending_txs_storage_;
258  std::shared_ptr<shared_model::interface::QueryResponseFactory>
259  query_response_factory_;
260  std::shared_ptr<shared_model::interface::PermissionToString>
261  perm_converter_;
262  logger::LoggerPtr log_;
263  };
264 
265  } // namespace ametsuchi
266 } // namespace iroha
267 
268 #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:29
Definition: query.hpp:35
Definition: get_transactions.hpp:14
std::string ErrorMessageType
Message type.
Definition: error_query_response.hpp:56
Definition: block_storage.hpp:22
shared_model::interface::ErrorQueryResponse ErrorQueryResponse
Definition: postgres_specific_query_executor.hpp:45
ErrorQueryResponse::ErrorCodeType QueryErrorCodeType
Definition: postgres_specific_query_executor.hpp:47
Definition: specific_query_executor.hpp:30
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:49
shared_model::interface::QueryResponseFactory::ErrorQueryType QueryErrorType
Definition: postgres_specific_query_executor.hpp:43
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:14
std::string AccountIdType
Type of account id.
Definition: types.hpp:39
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:23
ErrorQueryType
Definition: query_response_factory.hpp:108
uint32_t ErrorCodeType
Error code type.
Definition: error_query_response.hpp:64
Definition: get_block.hpp:14
ErrorQueryResponse::ErrorMessageType QueryErrorMessageType
Definition: postgres_specific_query_executor.hpp:46
Definition: get_role_permissions.hpp:18
Definition: command_executor.hpp:12
Definition: get_account_assets.hpp:20