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.hpp"
15 
16 namespace iroha {
17  namespace model {
18  class ModelCryptoProvider;
19  struct Query;
20  }
21 }
22 
23 namespace iroha_cli {
24  namespace interactive {
26  public:
27 
37  const std::string &account_id,
38  const std::string &default_peer_ip,
39  int default_port,
40  uint64_t query_counter,
41  const std::shared_ptr<iroha::model::ModelCryptoProvider> &provider);
45  void run();
46 
47  private:
48  using QueryName = std::string;
49  using QueryParams = std::vector<std::string>;
50 
51  // Menu for Queries
52  MenuPoints menu_points_;
57  void create_queries_menu();
58 
59  // Menu for Query result
60  MenuPoints result_points_;
61 
65  void create_result_menu();
66 
67  // ------ Query handlers -----------
68  const std::string GET_ACC = "get_acc";
69  const std::string GET_ACC_AST = "get_acc_ast";
70  const std::string GET_ACC_AST_TX = "get_acc_ast_tx";
71  const std::string GET_ACC_TX = "get_acc_tx";
72  const std::string GET_TX = "get_tx";
73  const std::string GET_ACC_SIGN = "get_acc_sign";
74  const std::string GET_ROLES = "get_roles";
75  const std::string GET_AST_INFO = "get_ast_info";
76  const std::string GET_ROLE_PERM = "get_role_perm";
77 
78  // ------ Query parsers ---------
79  using QueryHandler = std::shared_ptr<iroha::model::Query> (
80  InteractiveQueryCli::*)(QueryParams);
81  std::unordered_map<QueryName, QueryHandler> query_handlers_;
82  // Descriptions of queries
83  DescriptionMap description_map_;
84 
85  // Parameters descriptions of queries
86  ParamsMap query_params_map_;
87 
94  bool parseQuery(std::string line);
95  // --- Specific Query parsers ---
96  std::shared_ptr<iroha::model::Query> parseGetAccount(QueryParams params);
97  std::shared_ptr<iroha::model::Query> parseGetAccountAssets(
98  QueryParams params);
99  std::shared_ptr<iroha::model::Query> parseGetAccountAssetTransactions(
100  QueryParams params);
101  std::shared_ptr<iroha::model::Query> parseGetAccountTransactions(
102  QueryParams params);
103  std::shared_ptr<iroha::model::Query> parseGetTransactions(
104  QueryParams params);
105  std::shared_ptr<iroha::model::Query> parseGetSignatories(
106  QueryParams params);
107  std::shared_ptr<iroha::model::Query> parseGetRoles(QueryParams params);
108  std::shared_ptr<iroha::model::Query> parseGetRolePermissions(
109  QueryParams params);
110  std::shared_ptr<iroha::model::Query> parseGetAssetInfo(
111  QueryParams params);
112 
113  // ------ Result parsers -------
114  using ResultHandler = bool (InteractiveQueryCli::*)(QueryParams);
115  std::unordered_map<QueryName, ResultHandler> result_handlers_;
116 
117  // Parameters descriptions of result commands
118  ParamsMap result_params_map_;
119 
126  bool parseResult(std::string line);
127  // ---- Specific Result handlers
128  bool parseSendToIroha(QueryParams line);
129  bool parseSaveFile(QueryParams line);
130 
131  // Current context for query forming
132  MenuContext current_context_;
133 
134  // ------- Query data -----------
135  // Creator account id
136  std::string creator_;
137  // Default Iroha peer address
138  std::string default_peer_ip_;
139  int default_port_;
140 
141  // Local query counter of account creator_
142  uint64_t counter_;
143 
144  // Local time
145  uint64_t local_time_;
146 
147  // Processed query
148  std::shared_ptr<iroha::model::Query> query_;
149 
150  // Query generator for new queries
152 
153  // Logger
154  logger::Logger log_;
155 
156  // Crypto provider
157  std::shared_ptr<iroha::model::ModelCryptoProvider> provider_;
158  };
159  } // namespace interactive
160 } // namespace iroha_cli
161 #endif // IROHA_CLI_INTERACTIVE_QUERY_CLI_HPP
Definition: client.cpp:16
MenuContext
Definition: interactive_common_cli.hpp:29
Definition: interactive_query_cli.hpp:25
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::vector< std::string > MenuPoints
Definition: interactive_common_cli.hpp:60
std::shared_ptr< spdlog::logger > Logger
Definition: logger.hpp:26
Definition: block_query.hpp:16
std::unordered_map< std::string, ParamsDescription > ParamsMap
Definition: interactive_common_cli.hpp:62
std::unordered_map< std::string, std::string > DescriptionMap
Definition: interactive_common_cli.hpp:58
Definition: query_generator.hpp:23