LCOV - code coverage report
Current view: top level - irohad/multi_sig_transactions/storage/impl - mst_storage_impl.cpp (source / functions) Hit Total Coverage
Test: coverage_cleared.info Lines: 19 20 95.0 %
Date: 2018-12-05 17:11:35 Functions: 11 12 91.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 "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          26 :     auto target_state_iter = peer_states_.find(target_peer_key);
      14          26 :     if (target_state_iter == peer_states_.end()) {
      15          16 :       return peer_states_.insert({target_peer_key, MstState::empty(completer_)})
      16          16 :           .first;
      17             :     }
      18          10 :     return target_state_iter;
      19          26 :   }
      20             :   // -----------------------------| interface API |-----------------------------
      21             : 
      22             :   MstStorageStateImpl::MstStorageStateImpl(const CompleterType &completer)
      23         257 :       : MstStorage(),
      24         257 :         completer_(completer),
      25         257 :         own_state_(MstState::empty(completer_)) {}
      26             : 
      27             :   auto MstStorageStateImpl::applyImpl(
      28             :       const shared_model::crypto::PublicKey &target_peer_key,
      29             :       const MstState &new_state)
      30             :       -> decltype(apply(target_peer_key, new_state)) {
      31           3 :     auto target_state_iter = getState(target_peer_key);
      32           3 :     target_state_iter->second += new_state;
      33           3 :     return own_state_ += new_state;
      34             :   }
      35             : 
      36             :   auto MstStorageStateImpl::updateOwnStateImpl(const DataType &tx)
      37             :       -> decltype(updateOwnState(tx)) {
      38          33 :     return own_state_ += tx;
      39             :   }
      40             : 
      41             :   auto MstStorageStateImpl::getExpiredTransactionsImpl(
      42             :       const TimeType &current_time)
      43             :       -> decltype(getExpiredTransactions(current_time)) {
      44          22 :     return own_state_.eraseByTime(current_time);
      45             :   }
      46             : 
      47             :   auto MstStorageStateImpl::getDiffStateImpl(
      48             :       const shared_model::crypto::PublicKey &target_peer_key,
      49             :       const TimeType &current_time)
      50             :       -> decltype(getDiffState(target_peer_key, current_time)) {
      51          23 :     auto target_current_state_iter = getState(target_peer_key);
      52          23 :     auto new_diff_state = own_state_ - target_current_state_iter->second;
      53          23 :     new_diff_state.eraseByTime(current_time);
      54          23 :     return new_diff_state;
      55          23 :   }
      56             : 
      57             :   auto MstStorageStateImpl::whatsNewImpl(ConstRefState new_state) const
      58             :       -> decltype(whatsNew(new_state)) {
      59           0 :     return new_state - own_state_;
      60             :   }
      61             : 
      62             : }  // namespace iroha

Generated by: LCOV version 1.13