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_fwd.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:
34 
39  void handle(const iroha::protocol::QueryResponse &response);
40 
41  private:
42  void handleErrorResponse(const iroha::protocol::QueryResponse &response);
43  void handleAccountResponse(const iroha::protocol::QueryResponse &response);
44  void handleAccountAssetsResponse(
45  const iroha::protocol::QueryResponse &response);
46  void handleTransactionsResponse(
47  const iroha::protocol::QueryResponse &response);
48  void handleSignatoriesResponse(
49  const iroha::protocol::QueryResponse &response);
50  void handleRolesResponse(const iroha::protocol::QueryResponse &response);
51  void handleRolePermissionsResponse(
52  const iroha::protocol::QueryResponse &response);
53  void handleAssetResponse(const iroha::protocol::QueryResponse &response);
54  // -- --
55  using Handler =
57  using QueryResponseCode = iroha::protocol::QueryResponse::ResponseCase;
58  using ErrorResponseCode = iroha::protocol::ErrorResponse::Reason;
59 
60  // Map QueryResponse code -> Handle Method
61  std::unordered_map<QueryResponseCode, Handler, EnumTypeHash> handler_map_;
62  // Map ErrorResponse code -> String to print
63  std::unordered_map<ErrorResponseCode, std::string, EnumTypeHash>
64  error_handler_map_;
65 
66  logger::LoggerPtr log_;
67  };
68 
69 } // namespace iroha_cli
70 #endif // IROHA_QUERY_RESPONSE_HANDLER_HPP
Definition: client.cpp:16
Definition: query_response_handler.hpp:24
std::shared_ptr< Logger > LoggerPtr
Definition: logger_fwd.hpp:22
std::size_t operator()(T t) const
Definition: query_response_handler.hpp:26
Definition: query_response_handler.hpp:31