LCOV - code coverage report
Current view: top level - shared_model/interfaces/iroha_internal - transaction_batch_parser_impl.cpp (source / functions) Hit Total Coverage
Test: coverage_cleared.info Lines: 16 19 84.2 %
Date: 2018-12-05 17:11:35 Functions: 10 15 66.7 %

          Line data    Source code
       1             : /**
       2             :  * Copyright Soramitsu Co., Ltd. All Rights Reserved.
       3             :  * SPDX-License-Identifier: Apache-2.0
       4             :  */
       5             : 
       6             : #include "interfaces/iroha_internal/transaction_batch_parser_impl.hpp"
       7             : 
       8             : #include <boost/range/adaptor/indirected.hpp>
       9             : #include <boost/range/combine.hpp>
      10             : #include "interfaces/iroha_internal/batch_meta.hpp"
      11             : #include "interfaces/transaction.hpp"
      12             : 
      13             : namespace {
      14             :   /**
      15             :    * Zips in_range and out_range, where in_range elements are objects, parses
      16             :    * batches based on batchMeta values of in_range, and returns a collection of
      17             :    * corresponding sub-ranges of out_range
      18             :    */
      19             :   template <typename InRange, typename OutRange>
      20             :   auto parseBatchesImpl(InRange in_range, const OutRange &out_range) {
      21         790 :     std::vector<OutRange> result;
      22             :     auto meta = [](const auto &tx) { return boost::get<0>(tx).batchMeta(); };
      23             :     auto it = [](auto &p) { return boost::get<1>(p.get_iterator_tuple()); };
      24             : 
      25         790 :     auto range = boost::combine(in_range, out_range);
      26         790 :     auto begin = std::begin(range), end = std::end(range);
      27        1538 :     while (begin != end) {
      28         748 :       const auto beginning_tx_meta_opt = meta(*begin);
      29             :       auto next = std::find_if(std::next(begin), end, [&](const auto &tx) {
      30          23 :         const auto current_tx_meta_opt = meta(tx);
      31          23 :         return not(current_tx_meta_opt and beginning_tx_meta_opt)
      32          11 :             or (**current_tx_meta_opt != **beginning_tx_meta_opt);
      33          23 :       });
      34             : 
      35         748 :       result.emplace_back(it(begin), it(next));
      36         748 :       begin = next;
      37         748 :     }
      38             : 
      39         790 :     return result;
      40         790 :   }
      41             : }  // namespace
      42             : 
      43             : namespace shared_model {
      44             :   namespace interface {
      45             : 
      46             :     std::vector<types::TransactionsForwardCollectionType>
      47             :     TransactionBatchParserImpl::parseBatches(
      48             :         types::TransactionsForwardCollectionType txs) const noexcept {
      49           0 :       return parseBatchesImpl(txs, txs);
      50           0 :     }
      51             : 
      52             :     std::vector<types::TransactionsCollectionType>
      53             :     TransactionBatchParserImpl::parseBatches(
      54             :         types::TransactionsCollectionType txs) const noexcept {
      55         711 :       return parseBatchesImpl(txs, txs);
      56           0 :     }
      57             : 
      58             :     std::vector<types::SharedTxsCollectionType>
      59             :     TransactionBatchParserImpl::parseBatches(
      60             :         const types::SharedTxsCollectionType &txs) const noexcept {
      61         790 :       return parseBatchesImpl(txs | boost::adaptors::indirected, txs);
      62             :     }
      63             : 
      64             :   }  // namespace interface
      65             : }  // namespace shared_model

Generated by: LCOV version 1.13