LCOV - code coverage report
Current view: top level - irohad/torii/impl - command_client.cpp (source / functions) Hit Total Coverage
Test: coverage_cleared.info Lines: 31 35 88.6 %
Date: 2018-12-05 17:11:35 Functions: 14 17 82.4 %

          Line data    Source code
       1             : /*
       2             : Copyright 2017 Soramitsu Co., Ltd.
       3             : Licensed under the Apache License, Version 2.0 (the "License");
       4             : you may not use this file except in compliance with the License.
       5             : You may obtain a copy of the License at
       6             :     http://www.apache.org/licenses/LICENSE-2.0
       7             : Unless required by applicable law or agreed to in writing, software
       8             : distributed under the License is distributed on an "AS IS" BASIS,
       9             : WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      10             : See the License for the specific language governing permissions and
      11             : limitations under the License.
      12             : */
      13             : 
      14             : #include <thread>
      15             : 
      16             : #include <grpc++/grpc++.h>
      17             : 
      18             : #include "common/byteutils.hpp"
      19             : #include "network/impl/grpc_channel_builder.hpp"
      20             : #include "torii/command_client.hpp"
      21             : #include "transaction.pb.h"
      22             : 
      23             : namespace torii {
      24             : 
      25             :   using iroha::protocol::ToriiResponse;
      26             :   using iroha::protocol::Transaction;
      27             : 
      28             :   CommandSyncClient::CommandSyncClient(const std::string &ip, size_t port)
      29         274 :       : ip_(ip),
      30         274 :         port_(port),
      31         274 :         stub_(iroha::network::createClient<iroha::protocol::CommandService_v1>(
      32         274 :             ip + ":" + std::to_string(port))),
      33         274 :         log_(logger::log("CommandSyncClient")) {}
      34             : 
      35             :   CommandSyncClient::CommandSyncClient(const CommandSyncClient &rhs)
      36           6 :       : CommandSyncClient(rhs.ip_, rhs.port_) {}
      37             : 
      38             :   CommandSyncClient &CommandSyncClient::operator=(CommandSyncClient rhs) {
      39           0 :     swap(*this, rhs);
      40           0 :     return *this;
      41             :   }
      42             : 
      43             :   CommandSyncClient::CommandSyncClient(CommandSyncClient &&rhs) noexcept {
      44           2 :     swap(*this, rhs);
      45           2 :   }
      46             : 
      47             :   CommandSyncClient &CommandSyncClient::operator=(
      48             :       CommandSyncClient &&rhs) noexcept {
      49           0 :     swap(*this, rhs);
      50           0 :     return *this;
      51             :   }
      52             : 
      53             :   grpc::Status CommandSyncClient::Torii(const Transaction &tx) const {
      54         780 :     google::protobuf::Empty a;
      55         780 :     grpc::ClientContext context;
      56         780 :     return stub_->Torii(&context, tx, &a);
      57         780 :   }
      58             : 
      59             :   grpc::Status CommandSyncClient::ListTorii(
      60             :       const iroha::protocol::TxList &tx_list) const {
      61           8 :     google::protobuf::Empty a;
      62           8 :     grpc::ClientContext context;
      63           8 :     return stub_->ListTorii(&context, tx_list, &a);
      64           8 :   }
      65             : 
      66             :   grpc::Status CommandSyncClient::Status(
      67             :       const iroha::protocol::TxStatusRequest &request,
      68             :       iroha::protocol::ToriiResponse &response) const {
      69         823 :     grpc::ClientContext context;
      70         823 :     return stub_->Status(&context, request, &response);
      71         823 :   }
      72             : 
      73             :   void CommandSyncClient::StatusStream(
      74             :       const iroha::protocol::TxStatusRequest &tx,
      75             :       std::vector<iroha::protocol::ToriiResponse> &response) const {
      76           2 :     grpc::ClientContext context;
      77           2 :     ToriiResponse resp;
      78             :     std::unique_ptr<grpc::ClientReader<ToriiResponse> > reader(
      79           2 :         stub_->StatusStream(&context, tx));
      80           5 :     while (reader->Read(&resp)) {
      81           3 :       log_->debug("received new status: {}, hash {}",
      82             :                   resp.tx_status(),
      83           3 :                   iroha::bytestringToHexstring(resp.tx_hash()));
      84           3 :       response.push_back(resp);
      85             :     }
      86           2 :     reader->Finish();
      87           2 :   }
      88             : 
      89             :   void CommandSyncClient::swap(CommandSyncClient &lhs, CommandSyncClient &rhs) {
      90             :     using std::swap;
      91           2 :     swap(lhs.ip_, rhs.ip_);
      92             :     swap(lhs.port_, rhs.port_);
      93           2 :     swap(lhs.stub_, rhs.stub_);
      94           2 :   }
      95             : 
      96             : }  // namespace torii

Generated by: LCOV version 1.13