Skip to content

Commit

Permalink
Refactor query client:
Browse files Browse the repository at this point in the history
- Move query serializer to model/converters/json_query_factory
- Fix styling issues
- Add  model_converters to cmake
  • Loading branch information
grimadas committed Aug 6, 2017
1 parent a26709e commit 88c0205
Show file tree
Hide file tree
Showing 11 changed files with 45 additions and 387 deletions.
2 changes: 1 addition & 1 deletion iroha-cli/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ add_library(client
client.cpp
)
target_link_libraries(client
model
model_converters
crypto
optional
rapidjson
Expand Down
6 changes: 3 additions & 3 deletions iroha-cli/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
*/

#include "client.hpp"
#include <model/converters/json_query_factory.hpp>
#include <utility>
#include "model/converters/json_common.hpp"
#include "model/converters/json_transaction_factory.hpp"
#include <ametsuchi/query_serializer.hpp>
#include "model/converters/pb_transaction_factory.hpp"

namespace iroha_cli {
Expand Down Expand Up @@ -52,7 +52,7 @@ namespace iroha_cli {
}

iroha::protocol::QueryResponse CliClient::sendQuery(std::string json_query) {
iroha::ametsuchi::QuerySerializer serializer;
iroha::model::converters::JsonQueryFactory serializer;

auto query_opt = serializer.deserialize(std::move(json_query));

Expand All @@ -65,7 +65,7 @@ namespace iroha_cli {
return query_response;
}

query_client_.Find(*query_opt, query_response);
query_client_.Find(query_opt.value(), query_response);

return query_response;
}
Expand Down
38 changes: 20 additions & 18 deletions iroha-cli/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,17 @@ DEFINE_validator(torii_port, &iroha_cli::validate_port);
DEFINE_string(json_transaction, "", "Transaction in json format");
DEFINE_string(json_query, "", "Query in json format");

void create_account(std::string name);
void print_response(iroha::protocol::QueryResponse response){
// TODO: implement beautiful output
if (response.has_error_response()){
std::cout << "Iroha returned error " << response.error_response().reason()<< std::endl;
}
if (response.has_account_response()){
auto account = response.account_response().account();
std::cout << "[Account:] " << std::endl;
std::cout << "---- AccountID: "<< account.account_id() << std::endl;
}
}

int main(int argc, char* argv[]) {
gflags::ParseCommandLineFlags(&argc, &argv, true);
Expand Down Expand Up @@ -92,23 +102,15 @@ int main(int argc, char* argv[]) {
std::cout << "Transaction is not valid." << std::endl;
break;
}
if (not FLAGS_json_query.empty()){
std::cout << "Send query to " << FLAGS_address << ":"
<< FLAGS_torii_port << std::endl;
std::ifstream file(FLAGS_json_transaction);
std::string str((std::istreambuf_iterator<char>(file)),
std::istreambuf_iterator<char>());
auto response = client.sendQuery(str);
if (response.has_error_response()) {
std::cout << "Iroha returned error " << response.error_response().reason()<< std::endl;
}
if (response.has_account_response()){
auto account = response.account_response().account();
std::cout << "[Account:] " << std::endl;
std::cout << "---- AccountID: "<< account.account_id() << std::endl;
}
// TODO: implement beautiful output
}
}
if (not FLAGS_json_query.empty()){
std::cout << "Send query to " << FLAGS_address << ":"
<< FLAGS_torii_port << std::endl;
std::ifstream file(FLAGS_json_transaction);
std::string str((std::istreambuf_iterator<char>(file)),
std::istreambuf_iterator<char>());
auto response = client.sendQuery(str);
print_response(response);
}

} else {
Expand Down
2 changes: 0 additions & 2 deletions irohad/ametsuchi/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ add_library(ametsuchi
impl/postgres_wsv_query.cpp
impl/postgres_wsv_command.cpp
impl/block_serializer.cpp
impl/query_serializer.cpp

impl/peer_query_wsv.cpp
)

Expand Down
167 changes: 0 additions & 167 deletions irohad/ametsuchi/impl/query_serializer.cpp

This file was deleted.

77 changes: 0 additions & 77 deletions irohad/ametsuchi/query_serializer.hpp

This file was deleted.

11 changes: 11 additions & 0 deletions irohad/model/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,14 @@ target_link_libraries(model
rapidjson
logger
)


add_library(model_converters
converters/impl/json_query_factory.cpp
)

target_link_libraries(model_converters
rapidjson
optional
schema
)
Loading

0 comments on commit 88c0205

Please sign in to comment.