LCOV - code coverage report
Current view: top level - shared_model/interfaces/iroha_internal - transaction_sequence.cpp (source / functions) Hit Total Coverage
Test: coverage_cleared.info Lines: 17 23 73.9 %
Date: 2018-12-05 17:11:35 Functions: 5 7 71.4 %

          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_sequence.hpp"
       7             : 
       8             : #include <numeric>
       9             : 
      10             : #include "interfaces/iroha_internal/transaction_batch.hpp"
      11             : 
      12             : namespace shared_model {
      13             :   namespace interface {
      14             : 
      15             :     const types::SharedTxsCollectionType &TransactionSequence::transactions()
      16             :         const {
      17          11 :       if (not transactions_) {
      18           6 :         types::SharedTxsCollectionType result;
      19           6 :         auto transactions_amount =
      20           6 :             std::accumulate(std::begin(batches_),
      21           6 :                             std::end(batches_),
      22             :                             0ul,
      23             :                             [](size_t acc_size, auto batch) {
      24          14 :                               return acc_size + batch->transactions().size();
      25             :                             });
      26           6 :         result.reserve(transactions_amount);
      27          20 :         for (const auto &batch : batches_) {
      28          14 :           auto &transactions = batch->transactions();
      29          14 :           std::copy(transactions.begin(),
      30          14 :                     transactions.end(),
      31          14 :                     std::back_inserter(result));
      32             :         }
      33           6 :         transactions_.emplace(std::move(result));
      34           6 :       }
      35          11 :       return transactions_.value();
      36           0 :     }
      37             : 
      38             :     const types::BatchesCollectionType &TransactionSequence::batches() const {
      39           4 :       return batches_;
      40             :     }
      41             : 
      42             :     std::string TransactionSequence::toString() const {
      43           0 :       return detail::PrettyStringBuilder()
      44           0 :           .init("TransactionSequence")
      45           0 :           .appendAll(batches_,
      46             :                      [](const auto &batch) { return batch->toString(); })
      47           0 :           .finalize();
      48           0 :     }
      49             : 
      50             :     TransactionSequence::TransactionSequence(
      51             :         const types::BatchesCollectionType &batches)
      52           9 :         : batches_(batches) {}
      53             : 
      54             :   }  // namespace interface
      55             : }  // namespace shared_model

Generated by: LCOV version 1.13