Line data Source code
1 : /**
2 : * Copyright Soramitsu Co., Ltd. All Rights Reserved.
3 : * SPDX-License-Identifier: Apache-2.0
4 : */
5 :
6 : #include "client.hpp"
7 :
8 : #include "backend/protobuf/queries/proto_query.hpp"
9 : #include "backend/protobuf/transaction.hpp"
10 : #include "model/converters/json_query_factory.hpp"
11 : #include "model/converters/json_transaction_factory.hpp"
12 : #include "model/converters/pb_query_factory.hpp"
13 : #include "model/converters/pb_transaction_factory.hpp"
14 : #include "network/impl/grpc_channel_builder.hpp"
15 :
16 : namespace iroha_cli {
17 :
18 : CliClient::CliClient(std::string target_ip,
19 : int port,
20 : logger::LoggerPtr pb_qry_factory_log)
21 0 : : command_client_(
22 0 : iroha::network::createClient<iroha::protocol::CommandService_v1>(
23 0 : target_ip + ":" + std::to_string(port)),
24 0 : pb_qry_factory_log),
25 0 : query_client_(target_ip, port),
26 0 : pb_qry_factory_log_(std::move(pb_qry_factory_log)) {}
27 :
28 : CliClient::Response<CliClient::TxStatus> CliClient::sendTx(
29 : const shared_model::interface::Transaction &tx) {
30 : const auto proto_tx =
31 0 : static_cast<const shared_model::proto::Transaction &>(tx);
32 0 : CliClient::Response<CliClient::TxStatus> response;
33 : // Send to iroha:
34 0 : response.status = command_client_.Torii(proto_tx.getTransport());
35 :
36 : // TODO 12/10/2017 neewy implement return of real transaction status IR-494
37 0 : response.answer = TxStatus::OK;
38 :
39 0 : return response;
40 0 : }
41 :
42 : CliClient::Response<iroha::protocol::ToriiResponse> CliClient::getTxStatus(
43 : std::string tx_hash) {
44 0 : CliClient::Response<iroha::protocol::ToriiResponse> response;
45 : // Send to iroha:
46 0 : iroha::protocol::TxStatusRequest statusRequest;
47 0 : statusRequest.set_tx_hash(tx_hash);
48 0 : iroha::protocol::ToriiResponse toriiResponse;
49 0 : response.status = command_client_.Status(statusRequest, toriiResponse);
50 0 : response.answer = toriiResponse;
51 :
52 0 : return response;
53 0 : }
54 :
55 : CliClient::Response<iroha::protocol::QueryResponse> CliClient::sendQuery(
56 : const shared_model::interface::Query &query) {
57 0 : CliClient::Response<iroha::protocol::QueryResponse> response;
58 : // Convert to proto and send to Iroha
59 0 : iroha::model::converters::PbQueryFactory pb_factory(pb_qry_factory_log_);
60 0 : auto proto_query = static_cast<const shared_model::proto::Query &>(query);
61 0 : iroha::protocol::QueryResponse query_response;
62 0 : response.status =
63 0 : query_client_.Find(proto_query.getTransport(), query_response);
64 0 : response.answer = query_response;
65 0 : return response;
66 0 : }
67 :
68 : } // namespace iroha_cli
|