hyperledger/iroha
Iroha - A simple, decentralized ledger http://iroha.tech
postgres_query_executor.hpp
Go to the documentation of this file.
1 
6 #ifndef IROHA_POSTGRES_QUERY_EXECUTOR_HPP
7 #define IROHA_POSTGRES_QUERY_EXECUTOR_HPP
8 
10 
13 #include "ametsuchi/storage.hpp"
36 #include "logger/logger_fwd.hpp"
38 
39 namespace iroha {
40  namespace ametsuchi {
41 
42  using QueryErrorType =
44 
48 
50  : public boost::static_visitor<QueryExecutorResult> {
51  public:
53  soci::session &sql,
54  KeyValueStorage &block_store,
55  std::shared_ptr<PendingTransactionStorage> pending_txs_storage,
56  std::shared_ptr<shared_model::interface::BlockJsonConverter>
57  converter,
58  std::shared_ptr<shared_model::interface::QueryResponseFactory>
59  response_factory,
60  std::shared_ptr<shared_model::interface::PermissionToString>
61  perm_converter,
62  logger::LoggerPtr log);
63 
64  void setCreatorId(
66 
67  void setQueryHash(const shared_model::crypto::Hash &query_hash);
68 
77  const std::string &account_id) const;
78 
81 
84 
87 
90 
93 
96 
99 
102 
105 
108 
111 
114 
115  private:
120  template <typename RangeGen, typename Pred>
121  std::vector<std::unique_ptr<shared_model::interface::Transaction>>
122  getTransactionsFromBlock(uint64_t block_id,
123  RangeGen &&range_gen,
124  Pred &&pred);
125 
140  template <typename QueryTuple,
141  typename PermissionTuple,
142  typename QueryExecutor,
143  typename ResponseCreator,
144  typename PermissionsErrResponse>
145  QueryExecutorResult executeQuery(
146  QueryExecutor &&query_executor,
147  ResponseCreator &&response_creator,
148  PermissionsErrResponse &&perms_err_response);
149 
157  std::unique_ptr<shared_model::interface::QueryResponse>
158  logAndReturnErrorResponse(iroha::ametsuchi::QueryErrorType error_type,
159  QueryErrorMessageType error_body,
160  QueryErrorCodeType error_code) const;
161 
175  template <typename Query,
176  typename QueryChecker,
177  typename QueryApplier,
178  typename... Permissions>
179  QueryExecutorResult executeTransactionsQuery(
180  const Query &query,
181  QueryChecker &&qry_checker,
182  const std::string &related_txs,
183  QueryApplier applier,
184  Permissions... perms);
185 
201  template <typename ReturnValueType>
202  bool existsInDb(const std::string &table_name,
203  const std::string &key_name,
204  const std::string &value_name,
205  const std::string &value) const;
206 
207  struct QueryFallbackCheckResult {
208  QueryFallbackCheckResult() = default;
209  QueryFallbackCheckResult(
211  error_code,
213  &&error_message)
214  : contains_error{true},
215  error_code{error_code},
216  error_message{std::move(error_message)} {}
217 
218  explicit operator bool() const {
219  return contains_error;
220  }
221  bool contains_error = false;
223  0;
225  error_message = "";
226  };
227 
228  soci::session &sql_;
229  KeyValueStorage &block_store_;
232  std::shared_ptr<PendingTransactionStorage> pending_txs_storage_;
233  std::shared_ptr<shared_model::interface::BlockJsonConverter> converter_;
234  std::shared_ptr<shared_model::interface::QueryResponseFactory>
235  query_response_factory_;
236  std::shared_ptr<shared_model::interface::PermissionToString>
237  perm_converter_;
238  logger::LoggerPtr log_;
239  };
240 
242  public:
244  std::unique_ptr<soci::session> sql,
245  KeyValueStorage &block_store,
246  std::shared_ptr<PendingTransactionStorage> pending_txs_storage,
247  std::shared_ptr<shared_model::interface::BlockJsonConverter>
248  converter,
249  std::shared_ptr<shared_model::interface::QueryResponseFactory>
250  response_factory,
251  std::shared_ptr<shared_model::interface::PermissionToString>
252  perm_converter,
253  logger::LoggerManagerTreePtr log_manager);
254 
255  QueryExecutorResult validateAndExecute(
256  const shared_model::interface::Query &query,
257  const bool validate_signatories) override;
258 
259  bool validate(const shared_model::interface::BlocksQuery &query,
260  const bool validate_signatories) override;
261 
262  private:
263  template <class Q>
264  bool validateSignatures(const Q &query);
265 
266  std::unique_ptr<soci::session> sql_;
267  KeyValueStorage &block_store_;
268  std::shared_ptr<PendingTransactionStorage> pending_txs_storage_;
270  std::shared_ptr<shared_model::interface::QueryResponseFactory>
271  query_response_factory_;
272  logger::LoggerPtr log_;
273  };
274 
275  } // namespace ametsuchi
276 } // namespace iroha
277 
278 #endif // IROHA_POSTGRES_QUERY_EXECUTOR_HPP
Definition: get_pending_transactions.hpp:19
Definition: hash.hpp:18
Definition: get_asset_info.hpp:17
Definition: error_query_response.hpp:29
Definition: query.hpp:34
Definition: get_transactions.hpp:14
std::string ErrorMessageType
Message type.
Definition: error_query_response.hpp:56
shared_model::interface::ErrorQueryResponse ErrorQueryResponse
Definition: postgres_query_executor.hpp:45
ErrorQueryResponse::ErrorCodeType QueryErrorCodeType
Definition: postgres_query_executor.hpp:47
Definition: blocks_query.hpp:20
Definition: get_account_asset_transactions.hpp:21
std::shared_ptr< Logger > LoggerPtr
Definition: logger_fwd.hpp:22
Role
Definition: permissions.hpp:17
shared_model::interface::QueryResponseFactory::ErrorQueryType QueryErrorType
Definition: postgres_query_executor.hpp:43
Definition: get_signatories.hpp:18
Definition: get_account_transactions.hpp:21
Definition: block_query.hpp:16
std::string AccountIdType
Type of account id.
Definition: types.hpp:35
Definition: query_executor.hpp:25
Definition: get_roles.hpp:17
Definition: get_account_detail.hpp:28
Definition: get_account.hpp:14
std::shared_ptr< LoggerManagerTree > LoggerManagerTreePtr
Definition: logger_manager_fwd.hpp:14
bool hasAccountRolePermission(shared_model::interface::permissions::Role permission, const std::string &account_id) const
Definition: postgres_query_executor.cpp:328
std::unique_ptr< shared_model::interface::QueryResponse > QueryExecutorResult
Definition: query_executor.hpp:23
void setQueryHash(const shared_model::crypto::Hash &query_hash)
Definition: postgres_query_executor.cpp:368
ErrorQueryType
Definition: query_response_factory.hpp:91
uint32_t ErrorCodeType
Error code type.
Definition: error_query_response.hpp:64
Definition: get_block.hpp:14
PostgresQueryExecutorVisitor(soci::session &sql, KeyValueStorage &block_store, std::shared_ptr< PendingTransactionStorage > pending_txs_storage, std::shared_ptr< shared_model::interface::BlockJsonConverter > converter, std::shared_ptr< shared_model::interface::QueryResponseFactory > response_factory, std::shared_ptr< shared_model::interface::PermissionToString > perm_converter, logger::LoggerPtr log)
Definition: postgres_query_executor.cpp:345
ErrorQueryResponse::ErrorMessageType QueryErrorMessageType
Definition: postgres_query_executor.hpp:46
void setCreatorId(const shared_model::interface::types::AccountIdType &creator_id)
Definition: postgres_query_executor.cpp:363
Definition: get_role_permissions.hpp:18
Definition: key_value_storage.hpp:20
Definition: postgres_query_executor.hpp:241
Definition: postgres_query_executor.hpp:49
QueryExecutorResult operator()(const shared_model::interface::GetAccount &q)
Definition: postgres_query_executor.cpp:534
Definition: get_account_assets.hpp:17