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.hpp"
14 
15 namespace iroha {
16  namespace model {
17  struct Command;
18  class ModelCryptoProvider;
19  }
20 }
21 
22 namespace iroha_cli {
23  namespace interactive {
25  public:
34  const std::string &creator_account,
35  const std::string &default_peer_ip,
36  int default_port,
37  const std::shared_ptr<iroha::model::ModelCryptoProvider> &provider);
41  void run();
42 
43  private:
44  // Menu context used in cli
45  MenuContext current_context_;
46 
47  // Commands menu points
48  MenuPoints commands_menu_;
49 
50  // Transaction result points
51  MenuPoints result_menu_;
52 
57  void createCommandMenu();
61  void createResultMenu();
62 
63  // --- Shortcut namings for Iroha Commands ---
64  const std::string ADD_ASSET_QTY = "add_ast_qty";
65  const std::string ADD_PEER = "add_peer";
66  const std::string ADD_SIGN = "add_sign";
67  const std::string CREATE_ACC = "crt_acc";
68  const std::string CREATE_ASSET = "crt_ast";
69  const std::string CREATE_DOMAIN = "crt_dmn";
70  const std::string REMOVE_SIGN = "rem_sign";
71  const std::string SET_QUO = "set_qrm";
72  const std::string SET_ACC_KV = "set_acc_kv";
73  const std::string SUB_ASSET_QTY = "sub_ast_qty";
74  const std::string TRAN_ASSET = "tran_ast";
75 
76  const std::string CREATE_ROLE = "crt_role";
77  const std::string APPEND_ROLE = "apnd_role";
78  const std::string DETACH_ROLE = "detach";
79  const std::string GRANT_PERM = "grant_perm";
80  const std::string REVOKE_PERM = "revoke_perm";
81 
82  // ---- Command parsers ----
83  using CommandHandler = std::shared_ptr<iroha::model::Command> (
84  InteractiveTransactionCli::*)(std::vector<std::string>);
85 
86  // Specific parsers for each Iroha command
87  std::unordered_map<std::string, CommandHandler> command_handlers_;
88 
89  // Descriptions for commands parameters
90  ParamsMap command_params_map_;
91 
92  // Descriptions for commands
93  DescriptionMap commands_description_map_;
94 
101  bool parseCommand(std::string line);
102  // --- Specific model Command parsers -----
103  std::shared_ptr<iroha::model::Command> parseAddAssetQuantity(
104  std::vector<std::string> line);
105  std::shared_ptr<iroha::model::Command> parseAddPeer(
106  std::vector<std::string> line);
107  std::shared_ptr<iroha::model::Command> parseAddSignatory(
108  std::vector<std::string> line);
109  std::shared_ptr<iroha::model::Command> parseCreateAccount(
110  std::vector<std::string> line);
111  std::shared_ptr<iroha::model::Command> parseCreateAsset(
112  std::vector<std::string> line);
113  std::shared_ptr<iroha::model::Command> parseCreateDomain(
114  std::vector<std::string> line);
115  std::shared_ptr<iroha::model::Command> parseRemoveSignatory(
116  std::vector<std::string> line);
117  std::shared_ptr<iroha::model::Command> parseSetQuorum(
118  std::vector<std::string> line);
119  std::shared_ptr<iroha::model::Command> parseSetAccountDetail(
120  std::vector<std::string> line);
121  std::shared_ptr<iroha::model::Command> parseSubtractAssetQuantity(
122  std::vector<std::string> line);
123  std::shared_ptr<iroha::model::Command> parseTransferAsset(
124  std::vector<std::string> line);
125  std::shared_ptr<iroha::model::Command> parseAppendRole(
126  std::vector<std::string> line);
127  std::shared_ptr<iroha::model::Command> parseDetachRole(
128  std::vector<std::string> line);
129  std::shared_ptr<iroha::model::Command> parseCreateRole(
130  std::vector<std::string> line);
131  std::shared_ptr<iroha::model::Command> parseGrantPermission(
132  std::vector<std::string> line);
133  std::shared_ptr<iroha::model::Command> parseRevokePermission(
134  std::vector<std::string> line);
135 
136  // ---- Result parsers ------
137  using ResultHandler =
138  bool (InteractiveTransactionCli::*)(std::vector<std::string>);
139  std::unordered_map<std::string, ResultHandler> result_handlers_;
140 
141  // Description for result command
142  ParamsMap result_params_map;
143 
150  bool parseResult(std::string line);
151  // --- Specific result parsers ---
152  bool parseSendToIroha(std::vector<std::string> params);
153  bool parseSaveFile(std::vector<std::string> params);
154  bool parseGoBack(std::vector<std::string> params);
155  bool parseAddCommand(std::vector<std::string> params);
156 
160  void printTxHash(iroha::model::Transaction &tx);
161 
162  // ---- Tx data ----
163 
164  // Creator account id
165  std::string creator_;
166  std::string default_peer_ip_;
167  int default_port_;
168 
169  // Builder for new commands
171 
172  // Commands to be formed
173  std::vector<std::shared_ptr<iroha::model::Command>> commands_;
174 
175  // Logger
176  logger::Logger log_;
177 
178  // Crypto provider
179  std::shared_ptr<iroha::model::ModelCryptoProvider> provider_;
180 
181  // Transaction generator
183  };
184  } // namespace interactive
185 } // namespace iroha_cli
186 
187 #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:24
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: transaction_generator.hpp:16