Skip to content

Commit

Permalink
Add response handlers to cli :
Browse files Browse the repository at this point in the history
 - Implement role response, role permissions response

 - Add roles to account response

Signed-off-by: grimadas <[email protected]>
  • Loading branch information
grimadas committed Oct 17, 2017
1 parent 717f2f7 commit 6bfc4e1
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 5 deletions.
32 changes: 29 additions & 3 deletions iroha-cli/impl/query_response_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ namespace iroha_cli {
&QueryResponseHandler::handleSignatoriesResponse;
handler_map_[QueryResponse::ResponseCase::kTransactionsResponse] =
&QueryResponseHandler::handleTransactionsResponse;
handler_map_[QueryResponse::ResponseCase::kRolesResponse] =
&QueryResponseHandler::handleRolesResponse;
handler_map_[QueryResponse::ResponseCase::kRolePermissionsResponse] =
&QueryResponseHandler::handleRolePermissionsResponse;

// Error responses:
error_handler_map_[ErrorResponse::STATEFUL_INVALID] =
Expand All @@ -45,6 +49,7 @@ namespace iroha_cli {
error_handler_map_[ErrorResponse::NO_SIGNATORIES] = "No signatories found";
error_handler_map_[ErrorResponse::NOT_SUPPORTED] = "Query not supported";
error_handler_map_[ErrorResponse::WRONG_FORMAT] = "Query has wrong format";
error_handler_map_[ErrorResponse::NO_ROLES] = "No roles in the system";
}

void QueryResponseHandler::handle(
Expand Down Expand Up @@ -75,8 +80,28 @@ namespace iroha_cli {
auto account = response.account_response().account();
log_->info("[Account]:");
log_->info("-Id:- {}", account.account_id());
// TODO 06/08/17 grimadas: print roles IR-506
log_->info("-Domain- {}", account.domain_id());

log_->info("-Roles-: ");
auto roles = response.account_response().account_roles();
std::for_each(roles.begin(), roles.end(), [](auto role){
std::cout << " " << role;
});
}

void QueryResponseHandler::handleRolesResponse(
const iroha::protocol::QueryResponse &response) {
auto roles = response.roles_response().roles();
std::for_each(roles.begin(), roles.end(), [this](auto role) {
log_->info(" {} ", role);
});
}

void QueryResponseHandler::handleRolePermissionsResponse(const iroha::protocol::QueryResponse &response) {
auto perms = response.role_permissions_response().permissions();
std::for_each(perms.begin(), perms.end(), [this](auto perm) {
log_->info(" {} ", perm);
});
}

void QueryResponseHandler::handleAccountAssetsResponse(
Expand All @@ -95,8 +120,9 @@ namespace iroha_cli {
auto signatories = response.signatories_response().keys();
log_->info("[Signatories]");
std::for_each(
signatories.begin(), signatories.end(),
[this](auto signatory) { log_->info("-Signatory- {}", signatory); });
signatories.begin(), signatories.end(), [this](auto signatory) {
log_->info("-Signatory- {}", signatory);
});
}

void QueryResponseHandler::handleTransactionsResponse(
Expand Down
2 changes: 2 additions & 0 deletions iroha-cli/query_response_handler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ namespace iroha_cli {
const iroha::protocol::QueryResponse& response);
void handleSignatoriesResponse(
const iroha::protocol::QueryResponse& response);
void handleRolesResponse(const iroha::protocol::QueryResponse& response);
void handleRolePermissionsResponse(const iroha::protocol::QueryResponse& response);
// -- --
using Handler =
void (QueryResponseHandler::*)(const iroha::protocol::QueryResponse&);
Expand Down
3 changes: 3 additions & 0 deletions irohad/model/converters/impl/pb_query_response_factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ namespace iroha {
protocol::AccountResponse pb_response;
pb_response.mutable_account()->CopyFrom(
serializeAccount(accountResponse.account));
for (auto role : accountResponse.roles){
pb_response.add_account_roles(role);
}
return pb_response;
}

Expand Down
5 changes: 4 additions & 1 deletion irohad/model/impl/query_execution.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,14 +164,17 @@ std::shared_ptr<iroha::model::QueryResponse>
iroha::model::QueryProcessingFactory::executeGetAccount(
const model::GetAccount& query) {
auto acc = _wsvQuery->getAccount(query.account_id);
if (!acc.has_value()) {
auto roles = _wsvQuery->getAccountRoles(query.account_id);
if (not acc.has_value() or not roles.has_value()) {
iroha::model::ErrorResponse response;
response.query_hash = iroha::hash(query);
response.reason = iroha::model::ErrorResponse::NO_ACCOUNT;
return std::make_shared<ErrorResponse>(response);
}

iroha::model::AccountResponse response;
response.account = acc.value();
response.roles = roles.value();
response.query_hash = iroha::hash(query);
return std::make_shared<iroha::model::AccountResponse>(response);
}
Expand Down
8 changes: 7 additions & 1 deletion irohad/model/queries/responses/account_response.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,13 @@ namespace iroha {
/**
* Attached account
*/
Account account{};
Account account;

/**
* Account's roles
*/
std::vector<std::string> roles;

};
} // namespace model
} // namespace iroha
Expand Down
1 change: 1 addition & 0 deletions schema/responses.proto
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ message AccountAssetResponse {

message AccountResponse {
Account account = 1;
repeated string account_roles = 2;
}

message AssetResponse {
Expand Down

0 comments on commit 6bfc4e1

Please sign in to comment.