hyperledger/iroha
Iroha - A simple, decentralized ledger http://iroha.tech
interactive_transaction_cli.hpp
Go to the documentation of this file.
1 
6 #ifndef IROHA_CLI_INTERACTIVE_TRANSACTION_CLI_HPP
7 #define IROHA_CLI_INTERACTIVE_TRANSACTION_CLI_HPP
8 
9 #include <unordered_map>
10 
12 #include "logger/logger_fwd.hpp"
15 
16 namespace iroha {
17  namespace model {
18  struct Command;
19  class ModelCryptoProvider;
20  } // namespace model
21 } // namespace iroha
22 
23 namespace iroha_cli {
24  namespace interactive {
26  public:
38  const std::string &creator_account,
39  const std::string &default_peer_ip,
40  int default_port,
41  const std::shared_ptr<iroha::model::ModelCryptoProvider> &provider,
42  logger::LoggerManagerTreePtr response_handler_log_manager,
43  logger::LoggerPtr pb_qry_factory_log,
44  logger::LoggerPtr log);
48  void run();
49 
50  private:
51  // Menu context used in cli
52  MenuContext current_context_;
53 
54  // Commands menu points
55  MenuPoints commands_menu_;
56 
57  // Transaction result points
58  MenuPoints result_menu_;
59 
64  void createCommandMenu();
68  void createResultMenu();
69 
70  // --- Shortcut namings for Iroha Commands ---
71  const std::string ADD_ASSET_QTY = "add_ast_qty";
72  const std::string ADD_PEER = "add_peer";
73  const std::string ADD_SIGN = "add_sign";
74  const std::string CREATE_ACC = "crt_acc";
75  const std::string CREATE_ASSET = "crt_ast";
76  const std::string CREATE_DOMAIN = "crt_dmn";
77  const std::string REMOVE_SIGN = "rem_sign";
78  const std::string SET_QUO = "set_qrm";
79  const std::string SET_ACC_KV = "set_acc_kv";
80  const std::string SUB_ASSET_QTY = "sub_ast_qty";
81  const std::string TRAN_ASSET = "tran_ast";
82 
83  const std::string CREATE_ROLE = "crt_role";
84  const std::string APPEND_ROLE = "apnd_role";
85  const std::string DETACH_ROLE = "detach";
86  const std::string GRANT_PERM = "grant_perm";
87  const std::string REVOKE_PERM = "revoke_perm";
88 
89  // ---- Command parsers ----
90  using CommandHandler = std::shared_ptr<iroha::model::Command> (
91  InteractiveTransactionCli::*)(std::vector<std::string>);
92 
93  // Specific parsers for each Iroha command
94  std::unordered_map<std::string, CommandHandler> command_handlers_;
95 
96  // Descriptions for commands parameters
97  ParamsMap command_params_map_;
98 
99  // Descriptions for commands
100  DescriptionMap commands_description_map_;
101 
108  bool parseCommand(std::string line);
109  // --- Specific model Command parsers -----
110  std::shared_ptr<iroha::model::Command> parseAddAssetQuantity(
111  std::vector<std::string> line);
112  std::shared_ptr<iroha::model::Command> parseAddPeer(
113  std::vector<std::string> line);
114  std::shared_ptr<iroha::model::Command> parseAddSignatory(
115  std::vector<std::string> line);
116  std::shared_ptr<iroha::model::Command> parseCreateAccount(
117  std::vector<std::string> line);
118  std::shared_ptr<iroha::model::Command> parseCreateAsset(
119  std::vector<std::string> line);
120  std::shared_ptr<iroha::model::Command> parseCreateDomain(
121  std::vector<std::string> line);
122  std::shared_ptr<iroha::model::Command> parseRemoveSignatory(
123  std::vector<std::string> line);
124  std::shared_ptr<iroha::model::Command> parseSetQuorum(
125  std::vector<std::string> line);
126  std::shared_ptr<iroha::model::Command> parseSetAccountDetail(
127  std::vector<std::string> line);
128  std::shared_ptr<iroha::model::Command> parseSubtractAssetQuantity(
129  std::vector<std::string> line);
130  std::shared_ptr<iroha::model::Command> parseTransferAsset(
131  std::vector<std::string> line);
132  std::shared_ptr<iroha::model::Command> parseAppendRole(
133  std::vector<std::string> line);
134  std::shared_ptr<iroha::model::Command> parseDetachRole(
135  std::vector<std::string> line);
136  std::shared_ptr<iroha::model::Command> parseCreateRole(
137  std::vector<std::string> line);
138  std::shared_ptr<iroha::model::Command> parseGrantPermission(
139  std::vector<std::string> line);
140  std::shared_ptr<iroha::model::Command> parseRevokePermission(
141  std::vector<std::string> line);
142 
143  // ---- Result parsers ------
144  using ResultHandler =
145  bool (InteractiveTransactionCli::*)(std::vector<std::string>);
146  std::unordered_map<std::string, ResultHandler> result_handlers_;
147 
148  // Description for result command
149  ParamsMap result_params_map;
150 
157  bool parseResult(std::string line);
158  // --- Specific result parsers ---
159  bool parseSendToIroha(std::vector<std::string> params);
160  bool parseSaveFile(std::vector<std::string> params);
161  bool parseGoBack(std::vector<std::string> params);
162  bool parseAddCommand(std::vector<std::string> params);
163 
167  void printTxHash(iroha::model::Transaction &tx);
168 
169  // ---- Tx data ----
170 
171  // Creator account id
172  std::string creator_;
173  std::string default_peer_ip_;
174  int default_port_;
175 
176  // Builder for new commands
178 
179  // Commands to be formed
180  std::vector<std::shared_ptr<iroha::model::Command>> commands_;
181 
182  // Crypto provider
183  std::shared_ptr<iroha::model::ModelCryptoProvider> provider_;
184 
185  // Transaction generator
187 
189  logger::LoggerManagerTreePtr response_handler_log_manager_;
190 
192  logger::LoggerPtr pb_qry_factory_log_;
193 
195  logger::LoggerPtr log_;
196  };
197  } // namespace interactive
198 } // namespace iroha_cli
199 
200 #endif // IROHA_CLI_INTERACTIVE_TRANSACTION_CLI_HPP
Definition: command_generator.hpp:22
Definition: client.cpp:16
MenuContext
Definition: interactive_common_cli.hpp:29
Definition: transaction.hpp:26
Definition: interactive_transaction_cli.hpp:25
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:14
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: transaction_generator.hpp:17