hyperledger/iroha
Iroha - A simple, decentralized ledger http://iroha.tech
interactive_query_cli.hpp
Go to the documentation of this file.
1 
6 #ifndef IROHA_CLI_INTERACTIVE_QUERY_CLI_HPP
7 #define IROHA_CLI_INTERACTIVE_QUERY_CLI_HPP
8 
9 #include <memory>
10 #include <unordered_map>
11 
13 #include "logger/logger_fwd.hpp"
16 
17 namespace iroha {
18  namespace model {
19  class ModelCryptoProvider;
20  struct Query;
21  } // namespace model
22 } // namespace iroha
23 
24 namespace iroha_cli {
25  namespace interactive {
27  public:
41  const std::string &account_id,
42  const std::string &default_peer_ip,
43  int default_port,
44  uint64_t query_counter,
45  const std::shared_ptr<iroha::model::ModelCryptoProvider> &provider,
46  logger::LoggerManagerTreePtr response_handler_log_manager,
47  logger::LoggerPtr pb_qry_factory_log,
48  logger::LoggerPtr json_qry_factory_log,
49  logger::LoggerPtr log);
53  void run();
54 
55  private:
56  using QueryName = std::string;
57  using QueryParams = std::vector<std::string>;
58 
59  // Menu for Queries
60  MenuPoints menu_points_;
65  void create_queries_menu();
66 
67  // Menu for Query result
68  MenuPoints result_points_;
69 
73  void create_result_menu();
74 
75  // ------ Query handlers -----------
76  const std::string GET_ACC = "get_acc";
77  const std::string GET_ACC_AST = "get_acc_ast";
78  const std::string GET_ACC_AST_TX = "get_acc_ast_tx";
79  const std::string GET_ACC_TX = "get_acc_tx";
80  const std::string GET_TX = "get_tx";
81  const std::string GET_ACC_SIGN = "get_acc_sign";
82  const std::string GET_ROLES = "get_roles";
83  const std::string GET_AST_INFO = "get_ast_info";
84  const std::string GET_ROLE_PERM = "get_role_perm";
85 
86  // ------ Query parsers ---------
87  using QueryHandler = std::shared_ptr<iroha::model::Query> (
88  InteractiveQueryCli::*)(QueryParams);
89  std::unordered_map<QueryName, QueryHandler> query_handlers_;
90  // Descriptions of queries
91  DescriptionMap description_map_;
92 
93  // Parameters descriptions of queries
94  ParamsMap query_params_map_;
95 
102  bool parseQuery(std::string line);
103  // --- Specific Query parsers ---
104  std::shared_ptr<iroha::model::Query> parseGetAccount(QueryParams params);
105  std::shared_ptr<iroha::model::Query> parseGetAccountAssets(
106  QueryParams params);
107  std::shared_ptr<iroha::model::Query> parseGetAccountAssetTransactions(
108  QueryParams params);
109  std::shared_ptr<iroha::model::Query> parseGetAccountTransactions(
110  QueryParams params);
111  std::shared_ptr<iroha::model::Query> parseGetTransactions(
112  QueryParams params);
113  std::shared_ptr<iroha::model::Query> parseGetSignatories(
114  QueryParams params);
115  std::shared_ptr<iroha::model::Query> parseGetRoles(QueryParams params);
116  std::shared_ptr<iroha::model::Query> parseGetRolePermissions(
117  QueryParams params);
118  std::shared_ptr<iroha::model::Query> parseGetAssetInfo(
119  QueryParams params);
120 
121  // ------ Result parsers -------
122  using ResultHandler = bool (InteractiveQueryCli::*)(QueryParams);
123  std::unordered_map<QueryName, ResultHandler> result_handlers_;
124 
125  // Parameters descriptions of result commands
126  ParamsMap result_params_map_;
127 
134  bool parseResult(std::string line);
135  // ---- Specific Result handlers
136  bool parseSendToIroha(QueryParams line);
137  bool parseSaveFile(QueryParams line);
138 
139  // Current context for query forming
140  MenuContext current_context_;
141 
142  // ------- Query data -----------
143  // Creator account id
144  std::string creator_;
145  // Default Iroha peer address
146  std::string default_peer_ip_;
147  int default_port_;
148 
149  // Local query counter of account creator_
150  uint64_t counter_;
151 
152  // Local time
153  uint64_t local_time_;
154 
155  // Processed query
156  std::shared_ptr<iroha::model::Query> query_;
157 
158  // Query generator for new queries
160 
161  // Crypto provider
162  std::shared_ptr<iroha::model::ModelCryptoProvider> provider_;
163 
165  logger::LoggerManagerTreePtr response_handler_log_manager_;
166 
168  logger::LoggerPtr pb_qry_factory_log_;
169 
171  logger::LoggerPtr json_qry_factory_log_;
172 
174  logger::LoggerPtr log_;
175  };
176  } // namespace interactive
177 } // namespace iroha_cli
178 #endif // IROHA_CLI_INTERACTIVE_QUERY_CLI_HPP
Definition: client.cpp:16
MenuContext
Definition: interactive_common_cli.hpp:29
Definition: interactive_query_cli.hpp:26
std::vector< std::string > MenuPoints
Definition: interactive_common_cli.hpp:60
std::shared_ptr< Logger > LoggerPtr
Definition: logger_fwd.hpp:22
Definition: block_query.hpp:16
std::unordered_map< std::string, ParamsDescription > ParamsMap
Definition: interactive_common_cli.hpp:62
std::shared_ptr< LoggerManagerTree > LoggerManagerTreePtr
Definition: logger_manager_fwd.hpp:14
std::unordered_map< std::string, std::string > DescriptionMap
Definition: interactive_common_cli.hpp:58
Definition: query_generator.hpp:23