hyperledger/iroha
Iroha - A simple, decentralized ledger http://iroha.tech
query_response_handler.hpp
Go to the documentation of this file.
1 
6 #ifndef IROHA_CLI_QUERY_RESPONSE_HANDLER_HPP
7 #define IROHA_CLI_QUERY_RESPONSE_HANDLER_HPP
8 
9 #include <map>
10 #include <memory>
11 #include <typeindex>
12 #include <unordered_map>
13 
14 #include "logger/logger.hpp"
15 #include "qry_responses.pb.h"
16 
17 namespace iroha_cli {
18  /*
19  workaround for circle-ci compilation issue; see
20  http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#2148 and
21  https://stackoverflow.com/questions/18837857/cant-use-enum-class-as-unordered-map-key
22  for more details
23  */
24  struct EnumTypeHash {
25  template <typename T>
26  std::size_t operator()(T t) const {
27  return static_cast<std::size_t>(t);
28  }
29  };
30 
32  public:
33  explicit QueryResponseHandler(std::shared_ptr<spdlog::logger> log =
34  logger::log("QueryResponseHandler"));
35 
40  void handle(const iroha::protocol::QueryResponse &response);
41 
42  private:
43  void handleErrorResponse(const iroha::protocol::QueryResponse &response);
44  void handleAccountResponse(const iroha::protocol::QueryResponse &response);
45  void handleAccountAssetsResponse(
46  const iroha::protocol::QueryResponse &response);
47  void handleTransactionsResponse(
48  const iroha::protocol::QueryResponse &response);
49  void handleSignatoriesResponse(
50  const iroha::protocol::QueryResponse &response);
51  void handleRolesResponse(const iroha::protocol::QueryResponse &response);
52  void handleRolePermissionsResponse(
53  const iroha::protocol::QueryResponse &response);
54  void handleAssetResponse(const iroha::protocol::QueryResponse &response);
55  // -- --
56  using Handler =
58  using QueryResponseCode = iroha::protocol::QueryResponse::ResponseCase;
59  using ErrorResponseCode = iroha::protocol::ErrorResponse::Reason;
60 
61  // Map QueryResponse code -> Handle Method
62  std::unordered_map<QueryResponseCode, Handler, EnumTypeHash> handler_map_;
63  // Map ErrorResponse code -> String to print
64  std::unordered_map<ErrorResponseCode, std::string, EnumTypeHash>
65  error_handler_map_;
66 
67  std::shared_ptr<spdlog::logger> log_;
68  };
69 
70 } // namespace iroha_cli
71 #endif // IROHA_QUERY_RESPONSE_HANDLER_HPP
Definition: client.cpp:16
Definition: query_response_handler.hpp:24
std::size_t operator()(T t) const
Definition: query_response_handler.hpp:26
Logger log(const std::string &tag)
Definition: logger.cpp:48
Definition: query_response_handler.hpp:31