LCOV - code coverage report
Current view: top level - irohad/main/impl - raw_block_loader.cpp (source / functions) Hit Total Coverage
Test: cleared_cor.info Lines: 4 14 28.6 %
Date: 2019-03-07 14:46:43 Functions: 4 5 80.0 %

          Line data    Source code
       1             : /**
       2             :  * Copyright Soramitsu Co., Ltd. All Rights Reserved.
       3             :  * SPDX-License-Identifier: Apache-2.0
       4             :  */
       5             : 
       6             : #include "main/raw_block_loader.hpp"
       7             : 
       8             : #include <fstream>
       9             : 
      10             : #include "backend/protobuf/block.hpp"
      11             : #include "common/bind.hpp"
      12             : #include "converters/protobuf/json_proto_converter.hpp"
      13             : #include "logger/logger.hpp"
      14             : 
      15             : namespace iroha {
      16             :   namespace main {
      17             : 
      18             :     using shared_model::converters::protobuf::jsonToProto;
      19             :     using shared_model::interface::Block;
      20             : 
      21             :     BlockLoader::BlockLoader(logger::LoggerPtr log)
      22           1 :         : log_(std::move(log)) {}
      23             : 
      24             :     boost::optional<std::shared_ptr<Block>> BlockLoader::parseBlock(
      25             :         const std::string &data) {
      26             :       return jsonToProto<iroha::protocol::Block>(data) | [](auto &&block) {
      27           1 :         return boost::optional<std::shared_ptr<Block>>(
      28           1 :             std::make_shared<shared_model::proto::Block>(
      29           1 :                 std::move(block.block_v1())));
      30           0 :       };
      31           0 :     }
      32             : 
      33             :     boost::optional<std::string> BlockLoader::loadFile(
      34             :         const std::string &path) {
      35           0 :       std::ifstream file(path);
      36           0 :       if (not file) {
      37           0 :         log_->error("Cannot read '" + path + "'");
      38           0 :         return boost::none;
      39             :       }
      40           0 :       std::string str((std::istreambuf_iterator<char>(file)),
      41           0 :                       std::istreambuf_iterator<char>());
      42           0 :       return str;
      43           0 :     }
      44             : 
      45             :   }  // namespace main
      46             : }  // namespace iroha

Generated by: LCOV version 1.13