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.hpp"
37 
38 namespace iroha {
39  namespace ametsuchi {
40 
41  using QueryErrorType =
43 
47 
49  : public boost::static_visitor<QueryExecutorResult> {
50  public:
52  soci::session &sql,
53  KeyValueStorage &block_store,
54  std::shared_ptr<PendingTransactionStorage> pending_txs_storage,
55  std::shared_ptr<shared_model::interface::BlockJsonConverter>
56  converter,
57  std::shared_ptr<shared_model::interface::QueryResponseFactory>
58  response_factory,
59  std::shared_ptr<shared_model::interface::PermissionToString>
60  perm_converter,
61  logger::Logger log = logger::log("PostgresQueryExecutorVisitor"));
62 
63  void setCreatorId(
65 
66  void setQueryHash(const shared_model::crypto::Hash &query_hash);
67 
76  const std::string &account_id) const;
77 
80 
83 
86 
89 
92 
95 
98 
101 
104 
107 
110 
113 
114  private:
119  template <typename RangeGen, typename Pred>
120  std::vector<std::unique_ptr<shared_model::interface::Transaction>>
121  getTransactionsFromBlock(uint64_t block_id,
122  RangeGen &&range_gen,
123  Pred &&pred);
124 
139  template <typename QueryTuple,
140  typename PermissionTuple,
141  typename QueryExecutor,
142  typename ResponseCreator,
143  typename PermissionsErrResponse>
144  QueryExecutorResult executeQuery(
145  QueryExecutor &&query_executor,
146  ResponseCreator &&response_creator,
147  PermissionsErrResponse &&perms_err_response);
148 
156  std::unique_ptr<shared_model::interface::QueryResponse>
157  logAndReturnErrorResponse(iroha::ametsuchi::QueryErrorType error_type,
158  QueryErrorMessageType error_body,
159  QueryErrorCodeType error_code) const;
160 
174  template <typename Query,
175  typename QueryChecker,
176  typename QueryApplier,
177  typename... Permissions>
178  QueryExecutorResult executeTransactionsQuery(
179  const Query &query,
180  QueryChecker &&qry_checker,
181  const std::string &related_txs,
182  QueryApplier applier,
183  Permissions... perms);
184 
200  template <typename ReturnValueType>
201  bool existsInDb(const std::string &table_name,
202  const std::string &key_name,
203  const std::string &value_name,
204  const std::string &value) const;
205 
206  struct QueryFallbackCheckResult {
207  QueryFallbackCheckResult() = default;
208  QueryFallbackCheckResult(
210  error_code,
212  &&error_message)
213  : contains_error{true},
214  error_code{error_code},
215  error_message{std::move(error_message)} {}
216 
217  explicit operator bool() const {
218  return contains_error;
219  }
220  bool contains_error = false;
222  0;
224  error_message = "";
225  };
226 
227  soci::session &sql_;
228  KeyValueStorage &block_store_;
231  std::shared_ptr<PendingTransactionStorage> pending_txs_storage_;
232  std::shared_ptr<shared_model::interface::BlockJsonConverter> converter_;
233  std::shared_ptr<shared_model::interface::QueryResponseFactory>
234  query_response_factory_;
235  std::shared_ptr<shared_model::interface::PermissionToString>
236  perm_converter_;
237  logger::Logger log_;
238  };
239 
241  public:
243  std::unique_ptr<soci::session> sql,
244  KeyValueStorage &block_store,
245  std::shared_ptr<PendingTransactionStorage> pending_txs_storage,
246  std::shared_ptr<shared_model::interface::BlockJsonConverter>
247  converter,
248  std::shared_ptr<shared_model::interface::QueryResponseFactory>
249  response_factory,
250  std::shared_ptr<shared_model::interface::PermissionToString>
251  perm_converter,
252  logger::Logger log = logger::log("PostgresQueryExecutor"));
253 
254  QueryExecutorResult validateAndExecute(
255  const shared_model::interface::Query &query,
256  const bool validate_signatories) override;
257 
258  bool validate(const shared_model::interface::BlocksQuery &query,
259  const bool validate_signatories) override;
260 
261  private:
262  template <class Q>
263  bool validateSignatures(const Q &query);
264 
265  std::unique_ptr<soci::session> sql_;
266  KeyValueStorage &block_store_;
267  std::shared_ptr<PendingTransactionStorage> pending_txs_storage_;
269  std::shared_ptr<shared_model::interface::QueryResponseFactory>
270  query_response_factory_;
271  logger::Logger log_;
272  };
273 
274  } // namespace ametsuchi
275 } // namespace iroha
276 
277 #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:44
ErrorQueryResponse::ErrorCodeType QueryErrorCodeType
Definition: postgres_query_executor.hpp:46
Definition: blocks_query.hpp:20
Definition: get_account_asset_transactions.hpp:21
string(REPLACE".""/"CMAKE_SWIG_OUTDIR ${SWIG_JAVA_PKG}) else() set(CMAKE_SWIG_FLAGS"") endif() myswig_add_library(irohajava LANGUAGE java SOURCES bindings.i) unset(CMAKE_SWIG_FLAGS) swig_link_libraries(irohajava $
Definition: CMakeLists.txt:54
std::shared_ptr< spdlog::logger > Logger
Definition: logger.hpp:26
Role
Definition: permissions.hpp:17
shared_model::interface::QueryResponseFactory::ErrorQueryType QueryErrorType
Definition: postgres_query_executor.hpp:42
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:37
Definition: query_executor.hpp:25
Definition: get_roles.hpp:17
Logger log(const std::string &tag)
Definition: logger.cpp:48
Definition: get_account_detail.hpp:28
Definition: get_account.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::Logger log=logger::log("PostgresQueryExecutorVisitor"))
Definition: postgres_query_executor.cpp:342
bool hasAccountRolePermission(shared_model::interface::permissions::Role permission, const std::string &account_id) const
Definition: postgres_query_executor.cpp:325
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:365
ErrorQueryType
Definition: query_response_factory.hpp:91
uint32_t ErrorCodeType
Error code type.
Definition: error_query_response.hpp:64
Definition: get_block.hpp:14
ErrorQueryResponse::ErrorMessageType QueryErrorMessageType
Definition: postgres_query_executor.hpp:45
void setCreatorId(const shared_model::interface::types::AccountIdType &creator_id)
Definition: postgres_query_executor.cpp:360
Definition: get_role_permissions.hpp:18
Definition: key_value_storage.hpp:20
Definition: postgres_query_executor.hpp:240
Definition: postgres_query_executor.hpp:48
QueryExecutorResult operator()(const shared_model::interface::GetAccount &q)
Definition: postgres_query_executor.cpp:531
Definition: get_account_assets.hpp:17