LCOV - code coverage report
Current view: top level - irohad/multi_sig_transactions/storage/impl - mst_storage_impl.cpp (source / functions) Hit Total Coverage
Test: cleared_cor.info Lines: 23 24 95.8 %
Date: 2019-03-07 14:46:43 Functions: 8 9 88.9 %

          Line data    Source code
       1             : /**
       2             :  * Copyright Soramitsu Co., Ltd. All Rights Reserved.
       3             :  * SPDX-License-Identifier: Apache-2.0
       4             :  */
       5             : 
       6             : #include "multi_sig_transactions/storage/mst_storage_impl.hpp"
       7             : 
       8             : namespace iroha {
       9             :   // ------------------------------| private API |------------------------------
      10             : 
      11             :   auto MstStorageStateImpl::getState(
      12             :       const shared_model::crypto::PublicKey &target_peer_key) {
      13          28 :     auto target_state_iter = peer_states_.find(target_peer_key);
      14          28 :     if (target_state_iter == peer_states_.end()) {
      15          17 :       return peer_states_
      16          17 :           .insert(
      17          17 :               {target_peer_key, MstState::empty(mst_state_logger_, completer_)})
      18          17 :           .first;
      19             :     }
      20          11 :     return target_state_iter;
      21          28 :   }
      22             :   // -----------------------------| interface API |-----------------------------
      23             : 
      24             :   MstStorageStateImpl::MstStorageStateImpl(const CompleterType &completer,
      25             :                                            logger::LoggerPtr mst_state_logger,
      26             :                                            logger::LoggerPtr log)
      27         261 :       : MstStorage(log),
      28         261 :         completer_(completer),
      29         261 :         own_state_(MstState::empty(mst_state_logger, completer_)),
      30         261 :         mst_state_logger_(std::move(mst_state_logger)) {}
      31             : 
      32             :   auto MstStorageStateImpl::applyImpl(
      33             :       const shared_model::crypto::PublicKey &target_peer_key,
      34             :       const MstState &new_state)
      35             :       -> decltype(apply(target_peer_key, new_state)) {
      36           3 :     auto target_state_iter = getState(target_peer_key);
      37           3 :     target_state_iter->second += new_state;
      38           3 :     return own_state_ += new_state;
      39             :   }
      40             : 
      41             :   auto MstStorageStateImpl::updateOwnStateImpl(const DataType &tx)
      42             :       -> decltype(updateOwnState(tx)) {
      43          41 :     return own_state_ += tx;
      44             :   }
      45             : 
      46             :   auto MstStorageStateImpl::getExpiredTransactionsImpl(
      47             :       const TimeType &current_time)
      48             :       -> decltype(getExpiredTransactions(current_time)) {
      49          24 :     return own_state_.eraseByTime(current_time);
      50             :   }
      51             : 
      52             :   auto MstStorageStateImpl::getDiffStateImpl(
      53             :       const shared_model::crypto::PublicKey &target_peer_key,
      54             :       const TimeType &current_time)
      55             :       -> decltype(getDiffState(target_peer_key, current_time)) {
      56          25 :     auto target_current_state_iter = getState(target_peer_key);
      57          25 :     auto new_diff_state = own_state_ - target_current_state_iter->second;
      58          25 :     new_diff_state.eraseByTime(current_time);
      59          25 :     return new_diff_state;
      60          25 :   }
      61             : 
      62             :   auto MstStorageStateImpl::whatsNewImpl(ConstRefState new_state) const
      63             :       -> decltype(whatsNew(new_state)) {
      64           0 :     return new_state - own_state_;
      65             :   }
      66             : 
      67             :   bool MstStorageStateImpl::batchInStorageImpl(const DataType &batch) const {
      68         726 :     return own_state_.contains(batch);
      69             :   }
      70             : 
      71             : }  // namespace iroha

Generated by: LCOV version 1.13