Skip to content

Commit

Permalink
Add minor fixes to interactive cli:
Browse files Browse the repository at this point in the history
 - Add comments, rename variables, update function signatures

Signed-off-by: grimadas <[email protected]>
  • Loading branch information
grimadas committed Feb 2, 2018
1 parent 08fbb3e commit d61d58d
Show file tree
Hide file tree
Showing 11 changed files with 44 additions and 38 deletions.
2 changes: 1 addition & 1 deletion iroha-cli/interactive/impl/interactive_cli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ namespace iroha_cli {
InteractiveCli::InteractiveCli(
const std::string &account_name,
const std::string &default_peer_ip,
const int &default_port,
int default_port,
uint64_t tx_counter,
uint64_t qry_counter,
const std::shared_ptr<iroha::model::ModelCryptoProvider> &provider)
Expand Down
6 changes: 3 additions & 3 deletions iroha-cli/interactive/impl/interactive_common_cli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ namespace iroha_cli {
}

ParamsMap getCommonParamsMap(const std::string &default_ip,
const int &default_port) {
int default_port) {
return {
// commonParamsMap
{SAVE_CODE, {"Path to save json file"}},
Expand Down Expand Up @@ -94,8 +94,8 @@ namespace iroha_cli {
nonstd::optional<std::pair<std::string, uint16_t>> parseIrohaPeerParams(
ParamsDescription params,
const std::string &default_ip,
const int &default_port) {
auto address = params[0].empty() ? default_ip : params[0];
int default_port) {
const auto &address = params[0].empty() ? default_ip : params[0];
auto port = params[1].empty() ? default_port
: parser::parseValue<uint16_t>(params[1]);
if (not params.empty() and not port.has_value()) {
Expand Down
10 changes: 5 additions & 5 deletions iroha-cli/interactive/impl/interactive_query_cli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ namespace iroha_cli {
result_handlers_ = {{SAVE_CODE, &InteractiveQueryCli::parseSaveFile},
{SEND_CODE, &InteractiveQueryCli::parseSendToIroha}};
result_params_descriptions_ =
getCommonParamsMap(default_peer_ip, default_port);
getCommonParamsMap(default_peer_ip_, default_port_);

result_points_ = formMenu(result_handlers_,
result_params_descriptions_,
Expand All @@ -99,13 +99,13 @@ namespace iroha_cli {
InteractiveQueryCli::InteractiveQueryCli(
const std::string &account_name,
const std::string &default_peer_ip,
const int &default_port,
int default_port,
uint64_t query_counter,
const std::shared_ptr<iroha::model::ModelCryptoProvider> &provider)
: current_context_(MAIN),
creator_(account_name),
default_peer_ip(default_peer_ip),
default_port(default_port),
default_peer_ip_(default_peer_ip),
default_port_(default_port),
counter_(query_counter),
provider_(provider) {
log_ = logger::log("InteractiveQueryCli");
Expand Down Expand Up @@ -254,7 +254,7 @@ namespace iroha_cli {

bool InteractiveQueryCli::parseSendToIroha(QueryParams params) {
auto address =
parseIrohaPeerParams(params, default_peer_ip, default_port);
parseIrohaPeerParams(params, default_peer_ip_, default_port_);
if (not address.has_value()) {
return true;
}
Expand Down
8 changes: 4 additions & 4 deletions iroha-cli/interactive/impl/interactive_status_cli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ namespace iroha_cli {
"Transaction was not found in the system."}};

InteractiveStatusCli::InteractiveStatusCli(
const std::string &default_peer_ip, const int &default_port)
: default_peer_ip(default_peer_ip), default_port(default_port) {
const std::string &default_peer_ip, int default_port)
: default_peer_ip_(default_peer_ip), default_port_(default_port) {
createActionsMenu();
createResultMenu();
}
Expand All @@ -61,7 +61,7 @@ namespace iroha_cli {
resultHandlers_ = {{SEND_CODE, &InteractiveStatusCli::parseSendToIroha},
{SAVE_CODE, &InteractiveStatusCli::parseSaveFile}};
resultParamsDescriptions_ =
getCommonParamsMap(default_peer_ip, default_port);
getCommonParamsMap(default_peer_ip_, default_port_);

resultPoints_ = formMenu(resultHandlers_,
resultParamsDescriptions_,
Expand Down Expand Up @@ -127,7 +127,7 @@ namespace iroha_cli {
}

bool InteractiveStatusCli::parseSendToIroha(ActionParams line) {
auto address = parseIrohaPeerParams(line, default_peer_ip, default_port);
auto address = parseIrohaPeerParams(line, default_peer_ip_, default_port_);
if (not address.has_value()) {
return true;
}
Expand Down
10 changes: 5 additions & 5 deletions iroha-cli/interactive/impl/interactive_transaction_cli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ namespace iroha_cli {
{BACK_CODE, "Go back and start a new transaction"});

result_params_descriptions =
getCommonParamsMap(default_peer_ip, default_port);
getCommonParamsMap(default_peer_ip_, default_port_);

result_params_descriptions.insert({ADD_CMD, {}});
result_params_descriptions.insert({BACK_CODE, {}});
Expand All @@ -174,13 +174,13 @@ namespace iroha_cli {
InteractiveTransactionCli::InteractiveTransactionCli(
const std::string &creator_account,
const std::string &default_peer_ip,
const int &default_port,
int default_port,
uint64_t tx_counter,
const std::shared_ptr<iroha::model::ModelCryptoProvider> &provider)
: current_context_(MAIN),
creator_(creator_account),
default_peer_ip(default_peer_ip),
default_port(default_port),
default_peer_ip_(default_peer_ip),
default_port_(default_port),
tx_counter_(tx_counter),
provider_(provider) {
log_ = logger::log("InteractiveTransactionCli");
Expand Down Expand Up @@ -462,7 +462,7 @@ namespace iroha_cli {
bool InteractiveTransactionCli::parseSendToIroha(
std::vector<std::string> params) {
auto address = parseIrohaPeerParams(
std::move(params), default_peer_ip, default_port);
std::move(params), default_peer_ip_, default_port_);
if (not address.has_value()) {
return true;
}
Expand Down
2 changes: 1 addition & 1 deletion iroha-cli/interactive/interactive_cli.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ namespace iroha_cli {
InteractiveCli(
const std::string &account_name,
const std::string &default_peer_ip,
const int &default_port,
int default_port,
uint64_t tx_counter,
uint64_t qry_counter,
const std::shared_ptr<iroha::model::ModelCryptoProvider> &provider);
Expand Down
4 changes: 2 additions & 2 deletions iroha-cli/interactive/interactive_common_cli.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ namespace iroha_cli {
* @return Map with parameters of common commands
*/
ParamsMap getCommonParamsMap(const std::string &default_ip,
const int &default_port);
int default_port);

/**
* Handle error with empty command
Expand Down Expand Up @@ -187,7 +187,7 @@ namespace iroha_cli {
nonstd::optional<std::pair<std::string, uint16_t>> parseIrohaPeerParams(
std::vector<std::string> params,
const std::string &default_ip,
const int &default_port);
int default_port);

/**
* Handle parsing routine:
Expand Down
13 changes: 9 additions & 4 deletions iroha-cli/interactive/interactive_query_cli.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,19 @@ namespace iroha_cli {
namespace interactive {
class InteractiveQueryCli {
public:

/**
* @param account_id creator's account identification
* Class to form and send Iroha queries in interactive mode
* @param creator_account creator's account identification
* @param default_peer_ip of Iroha peer
* @param default_port of Iroha peer
* @param query_counter counter associated with creator's account
* @param provider for signing queries
*/
InteractiveQueryCli(
const std::string &account_id,
const std::string &default_peer_ip,
const int &default_port,
int default_port,
uint64_t query_counter,
const std::shared_ptr<iroha::model::ModelCryptoProvider> &provider);
/**
Expand Down Expand Up @@ -134,8 +139,8 @@ namespace iroha_cli {
// Creator account id
std::string creator_;
// Default Iroha peer address
std::string default_peer_ip;
int default_port;
std::string default_peer_ip_;
int default_port_;

// Local query counter of account creator_
uint64_t counter_;
Expand Down
6 changes: 3 additions & 3 deletions iroha-cli/interactive/interactive_status_cli.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ namespace iroha_cli {
class InteractiveStatusCli {
public:
InteractiveStatusCli(const std::string &default_peer_ip,
const int &default_port);
int default_port);
void run();

private:
Expand All @@ -55,8 +55,8 @@ namespace iroha_cli {

const std::string GET_TX_INFO = "get_tx_info";

std::string default_peer_ip;
int default_port;
std::string default_peer_ip_;
int default_port_;

std::unordered_map<ActionName, ResultHandler> resultHandlers_;
ParamsMap resultParamsDescriptions_;
Expand Down
14 changes: 7 additions & 7 deletions iroha-cli/interactive/interactive_transaction_cli.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,17 @@ namespace iroha_cli {
class InteractiveTransactionCli {
public:
/**
*
* @param creator_account
* @param default_peer_ip
* @param default_port
* Class to form and send Iroha transactions in interactive mode
* @param creator_account user Iroha account
* @param default_peer_ip of Iroha peer
* @param default_port of Iroha peer
* @param tx_counter synchronized with Iroha network
* @param provider for signing transactions
*/
InteractiveTransactionCli(
const std::string &creator_account,
const std::string &default_peer_ip,
const int &default_port,
int default_port,
uint64_t tx_counter,
const std::shared_ptr<iroha::model::ModelCryptoProvider> &provider);
/**
Expand Down Expand Up @@ -172,8 +172,8 @@ namespace iroha_cli {

// Creator account id
std::string creator_;
std::string default_peer_ip;
int default_port;
std::string default_peer_ip_;
int default_port_;

// Transaction counter specific for account creator
uint64_t tx_counter_;
Expand Down
7 changes: 4 additions & 3 deletions iroha-cli/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@
DEFINE_bool(
new_account,
false,
"Create new account, generate and save locally public/private keys.");
"Generate and save locally new public/private keys");
DEFINE_string(account_name,
"",
"Name of the account. Must be unique in iroha network");
DEFINE_string(pass_phrase, "", "Account pass_phrase");
DEFINE_string(key_path, ".", "Path to store user keys");
DEFINE_string(pass_phrase, "", "Account pass-phrase");
DEFINE_string(key_path, ".", "Path to user keys");

// Iroha peer to connect with
DEFINE_string(peer_ip, "0.0.0.0", "Address of the Iroha node");
Expand All @@ -63,6 +63,7 @@ DEFINE_string(peers_address,
// Run iroha-cli in interactive mode
DEFINE_bool(interactive, true, "Run iroha-cli in interactive mode");


using namespace iroha::protocol;
using namespace iroha::model::generators;
using namespace iroha::model::converters;
Expand Down

0 comments on commit d61d58d

Please sign in to comment.